Skip to content

Commit

Permalink
feat(validator): handle remove validator event
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Dec 23, 2022
1 parent fbfb01a commit 237740b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/actor/subscription/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func (a *Actor) receiveNewEvent(e event.Event) {
a.handleValidatorRegisteredEvent(e.Data)
case graphql.ValidatorUpdatedEventType:
a.handleValidatorUpdatedEvent(e.Data)
case graphql.ValidatorRemovedEventType:
a.handleValidatorRemovedEvent(e.Data)
case tweet.NewTweetEventType:
a.handleNewTweetEvent(e.Date, e.Data)
case graphql.TaskCompletedEventType:
Expand Down Expand Up @@ -232,6 +234,20 @@ func (a *Actor) handleValidatorUpdatedEvent(data map[string]interface{}) {
}
}

func (a *Actor) handleValidatorRemovedEvent(data map[string]interface{}) {
log.Info().Interface("event", data).Msg("Handle ValidatorRemoved event")

e := &graphql.ValidatorRemovedEvent{}
if err := e.Unmarshal(data); err != nil {
log.Panic().Err(err).Msg("❌ Failed unmarshal event to ValidatorRemoved")
return
}

if err := a.store.RemoveValidator(a.ctx, e.Validator); err != nil {
log.Err(err).Interface("data", data).Msg("🤕 Couldn't remove validator")
}
}

func (a *Actor) handleNewTweetEvent(when time.Time, data map[string]interface{}) {
log.Info().Interface("event", data).Msg("Handle NewTweet event")

Expand Down
10 changes: 10 additions & 0 deletions app/nemeton/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,16 @@ func (s *Store) UpdateValidator(
return err
}

func (s *Store) RemoveValidator(ctx context.Context, valoper types.ValAddress) error {
_, err := s.db.Collection(validatorsCollectionName).
DeleteOne(
ctx,
bson.M{
"valoper": valoper,
})
return err
}

func (s *Store) RegisterValidatorURL(ctx context.Context,
when time.Time,
urlType string,
Expand Down

0 comments on commit 237740b

Please sign in to comment.