From 0d47c096e0d66ee136df57c535a9f81ec178809c Mon Sep 17 00:00:00 2001 From: lash Date: Mon, 13 Jan 2025 18:15:54 +0000 Subject: [PATCH] Implement event handlers in dev emitter --- cmd/main.go | 34 +++++++++++++++++++++++++++------- go.mod | 4 ++-- go.sum | 8 ++++---- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index c37a9c6..f3d5bf1 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -10,15 +10,18 @@ import ( "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/resource" + "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/lang" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" "git.grassecon.net/grassrootseconomics/visedriver/storage" httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" devremote "git.grassecon.net/grassrootseconomics/sarafu-api/dev" "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/handlers" + "git.grassecon.net/grassrootseconomics/sarafu-vise/store" + "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event" ) var ( @@ -27,23 +30,33 @@ var ( menuSeparator = ": " ) +type devEmitter struct { + h *event.EventsHandler + store *store.UserDataStore + pe *persist.Persister +} + // WIP: placeholder emitter, should perform same action as events -func emitter(ctx context.Context, msg event.Msg) error { - if msg.Typ == event.EventTokenTransferTag { +func (d *devEmitter) emit(ctx context.Context, msg apievent.Msg) error { + var err error + if msg.Typ == apievent.EventTokenTransferTag { tx, ok := msg.Item.(devremote.Tx) if !ok { return fmt.Errorf("not a valid 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) if !ok { return fmt.Errorf("not a valid tx") } 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() { @@ -148,7 +161,14 @@ func main() { } 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") accountService = svc } else { diff --git a/go.mod b/go.mod index 13226af..a04f432 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.23.4 require ( 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/sarafu-api v0.0.0-20250113085238-f65abf625d34 + git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05 + 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-africastalking v0.0.0-20250113103030-f0b2056fd87d github.com/alecthomas/assert/v2 v2.2.2 diff --git a/go.sum b/go.sum index 2425992..32d83c5 100644 --- a/go.sum +++ b/go.sum @@ -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/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-20250112155828-b55686e830fd/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-20250113085238-f65abf625d34/go.mod h1:PEjJnAH5gYcjb4RRevaPCswa5VGGNqHSuyapZvIVR6w= +git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05 h1:BenzGx6aDHKDwE23/mWIFD2InYIXyzHroZWV3MF5WUk= +git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= +git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113181351-551195543805 h1:Okih7rAAjD8cpv7pi8QQc36mmp7SRBnOc7dc125GP/E= +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/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d h1:q/NO1rEgK3pia32D/tCq5hXfEuJp84COZRwceFvy/MM=