diff options
author | Felix Lange <fjl@twurst.com> | 2017-02-24 00:58:15 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2017-03-07 19:45:12 +0800 |
commit | 8cf08e4b25c4cd0e0955598342394f34feecca0c (patch) | |
tree | dcd215bd6a31dcf78aebcb8132b0cb522890a8b9 /core/types/gen_receipt_json.go | |
parent | eee96a5bb7439ccee583d23e53be018fe7c35cfb (diff) | |
download | go-tangerine-8cf08e4b25c4cd0e0955598342394f34feecca0c.tar go-tangerine-8cf08e4b25c4cd0e0955598342394f34feecca0c.tar.gz go-tangerine-8cf08e4b25c4cd0e0955598342394f34feecca0c.tar.bz2 go-tangerine-8cf08e4b25c4cd0e0955598342394f34feecca0c.tar.lz go-tangerine-8cf08e4b25c4cd0e0955598342394f34feecca0c.tar.xz go-tangerine-8cf08e4b25c4cd0e0955598342394f34feecca0c.tar.zst go-tangerine-8cf08e4b25c4cd0e0955598342394f34feecca0c.zip |
core/types: use gencodec for JSON marshaling code
Diffstat (limited to 'core/types/gen_receipt_json.go')
-rw-r--r-- | core/types/gen_receipt_json.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/core/types/gen_receipt_json.go b/core/types/gen_receipt_json.go new file mode 100644 index 000000000..b9e9bee26 --- /dev/null +++ b/core/types/gen_receipt_json.go @@ -0,0 +1,79 @@ +// generated by github.com/fjl/gencodec, do not edit. + +package types + +import ( + "encoding/json" + "errors" + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" +) + +func (r *Receipt) MarshalJSON() ([]byte, error) { + type ReceiptJSON struct { + PostState hexutil.Bytes `json:"root"` + CumulativeGasUsed *hexutil.Big `json:"cumulativeGasUsed"` + Bloom *Bloom `json:"logsBloom"` + Logs []*Log `json:"logs"` + TxHash *common.Hash `json:"transactionHash"` + ContractAddress *common.Address `json:"contractAddress" optional:"true"` + GasUsed *hexutil.Big `json:"gasUsed"` + } + var enc ReceiptJSON + enc.PostState = r.PostState + enc.CumulativeGasUsed = (*hexutil.Big)(r.CumulativeGasUsed) + enc.Bloom = &r.Bloom + enc.Logs = r.Logs + enc.TxHash = &r.TxHash + enc.ContractAddress = &r.ContractAddress + enc.GasUsed = (*hexutil.Big)(r.GasUsed) + return json.Marshal(&enc) +} + +func (r *Receipt) UnmarshalJSON(input []byte) error { + type ReceiptJSON struct { + PostState hexutil.Bytes `json:"root"` + CumulativeGasUsed *hexutil.Big `json:"cumulativeGasUsed"` + Bloom *Bloom `json:"logsBloom"` + Logs []*Log `json:"logs"` + TxHash *common.Hash `json:"transactionHash"` + ContractAddress *common.Address `json:"contractAddress" optional:"true"` + GasUsed *hexutil.Big `json:"gasUsed"` + } + var dec ReceiptJSON + if err := json.Unmarshal(input, &dec); err != nil { + return err + } + var x Receipt + if dec.PostState == nil { + return errors.New("missing required field 'root' for Receipt") + } + x.PostState = dec.PostState + if dec.CumulativeGasUsed == nil { + return errors.New("missing required field 'cumulativeGasUsed' for Receipt") + } + x.CumulativeGasUsed = (*big.Int)(dec.CumulativeGasUsed) + if dec.Bloom == nil { + return errors.New("missing required field 'logsBloom' for Receipt") + } + x.Bloom = *dec.Bloom + if dec.Logs == nil { + return errors.New("missing required field 'logs' for Receipt") + } + x.Logs = dec.Logs + if dec.TxHash == nil { + return errors.New("missing required field 'transactionHash' for Receipt") + } + x.TxHash = *dec.TxHash + if dec.ContractAddress != nil { + x.ContractAddress = *dec.ContractAddress + } + if dec.GasUsed == nil { + return errors.New("missing required field 'gasUsed' for Receipt") + } + x.GasUsed = (*big.Int)(dec.GasUsed) + *r = x + return nil +} |