From 444dd6fbd6acd0a4720cb6d3bdd12cde9c595392 Mon Sep 17 00:00:00 2001 From: Brent Date: Mon, 15 Oct 2018 12:28:02 -0500 Subject: [PATCH] types, rawdb: add block location fields to receipt --- core/rawdb/accessors_chain.go | 5 ++++- core/types/gen_receipt_json.go | 19 +++++++++++++++++++ core/types/receipt.go | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index da543283265f..62c76b995a63 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -278,7 +278,7 @@ func ReadReceipts(db DatabaseReader, hash common.Hash, number uint64) types.Rece if len(data) == 0 { return nil } - // Convert the revceipts from their storage form to their internal representation + // Convert the receipts from their storage form to their internal representation storageReceipts := []*types.ReceiptForStorage{} if err := rlp.DecodeBytes(data, &storageReceipts); err != nil { log.Error("Invalid receipt array RLP", "hash", hash, "err", err) @@ -287,6 +287,9 @@ func ReadReceipts(db DatabaseReader, hash common.Hash, number uint64) types.Rece receipts := make(types.Receipts, len(storageReceipts)) for i, receipt := range storageReceipts { receipts[i] = (*types.Receipt)(receipt) + receipts[i].BlockHash = hash + receipts[i].BlockNumber = big.NewInt(0).SetUint64(number) + receipts[i].TransactionIndex = big.NewInt(int64(i)) } return receipts } diff --git a/core/types/gen_receipt_json.go b/core/types/gen_receipt_json.go index 5c807a4ccbe1..495a78be93ca 100644 --- a/core/types/gen_receipt_json.go +++ b/core/types/gen_receipt_json.go @@ -5,6 +5,7 @@ package types import ( "encoding/json" "errors" + "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -23,6 +24,9 @@ func (r Receipt) MarshalJSON() ([]byte, error) { TxHash common.Hash `json:"transactionHash" gencodec:"required"` ContractAddress common.Address `json:"contractAddress"` GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` + BlockHash common.Hash `json:"blockHash,omitempty"` + BlockNumber *hexutil.Big `json:"blockNumber,omitempty"` + TransactionIndex *hexutil.Big `json:"transactionIndex,omitempty"` } var enc Receipt enc.PostState = r.PostState @@ -33,6 +37,9 @@ func (r Receipt) MarshalJSON() ([]byte, error) { enc.TxHash = r.TxHash enc.ContractAddress = r.ContractAddress enc.GasUsed = hexutil.Uint64(r.GasUsed) + enc.BlockHash = r.BlockHash + enc.BlockNumber = (*hexutil.Big)(r.BlockNumber) + enc.TransactionIndex = (*hexutil.Big)(r.TransactionIndex) return json.Marshal(&enc) } @@ -47,6 +54,9 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { TxHash *common.Hash `json:"transactionHash" gencodec:"required"` ContractAddress *common.Address `json:"contractAddress"` GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"` + BlockHash *common.Hash `json:"blockHash,omitempty"` + BlockNumber *hexutil.Big `json:"blockNumber,omitempty"` + TransactionIndex *hexutil.Big `json:"transactionIndex,omitempty"` } var dec Receipt if err := json.Unmarshal(input, &dec); err != nil { @@ -81,5 +91,14 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'gasUsed' for Receipt") } r.GasUsed = uint64(*dec.GasUsed) + if dec.BlockHash != nil { + r.BlockHash = *dec.BlockHash + } + if dec.BlockNumber != nil { + r.BlockNumber = (*big.Int)(dec.BlockNumber) + } + if dec.TransactionIndex != nil { + r.TransactionIndex = (*big.Int)(dec.TransactionIndex) + } return nil } diff --git a/core/types/receipt.go b/core/types/receipt.go index 3d1fc95aabce..37f679316ecf 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -20,6 +20,7 @@ import ( "bytes" "fmt" "io" + "math/big" "unsafe" "github.com/ethereum/go-ethereum/common" @@ -55,6 +56,11 @@ type Receipt struct { TxHash common.Hash `json:"transactionHash" gencodec:"required"` ContractAddress common.Address `json:"contractAddress"` GasUsed uint64 `json:"gasUsed" gencodec:"required"` + + // Block location fields - not part of the rlp + BlockHash common.Hash `json:"blockHash,omitempty"` + BlockNumber *big.Int `json:"blockNumber,omitempty"` + TransactionIndex *big.Int `json:"transactionIndex,omitempty"` } type receiptMarshaling struct { @@ -62,6 +68,8 @@ type receiptMarshaling struct { Status hexutil.Uint64 CumulativeGasUsed hexutil.Uint64 GasUsed hexutil.Uint64 + BlockNumber *hexutil.Big + TransactionIndex *hexutil.Big } // receiptRLP is the consensus encoding of a receipt.