ethclient: add cached sender to block transactions

This commit is contained in:
Felix Lange 2017-09-20 11:17:23 +02:00
parent e4ae593927
commit 81651c38da

View file

@ -70,9 +70,9 @@ func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Bl
} }
type rpcBlock struct { type rpcBlock struct {
Hash common.Hash `json:"hash"` Hash common.Hash `json:"hash"`
Transactions []*types.Transaction `json:"transactions"` Transactions []rpcTransaction `json:"transactions"`
UncleHashes []common.Hash `json:"uncles"` UncleHashes []common.Hash `json:"uncles"`
} }
func (ec *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*types.Block, error) { func (ec *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*types.Block, error) {
@ -129,7 +129,13 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
} }
} }
} }
return types.NewBlockWithHeader(head).WithBody(body.Transactions, uncles), nil // Fill the sender cache of transactions in the block.
txs := make([]*types.Transaction, len(body.Transactions))
for i, tx := range body.Transactions {
setSenderFromServer(tx.tx, tx.From)
txs[i] = tx.tx
}
return types.NewBlockWithHeader(head).WithBody(txs, uncles), nil
} }
// HeaderByHash returns the block header with the given hash. // HeaderByHash returns the block header with the given hash.