diff --git a/core/blockchain.go b/core/blockchain.go index 91c494489a..923cf6ac0d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -802,7 +802,7 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty // block location fields receipts[j].BlockHash = block.Hash() receipts[j].BlockNumber = block.Number() - receipts[j].TransactionIndex = big.NewInt(int64(j)) + receipts[j].TransactionIndex = uint(j) // The contract address can be derived from the transaction itself if transactions[j].To() == nil { diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index e6eb54c1fc..73ec45ab7f 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -308,7 +308,7 @@ func ReadReceipts(db DatabaseReader, hash common.Hash, number uint64) types.Rece receipts[i] = (*types.Receipt)(receipt) receipts[i].BlockHash = hash receipts[i].BlockNumber = big.NewInt(0).SetUint64(number) - receipts[i].TransactionIndex = big.NewInt(int64(i)) + receipts[i].TransactionIndex = uint(i) } return receipts } diff --git a/core/state_processor.go b/core/state_processor.go index b23b5cda79..6daa139e5f 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -25,7 +25,6 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" - "math/big" ) // StateProcessor is a basic Processor, which takes care of transitioning @@ -124,7 +123,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) receipt.BlockHash = header.Hash() receipt.BlockNumber = header.Number - receipt.TransactionIndex = big.NewInt(int64(statedb.TxIndex())) + receipt.TransactionIndex = uint(statedb.TxIndex()) return receipt, gas, err } diff --git a/core/types/gen_receipt_json.go b/core/types/gen_receipt_json.go index 495a78be93..790ed65b58 100644 --- a/core/types/gen_receipt_json.go +++ b/core/types/gen_receipt_json.go @@ -26,7 +26,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) { 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"` + TransactionIndex hexutil.Uint `json:"transactionIndex"` } var enc Receipt enc.PostState = r.PostState @@ -39,7 +39,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) { enc.GasUsed = hexutil.Uint64(r.GasUsed) enc.BlockHash = r.BlockHash enc.BlockNumber = (*hexutil.Big)(r.BlockNumber) - enc.TransactionIndex = (*hexutil.Big)(r.TransactionIndex) + enc.TransactionIndex = hexutil.Uint(r.TransactionIndex) return json.Marshal(&enc) } @@ -56,7 +56,7 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { 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"` + TransactionIndex *hexutil.Uint `json:"transactionIndex"` } var dec Receipt if err := json.Unmarshal(input, &dec); err != nil { @@ -98,7 +98,7 @@ func (r *Receipt) UnmarshalJSON(input []byte) error { r.BlockNumber = (*big.Int)(dec.BlockNumber) } if dec.TransactionIndex != nil { - r.TransactionIndex = (*big.Int)(dec.TransactionIndex) + r.TransactionIndex = uint(*dec.TransactionIndex) } return nil } diff --git a/core/types/gen_tx_json.go b/core/types/gen_tx_json.go index c27da67096..e676058ecc 100644 --- a/core/types/gen_tx_json.go +++ b/core/types/gen_tx_json.go @@ -13,6 +13,7 @@ import ( var _ = (*txdataMarshaling)(nil) +// MarshalJSON marshals as JSON. func (t txdata) MarshalJSON() ([]byte, error) { type txdata struct { AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"` @@ -40,6 +41,7 @@ func (t txdata) MarshalJSON() ([]byte, error) { return json.Marshal(&enc) } +// UnmarshalJSON unmarshals from JSON. func (t *txdata) UnmarshalJSON(input []byte) error { type txdata struct { AccountNonce *hexutil.Uint64 `json:"nonce" gencodec:"required"` diff --git a/core/types/receipt.go b/core/types/receipt.go index 4beed41bee..84230ca0c6 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -45,22 +45,24 @@ const ( // Receipt represents the results of a transaction. type Receipt struct { - // Consensus fields + // Consensus fields: These fields are defined by the Yellow Paper PostState []byte `json:"root"` Status uint64 `json:"status"` CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"` Bloom Bloom `json:"logsBloom" gencodec:"required"` Logs []*Log `json:"logs" gencodec:"required"` - // Implementation fields (don't reorder!) + // Implementation fields: These fields are added by geth when processing a transaction. + // They are stored in the chain database. 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 + // Inclusion information: These fields provide information about the inclusion of the + // transaction corresponding to this receipt. BlockHash common.Hash `json:"blockHash,omitempty"` BlockNumber *big.Int `json:"blockNumber,omitempty"` - TransactionIndex *big.Int `json:"transactionIndex,omitempty"` + TransactionIndex uint `json:"transactionIndex"` } type receiptMarshaling struct { @@ -69,7 +71,7 @@ type receiptMarshaling struct { CumulativeGasUsed hexutil.Uint64 GasUsed hexutil.Uint64 BlockNumber *hexutil.Big - TransactionIndex *hexutil.Big + TransactionIndex hexutil.Uint } // receiptRLP is the consensus encoding of a receipt. diff --git a/miner/worker.go b/miner/worker.go index 240de31d7a..80c1771b6d 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -569,7 +569,7 @@ func (w *worker) resultLoop() { // add block location fields receipt.BlockHash = hash receipt.BlockNumber = block.Number() - receipt.TransactionIndex = big.NewInt(int64(i)) + receipt.TransactionIndex = uint(i) receipts[i] = new(types.Receipt) *receipts[i] = *receipt