Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: pass actual Header through newRPCOutput function #26

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading