Implement event handlers in dev emitter

This commit is contained in:
lash 2025-01-13 18:15:54 +00:00
parent 6b22fe134a
commit 0d47c096e0
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 33 additions and 13 deletions

View File

@ -10,15 +10,18 @@ import (
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/lang" "git.defalsify.org/vise.git/lang"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config" "git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/storage"
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
devremote "git.grassecon.net/grassrootseconomics/sarafu-api/dev" devremote "git.grassecon.net/grassrootseconomics/sarafu-api/dev"
"git.grassecon.net/grassrootseconomics/sarafu-api/remote" "git.grassecon.net/grassrootseconomics/sarafu-api/remote"
"git.grassecon.net/grassrootseconomics/sarafu-api/event" apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
"git.grassecon.net/grassrootseconomics/sarafu-vise/args" "git.grassecon.net/grassrootseconomics/sarafu-vise/args"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
) )
var ( var (
@ -27,23 +30,33 @@ var (
menuSeparator = ": " menuSeparator = ": "
) )
type devEmitter struct {
h *event.EventsHandler
store *store.UserDataStore
pe *persist.Persister
}
// WIP: placeholder emitter, should perform same action as events // WIP: placeholder emitter, should perform same action as events
func emitter(ctx context.Context, msg event.Msg) error { func (d *devEmitter) emit(ctx context.Context, msg apievent.Msg) error {
if msg.Typ == event.EventTokenTransferTag { var err error
if msg.Typ == apievent.EventTokenTransferTag {
tx, ok := msg.Item.(devremote.Tx) tx, ok := msg.Item.(devremote.Tx)
if !ok { if !ok {
return fmt.Errorf("not a valid tx") return fmt.Errorf("not a valid tx")
} }
logg.InfoCtxf(ctx, "tx emit", "tx", tx) logg.InfoCtxf(ctx, "tx emit", "tx", tx)
} else if msg.Typ == event.EventRegistrationTag { ev := tx.ToTransferEvent()
err = d.h.HandleTokenTransfer(ctx, d.store, &ev)
} else if msg.Typ == apievent.EventRegistrationTag {
acc, ok := msg.Item.(devremote.Account) acc, ok := msg.Item.(devremote.Account)
if !ok { if !ok {
return fmt.Errorf("not a valid tx") return fmt.Errorf("not a valid tx")
} }
logg.InfoCtxf(ctx, "account emit", "account", acc) logg.InfoCtxf(ctx, "account emit", "account", acc)
ev := acc.ToRegistrationEvent()
err = d.h.HandleCustodialRegistration(ctx, d.store, d.pe, &ev)
} }
return nil return err
} }
func main() { func main() {
@ -148,7 +161,14 @@ func main() {
} }
if fakeDir != "" { if fakeDir != "" {
svc := devremote.NewDevAccountService(ctx, fakeDir).WithAutoVoucher(ctx, "FOO", 42).WithEmitter(emitter) svc := devremote.NewDevAccountService(ctx, fakeDir).WithAutoVoucher(ctx, "FOO", 42)
emitter := &devEmitter{
h: event.NewEventsHandler(svc),
store: &store.UserDataStore{
Db: userdatastore,
},
}
svc = svc.WithEmitter(emitter.emit)
svc.AddVoucher(ctx, "BAR") svc.AddVoucher(ctx, "BAR")
accountService = svc accountService = svc
} else { } else {

4
go.mod
View File

@ -4,8 +4,8 @@ go 1.23.4
require ( require (
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112155828-b55686e830fd git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113085238-f65abf625d34 git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113181351-551195543805
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893 git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d
github.com/alecthomas/assert/v2 v2.2.2 github.com/alecthomas/assert/v2 v2.2.2

8
go.sum
View File

@ -1,9 +1,9 @@
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d h1:bPAOVZOX4frSGhfOdcj7kc555f8dc9DmMd2YAyC2AMw= git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d h1:bPAOVZOX4frSGhfOdcj7kc555f8dc9DmMd2YAyC2AMw=
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck= git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112155828-b55686e830fd h1:OG20aG/sC5yNaU2/rzoAKYp2f0u4lmGP5/Qax8UQD5c= git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05 h1:BenzGx6aDHKDwE23/mWIFD2InYIXyzHroZWV3MF5WUk=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250112155828-b55686e830fd/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113085238-f65abf625d34 h1:Pl4OFKTeSehSTMMRUFosZUIDyUZRdXqm6CFn0+5+4qs= git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113181351-551195543805 h1:Okih7rAAjD8cpv7pi8QQc36mmp7SRBnOc7dc125GP/E=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113085238-f65abf625d34/go.mod h1:PEjJnAH5gYcjb4RRevaPCswa5VGGNqHSuyapZvIVR6w= git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113181351-551195543805/go.mod h1:e9Damfk0euyjWzn+CE8uxgg8p4ggd07wp99SOyEhGXY=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893 h1:MyDINzwY1sjfXkIFoc+6T5lXF/1xdFV6yjHrpSNZzWM= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893 h1:MyDINzwY1sjfXkIFoc+6T5lXF/1xdFV6yjHrpSNZzWM=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113103142-5bf0a0e85893/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d h1:q/NO1rEgK3pia32D/tCq5hXfEuJp84COZRwceFvy/MM= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d h1:q/NO1rEgK3pia32D/tCq5hXfEuJp84COZRwceFvy/MM=