Skip to content

Commit

Permalink
internal/ethapi: support retrieving header RLPs too
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Oct 1, 2021
1 parent f2491c5 commit 07a5bc1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 07a5bc1

Please sign in to comment.