diff --git a/pkg/beacon/api/api.go b/pkg/beacon/api/api.go index 75ac928..1faef83 100644 --- a/pkg/beacon/api/api.go +++ b/pkg/beacon/api/api.go @@ -18,6 +18,7 @@ type ConsensusClient interface { NodePeer(ctx context.Context, peerID string) (types.Peer, error) NodePeers(ctx context.Context) (types.Peers, error) NodePeerCount(ctx context.Context) (types.PeerCount, error) + RawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error) RawDebugBeaconState(ctx context.Context, stateID string, contentType string) ([]byte, error) DepositSnapshot(ctx context.Context) (*types.DepositSnapshot, error) } @@ -210,6 +211,16 @@ func (c *consensusClient) RawDebugBeaconState(ctx context.Context, stateID strin return data, nil } +// RawBlock returns the block in the requested format. +func (c *consensusClient) RawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error) { + data, err := c.getRaw(ctx, fmt.Sprintf("/eth/v2/beacon/blocks/%s", stateID), contentType) + if err != nil { + return nil, err + } + + return data, nil +} + // DepositSnapshot returns the deposit snapshot in the requested format. func (c *consensusClient) DepositSnapshot(ctx context.Context) (*types.DepositSnapshot, error) { data, err := c.get(ctx, "/eth/v1/beacon/deposit_snapshot") diff --git a/pkg/beacon/beacon.go b/pkg/beacon/beacon.go index 338c785..1040a78 100644 --- a/pkg/beacon/beacon.go +++ b/pkg/beacon/beacon.go @@ -58,6 +58,8 @@ type Node interface { // Fetchers - these are not cached and will always fetch from the node. // FetchBlock fetches the block for the given state id. FetchBlock(ctx context.Context, stateID string) (*spec.VersionedSignedBeaconBlock, error) + // FetchRawBlock fetches the raw, unparsed block for the given state id. + FetchRawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error) // FetchBeaconState fetches the beacon state for the given state id. FetchBeaconState(ctx context.Context, stateID string) (*spec.VersionedBeaconState, error) // FetchBeaconStateRoot fetches the state root for the given state id. diff --git a/pkg/beacon/fetch.go b/pkg/beacon/fetch.go index 366dce2..01a7634 100644 --- a/pkg/beacon/fetch.go +++ b/pkg/beacon/fetch.go @@ -67,6 +67,10 @@ func (n *node) FetchBlock(ctx context.Context, stateID string) (*spec.VersionedS return n.getBlock(ctx, stateID) } +func (n *node) FetchRawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error) { + return n.api.RawBlock(ctx, stateID, contentType) +} + func (n *node) FetchBeaconState(ctx context.Context, stateID string) (*spec.VersionedBeaconState, error) { provider, isProvider := n.client.(eth2client.BeaconStateProvider) if !isProvider {