This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
2021-09-13 03:25:47 +00:00
|
|
|
package heliumapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2021-09-26 04:42:34 +00:00
|
|
|
// query https://docs.helium.com/api/blockchain/stats#blockchain-stats
|
2021-09-26 03:53:20 +00:00
|
|
|
func GetBlockchainStats() (*BlockchainStats, error) {
|
2021-09-26 04:08:10 +00:00
|
|
|
path := "/v1/stats"
|
2021-09-13 03:25:47 +00:00
|
|
|
|
|
|
|
// query the api
|
|
|
|
respBody, err := getHeliumApi(path, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshal the response
|
2021-09-26 03:38:16 +00:00
|
|
|
respobject := BlockchainStatsResp{}
|
2021-09-13 03:25:47 +00:00
|
|
|
err = json.Unmarshal(respBody, &respobject)
|
|
|
|
if err != nil {
|
2021-09-26 04:08:10 +00:00
|
|
|
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
|
2021-09-13 03:25:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-26 03:53:20 +00:00
|
|
|
return &respobject.Data, nil
|
2021-09-13 03:25:47 +00:00
|
|
|
}
|