Skip to content

Commit

Permalink
fix: get-balance response parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
maharifu committed Sep 2, 2024
1 parent ae9a700 commit 9977d47
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ func getBalance(address string) (amount int64) {
cmd := exec.Command(
palomad,
"--node", rpcUrl,
"q", "bank", "balances",
"q", "bank", "balance",
"--output", "json",
"--chain-id", chainID,
address,
"ugrain",
)
res, err := cmd.CombinedOutput()

Expand All @@ -103,6 +104,11 @@ func getBalance(address string) (amount int64) {
if err != nil {
panic(err)
}

if balance.Amount == "" {
return 0
}

amount, err = strconv.ParseInt(balance.Amount, 10, 64)
if err != nil {
panic(err)
Expand Down Expand Up @@ -202,6 +208,7 @@ func createGetCoinsHandler(db *leveldb.DB) http.HandlerFunc {
return func(w http.ResponseWriter, request *http.Request) {
defer func() {
if err := recover(); err != nil {
fmt.Printf("req error: %v\n", err)
http.Error(w, err.(error).Error(), 400)
}
}()
Expand Down

0 comments on commit 9977d47

Please sign in to comment.