diff --git a/exporter.go b/exporter.go index e204943..fa8104b 100644 --- a/exporter.go +++ b/exporter.go @@ -577,7 +577,7 @@ func (e *Exporter) collectHotspotMetrics(wg *sync.WaitGroup, ch chan<- prometheu func (e *Exporter) collectHotspotActivityMetrics(wg *sync.WaitGroup, ch chan<- prometheus.Metric, account *Account, hotspotData heliumapi.AccountHotspot) { defer wg.Done() - hotspotActivityForAddress, err := heliumapi.GetHotspotActivityCount(hotspotData.Address) + hotspotActivityForAddress, err := heliumapi.GetHotspotActivityCounts(hotspotData.Address) if err != nil { fmt.Println(err) return diff --git a/go.mod b/go.mod index dace333..d0a766e 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.29.0 // indirect - github.com/prometheus/exporter-toolkit v0.6.1 // indirect github.com/prometheus/procfs v0.6.0 // indirect golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect google.golang.org/protobuf v1.26.0-rc.1 // indirect diff --git a/heliumapi/accounts.go b/heliumapi/accounts.go index 67ad492..ca11bc0 100644 --- a/heliumapi/accounts.go +++ b/heliumapi/accounts.go @@ -8,6 +8,7 @@ import ( "github.com/helium-blockchain-exporter/heliumapi/activity" ) +// query https://docs.helium.com/api/blockchain/accounts#account-for-address func GetAccountForAddress(account string) (*Account, error) { path := "/v1/accounts/" + account @@ -27,6 +28,7 @@ func GetAccountForAddress(account string) (*Account, error) { return &respobject.Data, nil } +// query https://docs.helium.com/api/blockchain/accounts#activity-for-account func GetActivityForAccount(account string, filterTypes []string, minTime *time.Time, maxTime *time.Time) (*activity.Activities, error) { path := "/v1/accounts/" + account + "/activity" params := map[string]string{} @@ -57,6 +59,7 @@ func GetActivityForAccount(account string, filterTypes []string, minTime *time.T return activity.NewActivities(combinedResp) } +// query https://docs.helium.com/api/blockchain/accounts#activity-counts-for-account func GetActivityCountsForAccount(account string) (*ActivityCounts, error) { path := "/v1/accounts/" + account + "/activity/count" @@ -76,6 +79,7 @@ func GetActivityCountsForAccount(account string) (*ActivityCounts, error) { return &respobject.Data, nil } +// query https://docs.helium.com/api/blockchain/accounts#reward-totals-for-an-account func GetRewardTotalsForAccount(account string, minTime *time.Time, maxTime *time.Time) (*RewardTotal, error) { path := "/v1/accounts/" + account + "/rewards/sum" params := map[string]string{} @@ -102,6 +106,7 @@ func GetRewardTotalsForAccount(account string, minTime *time.Time, maxTime *time return &respobject.Data, nil } +// query https://docs.helium.com/api/blockchain/accounts#hotspots-for-account func GetHotspotsForAccount(account string) (*[]AccountHotspot, error) { path := "/v1/accounts/" + account + "/hotspots" diff --git a/heliumapi/activity/activities.go b/heliumapi/activity/activities.go index d6c76a9..1a36746 100644 --- a/heliumapi/activity/activities.go +++ b/heliumapi/activity/activities.go @@ -9,6 +9,11 @@ type ActivityResp struct { Data []json.RawMessage `json:"data"` } +// Parse the response from the activity api. +// The helium api return a list of of activities in an array with mixed type. +// In order to operate on the array, we determine the type using the "type" +// property, unmarshal the activity with the proper model, and add it to the proper +// array in an Activities structure. func NewActivities(resp ActivityResp) (*Activities, error) { type ActivityType struct { Type string `json:"type"` diff --git a/heliumapi/hotspots.go b/heliumapi/hotspots.go index 2cd630d..dba606e 100644 --- a/heliumapi/hotspots.go +++ b/heliumapi/hotspots.go @@ -6,7 +6,8 @@ import ( "time" ) -func GetHotspotActivityCount(hotspot string) (*ActivityCounts, error) { +// 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 @@ -25,6 +26,7 @@ func GetHotspotActivityCount(hotspot string) (*ActivityCounts, error) { return &respobject.Data, nil } +// 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{} diff --git a/heliumapi/oracleprices.go b/heliumapi/oracleprices.go index aaa9229..e59c848 100644 --- a/heliumapi/oracleprices.go +++ b/heliumapi/oracleprices.go @@ -5,6 +5,7 @@ import ( "fmt" ) +// query https://docs.helium.com/api/blockchain/oracle-prices#current-oracle-price func GetCurrentOraclePrice() (*CurrentOraclePrice, error) { path := "/v1/oracle/prices/current" diff --git a/heliumapi/query.go b/heliumapi/query.go index c0df6b9..a544a82 100644 --- a/heliumapi/query.go +++ b/heliumapi/query.go @@ -12,6 +12,7 @@ var ( client = &http.Client{} ) +// createGetRequest create a GET request to the helium api func createGetRequest(path string, params map[string]string) (*http.Request, error) { req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s", ApiUrl, path), nil) @@ -33,6 +34,7 @@ func createGetRequest(path string, params map[string]string) (*http.Request, err return req, err } +// getHeliumApi query a regular helium api endpoint func getHeliumApi(path string, params *map[string]string) ([]byte, error) { // if params is nil, set it to an empty map if params == nil { @@ -60,6 +62,9 @@ func getHeliumApi(path string, params *map[string]string) ([]byte, error) { return body, nil } +// getHeliumApiWithCursor query a helium api with a cursor +// It will continue to query the api until all the cursors are exhausted. Combine all the +// responses in a single object. func getHeliumApiWithCursor(path string, params *map[string]string) ([][]byte, error) { // if params is nil, set it to an empty map if params == nil { diff --git a/heliumapi/stats.go b/heliumapi/stats.go index bd50948..417a8c0 100644 --- a/heliumapi/stats.go +++ b/heliumapi/stats.go @@ -5,6 +5,7 @@ import ( "fmt" ) +// query https://docs.helium.com/api/blockchain/stats#blockchain-stats func GetBlockchainStats() (*BlockchainStats, error) { path := "/v1/stats"