From b23399f4d9afdf51ff946c90807a0e17aedb9b75 Mon Sep 17 00:00:00 2001 From: Evangelos Pappas Date: Mon, 8 Oct 2018 15:02:21 +0100 Subject: [PATCH] ethclient: Adding TransactionExtraInfoByHash method to the Client Struct As a helper, I'm introducing the TransactionExtraInfoByHash that mimics the TransactionByHash method, but only returns the block hash and sender's address. --- ethclient/ethclient.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index b40837c8cc..b770471ea9 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -205,6 +205,25 @@ func (ec *Client) TransactionByHash(ctx context.Context, hash common.Hash) (tx * return json.tx, json.BlockNumber == nil, nil } +// TransactionExtraInfoByHash returns the transaction's extra info with the given hash. +func (ec *Client) TransactionExtraInfoByHash(ctx context.Context, hash common.Hash) (blockHash *common.Hash, from *common.Address, err error) { + var json *rpcTransaction + + err = ec.c.CallContext(ctx, &json, "eth_getTransactionByHash", hash) + if err != nil { + return nil, nil, err + } else if json == nil { + return nil, nil, ethereum.NotFound + } else if _, r, _ := json.tx.RawSignatureValues(); r == nil { + return nil, nil, fmt.Errorf("server returned transaction without signature") + } + if json.From != nil && json.BlockHash != nil { + setSenderFromServer(json.tx, *json.From, *json.BlockHash) + } + + return json.BlockHash, json.From, 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.