forked from cerc-io/plugeth
internal/ethapi: make header/block rlp retrieval canonical
This commit is contained in:
parent
b522f5e091
commit
5240725041
@ -1916,29 +1916,21 @@ func NewPublicDebugAPI(b Backend) *PublicDebugAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetHeaderRlp retrieves the RLP encoded for of a single header.
|
// 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))
|
header, _ := api.b.HeaderByNumber(ctx, rpc.BlockNumber(number))
|
||||||
if header == nil {
|
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)
|
return 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) (hexutil.Bytes, error) {
|
||||||
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
|
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return "", fmt.Errorf("block #%d not found", number)
|
return nil, fmt.Errorf("block #%d not found", number)
|
||||||
}
|
}
|
||||||
encoded, err := rlp.EncodeToBytes(block)
|
return rlp.EncodeToBytes(block)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%x", encoded), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the
|
// TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the
|
||||||
|
Loading…
Reference in New Issue
Block a user