Compare commits
5 Commits
d76063261a
...
1964623daa
Author | SHA1 | Date | |
---|---|---|---|
1964623daa | |||
59ff44214d | |||
231967b120 | |||
fc1b9e5bfa | |||
e4ebb02b77 |
225
cmd/main.go
225
cmd/main.go
@ -24,11 +24,14 @@ 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 {
|
||||
@ -53,6 +56,14 @@ 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
|
||||
@ -262,6 +273,212 @@ 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")
|
||||
@ -287,7 +504,6 @@ func main() {
|
||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_SUCCESS, "ACCOUNT_SUCCESS")
|
||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_PENDING, "ACCOUNT_PENDING")
|
||||
|
||||
|
||||
rfs := resource.NewFsResource(scriptDir)
|
||||
ca := cache.NewCache()
|
||||
cfg := engine.Config{
|
||||
@ -327,6 +543,13 @@ func main() {
|
||||
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)
|
||||
|
||||
cont, err := en.Init(ctx)
|
||||
if err != nil {
|
||||
|
2
go-vise
2
go-vise
@ -1 +1 @@
|
||||
Subproject commit ef9a4c3073e7e878846693d4aa7fd0cf1cc977a7
|
||||
Subproject commit 1f47a674d95380be8c387f410f0342eb72357df5
|
2
services/registration/amount
Normal file
2
services/registration/amount
Normal file
@ -0,0 +1,2 @@
|
||||
Maximum amount: {{.max_amount}}
|
||||
Enter amount:
|
9
services/registration/amount.vis
Normal file
9
services/registration/amount.vis
Normal file
@ -0,0 +1,9 @@
|
||||
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
|
0
services/registration/amount_swa
Normal file
0
services/registration/amount_swa
Normal file
1
services/registration/invalid_recipient
Normal file
1
services/registration/invalid_recipient
Normal file
@ -0,0 +1 @@
|
||||
{{.validate_recipient}} is not registered or invalid, please try again:
|
7
services/registration/invalid_recipient.vis
Normal file
7
services/registration/invalid_recipient.vis
Normal file
@ -0,0 +1,7 @@
|
||||
MAP validate_recipient
|
||||
LOAD transaction_reset 0
|
||||
MOUT retry 1
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP send 1
|
||||
INCMP quit 9
|
1
services/registration/invalid_recipient_swa
Normal file
1
services/registration/invalid_recipient_swa
Normal file
@ -0,0 +1 @@
|
||||
{{.validate_recipient}} haijasajiliwa au sio sahihi, tafadhali weka tena:
|
@ -1,2 +1 @@
|
||||
Balance: 0.00 SRF
|
||||
|
||||
Balance: {{.check_balance}}
|
||||
|
@ -1,9 +1,15 @@
|
||||
LOAD check_identifier 64
|
||||
RELOAD check_identifier
|
||||
MAP check_identifier
|
||||
LOAD check_balance 64
|
||||
RELOAD check_balance
|
||||
MAP check_balance
|
||||
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: 0.00 SRF
|
||||
Salio: {{.check_balance}}
|
||||
|
@ -3,3 +3,4 @@ MOUT kiswahili 1
|
||||
HALT
|
||||
INCMP terms 0
|
||||
INCMP terms 1
|
||||
INCMP . *
|
||||
|
1
services/registration/send
Normal file
1
services/registration/send
Normal file
@ -0,0 +1 @@
|
||||
Enter recipient's phone number:
|
7
services/registration/send.vis
Normal file
7
services/registration/send.vis
Normal file
@ -0,0 +1,7 @@
|
||||
LOAD transaction_reset 0
|
||||
MOUT back 0
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
LOAD validate_recipient 0
|
||||
MAP validate_recipient
|
||||
MOVE amount
|
1
services/registration/send_swa
Normal file
1
services/registration/send_swa
Normal file
@ -0,0 +1 @@
|
||||
Weka nambari ya simu:
|
2
services/registration/transaction_pin
Normal file
2
services/registration/transaction_pin
Normal file
@ -0,0 +1,2 @@
|
||||
{{.get_recipient}} will receive {{.validate_amount}} from {{.get_sender}}
|
||||
Please enter your PIN to confirm:
|
11
services/registration/transaction_pin.vis
Normal file
11
services/registration/transaction_pin.vis
Normal file
@ -0,0 +1,11 @@
|
||||
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
|
2
services/registration/transaction_pin_swa
Normal file
2
services/registration/transaction_pin_swa
Normal file
@ -0,0 +1,2 @@
|
||||
{{.get_recipient}} atapokea {{.validate_amount}} kutoka kwa {{.get_sender}}
|
||||
Tafadhali weka PIN yako kudhibitisha:
|
Loading…
Reference in New Issue
Block a user