From eab15200c2fce1dea16e30b9641b5344708cc9c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Wed, 10 Jan 2018 20:09:00 +0700 Subject: [PATCH] ethclient: BlockNumberByTransactionHash fixes #15210 --- ethclient/ethclient.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 87a912901a..eb9dd86b45 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -193,6 +193,21 @@ func (ec *Client) TransactionByHash(ctx context.Context, hash common.Hash) (tx * return json.tx, json.BlockNumber == nil, nil } +// BlockNumberByTransactionHash returns block number for the transaction with the given hash. +func (ec *Client) BlockNumberByTransactionHash(ctx context.Context, hash common.Hash) (blockNumber *string, err error) { + var json *rpcTransaction + err = ec.c.CallContext(ctx, &json, "eth_getTransactionByHash", hash) + if err != nil { + return nil, err + } else if json == nil { + return nil, ethereum.NotFound + } else if _, r, _ := json.tx.RawSignatureValues(); r == nil { + return nil, fmt.Errorf("server returned transaction without signature") + } + setSenderFromServer(json.tx, json.From, json.BlockHash) + return json.BlockNumber, nil +} + // TransactionSender returns the sender address of the given transaction. The transaction // must be known to the remote node and included in the blockchain at the given block and // index. The sender is the one derived by the protocol at the time of inclusion.