MCPcopy
hub / github.com/canopy-network/canopy / getAccountBalance

Function getAccountBalance

plugin/go/tutorial/rpc_test.go:253–269  ·  view source on GitHub ↗

getAccountBalance gets the balance of an account using raw JSON

(rpcURL, address string)

Source from the content-addressed store, hash-verified

251
252// getAccountBalance gets the balance of an account using raw JSON
253func 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
272func waitForTxInclusion(rpcURL, senderAddr, txHash string, timeout time.Duration) (bool, error) {

Callers 1

TestPluginTransactionsFunction · 0.70

Calls 3

postRawJSONFunction · 0.70
UnmarshalMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected