retrieve transaction data and display the PIN page
This commit is contained in:
parent
59ff44214d
commit
1964623daa
86
cmd/main.go
86
cmd/main.go
@ -398,6 +398,88 @@ func(fsd *fsData) max_amount(ctx context.Context, sym string, input []byte) (res
|
|||||||
return res, nil
|
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 (
|
var (
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
)
|
)
|
||||||
@ -422,7 +504,6 @@ func main() {
|
|||||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_SUCCESS, "ACCOUNT_SUCCESS")
|
state.FlagDebugger.Register(USERFLAG_ACCOUNT_SUCCESS, "ACCOUNT_SUCCESS")
|
||||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_PENDING, "ACCOUNT_PENDING")
|
state.FlagDebugger.Register(USERFLAG_ACCOUNT_PENDING, "ACCOUNT_PENDING")
|
||||||
|
|
||||||
|
|
||||||
rfs := resource.NewFsResource(scriptDir)
|
rfs := resource.NewFsResource(scriptDir)
|
||||||
ca := cache.NewCache()
|
ca := cache.NewCache()
|
||||||
cfg := engine.Config{
|
cfg := engine.Config{
|
||||||
@ -466,6 +547,9 @@ func main() {
|
|||||||
rfs.AddLocalFunc("validate_recipient", fs.validate_recipient)
|
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)
|
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)
|
cont, err := en.Init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3,4 +3,7 @@ MAP max_amount
|
|||||||
MOUT back 0
|
MOUT back 0
|
||||||
HALT
|
HALT
|
||||||
INCMP ^ 0
|
INCMP ^ 0
|
||||||
INCMP quit *
|
LOAD validate_amount 0
|
||||||
|
LOAD get_recipient 12
|
||||||
|
LOAD get_sender 64
|
||||||
|
MOVE transaction_pin
|
||||||
|
@ -3,3 +3,4 @@ MOUT kiswahili 1
|
|||||||
HALT
|
HALT
|
||||||
INCMP terms 0
|
INCMP terms 0
|
||||||
INCMP terms 1
|
INCMP terms 1
|
||||||
|
INCMP . *
|
||||||
|
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