|
|
@ -26,7 +26,6 @@ const (
|
|
|
|
USERFLAG_ACCOUNT_UNLOCKED
|
|
|
|
USERFLAG_ACCOUNT_UNLOCKED
|
|
|
|
USERFLAG_INVALID_RECIPIENT
|
|
|
|
USERFLAG_INVALID_RECIPIENT
|
|
|
|
USERFLAG_INVALID_RECIPIENT_WITH_INVITE
|
|
|
|
USERFLAG_INVALID_RECIPIENT_WITH_INVITE
|
|
|
|
USERFLAG_INCORRECTPIN
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
@ -97,12 +96,24 @@ func (fsd *fsData) create_account(ctx context.Context, sym string, input []byte)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f.Close()
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
|
|
|
|
accountResp, err := createAccount()
|
|
|
|
// accountResp, err := createAccount()
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
fmt.Println("Failed to create account:", err)
|
|
|
|
// fmt.Println("Failed to create account:", err)
|
|
|
|
return res, err
|
|
|
|
// return res, err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accountResp := accountResponse{
|
|
|
|
|
|
|
|
Ok: true,
|
|
|
|
|
|
|
|
Result: struct {
|
|
|
|
|
|
|
|
CustodialId json.Number `json:"custodialId"`
|
|
|
|
|
|
|
|
PublicKey string `json:"publicKey"`
|
|
|
|
|
|
|
|
TrackingId string `json:"trackingId"`
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
CustodialId: "636",
|
|
|
|
|
|
|
|
PublicKey: "0x8d86F9D4A4eae41Dc3B68034895EA97BcA90e8c1",
|
|
|
|
|
|
|
|
TrackingId: "45c67314-7995-4890-89d6-e5af987754ac",
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
|
|
accountData := map[string]string{
|
|
|
|
accountData := map[string]string{
|
|
|
|
"TrackingId": accountResp.Result.TrackingId,
|
|
|
|
"TrackingId": accountResp.Result.TrackingId,
|
|
|
@ -120,7 +131,8 @@ func (fsd *fsData) create_account(ctx context.Context, sym string, input []byte)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.FlagSet = append(res.FlagSet, USERFLAG_ACCOUNT_CREATED)
|
|
|
|
|
|
|
|
|
|
|
|
res.FlagSet = []uint32{USERFLAG_ACCOUNT_CREATED}
|
|
|
|
return res, err
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -144,32 +156,15 @@ func (fsd *fsData) checkIdentifier(ctx context.Context, sym string, input []byte
|
|
|
|
return res, nil
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) unLock(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) unlock(ctx context.Context,sym string,input []byte) (resource.Result,error){
|
|
|
|
res := resource.Result{}
|
|
|
|
res := resource.Result{}
|
|
|
|
pin := string(input)
|
|
|
|
//res.FlagSet = []uint32{USERFLAG_ACCOUNT_UNLOCKED}
|
|
|
|
if len(input) > 0 {
|
|
|
|
|
|
|
|
if pin == "0000" {
|
|
|
|
|
|
|
|
res.FlagSet = append(res.FlagSet, USERFLAG_INCORRECTPIN)
|
|
|
|
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if fsd.st.MatchFlag(USERFLAG_ACCOUNT_UNLOCKED, false) {
|
|
|
|
if fsd.st.MatchFlag(USERFLAG_ACCOUNT_UNLOCKED, false) {
|
|
|
|
res.FlagSet = append(res.FlagSet, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
res.FlagSet = append(res.FlagSet, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) ResetIncorrectPin(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
|
|
|
res := resource.Result{}
|
|
|
|
|
|
|
|
isIncorrectPinSet := fsd.st.MatchFlag(USERFLAG_INCORRECTPIN, true)
|
|
|
|
|
|
|
|
if isIncorrectPinSet {
|
|
|
|
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_INCORRECTPIN)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_INCORRECTPIN)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return res,nil
|
|
|
|
return res,nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -205,6 +200,8 @@ func (fsd *fsData) check_account_status(ctx context.Context, sym string, input [
|
|
|
|
res.FlagSet = append(res.FlagReset,USERFLAG_ACCOUNT_PENDING)
|
|
|
|
res.FlagSet = append(res.FlagReset,USERFLAG_ACCOUNT_PENDING)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updatedJsonData, err := json.Marshal(accountData)
|
|
|
|
updatedJsonData, err := json.Marshal(accountData)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
return res, err
|
|
|
@ -264,9 +261,15 @@ func checkAccountStatus(trackingId string) (string, error) {
|
|
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) quit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
func (fsd *fsData) quit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
res := resource.Result{
|
|
|
|
res := resource.Result{
|
|
|
|
Content: "Your account is being created",
|
|
|
|
Content: "",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
st := fsd.st
|
|
|
|
|
|
|
|
if(st.MatchFlag(USERFLAG_ACCOUNT_UNLOCKED,true)){
|
|
|
|
|
|
|
|
//res.FlagReset = []uint32{USERFLAG_ACCOUNT_UNLOCKED}
|
|
|
|
|
|
|
|
// res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
|
|
|
|
}else {
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -476,42 +479,6 @@ func (fsd *fsData) get_sender(ctx context.Context, sym string, input []byte) (re
|
|
|
|
return res, nil
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) quitWithBalance(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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.Get(checkBalanceURL + accountData["PublicKey"])
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var balanceResp balanceResponse
|
|
|
|
|
|
|
|
err = json.Unmarshal(body, &balanceResp)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
balance := balanceResp.Result.Balance
|
|
|
|
|
|
|
|
res.Content = fmt.Sprintf("Your account balance is: %s", balance)
|
|
|
|
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
scriptDir = path.Join("services", "registration")
|
|
|
|
scriptDir = path.Join("services", "registration")
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -529,13 +496,12 @@ 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(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")
|
|
|
|
state.FlagDebugger.Register(USERFLAG_INCORRECTPIN, "INCORRECTPIN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rfs := resource.NewFsResource(scriptDir)
|
|
|
|
rfs := resource.NewFsResource(scriptDir)
|
|
|
|
ca := cache.NewCache()
|
|
|
|
ca := cache.NewCache()
|
|
|
@ -552,7 +518,6 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pr := persist.NewFsPersister(dp)
|
|
|
|
pr := persist.NewFsPersister(dp)
|
|
|
|
en, err := engine.NewPersistedEngine(ctx, cfg, pr, rfs)
|
|
|
|
en, err := engine.NewPersistedEngine(ctx, cfg, pr, rfs)
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
pr = pr.WithContent(&st, ca)
|
|
|
|
pr = pr.WithContent(&st, ca)
|
|
|
|
err = pr.Save(cfg.SessionId)
|
|
|
|
err = pr.Save(cfg.SessionId)
|
|
|
@ -575,7 +540,7 @@ func main() {
|
|
|
|
rfs.AddLocalFunc("create_account", fs.create_account)
|
|
|
|
rfs.AddLocalFunc("create_account", fs.create_account)
|
|
|
|
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)
|
|
|
@ -584,11 +549,8 @@ func main() {
|
|
|
|
rfs.AddLocalFunc("validate_amount", fs.validate_amount)
|
|
|
|
rfs.AddLocalFunc("validate_amount", fs.validate_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("quit_with_balance", fs.quitWithBalance)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cont, err := en.Init(ctx)
|
|
|
|
cont, err := en.Init(ctx)
|
|
|
|
en.SetDebugger(engine.NewSimpleDebug(nil))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
|
|
|
|
fmt.Fprintf(os.Stderr, "engine init exited with error: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
os.Exit(1)
|
|
|
|