save the recipient to the user data
This commit is contained in:
parent
231967b120
commit
59ff44214d
74
cmd/main.go
74
cmd/main.go
@ -313,19 +313,88 @@ func (fsd *fsData) checkBalance(ctx context.Context, sym string, input []byte) (
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(fsd *fsData) send_transaction(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func(fsd *fsData) validate_recipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
res := resource.Result{}
|
res := resource.Result{}
|
||||||
recipient := string(input)
|
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.FlagSet = []uint32{invalidRecipient}
|
||||||
res.Content = recipient
|
res.Content = recipient
|
||||||
|
|
||||||
return res, nil
|
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) {
|
func(fsd *fsData) transaction_reset(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
res := resource.Result{}
|
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{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
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,8 +463,9 @@ func main() {
|
|||||||
rfs.AddLocalFunc("unlock_account", fs.unlock)
|
rfs.AddLocalFunc("unlock_account", fs.unlock)
|
||||||
rfs.AddLocalFunc("quit",fs.quit)
|
rfs.AddLocalFunc("quit",fs.quit)
|
||||||
rfs.AddLocalFunc("check_balance", fs.checkBalance)
|
rfs.AddLocalFunc("check_balance", fs.checkBalance)
|
||||||
rfs.AddLocalFunc("send_transaction", fs.send_transaction)
|
rfs.AddLocalFunc("validate_recipient", fs.validate_recipient)
|
||||||
rfs.AddLocalFunc("transaction_reset", fs.transaction_reset)
|
rfs.AddLocalFunc("transaction_reset", fs.transaction_reset)
|
||||||
|
rfs.AddLocalFunc("max_amount", fs.max_amount)
|
||||||
|
|
||||||
cont, err := en.Init(ctx)
|
cont, err := en.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
2
services/registration/amount
Normal file
2
services/registration/amount
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Maximum amount: {{.max_amount}}
|
||||||
|
Enter amount:
|
6
services/registration/amount.vis
Normal file
6
services/registration/amount.vis
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
LOAD max_amount 0
|
||||||
|
MAP max_amount
|
||||||
|
MOUT back 0
|
||||||
|
HALT
|
||||||
|
INCMP ^ 0
|
||||||
|
INCMP quit *
|
0
services/registration/amount_swa
Normal file
0
services/registration/amount_swa
Normal file
@ -1 +1 @@
|
|||||||
{{.send_transaction}} is not registered or invalid, please try again:
|
{{.validate_recipient}} is not registered or invalid, please try again:
|
@ -1,4 +1,4 @@
|
|||||||
MAP send_transaction
|
MAP validate_recipient
|
||||||
LOAD transaction_reset 0
|
LOAD transaction_reset 0
|
||||||
MOUT retry 1
|
MOUT retry 1
|
||||||
MOUT quit 9
|
MOUT quit 9
|
||||||
|
@ -1 +1 @@
|
|||||||
{{.send_transaction}} haijasajiliwa au sio sahihi, tafadhali weka tena:
|
{{.validate_recipient}} haijasajiliwa au sio sahihi, tafadhali weka tena:
|
@ -2,6 +2,6 @@ LOAD transaction_reset 0
|
|||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
INCMP ^ 0
|
INCMP ^ 0
|
||||||
LOAD send_transaction 0
|
LOAD validate_recipient 0
|
||||||
MAP send_transaction
|
MAP validate_recipient
|
||||||
MOVE invalid_recipient
|
MOVE amount
|
||||||
|
Loading…
Reference in New Issue
Block a user