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

fix txHash #78

Merged
merged 3 commits into from
Apr 2, 2024
Merged
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
29 changes: 23 additions & 6 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1446,20 +1446,37 @@ func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf
// newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, db ethdb.Database) *RPCTransaction {
txs := b.Transactions()
var borReceipt *types.Receipt

borReceipt := rawdb.ReadBorReceipt(db, b.Hash(), b.NumberU64())
if borReceipt != nil {
tx, _, _, _ := rawdb.ReadBorTransaction(db, borReceipt.TxHash)
if index >= uint64(len(txs)+1) {
return nil
}

if tx != nil {
txs = append(txs, tx)
// Read bor receipts if a state-sync transaction is requested
if index == uint64(len(txs)) {
borReceipt = rawdb.ReadBorReceipt(db, b.Hash(), b.NumberU64())
if borReceipt != nil {
if borReceipt.TxHash != (common.Hash{}) {
tx, _, _, _ := rawdb.ReadBorTransactionWithBlockHash(db, borReceipt.TxHash, b.Hash())

if tx != nil {
txs = append(txs, tx)
}
}
}
}

if index >= uint64(len(txs)) {
return nil
}
return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index, b.BaseFee())
rpcTx := newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index, b.BaseFee())

// If the transaction is a bor transaction, we need to set the hash to the derived bor tx hash. BorTx is always the last index.
if borReceipt != nil && index == uint64(len(txs)-1) {
rpcTx.Hash = borReceipt.TxHash
}

return rpcTx
}

// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
Expand Down
Loading