-
Notifications
You must be signed in to change notification settings - Fork 3
/
apiGetCoinInfo.go
68 lines (57 loc) · 2.1 KB
/
apiGetCoinInfo.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
65
66
67
68
package mintersdk
import (
//"encoding/json" -- переход на easyjson
"errors"
"fmt"
"io/ioutil"
"net/http"
"strconv"
)
//easyjson:json
type node_coininfo struct {
JSONRPC string `json:"jsonrpc"`
ID string `json:"id"`
Result CoinInfoResponse `json:"result"`
Error ErrorStruct `json:"error"`
}
type CoinInfoResponse struct {
Name string `json:"name" bson:"name" gorm:"name" db:"name"`
Symbol string `json:"symbol" bson:"symbol" gorm:"symbol" db:"symbol"`
VolumeTx string `json:"volume" bson:"-" gorm:"-" db:"-"`
Volume float32 `json:"volume_f32" bson:"volume_f32" gorm:"volume_f32" db:"volume_f32"`
CRRTx string `json:"crr" bson:"-" gorm:"-" db:"-"`
CRR int `json:"crr_i32" bson:"crr_i32" gorm:"crr_i32" db:"crr_i32"`
ReserveBalanceTx string `json:"reserve_balance" bson:"-" gorm:"-" db:"-"`
ReserveBalance float32 `json:"reserve_balance_f32" bson:"reserve_balance_f32" gorm:"reserve_balance_f32" db:"reserve_balance_f32"`
//Creator string `json:"creator" bson:"creator" gorm:"creator" db:"creator"` // TODO: del, нету
}
// получение доп.данных о монете: volume, reserve_balance
func (c *SDK) GetCoinInfo(coinSmbl string) (CoinInfoResponse, error) {
url := fmt.Sprintf("%s/coin_info?symbol=%s", c.MnAddress, coinSmbl)
res, err := http.Get(url)
if err != nil {
return CoinInfoResponse{}, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return CoinInfoResponse{}, err
}
var data node_coininfo
//json.Unmarshal(body, &data) -- переход на easyjson
err = data.UnmarshalJSON(body)
if err != nil {
panic(err)
}
if data.Error.Code != 0 {
err = errors.New(fmt.Sprint(data.Error.Code, " - ", data.Error.Message))
return CoinInfoResponse{}, err
}
data.Result.Volume = pipStr2bip_f32(data.Result.VolumeTx)
data.Result.ReserveBalance = pipStr2bip_f32(data.Result.ReserveBalanceTx)
data.Result.CRR, err = strconv.Atoi(data.Result.CRRTx)
if err != nil {
data.Result.CRR = 0
}
return data.Result, nil
}