Skip to content

Commit

Permalink
feat(beacon): Add FetchBeaconStateRoot method
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Jan 31, 2024
1 parent 634b504 commit 29cbd9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type Node interface {
FetchBlock(ctx context.Context, stateID string) (*spec.VersionedSignedBeaconBlock, 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.
FetchBeaconStateRoot(ctx context.Context, stateID string) (phase0.Root, error)
// FetchRawBeaconState fetches the raw, unparsed beacon state for the given state id.
FetchRawBeaconState(ctx context.Context, stateID string, contentType string) ([]byte, error)
// FetchFinality fetches the finality checkpoint for the state id.
Expand Down
16 changes: 16 additions & 0 deletions pkg/beacon/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ func (n *node) FetchDepositSnapshot(ctx context.Context) (*types.DepositSnapshot
return n.api.DepositSnapshot(ctx)
}

func (n *node) FetchBeaconStateRoot(ctx context.Context, state string) (phase0.Root, error) {
provider, isProvider := n.client.(eth2client.BeaconStateRootProvider)
if !isProvider {
return phase0.Root{}, errors.New("client does not implement eth2client.StateRootProvider")
}

rsp, err := provider.BeaconStateRoot(ctx, &api.BeaconStateRootOpts{
State: state,
})
if err != nil {
return phase0.Root{}, err
}

return *rsp.Data, nil
}

func (n *node) FetchBeaconCommittees(ctx context.Context, state string, epoch phase0.Epoch) ([]*v1.BeaconCommittee, error) {
provider, isProvider := n.client.(eth2client.BeaconCommitteesProvider)
if !isProvider {
Expand Down

0 comments on commit 29cbd9b

Please sign in to comment.