diff --git a/args/lang.go b/args/lang.go index f9afdc9..68efe52 100644 --- a/args/lang.go +++ b/args/lang.go @@ -10,7 +10,7 @@ type LangVar struct { v []lang.Language } -func(lv *LangVar) Set(s string) error { +func (lv *LangVar) Set(s string) error { v, err := lang.LanguageFromCode(s) if err != nil { return err @@ -19,16 +19,14 @@ func(lv *LangVar) Set(s string) error { return err } -func(lv *LangVar) String() string { +func (lv *LangVar) String() string { var s []string - for _, v := range(lv.v) { + for _, v := range lv.v { s = append(s, v.Code) } return strings.Join(s, ",") } -func(lv *LangVar) Langs() []lang.Language { +func (lv *LangVar) Langs() []lang.Language { return lv.v } - - diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index a7156e9..942c4ad 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -12,18 +12,18 @@ import ( "syscall" "git.defalsify.org/vise.git/engine" - "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/lang" + "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/resource" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/visedriver/request" - - at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking" + "git.grassecon.net/grassrootseconomics/visedriver/storage" + "git.grassecon.net/grassrootseconomics/sarafu-vise/args" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" "git.grassecon.net/grassrootseconomics/sarafu-vise/services" + at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking" ) var ( @@ -118,7 +118,7 @@ func main() { } accountService := services.New(ctx, menuStorageService) - + hl, err := lhs.GetHandler(accountService) if err != nil { fmt.Fprintf(os.Stderr, "httpaccountservice: %v\n", err) diff --git a/cmd/async/main.go b/cmd/async/main.go index 5ad6be2..91bd3f1 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -14,12 +14,12 @@ import ( "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/resource" - "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/visedriver/request" - "git.grassecon.net/grassrootseconomics/sarafu-vise/services" "git.grassecon.net/grassrootseconomics/sarafu-vise/args" + "git.grassecon.net/grassrootseconomics/sarafu-vise/config" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" + "git.grassecon.net/grassrootseconomics/sarafu-vise/services" + "git.grassecon.net/grassrootseconomics/visedriver/request" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) var ( diff --git a/cmd/http/main.go b/cmd/http/main.go index 684720f..63a510a 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -17,13 +17,13 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - httprequest "git.grassecon.net/grassrootseconomics/visedriver/request/http" "git.grassecon.net/grassrootseconomics/visedriver/request" + httprequest "git.grassecon.net/grassrootseconomics/visedriver/request/http" "git.grassecon.net/grassrootseconomics/visedriver/storage" - "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/services" ) var ( @@ -116,7 +116,7 @@ func main() { } accountService := services.New(ctx, menuStorageService) - + hl, err := lhs.GetHandler(accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) diff --git a/cmd/main.go b/cmd/main.go index a137f27..08eb2f1 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -10,14 +10,14 @@ import ( "syscall" "git.defalsify.org/vise.git/engine" + "git.defalsify.org/vise.git/lang" "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/resource" - "git.defalsify.org/vise.git/lang" - "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/sarafu-vise/services" "git.grassecon.net/grassrootseconomics/sarafu-vise/args" + "git.grassecon.net/grassrootseconomics/sarafu-vise/config" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" + "git.grassecon.net/grassrootseconomics/sarafu-vise/services" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) var ( @@ -86,7 +86,7 @@ func main() { fmt.Fprintf(os.Stderr, "menu storage service error: %v\n", err) os.Exit(1) } - + if gettextDir != "" { menuStorageService = menuStorageService.WithGettext(gettextDir, langs.Langs()) } diff --git a/cmd/ssh/main.go b/cmd/ssh/main.go index 31d5f65..abc4ce5 100644 --- a/cmd/ssh/main.go +++ b/cmd/ssh/main.go @@ -111,13 +111,13 @@ func main() { signal.Notify(cterm, os.Interrupt, syscall.SIGTERM) runner := &ssh.SshRunner{ - Cfg: cfg, - Debug: engineDebug, - FlagFile: pfp, - Conn: conns, - SrvKeyFile: sshKeyFile, - Host: host, - Port: port, + Cfg: cfg, + Debug: engineDebug, + FlagFile: pfp, + Conn: conns, + SrvKeyFile: sshKeyFile, + Host: host, + Port: port, } go func() { select { diff --git a/config/args.go b/config/args.go index 9bf020e..4ba4bc8 100644 --- a/config/args.go +++ b/config/args.go @@ -5,10 +5,10 @@ import ( ) type Override struct { - DbConn *string - StateConn *string + DbConn *string + StateConn *string ResourceConn *string - UserConn *string + UserConn *string } func NewOverride() *Override { @@ -17,10 +17,10 @@ func NewOverride() *Override { var c string var d string o := &Override{ - DbConn: &a, - StateConn: &b, + DbConn: &a, + StateConn: &b, ResourceConn: &c, - UserConn: &d, + UserConn: &d, } return o } diff --git a/config/config.go b/config/config.go index 397c4c6..a8e5b3a 100644 --- a/config/config.go +++ b/config/config.go @@ -1,14 +1,14 @@ package config import ( - "git.grassecon.net/grassrootseconomics/visedriver/env" - viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config" apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config" + viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config" + "git.grassecon.net/grassrootseconomics/visedriver/env" ) var ( GetConns = viseconfig.GetConns - EnvPath string + EnvPath string ) func loadEnv() { @@ -20,10 +20,10 @@ func loadEnv() { } const ( - defaultSSHHost string = "127.0.0.1" - defaultSSHPort uint = 7122 + defaultSSHHost string = "127.0.0.1" + defaultSSHPort uint = 7122 defaultHTTPHost string = "127.0.0.1" - defaultHTTPPort uint = 7123 + defaultHTTPPort uint = 7123 ) func LoadConfig() error { diff --git a/debug/db.go b/debug/db.go index 3cfadba..15e54d1 100644 --- a/debug/db.go +++ b/debug/db.go @@ -1,11 +1,11 @@ package debug import ( - "fmt" "encoding/binary" + "fmt" - storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" visedb "git.defalsify.org/vise.git/db" + storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" ) var ( @@ -13,10 +13,10 @@ var ( ) type KeyInfo struct { - SessionId string - Typ uint8 - SubTyp storedb.DataTyp - Label string + SessionId string + Typ uint8 + SubTyp storedb.DataTyp + Label string Description string } @@ -53,12 +53,11 @@ func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) { k = k[2:] } - return o, nil } func subTypToString(v storedb.DataTyp) string { - return dbTypStr[v + visedb.DATATYPE_USERDATA + 1] + return dbTypStr[v+visedb.DATATYPE_USERDATA+1] } func typToString(v uint8) string { diff --git a/debug/db_debug.go b/debug/db_debug.go index 03be181..f781d9f 100644 --- a/debug/db_debug.go +++ b/debug/db_debug.go @@ -1,3 +1,4 @@ +//go:build debugdb // +build debugdb package debug @@ -11,37 +12,37 @@ import ( func init() { DebugCap |= 1 dbTypStr[db.DATATYPE_STATE] = "internal state" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TRACKING_ID] = "tracking id" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_PUBLIC_KEY] = "public key" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACCOUNT_PIN] = "account pin" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_FIRST_NAME] = "first name" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_FAMILY_NAME] = "family name" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_YOB] = "year of birth" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_LOCATION] = "location" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_GENDER] = "gender" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_OFFERINGS] = "offerings" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_RECIPIENT] = "recipient" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_AMOUNT] = "amount" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TEMPORARY_VALUE] = "temporary value" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACTIVE_SYM] = "active sym" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACTIVE_BAL] = "active bal" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_BLOCKED_NUMBER] = "blocked number" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_PUBLIC_KEY_REVERSE] = "public_key_reverse" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACTIVE_DECIMAL] = "active decimal" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACTIVE_ADDRESS] = "active address" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_INCORRECT_PIN_ATTEMPTS] = "incorrect pin attempts" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_SELECTED_LANGUAGE_CODE] = "selected language" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_INITIAL_LANGUAGE_CODE] = "initial language" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_VOUCHER_SYMBOLS] = "voucher symbols" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_VOUCHER_BALANCES] = "voucher balances" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_VOUCHER_DECIMALS] = "voucher decimals" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_VOUCHER_ADDRESSES] = "voucher addresses" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_SENDERS] = "tx senders" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_RECIPIENTS] = "tx recipients" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_VALUES] = "tx values" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_ADDRESSES] = "tx addresses" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_HASHES] = "tx hashes" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_DATES] = "tx dates" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_SYMBOLS] = "tx symbols" - dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_DECIMALS] = "tx decimals" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TRACKING_ID] = "tracking id" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_PUBLIC_KEY] = "public key" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACCOUNT_PIN] = "account pin" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_FIRST_NAME] = "first name" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_FAMILY_NAME] = "family name" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_YOB] = "year of birth" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_LOCATION] = "location" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_GENDER] = "gender" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_OFFERINGS] = "offerings" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_RECIPIENT] = "recipient" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_AMOUNT] = "amount" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TEMPORARY_VALUE] = "temporary value" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACTIVE_SYM] = "active sym" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACTIVE_BAL] = "active bal" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_BLOCKED_NUMBER] = "blocked number" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_PUBLIC_KEY_REVERSE] = "public_key_reverse" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACTIVE_DECIMAL] = "active decimal" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACTIVE_ADDRESS] = "active address" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_INCORRECT_PIN_ATTEMPTS] = "incorrect pin attempts" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_SELECTED_LANGUAGE_CODE] = "selected language" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_INITIAL_LANGUAGE_CODE] = "initial language" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_VOUCHER_SYMBOLS] = "voucher symbols" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_VOUCHER_BALANCES] = "voucher balances" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_VOUCHER_DECIMALS] = "voucher decimals" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_VOUCHER_ADDRESSES] = "voucher addresses" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_SENDERS] = "tx senders" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_RECIPIENTS] = "tx recipients" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_VALUES] = "tx values" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_ADDRESSES] = "tx addresses" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_HASHES] = "tx hashes" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_DATES] = "tx dates" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_SYMBOLS] = "tx symbols" + dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_DECIMALS] = "tx decimals" } diff --git a/debug/db_test.go b/debug/db_test.go index 4c89fa9..c7b8930 100644 --- a/debug/db_test.go +++ b/debug/db_test.go @@ -3,8 +3,8 @@ package debug import ( "testing" - storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" visedb "git.defalsify.org/vise.git/db" + storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" ) func TestDebugDbSubKeyInfo(t *testing.T) { @@ -24,7 +24,7 @@ func TestDebugDbSubKeyInfo(t *testing.T) { if r.SubTyp != 2 { t.Fatalf("expected 2, got %d", r.SubTyp) } - if DebugCap & 1 > 0 { + if DebugCap&1 > 0 { if r.Label != "tracking id" { t.Fatalf("expected 'tracking id', got '%s'", r.Label) } @@ -45,7 +45,7 @@ func TestDebugDbKeyInfo(t *testing.T) { if r.Typ != 16 { t.Fatalf("expected 16, got %d", r.Typ) } - if DebugCap & 1 > 0 { + if DebugCap&1 > 0 { if r.Label != "internal state" { t.Fatalf("expected 'internal_state', got '%s'", r.Label) } @@ -68,7 +68,7 @@ func TestDebugDbKeyInfoRestore(t *testing.T) { if r.Typ != 32 { t.Fatalf("expected 32, got %d", r.Typ) } - if DebugCap & 1 > 0 { + if DebugCap&1 > 0 { if r.Label != "active sym" { t.Fatalf("expected 'active sym', got '%s'", r.Label) } diff --git a/devtools/admin/main.go b/devtools/admin/main.go index 7508905..5e408c4 100644 --- a/devtools/admin/main.go +++ b/devtools/admin/main.go @@ -10,14 +10,14 @@ import ( "git.defalsify.org/vise.git/logging" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/sarafu-vise/internal/cmd" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application" + "git.grassecon.net/grassrootseconomics/sarafu-vise/internal/cmd" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) var ( - logg = logging.NewVanilla().WithContextKey("SessionId") - scriptDir = path.Join("services", "registration") + logg = logging.NewVanilla().WithContextKey("SessionId") + scriptDir = path.Join("services", "registration") ) func main() { diff --git a/devtools/lang/main.go b/devtools/lang/main.go index 6023927..4dd3090 100644 --- a/devtools/lang/main.go +++ b/devtools/lang/main.go @@ -8,18 +8,17 @@ import ( "path" "strings" - "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/lang" + "git.defalsify.org/vise.git/logging" "git.grassecon.net/grassrootseconomics/visedriver/config" ) const ( - changeHeadSrc = `LOAD reset_account_authorized 0 LOAD reset_incorrect 0 CATCH incorrect_pin flag_incorrect_pin 1 CATCH pin_entry flag_account_authorized 0 -` +` selectSrc = `LOAD set_language 6 RELOAD set_language @@ -29,8 +28,8 @@ MOVE language_changed ) var ( - logg = logging.NewVanilla() - mouts string + logg = logging.NewVanilla() + mouts string incmps string ) @@ -63,7 +62,7 @@ func main() { } logg.Tracef("using languages", "lang", config.Languages) - for i, v := range(config.Languages) { + for i, v := range config.Languages { ln, err := lang.LanguageFromCode(v) if err != nil { fmt.Fprintf(os.Stderr, "error parsing language: %s\n", v) @@ -76,7 +75,7 @@ func main() { incmps += fmt.Sprintf("INCMP %s %v\n", v, n) p := path.Join(srcDir, v) - w, err := os.OpenFile(p, os.O_WRONLY | os.O_CREATE | os.O_EXCL, 0600) + w, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600) if err != nil { fmt.Fprintf(os.Stderr, "failed open language set template output: %v\n", err) os.Exit(1) @@ -93,7 +92,7 @@ func main() { src += "INCMP . *\n" p := path.Join(srcDir, "select_language.vis") - w, err := os.OpenFile(p, os.O_WRONLY | os.O_CREATE | os.O_EXCL, 0600) + w, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600) if err != nil { fmt.Fprintf(os.Stderr, "failed open select language vis output: %v\n", err) os.Exit(1) @@ -107,7 +106,7 @@ func main() { src = changeHeadSrc + src p = path.Join(srcDir, "change_language.vis") - w, err = os.OpenFile(p, os.O_WRONLY | os.O_CREATE | os.O_EXCL, 0600) + w, err = os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600) if err != nil { fmt.Fprintf(os.Stderr, "failed open select language vis output: %v\n", err) os.Exit(1) diff --git a/devtools/store/dump/main.go b/devtools/store/dump/main.go index dcbc4c7..a748cd0 100644 --- a/devtools/store/dump/main.go +++ b/devtools/store/dump/main.go @@ -7,11 +7,11 @@ import ( "os" "path" - "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/sarafu-vise/debug" "git.defalsify.org/vise.git/db" "git.defalsify.org/vise.git/logging" + "git.grassecon.net/grassrootseconomics/sarafu-vise/config" + "git.grassecon.net/grassrootseconomics/sarafu-vise/debug" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) var ( diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index d59d927..5679ecd 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -273,7 +273,7 @@ func (h *MenuHandlers) CheckBlockedStatus(ctx context.Context, sym string, input } pinAttemptsValue, _ := strconv.ParseUint(string(currentWrongPinAttempts), 0, 64) - + if pinAttemptsValue == 0 { res.FlagReset = append(res.FlagReset, flag_account_blocked) return res, nil diff --git a/handlers/event/custodial.go b/handlers/event/custodial.go index bcab999..b01b93a 100644 --- a/handlers/event/custodial.go +++ b/handlers/event/custodial.go @@ -35,13 +35,6 @@ func (eu *EventsUpdater) HandleCustodialRegistration(ctx context.Context, ev *ap if err != nil { return err } -// err = pe.Load(identity.SessionId) -// if err != nil { -// return err -// } -// st := pe.GetState() -// st.SetFlag(accountCreatedFlag) -// return pe.Save(identity.SessionId) logg.DebugCtxf(ctx, "received custodial registration event", "identity", identity) return nil } diff --git a/handlers/event/event.go b/handlers/event/event.go index bacda01..e654820 100644 --- a/handlers/event/event.go +++ b/handlers/event/event.go @@ -4,12 +4,12 @@ import ( "context" "fmt" - "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/logging" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/sarafu-vise/store" - "git.grassecon.net/grassrootseconomics/sarafu-api/remote" + "git.defalsify.org/vise.git/persist" apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event" + "git.grassecon.net/grassrootseconomics/sarafu-api/remote" + "git.grassecon.net/grassrootseconomics/sarafu-vise/store" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) var ( @@ -17,9 +17,9 @@ var ( ) type EventsUpdater struct { - api remote.AccountService + api remote.AccountService formatFunc func(string, int, any) string - store storage.StorageService + store storage.StorageService } func NewEventsUpdater(api remote.AccountService, store storage.StorageService) *EventsUpdater { diff --git a/handlers/event/token.go b/handlers/event/token.go index ef85800..713dab7 100644 --- a/handlers/event/token.go +++ b/handlers/event/token.go @@ -6,13 +6,13 @@ import ( "strings" "git.defalsify.org/vise.git/db" - "git.grassecon.net/grassrootseconomics/sarafu-vise/store" - storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" "git.grassecon.net/grassrootseconomics/common/identity" apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event" + "git.grassecon.net/grassrootseconomics/sarafu-vise/store" + storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" ) -// execute all +// execute all func (eu *EventsUpdater) updateToken(ctx context.Context, identity identity.Identity, userStore *store.UserDataStore, tokenAddress string) error { err := eu.updateTokenList(ctx, identity, userStore) if err != nil { @@ -47,7 +47,6 @@ func (eu *EventsUpdater) updateToken(ctx context.Context, identity identity.Iden return nil } - // set default token to given symbol. func (eu *EventsUpdater) updateDefaultToken(ctx context.Context, identity identity.Identity, userStore *store.UserDataStore, activeSym string) error { pfxDb := toPrefixDb(userStore, identity.SessionId) @@ -59,7 +58,6 @@ func (eu *EventsUpdater) updateDefaultToken(ctx context.Context, identity identi return store.UpdateVoucherData(ctx, userStore, identity.SessionId, tokenData) } - // handle token transfer. // // if from and to are NOT the same, handle code will be executed once for each side of the transfer. @@ -189,7 +187,7 @@ func (eu *EventsUpdater) updateTokenTransferList(ctx context.Context, identity i return err } - for i, tx := range(txs) { + for i, tx := range txs { r = append(r, eu.formatFunc(apievent.EventTokenTransferTag, i, tx)) } diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index d693787..ac286c1 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -5,8 +5,8 @@ import ( "fmt" "git.defalsify.org/vise.git/logging" - "git.grassecon.net/grassrootseconomics/visedriver/storage" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) var ( @@ -14,17 +14,17 @@ var ( ) type Cmd struct { - sessionId string - conn storage.ConnData + sessionId string + conn storage.ConnData flagParser *application.FlagManager - cmd int - enable bool - exec func(ctx context.Context, ss storage.StorageService) error + cmd int + enable bool + exec func(ctx context.Context, ss storage.StorageService) error } func NewCmd(sessionId string, flagParser *application.FlagManager) *Cmd { return &Cmd{ - sessionId: sessionId, + sessionId: sessionId, flagParser: flagParser, } } @@ -94,5 +94,3 @@ func (c *Cmd) Parse(args []string) error { return fmt.Errorf("unknown subcommand: %s", cmd) } - - diff --git a/menutraversal_test/menu_traversal_test.go b/menutraversal_test/menu_traversal_test.go index 381a508..7d9e4f0 100644 --- a/menutraversal_test/menu_traversal_test.go +++ b/menutraversal_test/menu_traversal_test.go @@ -9,14 +9,14 @@ import ( "regexp" "testing" - "github.com/gofrs/uuid" "git.defalsify.org/vise.git/logging" - "git.grassecon.net/grassrootseconomics/visedriver/testutil/driver" "git.grassecon.net/grassrootseconomics/sarafu-vise/testutil" + "git.grassecon.net/grassrootseconomics/visedriver/testutil/driver" + "github.com/gofrs/uuid" ) var ( - logg = logging.NewVanilla().WithDomain("menutraversaltest") + logg = logging.NewVanilla().WithDomain("menutraversaltest") testData = driver.ReadData() sessionID string src = rand.NewSource(42) diff --git a/profile/profile.go b/profile/profile.go index 1804d97..f6a3e5d 100644 --- a/profile/profile.go +++ b/profile/profile.go @@ -12,7 +12,7 @@ func (p *Profile) InsertOrShift(index int, value string) { for len(p.ProfileItems) < index { p.ProfileItems = append(p.ProfileItems, "0") } - p.ProfileItems = append(p.ProfileItems, "0") + p.ProfileItems = append(p.ProfileItems, "0") p.ProfileItems[index] = value } } diff --git a/services/local.go b/services/local.go index 3f266a9..0101142 100644 --- a/services/local.go +++ b/services/local.go @@ -1,16 +1,17 @@ +//go:build !online // +build !online package services import ( - "fmt" "context" + "fmt" - "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-api/remote" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) type localEmitter struct { diff --git a/services/remote.go b/services/remote.go index 2d31217..e639e24 100644 --- a/services/remote.go +++ b/services/remote.go @@ -1,3 +1,4 @@ +//go:build online // +build online package services @@ -5,9 +6,9 @@ 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" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) func New(ctx context.Context, storageService storage.StorageService, conn storage.ConnData) remote.AccountService { diff --git a/ssh/keystore.go b/ssh/keystore.go index 1219e0d..37ebdef 100644 --- a/ssh/keystore.go +++ b/ssh/keystore.go @@ -29,7 +29,7 @@ func NewSshKeyStore(ctx context.Context, dbDir string) (*SshKeyStore, error) { return keyStore, nil } -func(s *SshKeyStore) AddFromFile(ctx context.Context, fp string, sessionId string) error { +func (s *SshKeyStore) AddFromFile(ctx context.Context, fp string, sessionId string) error { _, err := os.Stat(fp) if err != nil { return fmt.Errorf("cannot open ssh server public key file: %v\n", err) @@ -51,7 +51,7 @@ func(s *SshKeyStore) AddFromFile(ctx context.Context, fp string, sessionId strin return s.store.Put(ctx, k, []byte(sessionId)) } -func(s *SshKeyStore) Get(ctx context.Context, pubKey ssh.PublicKey) (string, error) { +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) @@ -63,6 +63,6 @@ func(s *SshKeyStore) Get(ctx context.Context, pubKey ssh.PublicKey) (string, err return string(v), nil } -func(s *SshKeyStore) Close(ctx context.Context) error { +func (s *SshKeyStore) Close(ctx context.Context) error { return s.store.Close(ctx) } diff --git a/ssh/ssh.go b/ssh/ssh.go index 530291d..81d7835 100644 --- a/ssh/ssh.go +++ b/ssh/ssh.go @@ -2,8 +2,8 @@ package ssh import ( "context" - "encoding/hex" "encoding/base64" + "encoding/hex" "errors" "fmt" "net" @@ -16,9 +16,9 @@ import ( "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/state" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/sarafu-vise/services" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" + "git.grassecon.net/grassrootseconomics/sarafu-vise/services" + "git.grassecon.net/grassrootseconomics/visedriver/storage" ) var ( @@ -26,32 +26,32 @@ var ( ) type auther struct { - Ctx context.Context + Ctx context.Context keyStore *SshKeyStore - auth map[string]string + auth map[string]string } func NewAuther(ctx context.Context, keyStore *SshKeyStore) *auther { return &auther{ - Ctx: ctx, + Ctx: ctx, keyStore: keyStore, - auth: make(map[string]string), + auth: make(map[string]string), } } -func(a *auther) Check(conn ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) { +func (a *auther) Check(conn ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) { logg.TraceCtxf(a.Ctx, "looking for publickey", "pubkey", fmt.Sprintf("%x", pubKey)) va, err := a.keyStore.Get(a.Ctx, pubKey) if err != nil { return nil, err } ka := hex.EncodeToString(conn.SessionID()) - a.auth[ka] = va + a.auth[ka] = va fmt.Fprintf(os.Stderr, "connect: %s -> %s\n", ka, va) return nil, nil } -func(a *auther) FromConn(c *ssh.ServerConn) (string, error) { +func (a *auther) FromConn(c *ssh.ServerConn) (string, error) { if c == nil { return "", errors.New("nil server conn") } @@ -61,8 +61,7 @@ func(a *auther) FromConn(c *ssh.ServerConn) (string, error) { return a.Get(c.Conn.SessionID()) } - -func(a *auther) Get(k []byte) (string, error) { +func (a *auther) Get(k []byte) (string, error) { ka := hex.EncodeToString(k) v, ok := a.auth[ka] if !ok { @@ -72,19 +71,19 @@ func(a *auther) Get(k []byte) (string, error) { } type SshRunner struct { - Ctx context.Context - Cfg engine.Config - FlagFile string - Conn storage.Conns - Debug bool + Ctx context.Context + Cfg engine.Config + FlagFile string + Conn storage.Conns + Debug bool SrvKeyFile string - Host string - Port uint - wg sync.WaitGroup - lst net.Listener + Host string + Port uint + wg sync.WaitGroup + lst net.Listener } -func(s *SshRunner) serve(ctx context.Context, sessionId string, ch ssh.NewChannel, en engine.Engine) error { +func (s *SshRunner) serve(ctx context.Context, sessionId string, ch ssh.NewChannel, en engine.Engine) error { if ch == nil { return errors.New("nil channel") } @@ -101,7 +100,7 @@ func(s *SshRunner) serve(ctx context.Context, sessionId string, ch ssh.NewChanne go func(reqIn <-chan *ssh.Request) { defer s.wg.Done() for req := range reqIn { - req.Reply(req.Type == "shell", nil) + req.Reply(req.Type == "shell", nil) } _ = requests }(requests) @@ -141,11 +140,11 @@ func(s *SshRunner) serve(ctx context.Context, sessionId string, ch ssh.NewChanne return nil } -func(s *SshRunner) Stop() error { +func (s *SshRunner) Stop() error { return s.lst.Close() } -func(s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) { +func (s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) { ctx := s.Ctx menuStorageService := storage.NewMenuStorageService(s.Conn) @@ -202,7 +201,7 @@ func(s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) { } // adapted example from crypto/ssh package, NewServerConn doc -func(s *SshRunner) Run(ctx context.Context, keyStore *SshKeyStore) { +func (s *SshRunner) Run(ctx context.Context, keyStore *SshKeyStore) { s.Ctx = ctx running := true @@ -255,7 +254,7 @@ func(s *SshRunner) Run(ctx context.Context, keyStore *SshKeyStore) { ssh.DiscardRequests(rC) s.wg.Done() }() - + sessionId, err := auth.FromConn(srvConn) if err != nil { logg.ErrorCtxf(ctx, "Cannot find authentication") diff --git a/store/tokens_test.go b/store/tokens_test.go index ca7ca47..b8c0082 100644 --- a/store/tokens_test.go +++ b/store/tokens_test.go @@ -3,8 +3,8 @@ package store import ( "testing" - "github.com/alecthomas/assert/v2" storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" + "github.com/alecthomas/assert/v2" ) func TestParseAndScaleAmount(t *testing.T) { diff --git a/store/user_store.go b/store/user_store.go index 70e2539..eea6d7e 100644 --- a/store/user_store.go +++ b/store/user_store.go @@ -4,10 +4,10 @@ import ( "context" visedb "git.defalsify.org/vise.git/db" - storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" - "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" "git.grassecon.net/grassrootseconomics/common/hex" "git.grassecon.net/grassrootseconomics/common/identity" + "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" + storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" ) // TODO: Rename interface, "datastore" is redundant naming and too general diff --git a/testutil/engine.go b/testutil/engine.go index 50af445..97c38a3 100644 --- a/testutil/engine.go +++ b/testutil/engine.go @@ -9,24 +9,24 @@ import ( "path/filepath" "time" - "github.com/jackc/pgx/v5/pgxpool" "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/resource" - "git.grassecon.net/grassrootseconomics/sarafu-vise/config" - "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" - "git.grassecon.net/grassrootseconomics/visedriver/storage" - "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice" "git.grassecon.net/grassrootseconomics/sarafu-api/remote" httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http" + "git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice" + "git.grassecon.net/grassrootseconomics/sarafu-vise/config" + "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers" "git.grassecon.net/grassrootseconomics/sarafu-vise/testutil/testtag" + "git.grassecon.net/grassrootseconomics/visedriver/storage" + "github.com/jackc/pgx/v5/pgxpool" ) // CleanDatabase removes all test data from the database func CleanDatabase() { - for _, v := range([]int8{ + for _, v := range []int8{ storage.STORETYPE_STATE, storage.STORETYPE_USER, - }) { + } { conn := conns[v] logg.Infof("cleaning test database", "typ", v, "db", conn) if conn.DbType() == storage.DBTYPE_POSTGRES { diff --git a/testutil/fsdb.go b/testutil/fsdb.go index 2f620b3..7482bd0 100644 --- a/testutil/fsdb.go +++ b/testutil/fsdb.go @@ -1,10 +1,10 @@ +//go:build testfsdb // +build testfsdb package testutil import ( "os" - ) const ( diff --git a/testutil/gdbmdb.go b/testutil/gdbmdb.go index 908f5bf..09e7dd5 100644 --- a/testutil/gdbmdb.go +++ b/testutil/gdbmdb.go @@ -1,10 +1,11 @@ +//go:build testgdbmdb // +build testgdbmdb package testutil import ( - "os" "net/url" + "os" ) const ( diff --git a/testutil/setup.go b/testutil/setup.go index 919641c..f57cc2b 100644 --- a/testutil/setup.go +++ b/testutil/setup.go @@ -4,21 +4,21 @@ import ( "context" "path" - testdataloader "github.com/peteole/testdata-loader" - "git.defalsify.org/vise.git/logging" - fsdb "git.defalsify.org/vise.git/db/fs" "git.defalsify.org/vise.git/db" - "git.grassecon.net/grassrootseconomics/visedriver/storage" + fsdb "git.defalsify.org/vise.git/db/fs" + "git.defalsify.org/vise.git/logging" "git.grassecon.net/grassrootseconomics/sarafu-vise/config" + "git.grassecon.net/grassrootseconomics/visedriver/storage" + testdataloader "github.com/peteole/testdata-loader" ) var ( - logg = logging.NewVanilla().WithDomain("sarafu-vise.testutil").WithContextKey("SessionId") - conns storage.Conns + logg = logging.NewVanilla().WithDomain("sarafu-vise.testutil").WithContextKey("SessionId") + conns storage.Conns resourceDb db.Db - baseDir = testdataloader.GetBasePath() - scriptDir = path.Join(baseDir, "services", "registration") - override config.Override + baseDir = testdataloader.GetBasePath() + scriptDir = path.Join(baseDir, "services", "registration") + override config.Override ) func init() { diff --git a/testutil/testtag/offlinetest.go b/testutil/testtag/offlinetest.go index ed23fc7..e0e44a6 100644 --- a/testutil/testtag/offlinetest.go +++ b/testutil/testtag/offlinetest.go @@ -1,3 +1,4 @@ +//go:build !online // +build !online package testtag diff --git a/testutil/testtag/onlinetest.go b/testutil/testtag/onlinetest.go index 4874810..23e803a 100644 --- a/testutil/testtag/onlinetest.go +++ b/testutil/testtag/onlinetest.go @@ -1,3 +1,4 @@ +//go:build online // +build online package testtag