mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/ethapi: always use backend to find transaction
This commit is contained in:
parent
c692bed3dc
commit
c1c0d9f84b
4 changed files with 21 additions and 19 deletions
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common/math"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/bloombits"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
|
|
@ -174,8 +175,9 @@ func (b *EthAPIBackend) GetPoolTransaction(hash common.Hash) *types.Transaction
|
|||
return b.eth.txPool.Get(hash)
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) GetTransactionWithOdr(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
return nil, common.Hash{}, 0, 0, nil
|
||||
func (b *EthAPIBackend) GetCanonicalTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
tx, blockHash, blockNumber, index := rawdb.ReadTransaction(b.eth.ChainDb(), txHash)
|
||||
return tx, blockHash, blockNumber, index, nil
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) {
|
||||
|
|
|
|||
|
|
@ -1152,35 +1152,35 @@ func (s *PublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, addr
|
|||
}
|
||||
|
||||
// GetTransactionByHash returns the transaction for the given hash
|
||||
func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) *RPCTransaction {
|
||||
func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error) {
|
||||
// Try to return an already finalized transaction
|
||||
if tx, blockHash, blockNumber, index := rawdb.ReadTransaction(s.b.ChainDb(), hash); tx != nil {
|
||||
return newRPCTransaction(tx, blockHash, blockNumber, index)
|
||||
tx, blockHash, blockNumber, index, err := s.b.GetCanonicalTransaction(ctx, hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tx, blockHash, blockNumber, index, err := s.b.GetTransactionWithOdr(ctx, hash); tx != nil && err == nil {
|
||||
return newRPCTransaction(tx, blockHash, blockNumber, index)
|
||||
if tx != nil {
|
||||
return newRPCTransaction(tx, blockHash, blockNumber, index), nil
|
||||
}
|
||||
// No finalized transaction, try to retrieve it from the pool
|
||||
if tx := s.b.GetPoolTransaction(hash); tx != nil {
|
||||
return newRPCPendingTransaction(tx)
|
||||
return newRPCPendingTransaction(tx), nil
|
||||
}
|
||||
|
||||
// Transaction unknown, return as such
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetRawTransactionByHash returns the bytes of the transaction for the given hash.
|
||||
func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, hash common.Hash) (hexutil.Bytes, error) {
|
||||
var tx *types.Transaction
|
||||
|
||||
// Retrieve a finalized transaction, or a pooled otherwise
|
||||
if tx, _, _, _ = rawdb.ReadTransaction(s.b.ChainDb(), hash); tx == nil {
|
||||
if tx = s.b.GetPoolTransaction(hash); tx == nil {
|
||||
var err error
|
||||
if tx, _, _, _, err = s.b.GetTransactionWithOdr(ctx, hash); tx == nil || err != nil {
|
||||
// Transaction not found anywhere, abort
|
||||
tx, _, _, _, err := s.b.GetCanonicalTransaction(ctx, hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tx == nil {
|
||||
if tx = s.b.GetPoolTransaction(hash); tx == nil {
|
||||
// Transaction not found anywhere, abort
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
// Serialize to RLP and return
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ type Backend interface {
|
|||
|
||||
// TxPool API
|
||||
SendTx(ctx context.Context, signedTx *types.Transaction) error
|
||||
GetTransactionWithOdr(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
|
||||
GetCanonicalTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
|
||||
GetPoolTransactions() (types.Transactions, error)
|
||||
GetPoolTransaction(txHash common.Hash) *types.Transaction
|
||||
GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ func (b *LesApiBackend) GetPoolTransaction(txHash common.Hash) *types.Transactio
|
|||
return b.eth.txPool.GetTransaction(txHash)
|
||||
}
|
||||
|
||||
func (b *LesApiBackend) GetTransactionWithOdr(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
func (b *LesApiBackend) GetCanonicalTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) {
|
||||
return light.GetTransaction(ctx, b.eth.odr, txHash)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue