wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
Showing only changes of commit 9aedc5d48f - Show all commits

View File

@ -27,6 +27,8 @@ const (
USERFLAG_INVALID_RECIPIENT USERFLAG_INVALID_RECIPIENT
USERFLAG_INVALID_RECIPIENT_WITH_INVITE USERFLAG_INVALID_RECIPIENT_WITH_INVITE
USERFLAG_INCORRECTPIN USERFLAG_INCORRECTPIN
USERFLAG_UNLOCKFORUPDATE
USERFLAG_INVALID_AMOUNT
) )
const ( const (
@ -385,6 +387,39 @@ func (fsd *fsData) transaction_reset(ctx context.Context, sym string, input []by
return res, nil return res, nil
} }
func (fsd *fsData) reset_transaction_amount(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
}
// reset the amount
accountData["Amount"] = ""
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 = append(res.FlagReset, USERFLAG_INVALID_AMOUNT)
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{}
@ -411,9 +446,10 @@ func (fsd *fsData) validate_amount(ctx context.Context, sym string, input []byte
return res, err return res, err
} }
// mimic invalid amount check if amount != "0" {
if amount == "0" { // mimic invalid amount
// res.FlagSet = []uint32{invalidAmount} if amount == "00" {
res.FlagSet = append(res.FlagSet, USERFLAG_INVALID_AMOUNT)
res.Content = amount res.Content = amount
return res, nil return res, nil
@ -436,6 +472,9 @@ func (fsd *fsData) validate_amount(ctx context.Context, sym string, input []byte
return res, nil return res, nil
} }
return res, nil
}
func (fsd *fsData) get_recipient(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (fsd *fsData) get_recipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{} res := resource.Result{}
fp := fsd.path + "_data" fp := fsd.path + "_data"
@ -529,7 +568,7 @@ func main() {
fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir) fmt.Fprintf(os.Stderr, "starting session at symbol '%s' using resource dir: %s\n", root, dir)
ctx := context.Background() ctx := context.Background()
st := state.NewState(9) st := state.NewState(15)
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")
@ -582,6 +621,7 @@ func main() {
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("validate_amount", fs.validate_amount)
rfs.AddLocalFunc("reset_transaction_amount", fs.reset_transaction_amount)
rfs.AddLocalFunc("get_recipient", fs.get_recipient) rfs.AddLocalFunc("get_recipient", fs.get_recipient)
rfs.AddLocalFunc("get_sender", fs.get_sender) rfs.AddLocalFunc("get_sender", fs.get_sender)
rfs.AddLocalFunc("reset_incorrect", fs.ResetIncorrectPin) rfs.AddLocalFunc("reset_incorrect", fs.ResetIncorrectPin)