aboutsummaryrefslogtreecommitdiff
path: root/ethclient
diff options
context:
space:
mode:
authoraaronbuchwald <[email protected]>2020-11-25 11:21:55 -0500
committerGitHub <[email protected]>2020-11-25 11:21:55 -0500
commit44c27ae8f05bb7f1076d9159d4106afd41e2e010 (patch)
tree4fe0127968b5559bc6d48b4604e4b0a76257d01c /ethclient
parent244825095f38eadfe5687c2f226c5901088be3d3 (diff)
parente7d3954b726d26ac5fcc4e4011b0f50cd8375e79 (diff)
Merge pull request #60 from ava-labs/block_ext_data_fix
block extra data parse fix
Diffstat (limited to 'ethclient')
-rw-r--r--ethclient/ethclient.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go
index ed02182..6dd4df8 100644
--- a/ethclient/ethclient.go
+++ b/ethclient/ethclient.go
@@ -97,11 +97,11 @@ func (ec *Client) BlockNumber(ctx context.Context) (uint64, error) {
}
type rpcBlock struct {
- Hash common.Hash `json:"hash"`
- Transactions []rpcTransaction `json:"transactions"`
- UncleHashes []common.Hash `json:"uncles"`
- Version uint32 `json:"version"`
- ExtraData *[]byte `json:"blockExtraData"`
+ Hash common.Hash `json:"hash"`
+ Transactions []rpcTransaction `json:"transactions"`
+ UncleHashes []common.Hash `json:"uncles"`
+ Version uint32 `json:"version"`
+ BlockExtraData string `json:"blockExtraData"`
}
func (ec *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*types.Block, error) {
@@ -121,6 +121,16 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
if err := json.Unmarshal(raw, &body); err != nil {
return nil, err
}
+
+ var blockExtraData *[]byte
+ if len(body.BlockExtraData) != 0 {
+ blockExtraDataDecoded, err := hexutil.Decode(body.BlockExtraData)
+ if err != nil {
+ return nil, fmt.Errorf("problem parsing block extra data: %w", err)
+ }
+ blockExtraData = &blockExtraDataDecoded
+ }
+
// Quick-verify transaction and uncle lists. This mostly helps with debugging the server.
if head.UncleHash == types.EmptyUncleHash && len(body.UncleHashes) > 0 {
return nil, fmt.Errorf("server returned non-empty uncle list but block header indicates no uncles")
@@ -166,7 +176,7 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
}
txs[i] = tx.tx
}
- return types.NewBlockWithHeader(head).WithBody(txs, uncles, body.Version, body.ExtraData), nil
+ return types.NewBlockWithHeader(head).WithBody(txs, uncles, body.Version, blockExtraData), nil
}
// HeaderByHash returns the block header with the given hash.