2024-10-23 22:01:10 +02:00
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
2024-11-02 16:38:23 +01:00
|
|
|
"context"
|
2024-10-24 17:00:46 +02:00
|
|
|
"fmt"
|
|
|
|
|
2024-10-23 22:01:10 +02:00
|
|
|
geEvent "github.com/grassrootseconomics/eth-tracker/pkg/event"
|
2024-11-02 23:58:09 +01:00
|
|
|
|
2024-11-03 01:34:28 +01:00
|
|
|
"git.defalsify.org/vise.git/logging"
|
2024-11-02 23:58:09 +01:00
|
|
|
"git.grassecon.net/urdt/ussd/common"
|
2024-10-23 22:01:10 +02:00
|
|
|
)
|
|
|
|
|
2024-10-24 17:00:46 +02:00
|
|
|
// TODO: this vocabulary should be public in and provided by the eth-tracker repo
|
|
|
|
const (
|
|
|
|
evGive = "FAUCET_GIVE"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-11-03 01:34:28 +01:00
|
|
|
logg = logging.NewVanilla().WithDomain("term-event")
|
2024-10-24 17:00:46 +02:00
|
|
|
)
|
|
|
|
|
2024-10-23 22:01:10 +02:00
|
|
|
type Router struct {
|
2024-11-02 17:08:05 +01:00
|
|
|
Store *common.UserDataStore
|
2024-10-23 22:01:10 +02:00
|
|
|
}
|
|
|
|
|
2024-11-02 16:38:23 +01:00
|
|
|
func(r *Router) Route(ctx context.Context, gev *geEvent.Event) error {
|
2024-11-03 01:34:28 +01:00
|
|
|
logg.DebugCtxf(ctx, "have event", "ev", gev)
|
2024-10-24 17:00:46 +02:00
|
|
|
evCC, ok := asCustodialRegistrationEvent(gev)
|
2024-10-24 17:17:04 +02:00
|
|
|
if ok {
|
2024-11-02 16:38:23 +01:00
|
|
|
return handleCustodialRegistration(ctx, r.Store, evCC)
|
2024-10-24 17:00:46 +02:00
|
|
|
}
|
2024-11-03 01:34:28 +01:00
|
|
|
evTT, ok := asTokenTransferEvent(gev)
|
|
|
|
if ok {
|
|
|
|
return handleTokenTransfer(ctx, r.Store, evTT)
|
|
|
|
}
|
|
|
|
|
2024-10-24 17:00:46 +02:00
|
|
|
return fmt.Errorf("unexpected message")
|
2024-10-23 22:01:10 +02:00
|
|
|
}
|