|
|
|
@ -34,7 +34,6 @@ const (
|
|
|
|
|
USERFLAG_QUERYPIN
|
|
|
|
|
USERFLAG_VALIDPIN
|
|
|
|
|
USERFLAG_INVALIDPIN
|
|
|
|
|
USERFLAG_UNLOCKFORUPDATE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
@ -88,193 +87,6 @@ func codeFromCtx(ctx context.Context) string {
|
|
|
|
|
return code
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) saveFirstName(cxt 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
|
|
|
|
|
}
|
|
|
|
|
if len(input) > 0 {
|
|
|
|
|
name := string(input)
|
|
|
|
|
accountData["FirstName"] = name
|
|
|
|
|
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) saveFamilyName(cxt 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
|
|
|
|
|
}
|
|
|
|
|
if len(input) > 0 {
|
|
|
|
|
//Save name
|
|
|
|
|
secondname := string(input)
|
|
|
|
|
fmt.Println("FamilyName:", secondname)
|
|
|
|
|
accountData["FamilyName"] = secondname
|
|
|
|
|
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) saveYOB(cxt 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
|
|
|
|
|
}
|
|
|
|
|
if len(input) > 0 {
|
|
|
|
|
yob := string(input)
|
|
|
|
|
fmt.Println("YOB", yob)
|
|
|
|
|
accountData["YOB"] = yob
|
|
|
|
|
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) saveLocation(cxt 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
|
|
|
|
|
}
|
|
|
|
|
if len(input) > 0 {
|
|
|
|
|
location := string(input)
|
|
|
|
|
fmt.Println("Location:", location)
|
|
|
|
|
accountData["Location"] = location
|
|
|
|
|
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) saveGender(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
|
|
|
|
|
}
|
|
|
|
|
if len(input) > 0 {
|
|
|
|
|
gender := string(input)
|
|
|
|
|
|
|
|
|
|
switch gender {
|
|
|
|
|
case "1" : gender = "Male"
|
|
|
|
|
case "2" : gender = "Female"
|
|
|
|
|
case "3" : gender = "Other"
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("gender", gender)
|
|
|
|
|
accountData["Gender"] = gender
|
|
|
|
|
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) saveOfferings(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
|
|
|
|
|
}
|
|
|
|
|
if len(input) > 0 {
|
|
|
|
|
offerings := string(input)
|
|
|
|
|
fmt.Println("Offerings:", offerings)
|
|
|
|
|
accountData["Offerings"] = offerings
|
|
|
|
|
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) SetLanguageSelected(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
inputStr := string(input)
|
|
|
|
|
res := resource.Result{}
|
|
|
|
@ -302,18 +114,7 @@ func (fsd *fsData) create_account(ctx context.Context, sym string, input []byte)
|
|
|
|
|
}
|
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
|
|
//accountResp, err := createAccount()
|
|
|
|
|
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",
|
|
|
|
|
}}
|
|
|
|
|
accountResp, err := createAccount()
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Failed to create account:", err)
|
|
|
|
@ -340,21 +141,6 @@ func (fsd *fsData) create_account(ctx context.Context, sym string, input []byte)
|
|
|
|
|
return res, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) resetUnlockForUpdate(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
res := resource.Result{}
|
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_UNLOCKFORUPDATE)
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) resetAccountUnlocked(ctx context.Context,sym string,input []byte) (resource.Result,error){
|
|
|
|
|
res := resource.Result{}
|
|
|
|
|
st := fsd.st
|
|
|
|
|
isSet := st.MatchFlag(USERFLAG_ACCOUNT_UNLOCKED,true)
|
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
|
fmt.Println("ISSET:",isSet)
|
|
|
|
|
return res,nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) checkIdentifier(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
res := resource.Result{}
|
|
|
|
|
fp := fsd.path + "_data"
|
|
|
|
@ -385,11 +171,9 @@ func (fsd *fsData) unLock(ctx context.Context, sym string, input []byte) (resour
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
if fsd.st.MatchFlag(USERFLAG_ACCOUNT_UNLOCKED, false) {
|
|
|
|
|
//res.FlagSet = append(res.FlagSet, USERFLAG_UNLOCKFORUPDATE)
|
|
|
|
|
res.FlagSet = append(res.FlagSet, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
|
} else {
|
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_UNLOCKED)
|
|
|
|
|
//res.FlagReset = append(res.FlagReset, USERFLAG_UNLOCKFORUPDATE)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res, nil
|
|
|
|
@ -406,11 +190,6 @@ func (fsd *fsData) ResetIncorrectPin(ctx context.Context, sym string, input []by
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) ShowUpdateSuccess(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
res := resource.Result{}
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) check_account_status(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
|
|
|
res := resource.Result{}
|
|
|
|
|
fp := fsd.path + "_data"
|
|
|
|
@ -435,7 +214,7 @@ func (fsd *fsData) check_account_status(ctx context.Context, sym string, input [
|
|
|
|
|
|
|
|
|
|
accountData["Status"] = status
|
|
|
|
|
|
|
|
|
|
if status == "REVERTED" {
|
|
|
|
|
if status == "SUCCESS" {
|
|
|
|
|
res.FlagSet = append(res.FlagSet, USERFLAG_ACCOUNT_SUCCESS)
|
|
|
|
|
res.FlagReset = append(res.FlagReset, USERFLAG_ACCOUNT_PENDING)
|
|
|
|
|
} else {
|
|
|
|
@ -735,35 +514,6 @@ func (fsd *fsData) get_recipient(ctx context.Context, sym string, input []byte)
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (fsd *fsData) getProfileInfo(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
|
|
|
|
|
}
|
|
|
|
|
name := accountData["FirstName"]
|
|
|
|
|
gender := accountData["Gender"]
|
|
|
|
|
age := accountData["YOB"]
|
|
|
|
|
location := accountData["Location"]
|
|
|
|
|
|
|
|
|
|
// Format the data into a string
|
|
|
|
|
formattedData := fmt.Sprintf("Name: %s\nGender: %s\nAge: %s\nLocation: %s\n", name, gender, age, location)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.Content = formattedData
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
@ -952,20 +702,7 @@ func main() {
|
|
|
|
|
rfs.AddLocalFunc("get_recipient", fs.get_recipient)
|
|
|
|
|
rfs.AddLocalFunc("get_sender", fs.get_sender)
|
|
|
|
|
rfs.AddLocalFunc("reset_incorrect", fs.ResetIncorrectPin)
|
|
|
|
|
rfs.AddLocalFunc("save_firstname", fs.saveFirstName)
|
|
|
|
|
rfs.AddLocalFunc("save_familyname", fs.saveFamilyName)
|
|
|
|
|
rfs.AddLocalFunc("save_gender", fs.saveGender)
|
|
|
|
|
rfs.AddLocalFunc("save_location", fs.saveLocation)
|
|
|
|
|
rfs.AddLocalFunc("save_yob", fs.saveYOB)
|
|
|
|
|
rfs.AddLocalFunc("save_offerings", fs.saveOfferings)
|
|
|
|
|
rfs.AddLocalFunc("quit_with_balance", fs.quitWithBalance)
|
|
|
|
|
rfs.AddLocalFunc("show_update_success", fs.ShowUpdateSuccess)
|
|
|
|
|
rfs.AddLocalFunc("reset_unlocked",fs.resetAccountUnlocked)
|
|
|
|
|
rfs.AddLocalFunc("reset_unlock_for_update", fs.resetUnlockForUpdate)
|
|
|
|
|
rfs.AddLocalFunc("get_profile_info",fs.getProfileInfo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cont, err := en.Init(ctx)
|
|
|
|
|
en.SetDebugger(engine.NewSimpleDebug(nil))
|
|
|
|
|