internal/ethapi: return null inclusion info for pending transactions (#19901)

This change ensures 'blockHash', 'blockNumber' and 'transactionIndex'
are set to null for pending transactions. This behavior is required by
the Ethereum JSON-RPC spec.
This commit is contained in:
Felix Lange 2019-07-30 15:39:48 +02:00 committed by Péter Szilágyi
parent f34a3a6805
commit 96ab8e1575

View File

@ -1043,7 +1043,7 @@ func (s *PublicBlockChainAPI) rpcMarshalBlock(b *types.Block, inclTx bool, fullT
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
type RPCTransaction struct {
BlockHash common.Hash `json:"blockHash"`
BlockHash *common.Hash `json:"blockHash"`
BlockNumber *hexutil.Big `json:"blockNumber"`
From common.Address `json:"from"`
Gas hexutil.Uint64 `json:"gas"`
@ -1052,7 +1052,7 @@ type RPCTransaction struct {
Input hexutil.Bytes `json:"input"`
Nonce hexutil.Uint64 `json:"nonce"`
To *common.Address `json:"to"`
TransactionIndex hexutil.Uint `json:"transactionIndex"`
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
Value *hexutil.Big `json:"value"`
V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"`
@ -1083,9 +1083,9 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
S: (*hexutil.Big)(s),
}
if blockHash != (common.Hash{}) {
result.BlockHash = blockHash
result.BlockHash = &blockHash
result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber))
result.TransactionIndex = hexutil.Uint(index)
result.TransactionIndex = (*hexutil.Uint64)(&index)
}
return result
}