wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
8 changed files with 88 additions and 10 deletions
Showing only changes of commit 59ff44214d - Show all commits

View File

@ -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
}
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 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 {

View File

@ -0,0 +1,2 @@
Maximum amount: {{.max_amount}}
Enter amount:

View File

@ -0,0 +1,6 @@
LOAD max_amount 0
MAP max_amount
MOUT back 0
HALT
INCMP ^ 0
INCMP quit *

View File

View File

@ -1 +1 @@
{{.send_transaction}} is not registered or invalid, please try again: {{.validate_recipient}} is not registered or invalid, please try again:

View File

@ -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

View File

@ -1 +1 @@
{{.send_transaction}} haijasajiliwa au sio sahihi, tafadhali weka tena: {{.validate_recipient}} haijasajiliwa au sio sahihi, tafadhali weka tena:

View File

@ -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