Skip to content

Commit 5240725

Browse files
committed
internal/ethapi: make header/block rlp retrieval canonical
1 parent b522f5e commit 5240725

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

internal/ethapi/api.go

+6-14
Original file line numberDiff line numberDiff line change
@@ -1916,29 +1916,21 @@ func NewPublicDebugAPI(b Backend) *PublicDebugAPI {
19161916
}
19171917

19181918
// GetHeaderRlp retrieves the RLP encoded for of a single header.
1919-
func (api *PublicDebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (string, error) {
1919+
func (api *PublicDebugAPI) GetHeaderRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) {
19201920
header, _ := api.b.HeaderByNumber(ctx, rpc.BlockNumber(number))
19211921
if header == nil {
1922-
return "", fmt.Errorf("header #%d not found", number)
1922+
return nil, fmt.Errorf("header #%d not found", number)
19231923
}
1924-
encoded, err := rlp.EncodeToBytes(header)
1925-
if err != nil {
1926-
return "", err
1927-
}
1928-
return fmt.Sprintf("%x", encoded), nil
1924+
return rlp.EncodeToBytes(header)
19291925
}
19301926

19311927
// GetBlockRlp retrieves the RLP encoded for of a single block.
1932-
func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (string, error) {
1928+
func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexutil.Bytes, error) {
19331929
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
19341930
if block == nil {
1935-
return "", fmt.Errorf("block #%d not found", number)
1936-
}
1937-
encoded, err := rlp.EncodeToBytes(block)
1938-
if err != nil {
1939-
return "", err
1931+
return nil, fmt.Errorf("block #%d not found", number)
19401932
}
1941-
return fmt.Sprintf("%x", encoded), nil
1933+
return rlp.EncodeToBytes(block)
19421934
}
19431935

19441936
// TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the

0 commit comments

Comments
 (0)