Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ethapi: support retrieving header RLPs too #23670

Merged
merged 1 commit into from Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/ethapi/api.go
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
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