2024-10-24 17:00:46 +02:00
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
2024-11-02 16:38:23 +01:00
|
|
|
"context"
|
|
|
|
|
2024-10-24 17:00:46 +02:00
|
|
|
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
2024-11-02 16:38:23 +01:00
|
|
|
|
|
|
|
"git.grassecon.net/urdt/ussd/common"
|
|
|
|
"git.grassecon.net/term/lookup"
|
2024-10-24 17:00:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
evReg = "CUSTODIAL_REGISTRATION"
|
|
|
|
)
|
|
|
|
|
2024-11-03 20:04:44 +01:00
|
|
|
// fields used for handling custodial registration event.
|
2024-10-24 17:00:46 +02:00
|
|
|
type eventCustodialRegistration struct {
|
2024-11-02 16:38:23 +01:00
|
|
|
Account string
|
2024-10-24 17:00:46 +02:00
|
|
|
}
|
|
|
|
|
2024-11-03 20:04:44 +01:00
|
|
|
// attempt to coerce event as custodial registration.
|
2024-10-24 17:00:46 +02:00
|
|
|
func asCustodialRegistrationEvent(gev *geEvent.Event) (*eventCustodialRegistration, bool) {
|
|
|
|
var ok bool
|
|
|
|
var ev eventCustodialRegistration
|
|
|
|
if gev.TxType != evReg {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
pl := gev.Payload
|
2024-11-02 16:38:23 +01:00
|
|
|
ev.Account, ok = pl["account"].(string)
|
2024-10-24 17:00:46 +02:00
|
|
|
if !ok {
|
|
|
|
return nil, false
|
|
|
|
}
|
2024-11-03 01:34:28 +01:00
|
|
|
logg.Debugf("parsed ev", "pl", pl, "ev", ev)
|
2024-10-24 17:00:46 +02:00
|
|
|
return &ev, true
|
|
|
|
}
|
|
|
|
|
2024-11-03 20:04:44 +01:00
|
|
|
// handle custodial registration.
|
2024-11-02 17:08:05 +01:00
|
|
|
func handleCustodialRegistration(ctx context.Context, store *common.UserDataStore, ev *eventCustodialRegistration) error {
|
2024-11-02 16:38:23 +01:00
|
|
|
identity, err := lookup.IdentityFromAddress(ctx, store, ev.Account)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_ = identity
|
2024-10-24 17:00:46 +02:00
|
|
|
return nil
|
|
|
|
}
|