wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
6 changed files with 115 additions and 12 deletions
Showing only changes of commit 1964623daa - Show all commits

View File

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

View File

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

View File

@ -3,3 +3,4 @@ MOUT kiswahili 1
HALT HALT
INCMP terms 0 INCMP terms 0
INCMP terms 1 INCMP terms 1
INCMP . *

View File

@ -0,0 +1,2 @@
{{.get_recipient}} will receive {{.validate_amount}} from {{.get_sender}}
Please enter your PIN to confirm:

View 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

View File

@ -0,0 +1,2 @@
{{.get_recipient}} atapokea {{.validate_amount}} kutoka kwa {{.get_sender}}
Tafadhali weka PIN yako kudhibitisha: