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.
This commit is contained in:
Evangelos Pappas 2018-10-08 15:02:21 +01:00
parent dcae0d348b
commit b23399f4d9
No known key found for this signature in database
GPG key ID: F6FEDFFE62C87FC6

View file

@ -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.