Skip to content

Commit

Permalink
api: pass actual Header through newRPCOutput function
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomee1313 committed Jun 26, 2024
1 parent 788a8be commit db54174
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 7 additions & 6 deletions api/api_public_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions api/api_public_transaction_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/backend/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit db54174

Please sign in to comment.