Skip to content

Commit

Permalink
Delete also not started events, forbid fulfill/claim for inactive eve…
Browse files Browse the repository at this point in the history
…nts in nooneisforgotten
  • Loading branch information
violog committed Jul 1, 2024
1 parent 66e3e02 commit a7e1a5e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 29 deletions.
8 changes: 3 additions & 5 deletions internal/service/workers/expirywatch/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ func newWatcher(cfg config.Config) *watcher {
}

func (w *watcher) initialRun() error {
expired := w.types.Names(func(ev evtypes.EventConfig) bool {
return !ev.Disabled && !evtypes.FilterExpired(ev)
})
expired := w.types.Names(func(ev evtypes.EventConfig) bool { return !evtypes.FilterInactive(ev) })

if len(expired) == 0 {
w.log.Debug("No events were disabled or have expired")
w.log.Debug("No inactive events were found")
return nil
}

Expand All @@ -45,7 +43,7 @@ func (w *watcher) cleanOpen(types ...string) error {
return fmt.Errorf("clean open events [types=%v]: %w", types, err)
}

w.log.Infof("Deleted %d expired and disabled open events, types: %v", deleted, types)
w.log.Infof("Deleted %d deactivated open events, types: %v", deleted, types)
return nil
}

Expand Down
27 changes: 4 additions & 23 deletions internal/service/workers/nooneisforgotten/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,12 @@ func Run(cfg config.Config, sig chan struct{}) {
// First, there is an attempt to claim as many events as
// possible and to fulfill the rest of the events.
//
// Events may not be fulfilled if the event is not active.
// Event may not be claimed if AutoClaim is disabled.
// If the event is not active, only fulfilled events will be claimed.
// Event will not be claimed if AutoClaim is disabled.
func updatePassportScanEvents(db *pgdb.DB, types evtypes.Types, levels config.Levels) error {
// if event inactive - fulfilled event can be claimed
evType := types.Get(evtypes.TypePassportScan)
evType := types.Get(evtypes.TypePassportScan, evtypes.FilterInactive)
if evType == nil {
return nil
}
if evType.Disabled {
return nil
}

if evtypes.FilterInactive(*evType) {
return nil
Expand Down Expand Up @@ -154,10 +148,6 @@ func updatePassportScanEvents(db *pgdb.DB, types evtypes.Types, levels config.Le
}
}

if evtypes.FilterInactive(*evType) {
return nil
}

toFulfill = make([]string, 0, len(balances))
for _, balances := range countriesBalancesMap {
for _, balance := range balances {
Expand All @@ -183,8 +173,6 @@ func updatePassportScanEvents(db *pgdb.DB, types evtypes.Types, levels config.Le

// updateReferralUserEvents is used to add events for referrers
// for friends who have scanned the passport, if they have not been added.
//
// Events are not added if the event is inactive or disabled
func updateReferralUserEvents(db *pgdb.DB, types evtypes.Types) error {
evTypeRef := types.Get(evtypes.TypeReferralSpecific, evtypes.FilterInactive)
if evTypeRef == nil {
Expand Down Expand Up @@ -220,14 +208,8 @@ func updateReferralUserEvents(db *pgdb.DB, types evtypes.Types) error {
// claimReferralSpecificEvents claim fulfilled events for invited
// friends which have passport scanned, if it possible
func claimReferralSpecificEvents(db *pgdb.DB, types evtypes.Types, levels config.Levels) error {
evType := types.Get(evtypes.TypeReferralSpecific)
if evType == nil {
return nil
}
if evType.Disabled {
return nil
}
if !evType.AutoClaim {
evType := types.Get(evtypes.TypeReferralSpecific, evtypes.FilterInactive)
if evType == nil || !evType.AutoClaim {
return nil
}

Expand Down Expand Up @@ -267,7 +249,6 @@ func claimReferralSpecificEvents(db *pgdb.DB, types evtypes.Types, levels config
if !balance.ReferredBy.Valid || balance.Country == nil {
continue
}
// country can't be nil because of db query logic
if _, ok := countriesBalancesMap[*balance.Country]; !ok {
countriesBalancesMap[*balance.Country] = make([]data.Balance, 0, len(balances))
}
Expand Down
2 changes: 1 addition & 1 deletion requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ func verifyPassportBody(nullifier string, proof zkptypes.ZKProof) resources.Veri
Type: resources.VERIFY_PASSPORT,
},
Attributes: resources.VerifyPassportAttributes{
Proof: proof,
Proof: &proof,
},
},
}
Expand Down

0 comments on commit a7e1a5e

Please sign in to comment.