Compare commits
No commits in common. "1964623daa0d83005c54911d48ea4d068a7260d9" and "d76063261a0258db475b0360acd001067e673f44" have entirely different histories.
1964623daa
...
d76063261a
233
cmd/main.go
233
cmd/main.go
@ -24,14 +24,11 @@ const (
|
||||
USERFLAG_ACCOUNT_PENDING
|
||||
USERFLAG_ACCOUNT_SUCCESS
|
||||
USERFLAG_ACCOUNT_UNLOCKED
|
||||
invalidRecipient
|
||||
invalidRecipientWithInvite
|
||||
)
|
||||
|
||||
const (
|
||||
createAccountURL = "https://custodial.sarafu.africa/api/account/create"
|
||||
trackStatusURL = "https://custodial.sarafu.africa/api/track/"
|
||||
checkBalanceURL = "https://custodial.sarafu.africa/api/account/status/"
|
||||
)
|
||||
|
||||
type accountResponse struct {
|
||||
@ -56,14 +53,6 @@ type trackStatusResponse struct {
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
type balanceResponse struct {
|
||||
Ok bool `json:"ok"`
|
||||
Result struct {
|
||||
Balance string `json:"balance"`
|
||||
Nonce json.Number `json:"nonce"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
type fsData struct {
|
||||
path string
|
||||
st *state.State
|
||||
@ -273,212 +262,6 @@ func (fsd *fsData) quit(ctx context.Context, sym string, input []byte) (resourc
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (fsd *fsData) checkBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
res := resource.Result{}
|
||||
|
||||
fp := fsd.path + "_data"
|
||||
|
||||
jsonData, err := os.ReadFile(fp)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountData map[string]string
|
||||
err = json.Unmarshal(jsonData, &accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
resp, err := http.Get(checkBalanceURL + accountData["PublicKey"])
|
||||
if err != nil {
|
||||
return res, nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
var balanceResp balanceResponse
|
||||
err = json.Unmarshal(body, &balanceResp)
|
||||
if err != nil {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
balance := balanceResp.Result.Balance
|
||||
|
||||
res.Content = balance
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (fsd *fsData) validate_recipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
res := resource.Result{}
|
||||
recipient := string(input)
|
||||
|
||||
res.FlagReset = []uint32{invalidRecipient}
|
||||
res.FlagReset = []uint32{invalidRecipientWithInvite}
|
||||
|
||||
fp := fsd.path + "_data"
|
||||
|
||||
jsonData, err := os.ReadFile(fp)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountData map[string]string
|
||||
err = json.Unmarshal(jsonData, &accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// mimic invalid number check
|
||||
if recipient == "000" {
|
||||
res.FlagSet = []uint32{invalidRecipient}
|
||||
res.Content = recipient
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
accountData["Recipient"] = recipient
|
||||
|
||||
updatedJsonData, err := json.Marshal(accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
err = os.WriteFile(fp, updatedJsonData, 0644)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (fsd *fsData) transaction_reset(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
res := resource.Result{}
|
||||
fp := fsd.path + "_data"
|
||||
|
||||
jsonData, err := os.ReadFile(fp)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountData map[string]string
|
||||
err = json.Unmarshal(jsonData, &accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// reset the recipient
|
||||
accountData["Recipient"] = ""
|
||||
|
||||
updatedJsonData, err := json.Marshal(accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
err = os.WriteFile(fp, updatedJsonData, 0644)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.FlagReset = []uint32{invalidRecipient}
|
||||
res.FlagReset = []uint32{invalidRecipientWithInvite}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (fsd *fsData) max_amount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
res := resource.Result{}
|
||||
|
||||
// mimic a max amount
|
||||
res.Content = "10.00"
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (fsd *fsData) validate_amount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
res := resource.Result{}
|
||||
amount := string(input)
|
||||
|
||||
fp := fsd.path + "_data"
|
||||
|
||||
jsonData, err := os.ReadFile(fp)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountData map[string]string
|
||||
err = json.Unmarshal(jsonData, &accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// mimic invalid amount check
|
||||
if amount == "0" {
|
||||
// res.FlagSet = []uint32{invalidAmount}
|
||||
res.Content = amount
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
res.Content = amount
|
||||
|
||||
accountData["Amount"] = amount
|
||||
|
||||
updatedJsonData, err := json.Marshal(accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
err = os.WriteFile(fp, updatedJsonData, 0644)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (fsd *fsData) get_recipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
res := resource.Result{}
|
||||
fp := fsd.path + "_data"
|
||||
|
||||
jsonData, err := os.ReadFile(fp)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountData map[string]string
|
||||
err = json.Unmarshal(jsonData, &accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = accountData["Recipient"]
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (fsd *fsData) get_sender(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
res := resource.Result{}
|
||||
fp := fsd.path + "_data"
|
||||
|
||||
jsonData, err := os.ReadFile(fp)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var accountData map[string]string
|
||||
err = json.Unmarshal(jsonData, &accountData)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = accountData["PublicKey"]
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
var (
|
||||
scriptDir = path.Join("services", "registration")
|
||||
@ -500,9 +283,10 @@ func main() {
|
||||
st := state.NewState(7)
|
||||
st.UseDebug()
|
||||
state.FlagDebugger.Register(USERFLAG_LANGUAGE_SET, "LANGUAGE_CHANGE")
|
||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED, "ACCOUNT_CREATED")
|
||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_SUCCESS, "ACCOUNT_SUCCESS")
|
||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_PENDING, "ACCOUNT_PENDING")
|
||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED,"ACCOUNT_CREATED")
|
||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_SUCCESS,"ACCOUNT_SUCCESS")
|
||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_PENDING,"ACCOUNT_PENDING")
|
||||
|
||||
|
||||
rfs := resource.NewFsResource(scriptDir)
|
||||
ca := cache.NewCache()
|
||||
@ -542,14 +326,7 @@ func main() {
|
||||
rfs.AddLocalFunc("check_identifier", fs.checkIdentifier)
|
||||
rfs.AddLocalFunc("check_account_status", fs.check_account_status)
|
||||
rfs.AddLocalFunc("unlock_account", fs.unlock)
|
||||
rfs.AddLocalFunc("quit", fs.quit)
|
||||
rfs.AddLocalFunc("check_balance", fs.checkBalance)
|
||||
rfs.AddLocalFunc("validate_recipient", fs.validate_recipient)
|
||||
rfs.AddLocalFunc("transaction_reset", fs.transaction_reset)
|
||||
rfs.AddLocalFunc("max_amount", fs.max_amount)
|
||||
rfs.AddLocalFunc("validate_amount", fs.validate_amount)
|
||||
rfs.AddLocalFunc("get_recipient", fs.get_recipient)
|
||||
rfs.AddLocalFunc("get_sender", fs.get_sender)
|
||||
rfs.AddLocalFunc("quit",fs.quit)
|
||||
|
||||
cont, err := en.Init(ctx)
|
||||
if err != nil {
|
||||
|
2
go-vise
2
go-vise
@ -1 +1 @@
|
||||
Subproject commit 1f47a674d95380be8c387f410f0342eb72357df5
|
||||
Subproject commit ef9a4c3073e7e878846693d4aa7fd0cf1cc977a7
|
@ -1,2 +0,0 @@
|
||||
Maximum amount: {{.max_amount}}
|
||||
Enter amount:
|
@ -1,9 +0,0 @@
|
||||
LOAD max_amount 0
|
||||
MAP max_amount
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
LOAD validate_amount 0
|
||||
LOAD get_recipient 12
|
||||
LOAD get_sender 64
|
||||
MOVE transaction_pin
|
@ -1 +0,0 @@
|
||||
{{.validate_recipient}} is not registered or invalid, please try again:
|
@ -1,7 +0,0 @@
|
||||
MAP validate_recipient
|
||||
LOAD transaction_reset 0
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP send 1
|
||||
INCMP quit 9
|
@ -1 +0,0 @@
|
||||
{{.validate_recipient}} haijasajiliwa au sio sahihi, tafadhali weka tena:
|
@ -1 +1,2 @@
|
||||
Balance: {{.check_balance}}
|
||||
Balance: 0.00 SRF
|
||||
|
||||
|
@ -1,15 +1,9 @@
|
||||
LOAD check_balance 64
|
||||
RELOAD check_balance
|
||||
MAP check_balance
|
||||
LOAD check_identifier 64
|
||||
RELOAD check_identifier
|
||||
MAP check_identifier
|
||||
MOUT send 1
|
||||
MOUT vouchers 2
|
||||
MOUT account 3
|
||||
MOUT help 4
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP send 1
|
||||
INCMP vouchers 2
|
||||
INCMP my_account 3
|
||||
INCMP help 4
|
||||
INCMP quit 9
|
||||
INCMP . *
|
||||
|
@ -1 +1 @@
|
||||
Salio: {{.check_balance}}
|
||||
Salio: 0.00 SRF
|
||||
|
@ -3,4 +3,3 @@ MOUT kiswahili 1
|
||||
HALT
|
||||
INCMP terms 0
|
||||
INCMP terms 1
|
||||
INCMP . *
|
||||
|
@ -1 +0,0 @@
|
||||
Enter recipient's phone number:
|
@ -1,7 +0,0 @@
|
||||
LOAD transaction_reset 0
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
LOAD validate_recipient 0
|
||||
MAP validate_recipient
|
||||
MOVE amount
|
@ -1 +0,0 @@
|
||||
Weka nambari ya simu:
|
@ -1,2 +0,0 @@
|
||||
{{.get_recipient}} will receive {{.validate_amount}} from {{.get_sender}}
|
||||
Please enter your PIN to confirm:
|
@ -1,11 +0,0 @@
|
||||
RELOAD validate_amount
|
||||
MAP validate_amount
|
||||
RELOAD get_recipient
|
||||
MAP get_recipient
|
||||
RELOAD get_sender
|
||||
MAP get_sender
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
INCMP quit 9
|
@ -1,2 +0,0 @@
|
||||
{{.get_recipient}} atapokea {{.validate_amount}} kutoka kwa {{.get_sender}}
|
||||
Tafadhali weka PIN yako kudhibitisha:
|
Loading…
Reference in New Issue
Block a user