Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update anonymous ID on passport verification instead of restriction #40

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions internal/service/handlers/verify_passport.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ func VerifyPassport(w http.ResponseWriter, r *http.Request) {
return
}

var balAID string
if balance.AnonymousID != nil {
balAID = *balance.AnonymousID
}

proofCountry, err := requests.ExtractCountry(*proof)
if err != nil {
log.WithError(err).Error("failed to extract country while proof was successfully verified")
Expand All @@ -107,17 +102,23 @@ func VerifyPassport(w http.ResponseWriter, r *http.Request) {

err = validation.Errors{
"data/attributes/country": validation.Validate(*balance.Country, validation.Required, validation.In(country)),
"data/attributes/anonymous_id": validation.Validate(anonymousID, validation.Required, validation.In(balAID)),
"data/attributes/proof/pub_signals/country": validation.Validate(proofCountry, validation.Required, validation.In(*balance.Country)),
}.Filter()
if err != nil {
ape.RenderErr(w, problems.BadRequest(err)...)
return
}

err = BalancesQ(r).FilterByNullifier(balance.Nullifier).Update(map[string]any{
toUpd := map[string]any{
data.ColIsPassport: true,
})
}
if balance.AnonymousID != nil && *balance.AnonymousID != anonymousID {
log.Infof("Balance %s is updating anonymous ID", balance.Nullifier)
toUpd[data.ColAnonymousID] = anonymousID
balance.AnonymousID = &anonymousID
}

err = BalancesQ(r).FilterByNullifier(balance.Nullifier).Update(toUpd)
if err != nil {
log.WithError(err).Error("Failed to update balance")
ape.RenderErr(w, problems.InternalError())
Expand Down
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
Loading