Skip to content

Commit 9fc220a

Browse files
committed
Add /api/coinmarketcap endpoint
1 parent b2c1010 commit 9fc220a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

explorer.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ func buildSkycoinURL(path string, query url.Values) string {
124124
return u.String()
125125
}
126126

127+
type CoinSupply struct {
128+
// Coins distributed beyond the project:
129+
CurrentSupply string `json:"current_supply"`
130+
// TotalSupply is CurrentSupply plus coins held by the distribution addresses that are spendable
131+
TotalSupply string `json:"total_supply"`
132+
// MaxSupply is the maximum number of coins to be distributed ever
133+
MaxSupply string `json:"max_supply"`
134+
// CurrentCoinHourSupply is coins hours in non distribution addresses
135+
CurrentCoinHourSupply string `json:"current_coinhour_supply"`
136+
// TotalCoinHourSupply is coin hours in all addresses including unlocked distribution addresses
137+
TotalCoinHourSupply string `json:"total_coinhour_supply"`
138+
// Distribution addresses which count towards total supply
139+
UnlockedAddresses []string `json:"unlocked_distribution_addresses"`
140+
// Distribution addresses which are locked and do not count towards total supply
141+
LockedAddresses []string `json:"locked_distribution_addresses"`
142+
}
143+
127144
type APIEndpoint struct {
128145
ExplorerPath string `json:"explorer_path"`
129146
SkycoinPath string `json:"skycoin_path"`
@@ -163,6 +180,21 @@ func (s APIEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
163180
defer resp.Body.Close()
164181

165182
w.WriteHeader(resp.StatusCode)
183+
184+
if s.ExplorerPath == "/api/coinmarketcap" {
185+
w.Header().Set("Content-Type", "text/plain")
186+
var cs CoinSupply
187+
if err := json.NewDecoder(resp.Body).Decode(&cs); err != nil {
188+
msg := "Decode CoinSupply result failed"
189+
log.Println("ERROR:", msg, skycoinURL, err)
190+
http.Error(w, msg, http.StatusInternalServerError)
191+
return
192+
}
193+
194+
fmt.Fprintf(w, "%s", cs.CurrentSupply)
195+
return
196+
}
197+
166198
w.Header().Set("Content-Type", "application/json")
167199

168200
if n, err := io.Copy(w, resp.Body); err != nil {
@@ -205,6 +237,13 @@ var apiEndpoints = []APIEndpoint{
205237
]
206238
}`,
207239
},
240+
{
241+
ExplorerPath: "/api/coinmarketcap",
242+
SkycoinPath: "/coinSupply",
243+
Description: "Returns circulating supply coin number.",
244+
ExampleRequest: "/api/coinmarketcap",
245+
ExampleResponse: "7187500.000000",
246+
},
208247
{
209248
ExplorerPath: "/api/address",
210249
SkycoinPath: "/explorer/address",

0 commit comments

Comments
 (0)