Compare commits
22 Commits
master
...
route-api-
Author | SHA1 | Date | |
---|---|---|---|
58242c8d55 | |||
cab90ed89a | |||
73c3486400 | |||
3c84fb5ae7 | |||
04880b58a8 | |||
0458ac9498 | |||
a7e8c184f5 | |||
3615348efd | |||
d0be79d817 | |||
7883063e53 | |||
f562ce8adf | |||
cd2f4328a8 | |||
95b9a6e486 | |||
9674a04cbc | |||
6c46c097fb | |||
c814c4ae5c | |||
bbecec0310 | |||
eaa89c29df | |||
e832f46d22 | |||
039117f40e | |||
3532f72fbd | |||
04c7e20457 |
@ -21,7 +21,7 @@ RUN make VISE_PATH=/build/go-vise -B
|
||||
WORKDIR /build/sarafu-vise
|
||||
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
|
||||
RUN go mod download
|
||||
RUN go build -tags logdebug,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
|
||||
RUN go build -tags logwarn,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.grassecon.net/grassrootseconomics/sarafu-vise
|
||||
go 1.23.4
|
||||
|
||||
require (
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250401123711-d481b04a6805
|
||||
git.defalsify.org/vise.git v0.3.1
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.2
|
||||
|
2
go.sum
2
go.sum
@ -1,7 +1,5 @@
|
||||
git.defalsify.org/vise.git v0.3.1 h1:A6FhMcur09ft/JzUPGXR+KpA17fltfeBnasyvLMZmq4=
|
||||
git.defalsify.org/vise.git v0.3.1/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250401123711-d481b04a6805 h1:FnT39aqXcP5YWhwPDBABopSjCu2SlbPFoOVitSpAVxU=
|
||||
git.defalsify.org/vise.git v0.3.2-0.20250401123711-d481b04a6805/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b h1:xiTpaqWWoF5qcnarY/9ZkT6aVdnKwqztb2gzIahJn4w=
|
||||
|
@ -186,10 +186,16 @@ func (h *MenuHandlers) SetLanguage(ctx context.Context, sym string, input []byte
|
||||
// handles the account creation when no existing account is present for the session and stores associated data in the user data store.
|
||||
func (h *MenuHandlers) createAccountNoExist(ctx context.Context, sessionId string, res *resource.Result) error {
|
||||
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
|
||||
flag_account_creation_failed, _ := h.flagManager.GetFlag("flag_account_creation_failed")
|
||||
|
||||
r, err := h.accountService.CreateAccount(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
res.FlagSet = append(res.FlagSet, flag_account_creation_failed)
|
||||
logg.ErrorCtxf(ctx, "failed to create an account", "error", err)
|
||||
return nil
|
||||
}
|
||||
res.FlagReset = append(res.FlagReset, flag_account_creation_failed)
|
||||
|
||||
trackingId := r.TrackingId
|
||||
publicKey := r.PublicKey
|
||||
|
||||
@ -245,7 +251,6 @@ func (h *MenuHandlers) CreateAccount(ctx context.Context, sym string, input []by
|
||||
|
||||
func (h *MenuHandlers) CheckAccountCreated(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
flag_language_set, _ := h.flagManager.GetFlag("flag_language_set")
|
||||
flag_account_created, _ := h.flagManager.GetFlag("flag_account_created")
|
||||
|
||||
store := h.userdataStore
|
||||
@ -257,17 +262,11 @@ func (h *MenuHandlers) CheckAccountCreated(ctx context.Context, sym string, inpu
|
||||
|
||||
_, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
||||
if err != nil {
|
||||
if db.IsNotFound(err) {
|
||||
// reset major flags
|
||||
res.FlagReset = append(res.FlagReset, flag_language_set)
|
||||
res.FlagReset = append(res.FlagReset, flag_account_created)
|
||||
|
||||
return res, nil
|
||||
if !db.IsNotFound(err) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
res.FlagSet = append(res.FlagSet, flag_account_created)
|
||||
return res, nil
|
||||
}
|
||||
@ -494,6 +493,14 @@ func (h *MenuHandlers) ResetInvalidPIN(ctx context.Context, sym string, input []
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ResetApiCallFailure resets the api call failure flag
|
||||
func (h *MenuHandlers) ResetApiCallFailure(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ConfirmPinChange validates user's new PIN. If input matches the temporary PIN, saves it as the new account PIN.
|
||||
func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
@ -1410,7 +1417,7 @@ func (h *MenuHandlers) CheckAccountStatus(ctx context.Context, sym string, input
|
||||
if err != nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||
logg.ErrorCtxf(ctx, "failed on TrackAccountStatus", "error", err)
|
||||
return res, err
|
||||
return res, nil
|
||||
}
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||
@ -1576,6 +1583,7 @@ func (h *MenuHandlers) ValidateRecipient(ctx context.Context, sym string, input
|
||||
}
|
||||
flag_invalid_recipient, _ := h.flagManager.GetFlag("flag_invalid_recipient")
|
||||
flag_invalid_recipient_with_invite, _ := h.flagManager.GetFlag("flag_invalid_recipient_with_invite")
|
||||
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
|
||||
recipient := string(input)
|
||||
|
||||
@ -1649,10 +1657,13 @@ func (h *MenuHandlers) ValidateRecipient(ctx context.Context, sym string, input
|
||||
logg.InfoCtxf(ctx, "Resolving with fqdn alias", "alias", fqdn)
|
||||
AliasAddress, err = h.accountService.CheckAliasAddress(ctx, fqdn)
|
||||
if err == nil {
|
||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||
AliasAddressResult = AliasAddress.Address
|
||||
continue
|
||||
} else {
|
||||
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||
logg.ErrorCtxf(ctx, "failed to resolve alias", "alias", recipient, "error_alias_check", err)
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1967,6 +1978,7 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
}
|
||||
|
||||
flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher")
|
||||
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
|
||||
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
||||
if err != nil {
|
||||
@ -1977,9 +1989,10 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
// Fetch vouchers from API
|
||||
vouchersResp, err := h.accountService.FetchVouchers(ctx, string(publicKey))
|
||||
if err != nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_no_active_voucher)
|
||||
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||
return res, nil
|
||||
}
|
||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||
|
||||
if len(vouchersResp) == 0 {
|
||||
res.FlagSet = append(res.FlagSet, flag_no_active_voucher)
|
||||
@ -2190,6 +2203,7 @@ func (h *MenuHandlers) GetVoucherDetails(ctx context.Context, sym string, input
|
||||
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||
return res, nil
|
||||
}
|
||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||
|
||||
res.Content = fmt.Sprintf(
|
||||
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", voucherData.TokenName, voucherData.TokenSymbol, voucherData.TokenCommodity, voucherData.TokenLocation,
|
||||
@ -2223,6 +2237,7 @@ func (h *MenuHandlers) CheckTransactions(ctx context.Context, sym string, input
|
||||
logg.ErrorCtxf(ctx, "failed on FetchTransactions", "error", err)
|
||||
return res, err
|
||||
}
|
||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||
|
||||
// Return if there are no transactions
|
||||
if len(transactionsResp) == 0 {
|
||||
@ -2460,6 +2475,8 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
||||
return res, nil
|
||||
}
|
||||
|
||||
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||
|
||||
store := h.userdataStore
|
||||
aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
||||
if err != nil {
|
||||
@ -2483,9 +2500,12 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
||||
sanitizedInput := sanitizeAliasHint(string(input))
|
||||
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), sanitizedInput)
|
||||
if err != nil {
|
||||
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||
logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err)
|
||||
return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error())
|
||||
return res, nil
|
||||
}
|
||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||
|
||||
alias := aliasResult.Alias
|
||||
logg.InfoCtxf(ctx, "Suggested alias ", "alias", alias)
|
||||
|
||||
|
@ -201,6 +201,8 @@ func TestCreateAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
flag_account_created, err := fm.GetFlag("flag_account_created")
|
||||
flag_account_creation_failed, _ := fm.GetFlag("flag_account_creation_failed")
|
||||
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
@ -217,7 +219,8 @@ func TestCreateAccount(t *testing.T) {
|
||||
PublicKey: "0xD3adB33f",
|
||||
},
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_account_created},
|
||||
FlagSet: []uint32{flag_account_created},
|
||||
FlagReset: []uint32{flag_account_creation_failed},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -2002,6 +2005,11 @@ func TestManageVouchers(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
flag_no_active_voucher, err := fm.GetFlag("flag_no_active_voucher")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
flag_api_error, err := fm.GetFlag("flag_api_call_error")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -2025,7 +2033,8 @@ func TestManageVouchers(t *testing.T) {
|
||||
expectedVoucherSymbols: []byte(""),
|
||||
expectedUpdatedAddress: []byte(""),
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_no_active_voucher},
|
||||
FlagSet: []uint32{flag_no_active_voucher},
|
||||
FlagReset: []uint32{flag_api_error},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -2041,7 +2050,7 @@ func TestManageVouchers(t *testing.T) {
|
||||
expectedVoucherSymbols: []byte("1:TOKEN1"),
|
||||
expectedUpdatedAddress: []byte("0x123"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_no_active_voucher},
|
||||
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -2054,7 +2063,7 @@ func TestManageVouchers(t *testing.T) {
|
||||
expectedVoucherSymbols: []byte("1:SRF\n2:MILO"),
|
||||
expectedUpdatedAddress: []byte("0xd4c288865Ce"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_no_active_voucher},
|
||||
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -2205,6 +2214,8 @@ func TestGetVoucherDetails(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
|
||||
flag_api_error, _ := fm.GetFlag("flag_api_call_error")
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
sessionId := "session123"
|
||||
@ -2232,8 +2243,8 @@ func TestGetVoucherDetails(t *testing.T) {
|
||||
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation,
|
||||
)
|
||||
mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil)
|
||||
|
||||
res, err := h.GetVoucherDetails(ctx, "SessionId", []byte(""))
|
||||
expectedResult.FlagReset = append(expectedResult.FlagReset, flag_api_error)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedResult, res)
|
||||
}
|
||||
|
@ -128,6 +128,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias)
|
||||
ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias)
|
||||
ls.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated)
|
||||
ls.DbRs.AddLocalFunc("reset_api_call_failure", appHandlers.ResetApiCallFailure)
|
||||
|
||||
ls.first = appHandlers.Init
|
||||
|
||||
|
@ -612,7 +612,7 @@
|
||||
},
|
||||
{
|
||||
"input": "1234",
|
||||
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: \n\n0:Back\n9:Quit"
|
||||
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: Not Provided\n\n0:Back\n9:Quit"
|
||||
},
|
||||
{
|
||||
"input": "0",
|
||||
|
@ -6,7 +6,6 @@ MOUT back 0
|
||||
HALT
|
||||
LOAD validate_amount 64
|
||||
RELOAD validate_amount
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH invalid_amount flag_invalid_amount 1
|
||||
INCMP _ 0
|
||||
LOAD get_recipient 0
|
||||
|
@ -1 +1 @@
|
||||
Failed to connect to the custodial service.Please try again.
|
||||
Failed to connect to the custodial service .Please try again.
|
@ -1,5 +1,7 @@
|
||||
LOAD reset_api_call_failure 6
|
||||
RELOAD reset_api_call_failure
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP _ 1
|
||||
INCMP ^ 1
|
||||
INCMP quit 9
|
||||
|
1
services/registration/api_failure_swa
Normal file
1
services/registration/api_failure_swa
Normal file
@ -0,0 +1 @@
|
||||
Imeshindwa kuunganisha kwenye huduma ya uangalizi. Tafadhali jaribu tena.
|
@ -1,5 +1,6 @@
|
||||
LOAD check_transactions 0
|
||||
RELOAD check_transactions
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH no_transfers flag_no_transfers 1
|
||||
LOAD authorize_account 6
|
||||
MOUT back 0
|
||||
|
@ -2,6 +2,7 @@ LOAD clear_temporary_value 2
|
||||
RELOAD clear_temporary_value
|
||||
LOAD manage_vouchers 160
|
||||
RELOAD manage_vouchers
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
LOAD check_balance 128
|
||||
RELOAD check_balance
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
|
@ -5,4 +5,5 @@ HALT
|
||||
INCMP _ 0
|
||||
LOAD request_custom_alias 0
|
||||
RELOAD request_custom_alias
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
INCMP confirm_new_alias *
|
||||
|
@ -5,6 +5,7 @@ MOUT back 0
|
||||
HALT
|
||||
LOAD validate_recipient 50
|
||||
RELOAD validate_recipient
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH invalid_recipient flag_invalid_recipient 1
|
||||
CATCH invite_recipient flag_invalid_recipient_with_invite 1
|
||||
INCMP _ 0
|
||||
|
@ -1,5 +1,7 @@
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
LOAD get_voucher_details 0
|
||||
RELOAD get_voucher_details
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
MAP get_voucher_details
|
||||
MOUT back 0
|
||||
HALT
|
||||
|
Loading…
Reference in New Issue
Block a user