wip-account-creation #4
100
cmd/main.go
100
cmd/main.go
@ -313,7 +313,7 @@ func (fsd *fsData) checkBalance(ctx context.Context, sym string, input []byte) (
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(fsd *fsData) validate_recipient(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)
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ func(fsd *fsData) validate_recipient(ctx context.Context, sym string, input []by
|
|||||||
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"
|
fp := fsd.path + "_data"
|
||||||
|
|
||||||
@ -389,7 +389,7 @@ func(fsd *fsData) transaction_reset(ctx context.Context, sym string, input []byt
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(fsd *fsData) max_amount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (fsd *fsData) max_amount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
res := resource.Result{}
|
res := resource.Result{}
|
||||||
|
|
||||||
// mimic a max amount
|
// mimic a max amount
|
||||||
@ -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")
|
||||||
)
|
)
|
||||||
@ -418,10 +500,9 @@ func main() {
|
|||||||
st := state.NewState(7)
|
st := state.NewState(7)
|
||||||
st.UseDebug()
|
st.UseDebug()
|
||||||
state.FlagDebugger.Register(USERFLAG_LANGUAGE_SET, "LANGUAGE_CHANGE")
|
state.FlagDebugger.Register(USERFLAG_LANGUAGE_SET, "LANGUAGE_CHANGE")
|
||||||
state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED,"ACCOUNT_CREATED")
|
state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED, "ACCOUNT_CREATED")
|
||||||
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()
|
||||||
@ -461,11 +542,14 @@ func main() {
|
|||||||
rfs.AddLocalFunc("check_identifier", fs.checkIdentifier)
|
rfs.AddLocalFunc("check_identifier", fs.checkIdentifier)
|
||||||
rfs.AddLocalFunc("check_account_status", fs.check_account_status)
|
rfs.AddLocalFunc("check_account_status", fs.check_account_status)
|
||||||
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("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