diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2017-03-22 08:36:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-22 08:36:22 +0800 |
commit | 06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462 (patch) | |
tree | d764690055f2ee7d880bcce2e413a3665fc1e7e9 /core/types/gen_log_json.go | |
parent | 1dfd65f6d047407585845dfe9be2ff52a8b9f3ab (diff) | |
parent | 8cf08e4b25c4cd0e0955598342394f34feecca0c (diff) | |
download | go-tangerine-06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462.tar go-tangerine-06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462.tar.gz go-tangerine-06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462.tar.bz2 go-tangerine-06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462.tar.lz go-tangerine-06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462.tar.xz go-tangerine-06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462.tar.zst go-tangerine-06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462.zip |
Merge pull request #3756 from fjl/core-types-gencodec
core/types: use gencodec for JSON marshaling code
Diffstat (limited to 'core/types/gen_log_json.go')
-rw-r--r-- | core/types/gen_log_json.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/core/types/gen_log_json.go b/core/types/gen_log_json.go new file mode 100644 index 000000000..ef2cdfd89 --- /dev/null +++ b/core/types/gen_log_json.go @@ -0,0 +1,90 @@ +// generated by github.com/fjl/gencodec, do not edit. + +package types + +import ( + "encoding/json" + "errors" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" +) + +func (l *Log) MarshalJSON() ([]byte, error) { + type LogJSON struct { + Address *common.Address `json:"address"` + Topics []common.Hash `json:"topics"` + Data hexutil.Bytes `json:"data"` + BlockNumber *hexutil.Uint64 `json:"blockNumber" optional:"yes"` + TxHash *common.Hash `json:"transactionHash"` + TxIndex *hexutil.Uint `json:"transactionIndex"` + BlockHash *common.Hash `json:"blockHash" optional:"yes"` + Index *hexutil.Uint `json:"logIndex"` + Removed *bool `json:"removed" optional:"yes"` + } + var enc LogJSON + enc.Address = &l.Address + enc.Topics = l.Topics + enc.Data = l.Data + enc.BlockNumber = (*hexutil.Uint64)(&l.BlockNumber) + enc.TxHash = &l.TxHash + enc.TxIndex = (*hexutil.Uint)(&l.TxIndex) + enc.BlockHash = &l.BlockHash + enc.Index = (*hexutil.Uint)(&l.Index) + enc.Removed = &l.Removed + return json.Marshal(&enc) +} + +func (l *Log) UnmarshalJSON(input []byte) error { + type LogJSON struct { + Address *common.Address `json:"address"` + Topics []common.Hash `json:"topics"` + Data hexutil.Bytes `json:"data"` + BlockNumber *hexutil.Uint64 `json:"blockNumber" optional:"yes"` + TxHash *common.Hash `json:"transactionHash"` + TxIndex *hexutil.Uint `json:"transactionIndex"` + BlockHash *common.Hash `json:"blockHash" optional:"yes"` + Index *hexutil.Uint `json:"logIndex"` + Removed *bool `json:"removed" optional:"yes"` + } + var dec LogJSON + if err := json.Unmarshal(input, &dec); err != nil { + return err + } + var x Log + if dec.Address == nil { + return errors.New("missing required field 'address' for Log") + } + x.Address = *dec.Address + if dec.Topics == nil { + return errors.New("missing required field 'topics' for Log") + } + x.Topics = dec.Topics + if dec.Data == nil { + return errors.New("missing required field 'data' for Log") + } + x.Data = dec.Data + if dec.BlockNumber != nil { + x.BlockNumber = uint64(*dec.BlockNumber) + } + if dec.TxHash == nil { + return errors.New("missing required field 'transactionHash' for Log") + } + x.TxHash = *dec.TxHash + if dec.TxIndex == nil { + return errors.New("missing required field 'transactionIndex' for Log") + } + x.TxIndex = uint(*dec.TxIndex) + if dec.BlockHash != nil { + x.BlockHash = *dec.BlockHash + } + if dec.Index == nil { + return errors.New("missing required field 'logIndex' for Log") + } + x.Index = uint(*dec.Index) + if dec.Removed != nil { + x.Removed = *dec.Removed + } + *l = x + return nil +} |