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

Function getHeight

plugin/go/tutorial/rpc_test.go:236–250  ·  view source on GitHub ↗

getHeight gets the current blockchain height using raw JSON

(rpcURL string)

Source from the content-addressed store, hash-verified

234
235// getHeight gets the current blockchain height using raw JSON
236func getHeight(rpcURL string) (uint64, error) {
237 respBody, err := postRawJSON(rpcURL+"/v1/query/height", "{}")
238 if err != nil {
239 return 0, err
240 }
241
242 var result struct {
243 Height uint64 `json:"height"`
244 }
245 if err := json.Unmarshal(respBody, &result); err != nil {
246 return 0, fmt.Errorf("failed to parse response: %v", err)
247 }
248
249 return result.Height, nil
250}
251
252// getAccountBalance gets the balance of an account using raw JSON
253func getAccountBalance(rpcURL, address string) (uint64, error) {

Callers 1

TestPluginTransactionsFunction · 0.70

Calls 3

postRawJSONFunction · 0.70
UnmarshalMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected