diff --git a/core/rawdb/bor_receipt.go b/core/rawdb/bor_receipt.go index 676406a762..63c4be12a1 100644 --- a/core/rawdb/bor_receipt.go +++ b/core/rawdb/bor_receipt.go @@ -146,7 +146,25 @@ func DeleteBorReceipt(db ethdb.KeyValueWriter, hash common.Hash, number uint64) } } -// ReadBorTransaction retrieves a specific bor (fake) transaction, along with +// ReadBorTransactionWithBlockHash retrieves a specific bor (fake) transaction by tx hash and block hash, along with +// its added positional metadata. +func ReadBorTransactionWithBlockHash(db ethdb.Reader, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { + blockNumber := ReadBorTxLookupEntry(db, txHash) + if blockNumber == nil { + return nil, common.Hash{}, 0, 0 + } + + body := ReadBody(db, blockHash, *blockNumber) + if body == nil { + log.Error("Transaction referenced missing", "number", blockNumber, "hash", blockHash) + return nil, common.Hash{}, 0, 0 + } + + // fetch receipt and return it + return types.NewBorTransaction(), blockHash, *blockNumber, uint64(len(body.Transactions)) +} + +// ReadBorTransaction retrieves a specific bor (fake) transaction by hash, along with // its added positional metadata. func ReadBorTransaction(db ethdb.Reader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { blockNumber := ReadBorTxLookupEntry(db, hash) diff --git a/eth/bor_api_backend.go b/eth/bor_api_backend.go index 7f17c5b50c..a6ff090c3f 100644 --- a/eth/bor_api_backend.go +++ b/eth/bor_api_backend.go @@ -58,6 +58,11 @@ func (b *EthAPIBackend) GetBorBlockTransaction(ctx context.Context, hash common. return tx, blockHash, blockNumber, index, nil } +func (b *EthAPIBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { + tx, blockHash, blockNumber, index := rawdb.ReadBorTransactionWithBlockHash(b.eth.ChainDb(), txHash, blockHash) + return tx, blockHash, blockNumber, index, nil +} + // SubscribeStateSyncEvent subscribes to state sync event func (b *EthAPIBackend) SubscribeStateSyncEvent(ch chan<- core.StateSyncEvent) event.Subscription { return b.eth.BlockChain().SubscribeStateSyncEvent(ch) diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 8fe8d2d019..e8c263f717 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -92,6 +92,7 @@ type Backend interface { GetBorBlockReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error) GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]*types.Log, error) GetBorBlockTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) + GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) ChainConfig() *params.ChainConfig Engine() consensus.Engine diff --git a/internal/ethapi/bor_api.go b/internal/ethapi/bor_api.go index 384cc7741b..adcfe39026 100644 --- a/internal/ethapi/bor_api.go +++ b/internal/ethapi/bor_api.go @@ -27,7 +27,7 @@ func (s *PublicBlockChainAPI) GetBorBlockReceipt(ctx context.Context, hash commo func (s *PublicBlockChainAPI) appendRPCMarshalBorTransaction(ctx context.Context, block *types.Block, fields map[string]interface{}, fullTx bool) map[string]interface{} { if block != nil { txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash())) - borTx, blockHash, blockNumber, txIndex, _ := s.b.GetBorBlockTransaction(ctx, txHash) + borTx, blockHash, blockNumber, txIndex, _ := s.b.GetBorBlockTransactionWithBlockHash(ctx, txHash, block.Hash()) if borTx != nil { formattedTxs := fields["transactions"].([]interface{}) if fullTx { diff --git a/les/api_backend.go b/les/api_backend.go index e4e97d384e..53d925b652 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -324,3 +324,7 @@ func (b *LesApiBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ( func (b *LesApiBackend) GetBorBlockTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { return nil, common.Hash{}, 0, 0, errors.New("Not implemented") } + +func (b *LesApiBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { + return nil, common.Hash{}, 0, 0, errors.New("Not implemented") +}