-
Notifications
You must be signed in to change notification settings - Fork 4
/
coin_info.go
64 lines (52 loc) · 1.46 KB
/
coin_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package api
import (
"encoding/json"
"github.com/MinterTeam/minter-go-node/core/types"
"github.com/gorilla/mux"
"net/http"
)
type CoinInfoResponse struct {
Name string `json:"name"`
Symbol types.CoinSymbol `json:"symbol"`
Volume string `json:"volume"`
Crr uint `json:"crr"`
ReserveBalance string `json:"reserve_balance"`
}
func GetCoinInfo(w http.ResponseWriter, r *http.Request) {
cState, err := GetStateForRequest(r)
if err != nil {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusNotFound)
_ = json.NewEncoder(w).Encode(Response{
Code: 404,
Log: "State for given height not found",
})
return
}
vars := mux.Vars(r)
symbol := vars["symbol"]
var coinSymbol types.CoinSymbol
copy(coinSymbol[:], []byte(symbol))
coin := cState.GetStateCoin(coinSymbol)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
if coin == nil {
w.WriteHeader(http.StatusNotFound)
_ = json.NewEncoder(w).Encode(Response{
Code: 404,
Result: nil,
Log: "Coin not found",
})
return
}
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(Response{
Code: 0,
Result: CoinInfoResponse{
Name: coin.Data().Name,
Symbol: coin.Data().Symbol,
Volume: coin.Data().Volume.String(),
Crr: coin.Data().Crr,
ReserveBalance: coin.Data().ReserveBalance.String(),
},
})
}