forked from urdt/ussd
Added main template and check balance
This commit is contained in:
parent
d76063261a
commit
e4ebb02b77
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
|
||||
}
|
||||
|
||||
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
|
||||
INCMP quit 9
|
||||
INCMP . *
|
||||
|
@ -1 +1 @@
|
||||
Salio: 0.00 SRF
|
||||
Salio: {{.check_balance}}
|
||||
|
Loading…
Reference in New Issue
Block a user