diff options
author | Todd Stock <[email protected]> | 2020-11-22 06:56:30 -0500 |
---|---|---|
committer | Todd Stock <[email protected]> | 2020-11-22 06:56:30 -0500 |
commit | 57cda741e1ecb09338cb9ebae572cb41d7920fc1 (patch) | |
tree | f59f296c73c07bc1c418fed8531569fa08fdf451 | |
parent | 7ce0588c5320894ddfae4069de45fe07d78b9f6f (diff) |
parse string
-rw-r--r-- | ethclient/ethclient.go | 14 | ||||
-rw-r--r-- | internal/ethapi/api.go | 4 |
2 files changed, 15 insertions, 3 deletions
diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 6c1fa8d..c44a3e9 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -101,7 +101,7 @@ type rpcBlock struct { Transactions []rpcTransaction `json:"transactions"` UncleHashes []common.Hash `json:"uncles"` Version uint32 `json:"version"` - BlockExtraData []byte `json:"blockExtraData"` + 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, 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.BlockExtraData), nil + return types.NewBlockWithHeader(head).WithBody(txs, uncles, body.Version, blockExtraData), nil } // HeaderByHash returns the block header with the given hash. diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 1a95d9b..77efcab 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1161,7 +1161,9 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool) (map[string]i fields := RPCMarshalHeader(block.Header()) fields["size"] = hexutil.Uint64(block.Size()) - fields["blockExtraData"] = hexutil.Bytes(block.ExtraData()) + if len(block.ExtraData()) != 0 { + fields["blockExtraData"] = hexutil.Encode(block.ExtraData()) + } if inclTx { formatTx := func(tx *types.Transaction) (interface{}, error) { |