diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 6945fc8f23..cb52975fdf 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "github.com/paxosglobal/go-ethereum" "math/big" "sync" "time" @@ -182,7 +183,13 @@ func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common // TransactionByHash returns the transaction with the given hash. func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error) { transaction, _, blockNumber, _ := rawdb.ReadTransaction(b.database, txHash) - return transaction, blockNumber != 0, nil + return transaction, blockNumber == 0, nil +} + +// TransactionByHash returns the transaction with the given hash. +func (b *SimulatedBackend) TransactionByHashWithBlockNum(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending string, err error) { + transaction, _, blockNumber, _ := rawdb.ReadTransaction(b.database, txHash) + return transaction, string(blockNumber), nil } // BlockByNumber retrieves a block from the database by number, caching it diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index b40837c8cc..04354dd90d 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -22,6 +22,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/paxosglobal/go-ethereum" "math/big" "github.com/ethereum/go-ethereum" @@ -188,6 +189,28 @@ func (tx *rpcTransaction) UnmarshalJSON(msg []byte) error { return json.Unmarshal(msg, &tx.txExtraInfo) } +// TransactionByHash returns the transaction with the given hash. +func (ec *Client) TransactionByHashWithBlockNum(ctx context.Context, hash common.Hash) (tx *types.Transaction, BlockNumber string, err error) { + var json *rpcTransaction + err = ec.c.CallContext(ctx, &json, "eth_getTransactionByHash", hash) + if err != nil { + return nil, false, err + } else if json == nil { + return nil, false, ethereum.NotFound + } else if _, r, _ := json.tx.RawSignatureValues(); r == nil { + return nil, false, fmt.Errorf("server returned transaction without signature") + } + if json.From != nil && json.BlockHash != nil { + setSenderFromServer(json.tx, *json.From, *json.BlockHash) + } + + if json.BlockNumber == nil { + return json.tx, "0", nil + } + + return json.tx, *json.BlockNumber, nil +} + // TransactionByHash returns the transaction with the given hash. func (ec *Client) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) { var json *rpcTransaction diff --git a/interfaces.go b/interfaces.go index 26b0fcbc17..920271a272 100644 --- a/interfaces.go +++ b/interfaces.go @@ -83,6 +83,9 @@ type TransactionReader interface { // transaction may not be included in the current canonical chain even if a receipt // exists. TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) + + // Same as TransactionByHash but returns the BlockNum + TransactionByHashWithBlockNum(ctx context.Context, hash common.Hash) (tx *types.Transaction, BlockNumber string, err error) } // ChainStateReader wraps access to the state trie of the canonical blockchain. Note that