diff --git a/api/api_public_blockchain.go b/api/api_public_blockchain.go index 3dfb1bac5..7fa14b355 100644 --- a/api/api_public_blockchain.go +++ b/api/api_public_blockchain.go @@ -614,13 +614,13 @@ func getFrom(tx *types.Transaction) common.Address { return from } -func NewRPCTransaction(b *types.Block, tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, config *params.ChainConfig) map[string]interface{} { - return newRPCTransaction(b, tx, blockHash, blockNumber, index, config) +func NewRPCTransaction(head *types.Header, tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, config *params.ChainConfig) map[string]interface{} { + return newRPCTransaction(head, tx, blockHash, blockNumber, index, config) } // newRPCTransaction returns a transaction that will serialize to the RPC // representation, with the given location metadata set (if available). -func newRPCTransaction(b *types.Block, tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, config *params.ChainConfig) map[string]interface{} { +func newRPCTransaction(header *types.Header, tx *types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, config *params.ChainConfig) map[string]interface{} { output := tx.MakeRPCOutput() output["senderTxHash"] = tx.SenderTxHashAll() output["blockHash"] = blockHash @@ -629,8 +629,8 @@ func newRPCTransaction(b *types.Block, tx *types.Transaction, blockHash common.H output["hash"] = tx.Hash() output["transactionIndex"] = hexutil.Uint(index) if tx.Type() == types.TxTypeEthereumDynamicFee { - if b != nil { - output["gasPrice"] = (*hexutil.Big)(tx.EffectiveGasPrice(b.Header(), config)) + if header != nil { + output["gasPrice"] = (*hexutil.Big)(tx.EffectiveGasPrice(header, config)) } else { // transaction is not processed yet output["gasPrice"] = (*hexutil.Big)(tx.EffectiveGasPrice(nil, nil)) @@ -646,12 +646,13 @@ func newRPCPendingTransaction(tx *types.Transaction, config *params.ChainConfig) } // newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation. +// non-null of b(block) is guaranteed func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig) map[string]interface{} { txs := b.Transactions() if index >= uint64(len(txs)) { return nil } - return newRPCTransaction(b, txs[index], b.Hash(), b.NumberU64(), index, config) + return newRPCTransaction(b.Header(), txs[index], b.Hash(), b.NumberU64(), index, config) } // newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index. diff --git a/api/api_public_transaction_pool.go b/api/api_public_transaction_pool.go index c7c7ad976..865db33da 100644 --- a/api/api_public_transaction_pool.go +++ b/api/api_public_transaction_pool.go @@ -135,7 +135,11 @@ func (s *PublicTransactionPoolAPI) GetTransactionBySenderTxHash(ctx context.Cont func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) map[string]interface{} { // Try to return an already finalized transaction if tx, blockHash, blockNumber, index := s.b.ChainDB().ReadTxAndLookupInfo(hash); tx != nil { - return newRPCTransaction(nil, tx, blockHash, blockNumber, index, s.b.ChainConfig()) + header, err := s.b.HeaderByHash(ctx, blockHash) + if err != nil { + return nil + } + return newRPCTransaction(header, tx, blockHash, blockNumber, index, s.b.ChainConfig()) } // No finalized transaction, try to retrieve it from the pool if tx := s.b.GetPoolTransaction(hash); tx != nil { @@ -210,7 +214,7 @@ func RpcOutputReceipt(header *types.Header, tx *types.Transaction, blockHash com return nil } - fields := newRPCTransaction(nil, tx, blockHash, blockNumber, index, config) + fields := newRPCTransaction(header, tx, blockHash, blockNumber, index, config) if receipt.Status != types.ReceiptStatusSuccessful { fields["status"] = hexutil.Uint(types.ReceiptStatusFailed) diff --git a/consensus/istanbul/backend/api.go b/consensus/istanbul/backend/api.go index d8efb8865..63ea5a7a9 100644 --- a/consensus/istanbul/backend/api.go +++ b/consensus/istanbul/backend/api.go @@ -328,7 +328,7 @@ func (api *APIExtension) makeRPCBlockOutput(b *types.Block, rpcTransactions[i] = kaiaApi.RpcOutputReceipt(head, tx, hash, head.Number.Uint64(), uint64(i), receipts[i], api.chain.Config()) } else { // fill the transaction output if receipt is not found - rpcTransactions[i] = kaiaApi.NewRPCTransaction(b, tx, hash, head.Number.Uint64(), uint64(i), api.chain.Config()) + rpcTransactions[i] = kaiaApi.NewRPCTransaction(head, tx, hash, head.Number.Uint64(), uint64(i), api.chain.Config()) } }