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

@ -59,8 +59,8 @@ type trackStatusResponse struct {
type balanceResponse struct {
Ok bool `json:"ok"`
Result struct {
Balance string `json:"balance"`
Nonce json.Number `json:"nonce"`
Balance string `json:"balance"`
Nonce json.Number `json:"nonce"`
} `json:"result"`
}
@ -313,7 +313,7 @@ func (fsd *fsData) checkBalance(ctx context.Context, sym string, input []byte) (
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{}
recipient := string(input)
@ -356,7 +356,7 @@ func(fsd *fsData) validate_recipient(ctx context.Context, sym string, input []by
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{}
fp := fsd.path + "_data"
@ -389,12 +389,94 @@ func(fsd *fsData) transaction_reset(ctx context.Context, sym string, input []byt
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{}
// mimic a max amount
res.Content = "10.00"
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
}
@ -418,10 +500,9 @@ func main() {
st := state.NewState(7)
st.UseDebug()
state.FlagDebugger.Register(USERFLAG_LANGUAGE_SET, "LANGUAGE_CHANGE")
state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED,"ACCOUNT_CREATED")
state.FlagDebugger.Register(USERFLAG_ACCOUNT_SUCCESS,"ACCOUNT_SUCCESS")
state.FlagDebugger.Register(USERFLAG_ACCOUNT_PENDING,"ACCOUNT_PENDING")
state.FlagDebugger.Register(USERFLAG_ACCOUNT_CREATED, "ACCOUNT_CREATED")
state.FlagDebugger.Register(USERFLAG_ACCOUNT_SUCCESS, "ACCOUNT_SUCCESS")
state.FlagDebugger.Register(USERFLAG_ACCOUNT_PENDING, "ACCOUNT_PENDING")
rfs := resource.NewFsResource(scriptDir)
ca := cache.NewCache()
@ -461,11 +542,14 @@ func main() {
rfs.AddLocalFunc("check_identifier", fs.checkIdentifier)
rfs.AddLocalFunc("check_account_status", fs.check_account_status)
rfs.AddLocalFunc("unlock_account", fs.unlock)
rfs.AddLocalFunc("quit",fs.quit)
rfs.AddLocalFunc("quit", fs.quit)
rfs.AddLocalFunc("check_balance", fs.checkBalance)
rfs.AddLocalFunc("validate_recipient", fs.validate_recipient)
rfs.AddLocalFunc("transaction_reset", fs.transaction_reset)
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)
if err != nil {

View File

@ -3,4 +3,7 @@ MAP max_amount
MOUT back 0
HALT
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
INCMP terms 0
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
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

This stops and gets stuck on correct pin put:

124125 will receive 22 from 0xA780F64fC93D8e78C20c4120f9E18AeEBeaD9631
Please enter your PIN to confirm:
0:Back
9:quit
1234
[I] engine:engine.go:173 new VM execution with input    input=1234
[D] engine:engine.go:182 start new VM run       code=0008015f0130000804717569740139
[T] vm:runner.go:81 new vm run
[D] vm:runner.go:113 execute code       opcode=8, op=INCMP, code=015f0130000804717569740139
[D] vm:runner.go:114 state=moves: 44 idx: 0 flags: 0x081b09 path: root/main/send/amount/transaction_pin lang: eng (English)
[T] vm:runner.go:361 testing sym        sym=_, input=31323334
[D] vm:runner.go:113 execute code       opcode=8, op=INCMP, code=04717569740139
[D] vm:runner.go:114 state=moves: 44 idx: 0 flags: 0x091b09 path: root/main/send/amount/transaction_pin lang: eng (English)
[T] vm:runner.go:361 testing sym        sym=quit, input=31323334
[T] vm:runner.go:200 no code remaining but not terminating
[D] vm:runner.go:113 execute code       opcode=6, op=MOVE, code=065f6361746368
[D] vm:runner.go:114 state=moves: 44 idx: 0 flags: 0x091b09 path: root/main/send/amount/transaction_pin lang: eng (English)
[T] engine:persist.go:47 that's a wrap  engine={0xc000140b00 0xc0000721a0}
[D] persist:fs.go:70 saved state and cache      key=aaaaa, bytecode=, flags=091b09
loop exited with error: unexpected termination: open /srv/git/grassrootseconomics/urdt-ussd.git/services/registration/_catch.bin: no such file or directory

exit status 1

This stops and gets stuck on correct pin put: ``` 124125 will receive 22 from 0xA780F64fC93D8e78C20c4120f9E18AeEBeaD9631 Please enter your PIN to confirm: 0:Back 9:quit 1234 [I] engine:engine.go:173 new VM execution with input input=1234 [D] engine:engine.go:182 start new VM run code=0008015f0130000804717569740139 [T] vm:runner.go:81 new vm run [D] vm:runner.go:113 execute code opcode=8, op=INCMP, code=015f0130000804717569740139 [D] vm:runner.go:114 state=moves: 44 idx: 0 flags: 0x081b09 path: root/main/send/amount/transaction_pin lang: eng (English) [T] vm:runner.go:361 testing sym sym=_, input=31323334 [D] vm:runner.go:113 execute code opcode=8, op=INCMP, code=04717569740139 [D] vm:runner.go:114 state=moves: 44 idx: 0 flags: 0x091b09 path: root/main/send/amount/transaction_pin lang: eng (English) [T] vm:runner.go:361 testing sym sym=quit, input=31323334 [T] vm:runner.go:200 no code remaining but not terminating [D] vm:runner.go:113 execute code opcode=6, op=MOVE, code=065f6361746368 [D] vm:runner.go:114 state=moves: 44 idx: 0 flags: 0x091b09 path: root/main/send/amount/transaction_pin lang: eng (English) [T] engine:persist.go:47 that's a wrap engine={0xc000140b00 0xc0000721a0} [D] persist:fs.go:70 saved state and cache key=aaaaa, bytecode=, flags=091b09 loop exited with error: unexpected termination: open /srv/git/grassrootseconomics/urdt-ussd.git/services/registration/_catch.bin: no such file or directory exit status 1 ```
INCMP quit 9

View File

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