From 52407250416fb838b9c2b0fd9918c432413b03f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Sun, 3 Oct 2021 16:47:21 +0300 Subject: [PATCH] internal/ethapi: make header/block rlp retrieval canonical --- internal/ethapi/api.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 32757e75ffd55..1b09420b0d9a4 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1916,29 +1916,21 @@ func NewPublicDebugAPI(b Backend) *PublicDebugAPI { } // GetHeaderRlp retrieves the RLP encoded for of a single header. -func (api *PublicDebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (string, error) { +func (api *PublicDebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) { header, _ := api.b.HeaderByNumber(ctx, rpc.BlockNumber(number)) if header == nil { - return "", fmt.Errorf("header #%d not found", number) + return nil, fmt.Errorf("header #%d not found", number) } - encoded, err := rlp.EncodeToBytes(header) - if err != nil { - return "", err - } - return fmt.Sprintf("%x", encoded), nil + return rlp.EncodeToBytes(header) } // GetBlockRlp retrieves the RLP encoded for of a single block. -func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (string, error) { +func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) { block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) if block == nil { - return "", fmt.Errorf("block #%d not found", number) - } - encoded, err := rlp.EncodeToBytes(block) - if err != nil { - return "", err + return nil, fmt.Errorf("block #%d not found", number) } - return fmt.Sprintf("%x", encoded), nil + return rlp.EncodeToBytes(block) } // TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the