package heliumapi import ( "encoding/json" "fmt" "time" ) // query https://docs.helium.com/api/blockchain/blocks/#height func GetHeight(maxTime *time.Time) (int, error) { // TODO: the result of this query could be cached path := "/v1/blocks/height" params := map[string]string{} if maxTime != nil { params["max_time"] = maxTime.UTC().Format(time.RFC3339) } // query the api respBody, err := getHeliumApi(path, ¶ms) if err != nil { return -1, err } // unmarshal the response respobject := HeightResp{} err = json.Unmarshal(respBody, &respobject) if err != nil { return -1, fmt.Errorf("failed to unmarshal response from %v: %v", path, err) } return respobject.Data.Height, nil }