From 07a5bc1b0b4b4cbab9b4dc5f75400f9dbfd1e576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 1 Oct 2021 11:45:47 +0300 Subject: [PATCH] internal/ethapi: support retrieving header RLPs too --- internal/ethapi/api.go | 13 +++++++++++++ internal/web3ext/web3ext.go | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 6997f2c828..32757e75ff 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1915,6 +1915,19 @@ func NewPublicDebugAPI(b Backend) *PublicDebugAPI { return &PublicDebugAPI{b: b} } +// GetHeaderRlp retrieves the RLP encoded for of a single header. +func (api *PublicDebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (string, error) { + header, _ := api.b.HeaderByNumber(ctx, rpc.BlockNumber(number)) + if header == nil { + return "", fmt.Errorf("header #%d not found", number) + } + encoded, err := rlp.EncodeToBytes(header) + if err != nil { + return "", err + } + return fmt.Sprintf("%x", encoded), nil +} + // GetBlockRlp retrieves the RLP encoded for of a single block. func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (string, error) { block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index ad459362a5..fe9292f5f8 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -223,6 +223,11 @@ web3._extend({ params: 1, outputFormatter: console.log }), + new web3._extend.Method({ + name: 'getHeaderRlp', + call: 'debug_getHeaderRlp', + params: 1 + }), new web3._extend.Method({ name: 'getBlockRlp', call: 'debug_getBlockRlp',