From ad69f1b1db47e06588a1e961d4703bdd670a6029 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Tue, 5 Dec 2023 16:17:44 +1000 Subject: [PATCH] feat(event): add BeaconP2PAttestation event type (#254) --- .../beacon/eth/v1/beacon_p2p_attestation.go | 42 +++++++++++++++++++ .../service/event-ingester/event/event.go | 4 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 pkg/server/service/event-ingester/event/beacon/eth/v1/beacon_p2p_attestation.go diff --git a/pkg/server/service/event-ingester/event/beacon/eth/v1/beacon_p2p_attestation.go b/pkg/server/service/event-ingester/event/beacon/eth/v1/beacon_p2p_attestation.go new file mode 100644 index 00000000..e0a1f997 --- /dev/null +++ b/pkg/server/service/event-ingester/event/beacon/eth/v1/beacon_p2p_attestation.go @@ -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 +} diff --git a/pkg/server/service/event-ingester/event/event.go b/pkg/server/service/event-ingester/event/event.go index 162b923d..9d3f0c1e 100644 --- a/pkg/server/service/event-ingester/event/event.go +++ b/pkg/server/service/event-ingester/event/event.go @@ -52,6 +52,7 @@ const ( TypeBlockprintBlockClassification Type = blockprint.BlockClassificationType TypeBeaconETHV1EventsBlobSidecar Type = v1.EventsBlobSidecarType TypeBeaconETHV1BeaconBlobSidecar Type = v1.BeaconBlobSidecarType + TypeBeaconP2PAttestation Type = v1.BeaconP2PAttestationType ) type Event interface { @@ -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) }