Compare commits

..

13 Commits

16 changed files with 127 additions and 70 deletions

View File

@ -22,9 +22,8 @@ import (
at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking"
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
)
var (
@ -121,7 +120,8 @@ func main() {
os.Exit(1)
}
accountService := &httpremote.HTTPAccountService{}
accountService := services.New(ctx, menuStorageService, connData)
hl, err := lhs.GetHandler(accountService)
if err != nil {
fmt.Fprintf(os.Stderr, "httpaccountservice: %v\n", err)

View File

@ -17,7 +17,7 @@ import (
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/visedriver/request"
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
)
@ -125,7 +125,8 @@ func main() {
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
lhs.SetDataStore(&userdataStore)
accountService := &httpremote.HTTPAccountService{}
accountService := services.New(ctx, menuStorageService, connData)
hl, err := lhs.GetHandler(accountService)
if err != nil {

View File

@ -21,7 +21,7 @@ import (
"git.grassecon.net/grassrootseconomics/visedriver/request"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
)
@ -116,7 +116,8 @@ func main() {
os.Exit(1)
}
accountService := &httpremote.HTTPAccountService{}
accountService := services.New(ctx, menuStorageService, connData)
hl, err := lhs.GetHandler(accountService)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
@ -130,6 +131,8 @@ func main() {
}
defer stateStore.Close()
//accountService := services.New(ctx, menuStorageService, connData)
rp := &httprequest.DefaultRequestParser{}
bsh := request.NewBaseRequestHandler(cfg, rs, stateStore, userdataStore, rp, hl)
sh := httprequest.NewHTTPRequestHandler(bsh)

View File

@ -13,13 +13,9 @@ import (
"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"
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
)
var (
@ -28,37 +24,9 @@ var (
menuSeparator = ": "
)
type devEmitter struct {
h *apievent.EventsHandler
}
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)
ev := tx.ToTransferEvent()
err = d.h.Handle(ctx, apievent.EventTokenTransferTag, &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.Handle(ctx, apievent.EventRegistrationTag, &ev)
}
return err
}
func main() {
config.LoadConfig()
var accountService remote.AccountService
var fakeDir string
var connStr string
var size uint
var sessionId string
@ -71,7 +39,6 @@ func main() {
flag.StringVar(&resourceDir, "resourcedir", scriptDir, "resource dir")
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&connStr, "c", "", "connection string")
flag.StringVar(&fakeDir, "fakedir", "", "if valid path, enables fake api with fsdb backend")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory")
@ -155,20 +122,7 @@ func main() {
os.Exit(1)
}
if fakeDir != "" {
svc := devremote.NewDevAccountService()
svc = svc.WithFs(ctx, fakeDir)
svc = svc.WithAutoVoucher(ctx, "FOO", 42)
eu := event.NewEventsUpdater(svc, menuStorageService)
emitter := &devEmitter{
h: eu.ToEventsHandler(),
}
svc = svc.WithEmitter(emitter.emit)
svc.AddVoucher(ctx, "BAR")
accountService = svc
} else {
accountService = &httpremote.HTTPAccountService{}
}
accountService := services.New(ctx, menuStorageService, connData)
hl, err := lhs.GetHandler(accountService)
if err != nil {
fmt.Fprintf(os.Stderr, "get accounts service handler: %v\n", err)

View File

@ -86,7 +86,7 @@ func main() {
cfg := engine.Config{
Root: "root",
OutputSize: uint32(size),
FlagCount: uint32(16),
FlagCount: uint32(128),
}
if stateDebug {
cfg.StateDebug = true

6
go.mod
View File

@ -3,10 +3,10 @@ module git.grassecon.net/grassrootseconomics/sarafu-vise
go 1.23.4
require (
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d
git.defalsify.org/vise.git v0.2.3-0.20250115000535-e2d329b3f739
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250114142051-9645a2af7bef
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250115072214-bca7c5de969f
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d
github.com/alecthomas/assert/v2 v2.2.2
github.com/gofrs/uuid v4.4.0+incompatible

12
go.sum
View File

@ -1,11 +1,11 @@
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.20250115000535-e2d329b3f739 h1:w7pj1oh7jXrfajahVYU7m7AfHst4C6jNVzDVoaqJ7e8=
git.defalsify.org/vise.git v0.2.3-0.20250115000535-e2d329b3f739/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
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-20250114142051-9645a2af7bef h1:ukxNTuI+MF6ic2SkRlc8ZjlnsTR8g6owuHkAvnQNY8A=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250114142051-9645a2af7bef/go.mod h1:BRIbXv0aulFWqR2XV87haWB4oNRlVEu8KyldLQsAroQ=
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=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250115072214-bca7c5de969f h1:FgccQi8vipX6dUt+GRiRDYHMR3UqC+plz73vw7y3fyU=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250115072214-bca7c5de969f/go.mod h1:tbA4whUGMUIDgQVdIW0sxWPuuXOvZRSny5zeku5hX4k=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63 h1:bX7klKZpX+ZZu1LKbtOXDAhV/KK0YwExehiIi0jusAM=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63/go.mod h1:Syw9TZyigPAM7t9FvicOm36iUnidt45f0SxzT2JniQ8=
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/go.mod h1:AH15xABcvaJr1TCGlih3oGSuwWC0E5IdbHQwuu+E1KI=
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=

View File

@ -2187,6 +2187,23 @@ func (h *MenuHandlers) resetIncorrectPINAttempts(ctx context.Context, sessionId
return nil
}
func (h *MenuHandlers) persistInitialLanguageCode(ctx context.Context, sessionId string, code string) error {
store := h.userdataStore
_, err := store.ReadEntry(ctx, sessionId, storedb.DATA_INITIAL_LANGUAGE_CODE)
if err == nil {
return nil
}
if !db.IsNotFound(err) {
return err
}
err = store.WriteEntry(ctx, sessionId, storedb.DATA_INITIAL_LANGUAGE_CODE, []byte(code))
if err != nil {
logg.ErrorCtxf(ctx, "failed to persist initial language code", "key", storedb.DATA_INITIAL_LANGUAGE_CODE, "value", code, "error", err)
return err
}
return nil
}
// persistLanguageCode persists the selected ISO 639 language code
func (h *MenuHandlers) persistLanguageCode(ctx context.Context, code string) error {
store := h.userdataStore
@ -2199,5 +2216,5 @@ func (h *MenuHandlers) persistLanguageCode(ctx context.Context, code string) err
logg.ErrorCtxf(ctx, "failed to persist language code", "key", storedb.DATA_SELECTED_LANGUAGE_CODE, "value", code, "error", err)
return err
}
return nil
return h.persistInitialLanguageCode(ctx, sessionId, code)
}

View File

@ -825,6 +825,17 @@ func TestSetLanguage(t *testing.T) {
// Assert that the Result FlagSet has the required flags after language switch
assert.Equal(t, res, tt.expectedResult, "Result should match expected result")
code, err := store.ReadEntry(ctx, sessionId, storedb.DATA_SELECTED_LANGUAGE_CODE)
if err != nil {
t.Error(err)
}
assert.Equal(t, string(code), tt.expectedResult.Content)
code, err = store.ReadEntry(ctx, sessionId, storedb.DATA_INITIAL_LANGUAGE_CODE)
if err != nil {
t.Error(err)
}
assert.Equal(t, string(code), "eng")
})
}
}

50
services/local.go Normal file
View File

@ -0,0 +1,50 @@
// +build !online
package services
import (
"fmt"
"context"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
devremote "git.grassecon.net/grassrootseconomics/sarafu-api/dev"
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
)
type localEmitter struct {
h *apievent.EventsHandler
}
func (d *localEmitter) 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")
}
ev := tx.ToTransferEvent()
err = d.h.Handle(ctx, apievent.EventTokenTransferTag, &ev)
} else if msg.Typ == apievent.EventRegistrationTag {
acc, ok := msg.Item.(devremote.Account)
if !ok {
return fmt.Errorf("not a valid tx")
}
ev := acc.ToRegistrationEvent()
err = d.h.Handle(ctx, apievent.EventRegistrationTag, &ev)
}
return err
}
func New(ctx context.Context, storageService storage.StorageService, conn storage.ConnData) remote.AccountService {
svc := devremote.NewDevAccountService(ctx, storageService)
svc = svc.WithAutoVoucher(ctx, "FOO", 42)
eu := event.NewEventsUpdater(svc, storageService)
emitter := &localEmitter{
h: eu.ToEventsHandler(),
}
svc = svc.WithEmitter(emitter.emit)
svc.AddVoucher(ctx, "BAR")
return svc
}

View File

@ -1 +1 @@
Your account is still being created.
Your account is still being created. For more help, please call: 0757628885

View File

@ -1 +1 @@
Akaunti yako bado inatengenezwa
Akaunti yako bado inatengenezwa. Kwa usaidizi zaidi, piga: 0757628885

15
services/remote.go Normal file
View File

@ -0,0 +1,15 @@
// +build online
package services
import (
"context"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
)
func New(ctx context.Context, storageService storage.StorageService, conn storage.ConnData) remote.AccountService {
return &httpremote.HTTPAccountService{}
}

View File

@ -44,6 +44,8 @@ func(s *SshKeyStore) AddFromFile(ctx context.Context, fp string, sessionId strin
return fmt.Errorf("Failed to parse public key: %v", err)
}
k := append([]byte{0x01}, pubKey.Marshal()...)
s.store.SetLanguage(nil)
s.store.SetSession("")
s.store.SetPrefix(storage.DATATYPE_EXTEND)
logg.Infof("Added key", "sessionId", sessionId, "public key", string(publicBytes))
return s.store.Put(ctx, k, []byte(sessionId))
@ -51,6 +53,7 @@ func(s *SshKeyStore) AddFromFile(ctx context.Context, fp string, sessionId strin
func(s *SshKeyStore) Get(ctx context.Context, pubKey ssh.PublicKey) (string, error) {
s.store.SetLanguage(nil)
s.store.SetSession("")
s.store.SetPrefix(storage.DATATYPE_EXTEND)
k := append([]byte{0x01}, pubKey.Marshal()...)
v, err := s.store.Get(ctx, k)

View File

@ -17,7 +17,7 @@ import (
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/state"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
)
@ -180,7 +180,8 @@ func(s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) {
}
// TODO: clear up why pointer here and by-value other cmds
accountService := &httpremote.HTTPAccountService{}
accountService := services.New(ctx, menuStorageService, s.Conn)
hl, err := lhs.GetHandler(accountService)
if err != nil {
return nil, nil, err

View File

@ -59,6 +59,8 @@ const (
DATA_INCORRECT_PIN_ATTEMPTS
//ISO 639 code for the selected language.
DATA_SELECTED_LANGUAGE_CODE
//ISO 639 code for the language initially selected.
DATA_INITIAL_LANGUAGE_CODE
)
const (