Skip to content

Commit

Permalink
feat(event): add BeaconCommittee event type
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Jul 20, 2023
1 parent 3072ffb commit d5b172c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v1

import (
"context"
"errors"

"github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/sirupsen/logrus"
)

const (
BeaconCommitteeType = "BEACON_API_ETH_V1_BEACON_COMMITTEE"
)

type BeaconCommittee struct {
log logrus.FieldLogger
event *xatu.DecoratedEvent
}

func NewBeaconCommittee(log logrus.FieldLogger, event *xatu.DecoratedEvent) *BeaconCommittee {
return &BeaconCommittee{
log: log.WithField("event", BeaconCommitteeType),
event: event,
}
}

func (b *BeaconCommittee) Type() string {
return EventsHeadType
}

func (b *BeaconCommittee) Validate(_ context.Context) error {
_, ok := b.event.GetData().(*xatu.DecoratedEvent_EthV1BeaconCommittee)
if !ok {
return errors.New("failed to cast event data")
}

return nil
}

func (b *BeaconCommittee) Filter(_ context.Context) bool {
return false
}
3 changes: 3 additions & 0 deletions pkg/server/service/event-ingester/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
TypeBeaconETHV2BeaconBlock Type = v2.BeaconBlockType
TypeDebugForkChoice Type = v1.DebugForkChoiceType
TypeDebugForkChoiceReorg Type = v1.DebugForkChoiceReorgType
TypeBeaconEthV1BeaconCommittee Type = v1.BeaconCommitteeType
)

type Event interface {
Expand Down Expand Up @@ -64,6 +65,8 @@ func New(eventType Type, log logrus.FieldLogger, event *xatu.DecoratedEvent, cac
return v1.NewDebugForkChoice(log, event), nil
case TypeDebugForkChoiceReorg:
return v1.NewDebugForkChoiceReorg(log, event), nil
case TypeBeaconEthV1BeaconCommittee:
return v1.NewBeaconCommittee(log, event), nil
default:
return nil, fmt.Errorf("event type %s is unknown", eventType)
}
Expand Down

0 comments on commit d5b172c

Please sign in to comment.