Skip to content

Commit

Permalink
Merge pull request ethereum#23677 from karalabe/canon-rlp-fetcher
Browse files Browse the repository at this point in the history
internal/ethapi: make header/block rlp retrieval canonical
  • Loading branch information
karalabe authored and jagdeep sidhu committed Oct 3, 2021
1 parent 90b12d4 commit 1b81116
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions internal/ethapi/api.go
Expand Up @@ -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
Expand Down

0 comments on commit 1b81116

Please sign in to comment.