/
token.go
127 lines (106 loc) · 3.69 KB
/
token.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package types
import (
"encoding/json"
sdk "github.com/cosmos/cosmos-sdk/types"
)
type Token struct {
Description string `json:"description" v2:"description"` // e.g. "OK Group Global Utility Token"
Symbol string `json:"symbol" v2:"symbol"` // e.g. "okt"
OriginalSymbol string `json:"original_symbol" v2:"original_symbol"` // e.g. "OKT"
WholeName string `json:"whole_name" v2:"whole_name"` // e.g. "OKT"
OriginalTotalSupply sdk.Dec `json:"original_total_supply" v2:"original_total_supply"` // e.g. 1000000000.00000000
Type int `json:"type"` //e.g. 1 common token, 2 interest token
Owner sdk.AccAddress `json:"owner" v2:"owner"` // e.g. blockchain1hw4r48aww06ldrfeuq2v438ujnl6alsz0685a0
Mintable bool `json:"mintable" v2:"mintable"` // e.g. false
}
func (token Token) String() string {
b, err := json.Marshal(token)
if err != nil {
return "{}"
}
return string(b)
}
type TokenResp struct {
Description string `json:"description" v2:"description"`
Symbol string `json:"symbol" v2:"symbol"`
OriginalSymbol string `json:"original_symbol" v2:"original_symbol"`
WholeName string `json:"whole_name" v2:"whole_name"`
OriginalTotalSupply sdk.Dec `json:"original_total_supply" v2:"original_total_supply"`
Type int `json:"type"`
Owner sdk.AccAddress `json:"owner" v2:"owner"`
Mintable bool `json:"mintable" v2:"mintable"`
TotalSupply sdk.Dec `json:"total_supply" v2:"total_supply"`
}
func (token TokenResp) String() string {
b, err := json.Marshal(token)
if err != nil {
return "{}"
}
return string(b)
}
type Tokens []TokenResp
func (tokens Tokens) String() string {
b, err := json.Marshal(tokens)
if err != nil {
return "[{}]"
}
return string(b)
}
type Currency struct {
Description string `json:"description"`
Symbol string `json:"symbol"`
TotalSupply sdk.Dec `json:"total_supply"`
}
func (currency Currency) String() string {
b, err := json.Marshal(currency)
if err != nil {
return "[{}]"
}
return string(b)
}
type Transfer struct {
To string `json:"to"`
Amount string `json:"amount"`
}
type TransferUnit struct {
To sdk.AccAddress `json:"to"`
Coins sdk.SysCoins `json:"coins"`
}
type CoinsInfo []CoinInfo
func (d CoinsInfo) Len() int { return len(d) }
func (d CoinsInfo) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
func (d CoinsInfo) Less(i, j int) bool { return d[i].Symbol < d[j].Symbol }
type AccountResponse struct {
Address string `json:"address"`
Currencies CoinsInfo `json:"currencies"`
}
func NewAccountResponse(addr string) AccountResponse {
var accountResponse AccountResponse
accountResponse.Address = addr
accountResponse.Currencies = []CoinInfo{}
return accountResponse
}
type CoinInfo struct {
Symbol string `json:"symbol" v2:"currency"`
Available string `json:"available" v2:"available"`
Locked string `json:"locked" v2:"locked"`
}
func NewCoinInfo(symbol, available, locked string) *CoinInfo {
return &CoinInfo{
Symbol: symbol,
Available: available,
Locked: locked,
}
}
type AccountParam struct {
Symbol string `json:"symbol"`
Show string `json:"show"`
}
type AccountParamV2 struct {
Currency string `json:"currency"`
HideZero string `json:"hide_zero"`
}
type AccCoins struct {
Acc sdk.AccAddress `json:"address"`
Coins sdk.SysCoins `json:"coins"`
}