1
0
Fork 0
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.
helium-blockchain-exporter/heliumapi/hotspots.go

95 lines
2.4 KiB
Go
Raw Normal View History

package heliumapi
import (
"encoding/json"
"fmt"
"time"
)
2021-09-26 04:42:34 +00:00
// query https://docs.helium.com/api/blockchain/hotspots#hotspots-activity-counts
func GetHotspotActivityCounts(hotspot string) (*ActivityCounts, error) {
path := "/v1/hotspots/" + hotspot + "/activity/count"
// query the api
respBody, err := getHeliumApi(path, nil)
if err != nil {
return nil, err
}
// unmarshal the response
respobject := ActivityCountsResp{}
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)
}
return &respobject.Data, nil
}
2021-09-26 04:42:34 +00:00
// query https://docs.helium.com/api/blockchain/hotspots#reward-total-for-a-hotspot
func GetRewardsTotalForHotspot(hotspot string, minTime *time.Time, maxTime *time.Time) (*RewardTotal, error) {
path := "/v1/hotspots/" + hotspot + "/rewards/sum"
params := map[string]string{}
if minTime != nil {
2021-10-12 13:19:58 +00:00
params["min_time"] = minTime.UTC().Format(timeFormat)
}
if maxTime != nil {
2021-10-12 13:19:58 +00:00
params["max_time"] = maxTime.UTC().Format(timeFormat)
}
// query the api
respBody, err := getHeliumApi(path, &params)
if err != nil {
return nil, err
}
// unmarshal the response
respobject := RewardTotalResp{}
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)
}
return &respobject.Data, nil
}
2021-10-07 14:24:46 +00:00
// query https://docs.helium.com/api/blockchain/hotspots#witnesses-for-a-hotspot
2021-10-12 13:19:58 +00:00
func GetWitnessesForHotspot(hotspot string) ([]Hotspot, error) {
2021-10-07 14:24:46 +00:00
path := "/v1/hotspots/" + hotspot + "/witnesses"
// query the api
respBody, err := getHeliumApi(path, nil)
if err != nil {
return nil, err
}
// unmarshal the response
respobject := WitnessesResp{}
err = json.Unmarshal(respBody, &respobject)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
}
2021-10-12 13:19:58 +00:00
return respobject.Data, nil
2021-10-07 14:24:46 +00:00
}
// query https://docs.helium.com/api/blockchain/hotspots#witnessed-for-a-hotspot
2021-10-12 13:19:58 +00:00
func GetWitnessedForHotspot(hotspot string) ([]Hotspot, error) {
2021-10-07 14:24:46 +00:00
path := "/v1/hotspots/" + hotspot + "/witnessed"
// query the api
respBody, err := getHeliumApi(path, nil)
if err != nil {
return nil, err
}
// unmarshal the response
respobject := WitnessedResp{}
err = json.Unmarshal(respBody, &respobject)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal response from %v: %v", path, err)
}
2021-10-12 13:19:58 +00:00
return respobject.Data, nil
2021-10-07 14:24:46 +00:00
}