From 9dbf725ceda48de96eed28518b24d4c7ec7e25fa Mon Sep 17 00:00:00 2001 From: Diep Pham Date: Wed, 6 Jun 2018 17:46:34 +0700 Subject: [PATCH] common: add BlockNumber to transaction receipt --- core/types/gen_receipt_json.go | 7 +++++++ core/types/receipt.go | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/types/gen_receipt_json.go b/core/types/gen_receipt_json.go index 5c807a4ccb..06710471b0 100644 --- a/core/types/gen_receipt_json.go +++ b/core/types/gen_receipt_json.go @@ -20,6 +20,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) { CumulativeGasUsed hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"` Bloom Bloom `json:"logsBloom" gencodec:"required"` Logs []*Log `json:"logs" gencodec:"required"` + BlockNumber hexutil.Uint64 `json:"blockNumber" gencodec:"required"` TxHash common.Hash `json:"transactionHash" gencodec:"required"` ContractAddress common.Address `json:"contractAddress"` GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` @@ -30,6 +31,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) { enc.CumulativeGasUsed = hexutil.Uint64(r.CumulativeGasUsed) enc.Bloom = r.Bloom enc.Logs = r.Logs + enc.BlockNumber = hexutil.Uint64(r.BlockNumber) enc.TxHash = r.TxHash enc.ContractAddress = r.ContractAddress enc.GasUsed = hexutil.Uint64(r.GasUsed) @@ -44,6 +46,7 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { CumulativeGasUsed *hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"` Bloom *Bloom `json:"logsBloom" gencodec:"required"` Logs []*Log `json:"logs" gencodec:"required"` + BlockNumber *hexutil.Uint64 `json:"blockNumber" gencodec:"required"` TxHash *common.Hash `json:"transactionHash" gencodec:"required"` ContractAddress *common.Address `json:"contractAddress"` GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"` @@ -70,6 +73,10 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'logs' for Receipt") } r.Logs = dec.Logs + if dec.BlockNumber == nil { + return errors.New("missing required field 'blockNumber' for Receipt") + } + r.BlockNumber = uint64(*dec.BlockNumber) if dec.TxHash == nil { return errors.New("missing required field 'transactionHash' for Receipt") } diff --git a/core/types/receipt.go b/core/types/receipt.go index 3d1fc95aab..c8cad093b7 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -50,6 +50,7 @@ type Receipt struct { CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"` Bloom Bloom `json:"logsBloom" gencodec:"required"` Logs []*Log `json:"logs" gencodec:"required"` + BlockNumber uint64 `json:"blockNumber" gencodec:"required"` // Implementation fields (don't reorder!) TxHash common.Hash `json:"transactionHash" gencodec:"required"` @@ -61,6 +62,7 @@ type receiptMarshaling struct { PostState hexutil.Bytes Status hexutil.Uint64 CumulativeGasUsed hexutil.Uint64 + BlockNumber hexutil.Uint64 GasUsed hexutil.Uint64 } @@ -70,6 +72,7 @@ type receiptRLP struct { CumulativeGasUsed uint64 Bloom Bloom Logs []*Log + BlockNumber uint64 } type receiptStorageRLP struct { @@ -79,6 +82,7 @@ type receiptStorageRLP struct { TxHash common.Hash ContractAddress common.Address Logs []*LogForStorage + BlockNumber uint64 GasUsed uint64 } @@ -96,7 +100,7 @@ func NewReceipt(root []byte, failed bool, cumulativeGasUsed uint64) *Receipt { // EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt // into an RLP stream. If no post state is present, byzantium fork is assumed. func (r *Receipt) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}) + return rlp.Encode(w, &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs, r.BlockNumber}) } // DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt