Merge pull request #23670 from karalabe/get-header-rlp

internal/ethapi: support retrieving header RLPs too
This commit is contained in:
Péter Szilágyi 2021-10-01 12:14:32 +03:00 committed by GitHub
commit a47b8cf6f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -1915,6 +1915,19 @@ func NewPublicDebugAPI(b Backend) *PublicDebugAPI {
return &PublicDebugAPI{b: b} 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. // 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) (string, error) {
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))

View File

@ -223,6 +223,11 @@ web3._extend({
params: 1, params: 1,
outputFormatter: console.log outputFormatter: console.log
}), }),
new web3._extend.Method({
name: 'getHeaderRlp',
call: 'debug_getHeaderRlp',
params: 1
}),
new web3._extend.Method({ new web3._extend.Method({
name: 'getBlockRlp', name: 'getBlockRlp',
call: 'debug_getBlockRlp', call: 'debug_getBlockRlp',