2021-09-17 20:45:01 +00:00
|
|
|
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) {
|
2021-09-17 20:45:01 +00:00
|
|
|
path := "/v1/hotspots/" + hotspot + "/activity/count"
|
|
|
|
|
|
|
|
// 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 := ActivityCountsResp{}
|
2021-09-17 20:45:01 +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-17 20:45:01 +00:00
|
|
|
}
|
|
|
|
|
2021-09-26 03:53:20 +00:00
|
|
|
return &respobject.Data, nil
|
2021-09-17 20:45:01 +00:00
|
|
|
}
|
|
|
|
|
2021-09-26 04:42:34 +00:00
|
|
|
// query https://docs.helium.com/api/blockchain/hotspots#reward-total-for-a-hotspot
|
2021-09-26 03:53:20 +00:00
|
|
|
func GetRewardsTotalForHotspot(hotspot string, minTime *time.Time, maxTime *time.Time) (*RewardTotal, error) {
|
2021-09-17 20:45:01 +00:00
|
|
|
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)
|
2021-09-17 20:45:01 +00:00
|
|
|
}
|
|
|
|
if maxTime != nil {
|
2021-10-12 13:19:58 +00:00
|
|
|
params["max_time"] = maxTime.UTC().Format(timeFormat)
|
2021-09-17 20:45:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// query the api
|
|
|
|
respBody, err := getHeliumApi(path, ¶ms)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmarshal the response
|
2021-09-26 03:38:16 +00:00
|
|
|
respobject := RewardTotalResp{}
|
2021-09-17 20:45:01 +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-17 20:45:01 +00:00
|
|
|
}
|
|
|
|
|
2021-09-26 03:53:20 +00:00
|
|
|
return &respobject.Data, nil
|
2021-09-17 20:45:01 +00:00
|
|
|
}
|
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
|
|
|
}
|