wip-account-creation #4
49
cmd/main.go
49
cmd/main.go
@ -29,6 +29,7 @@ const (
|
||||
const (
|
||||
createAccountURL = "https://custodial.sarafu.africa/api/account/create"
|
||||
trackStatusURL = "https://custodial.sarafu.africa/api/track/"
|
||||
checkBalanceURL = "https://custodial.sarafu.africa/api/account/status/"
|
||||
)
|
||||
|
||||
type accountResponse struct {
|
||||
@ -53,6 +54,14 @@ type trackStatusResponse struct {
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
type balanceResponse struct {
|
||||
Ok bool `json:"ok"`
|
||||
Result struct {
|
||||
Balance string `json:"balance"`
|
||||
Nonce json.Number `json:"nonce"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
type fsData struct {
|
||||
path string
|
||||
st *state.State
|
||||
@ -262,6 +271,45 @@ func (fsd *fsData) quit(ctx context.Context, sym string, input []byte) (resourc
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (fsd *fsData) checkBalance(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
|
||||
Alfred-mk marked this conversation as resolved
Outdated
lash
commented
should error? should error?
lash
commented
priority **priority**
Alfred-mk
commented
The switch only takes in two options, 0 or 1. The switch only takes in two options, 0 or 1.
The menu remains on the select language node if an alternative input is provided
|
||||
}
|
||||
|
||||
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 = balance
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
var (
|
||||
scriptDir = path.Join("services", "registration")
|
||||
@ -327,6 +375,7 @@ func main() {
|
||||
rfs.AddLocalFunc("check_account_status", fs.check_account_status)
|
||||
rfs.AddLocalFunc("unlock_account", fs.unlock)
|
||||
rfs.AddLocalFunc("quit",fs.quit)
|
||||
rfs.AddLocalFunc("check_balance", fs.checkBalance)
|
||||
|
||||
cont, err := en.Init(ctx)
|
||||
if err != nil {
|
||||
|
2
go-vise
2
go-vise
@ -1 +1 @@
|
||||
Subproject commit ef9a4c3073e7e878846693d4aa7fd0cf1cc977a7
|
||||
Subproject commit 1f47a674d95380be8c387f410f0342eb72357df5
|
@ -1,2 +1 @@
|
||||
Balance: 0.00 SRF
|
||||
|
||||
Balance: {{.check_balance}}
|
||||
|
@ -1,9 +1,15 @@
|
||||
LOAD check_identifier 64
|
||||
RELOAD check_identifier
|
||||
MAP check_identifier
|
||||
LOAD check_balance 64
|
||||
RELOAD check_balance
|
||||
MAP check_balance
|
||||
MOUT send 1
|
||||
MOUT vouchers 2
|
||||
MOUT account 3
|
||||
MOUT help 4
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP send 1
|
||||
INCMP vouchers 2
|
||||
INCMP my_account 3
|
||||
INCMP help 4
|
||||
Alfred-mk marked this conversation as resolved
Outdated
lash
commented
not implemented, and state gets stuck if its chosen. At a minimum please add an immediate quit in such cases. not implemented, and state gets stuck if its chosen. At a minimum please add an immediate quit in such cases.
|
||||
INCMP quit 9
|
||||
INCMP . *
|
||||
|
@ -1 +1 @@
|
||||
Salio: 0.00 SRF
|
||||
Salio: {{.check_balance}}
|
||||
|
Loading…
Reference in New Issue
Block a user
this shouldnt switch on the input string; that requires manual syncing between here and the menu code.
how about using INCMP and the language switches on the sym instead?
Have a look at the
lash/reuse-example
go-vise branch, I've added an example that might illustrate.priority
I see this still isn't resolved.
I will make an issue of this, and mark it priority. We will handle it after merge.