diff --git a/cmd/main.go b/cmd/main.go index af3237c..3fa5fe8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -43,8 +43,9 @@ func main() { menuStorageService := storage.NewMenuStorageService(connData, "") - eh := viseevent.NewEventsHandler(lookup.Api) - n := nats.NewNatsSubscription(menuStorageService, eh) + eu := viseevent.NewEventsUpdater(lookup.Api, menuStorageService) + eh := eu.ToEventsHandler() + n := nats.NewNatsSubscription(eh) err = n.Connect(ctx, config.JetstreamURL) if err != nil { fmt.Fprintf(os.Stderr, "Stream connect err: %v", err) diff --git a/event/nats/nats.go b/event/nats/nats.go index f735b9f..a3bf0b7 100644 --- a/event/nats/nats.go +++ b/event/nats/nats.go @@ -46,6 +46,8 @@ func NewNatsSubscription(handler *apievent.EventsHandler) *NatsSubscription { func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error { var err error + // enables set ctx in test, even if the connstr is invalid (js msg handler doesnt take context) + n.ctx = ctx n.conn, err = nats.Connect(connStr) if err != nil { return err @@ -67,7 +69,6 @@ func(n *NatsSubscription) Connect(ctx context.Context, connStr string) error { serverInfo := toServerInfo(n.conn) logg.DebugCtxf(ctx, "nats connected, starting consumer", "status", n.conn.Status(), "server", serverInfo) - n.ctx = ctx n.cctx, err = n.cs.Consume(n.handleEvent) if err != nil { return err diff --git a/event/nats/nats_test.go b/event/nats/nats_test.go index bfab5f8..dada6f0 100644 --- a/event/nats/nats_test.go +++ b/event/nats/nats_test.go @@ -145,6 +145,7 @@ func TestHandleMsg(t *testing.T) { eh := eu.ToEventsHandler() sub := NewNatsSubscription(eh) + _ = sub.Connect(ctx, "") data := fmt.Sprintf(`{ "block": %d, diff --git a/event/route.go b/event/route.go index f6b32af..bf806ef 100644 --- a/event/route.go +++ b/event/route.go @@ -34,11 +34,11 @@ func(r *Router) Route(ctx context.Context, gev *geEvent.Event) error { logg.DebugCtxf(ctx, "have event", "ev", gev) evCC, ok := asCustodialRegistrationEvent(gev) if ok { - return r.handler.Handle(ctx, apievent.EventTokenTransferTag, evCC) + return r.handler.Handle(ctx, apievent.EventRegistrationTag, evCC) } evTT, ok := asTokenTransferEvent(gev) if ok { - return r.handler.Handle(ctx, apievent.EventRegistrationTag, evTT) + return r.handler.Handle(ctx, apievent.EventTokenTransferTag, evTT) } return fmt.Errorf("unexpected message") diff --git a/go.mod b/go.mod index 283771d..f3457fb 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05 git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7 - git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113213915-63eb803022af + git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113220020-f67edfb5411d git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b github.com/grassrootseconomics/eth-tracker v1.3.0-rc github.com/grassrootseconomics/ussd-data-service v1.2.0-beta diff --git a/go.sum b/go.sum index e63472a..858c85d 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05 git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7 h1:P+Bi5jcQbnCrLnKNC5k8XDTBsocyZTVifqDyZY6d0w8= git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7/go.mod h1:X9aQF93xw3vcW2QftJfzLewvbotRM0U00DRtdmFw294= -git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113213915-63eb803022af h1:iwJ4iiF3Wbmkob++qCfj67URtdV2i6pdb9IkvmnBvQw= -git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113213915-63eb803022af/go.mod h1:1WryKcUnFI1J4Jl3wZJ4DX/7lnew+0PDY8xWvqc46UI= +git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113220020-f67edfb5411d h1:4nj54h7Fb/Rok6afR3wbMZPeNKKXr/1j0eYYSj/T2wk= +git.grassecon.net/grassrootseconomics/sarafu-vise v0.0.0-20250113220020-f67edfb5411d/go.mod h1:1WryKcUnFI1J4Jl3wZJ4DX/7lnew+0PDY8xWvqc46UI= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b h1:6SieNUSEKbkjzquuwazs/lVG56zdEWF10zQQEMRJfMs= git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U= github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=