From 0686a2ed5af2da04f06b8ebae9a4cbe0d9f2b212 Mon Sep 17 00:00:00 2001 From: Todd Stock Date: Sat, 21 Nov 2020 11:55:20 -0500 Subject: use byte array --- ethclient/ethclient.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethclient') diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index ed02182..dfd260c 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"` - ExtraData *[]byte `json:"blockExtraData"` + BlockExtraData *[]byte `json:"blockExtraData"` } func (ec *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*types.Block, error) { @@ -166,7 +166,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, body.BlockExtraData), nil } // HeaderByHash returns the block header with the given hash. -- cgit v1.2.3-70-g09d2 From 7ec00e3668f99df1d041b63ebcdfb718275a52b0 Mon Sep 17 00:00:00 2001 From: Todd Stock Date: Sat, 21 Nov 2020 12:07:18 -0500 Subject: format --- ethclient/ethclient.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ethclient') diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index dfd260c..deafa54 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"` - BlockExtraData *[]byte `json:"blockExtraData"` + Hash common.Hash `json:"hash"` + Transactions []rpcTransaction `json:"transactions"` + UncleHashes []common.Hash `json:"uncles"` + Version uint32 `json:"version"` + BlockExtraData *[]byte `json:"blockExtraData"` } func (ec *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*types.Block, error) { -- cgit v1.2.3-70-g09d2 From 7ce0588c5320894ddfae4069de45fe07d78b9f6f Mon Sep 17 00:00:00 2001 From: Todd Stock Date: Sat, 21 Nov 2020 12:30:06 -0500 Subject: fix ptr --- ethclient/ethclient.go | 4 ++-- internal/ethapi/api.go | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'ethclient') diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index deafa54..6c1fa8d 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 []byte `json:"blockExtraData"` } func (ec *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*types.Block, error) { @@ -166,7 +166,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, &body.BlockExtraData), nil } // HeaderByHash returns the block header with the given hash. diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index cb1b4bd..1a95d9b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1161,9 +1161,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool) (map[string]i fields := RPCMarshalHeader(block.Header()) fields["size"] = hexutil.Uint64(block.Size()) - if len(block.ExtraData()) != 0 { - fields["blockExtraData"] = block.ExtraData() - } + fields["blockExtraData"] = hexutil.Bytes(block.ExtraData()) if inclTx { formatTx := func(tx *types.Transaction) (interface{}, error) { -- cgit v1.2.3-70-g09d2 From 57cda741e1ecb09338cb9ebae572cb41d7920fc1 Mon Sep 17 00:00:00 2001 From: Todd Stock Date: Sun, 22 Nov 2020 06:56:30 -0500 Subject: parse string --- ethclient/ethclient.go | 14 ++++++++++++-- internal/ethapi/api.go | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'ethclient') 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) { -- cgit v1.2.3-70-g09d2 From e7d3954b726d26ac5fcc4e4011b0f50cd8375e79 Mon Sep 17 00:00:00 2001 From: Todd Stock Date: Wed, 25 Nov 2020 10:49:48 -0500 Subject: extend error message --- ethclient/ethclient.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethclient') diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index c44a3e9..6dd4df8 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -126,7 +126,7 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface if len(body.BlockExtraData) != 0 { blockExtraDataDecoded, err := hexutil.Decode(body.BlockExtraData) if err != nil { - return nil, err + return nil, fmt.Errorf("problem parsing block extra data: %w", err) } blockExtraData = &blockExtraDataDecoded } -- cgit v1.2.3-70-g09d2