Skip to content

Commit

Permalink
method for fetching the coins as a list
Browse files Browse the repository at this point in the history
  • Loading branch information
solipsis committed Jan 17, 2018
1 parent 4acbd5f commit 98991ea
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions shapeshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"strconv"
)
Expand Down Expand Up @@ -244,6 +245,32 @@ func TimeRemaining(addr string) (*TimeRemainingResponse, error) {
return &g, err
}

func CoinsAsList() ([]Coin, error) {
var coins []Coin
r, err := DoHttp("GET", "getcoins", "")
if err != nil {
return nil, err
}

// User json.RawMessage to delay marshalling to support arbitrary top level keys
var coinmap map[string]*json.RawMessage
if err := json.Unmarshal(r, &coinmap); err != nil {
return coins, err
}

for _, coinJSON := range coinmap {
var c Coin
err := json.Unmarshal([]byte(*coinJSON), &c)
if err != nil {
log.Println("Error unmarshalling coin:", err)
continue
}
coins = append(coins, c)
}

return coins, nil
}

func Coins() (*CoinsResponse, error) {
r, err := DoHttp("GET", "getcoins", "")
if err != nil {
Expand Down

0 comments on commit 98991ea

Please sign in to comment.