Skip to content

Commit

Permalink
feat(event): add BeaconP2PAttestation event type (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm authored Dec 5, 2023
1 parent 17faf5b commit ad69f1b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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 (
BeaconP2PAttestationType = "BEACON_P2P_ATTESTATION"
)

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

func NewBeaconP2PAttestation(log logrus.FieldLogger, event *xatu.DecoratedEvent) *BeaconP2PAttestation {
return &BeaconP2PAttestation{
log: log.WithField("event", BeaconP2PAttestationType),
event: event,
}
}

func (b *BeaconP2PAttestation) Type() string {
return BeaconP2PAttestationType
}

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

return nil
}

func (b *BeaconP2PAttestation) Filter(_ context.Context) bool {
return false
}
4 changes: 3 additions & 1 deletion pkg/server/service/event-ingester/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
TypeBlockprintBlockClassification Type = blockprint.BlockClassificationType
TypeBeaconETHV1EventsBlobSidecar Type = v1.EventsBlobSidecarType
TypeBeaconETHV1BeaconBlobSidecar Type = v1.BeaconBlobSidecarType
TypeBeaconP2PAttestation Type = v1.BeaconP2PAttestationType
)

type Event interface {
Expand Down Expand Up @@ -135,7 +136,8 @@ func New(eventType Type, log logrus.FieldLogger, event *xatu.DecoratedEvent, cac
return v1.NewEventsBlobSidecar(log, event), nil
case TypeBeaconETHV1BeaconBlobSidecar:
return v1.NewBeaconBlobSidecar(log, event), nil

case TypeBeaconP2PAttestation:
return v1.NewBeaconP2PAttestation(log, event), nil
default:
return nil, fmt.Errorf("event type %s is unknown", eventType)
}
Expand Down

0 comments on commit ad69f1b

Please sign in to comment.