getAccountBalance gets the balance of an account using raw JSON
(rpcURL, address string)
| 251 | |
| 252 | // getAccountBalance gets the balance of an account using raw JSON |
| 253 | func getAccountBalance(rpcURL, address string) (uint64, error) { |
| 254 | reqJSON := fmt.Sprintf(`{"address":"%s"}`, address) |
| 255 | |
| 256 | respBody, err := postRawJSON(rpcURL+"/v1/query/account", reqJSON) |
| 257 | if err != nil { |
| 258 | return 0, err |
| 259 | } |
| 260 | |
| 261 | var result struct { |
| 262 | Amount uint64 `json:"amount"` |
| 263 | } |
| 264 | if err := json.Unmarshal(respBody, &result); err != nil { |
| 265 | return 0, fmt.Errorf("failed to parse response: %v, body: %s", err, string(respBody)) |
| 266 | } |
| 267 | |
| 268 | return result.Amount, nil |
| 269 | } |
| 270 | |
| 271 | // waitForTxInclusion waits for a transaction to be included in a block |
| 272 | func waitForTxInclusion(rpcURL, senderAddr, txHash string, timeout time.Duration) (bool, error) { |
no test coverage detected