-
Notifications
You must be signed in to change notification settings - Fork 26
/
chain.go
331 lines (320 loc) · 10.1 KB
/
chain.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package bot
import (
"context"
"encoding/json"
"time"
)
const (
BitcoinChainId = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
BitcoinCashChainId = "fd11b6e3-0b87-41f1-a41f-f0e9b49e5bf0"
BitcoinSVChainId = "574388fd-b93f-4034-a682-01c2bc095d17"
LitecoinChainId = "76c802a2-7c88-447f-a93e-c29c9e5dd9c8"
EthereumChainId = "43d61dcd-e413-450d-80b8-101d5e903357"
EthereumClassicChainId = "2204c1ee-0ea2-4add-bb9a-b3719cfff93a"
BSCChainId = "1949e683-6a08-49e2-b087-d6b72398588f"
PolygonChainId = "b7938396-3f94-4e0a-9179-d3440718156f"
BaseChainId = "3fb612c5-6844-3979-ae4a-5a84e79da870"
MVMChainId = "a0ffd769-5850-4b48-9651-d2ae44a3e64d"
DecredChainId = "8f5caf2a-283d-4c85-832a-91e83bbf290b"
RippleChainId = "23dfb5a5-5d7b-48b6-905f-3970e3176e27"
SiacoinChainId = "990c4c29-57e9-48f6-9819-7d986ea44985"
EOSChainId = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d"
DogecoinChainId = "6770a1e5-6086-44d5-b60f-545f9d9e8ffd"
DashChainId = "6472e7e3-75fd-48b6-b1dc-28d294ee1476"
ZcashChainId = "c996abc9-d94e-4494-b1cf-2a3fd3ac5714"
NEMChainId = "27921032-f73e-434e-955f-43d55672ee31"
ArweaveChainId = "882eb041-64ea-465f-a4da-817bd3020f52"
HorizenChainId = "a2c5d22b-62a2-4c13-b3f0-013290dbac60"
TRONChainId = "25dabac5-056a-48ff-b9f9-f67395dc407c"
StellarChainId = "56e63c06-b506-4ec5-885a-4a5ac17b83c1"
MassGridChainId = "b207bce9-c248-4b8e-b6e3-e357146f3f4c"
BytomChainId = "443e1ef5-bc9b-47d3-be77-07f328876c50"
BytomPoSChainId = "71a0e8b5-a289-4845-b661-2b70ff9968aa"
CosmosChainId = "7397e9f1-4e42-4dc8-8a3b-171daaadd436"
AkashChainId = "9c612618-ca59-4583-af34-be9482f5002d"
BinanceChainId = "17f78d7c-ed96-40ff-980c-5dc62fecbc85"
MoneroChainId = "05c5ac01-31f9-4a69-aa8a-ab796de1d041"
StarcoinChainId = "c99a3779-93df-404d-945d-eddc440aa0b2"
BitSharesChainId = "05891083-63d2-4f3d-bfbe-d14d7fb9b25a"
RavencoinChainId = "6877d485-6b64-4225-8d7e-7333393cb243"
GrinChainId = "1351e6bd-66cf-40c1-8105-8a8fe518a222"
VCashChainId = "c3b9153a-7fab-4138-a3a4-99849cadc073"
HandshakeChainId = "13036886-6b83-4ced-8d44-9f69151587bf"
NervosChainId = "d243386e-6d84-42e6-be03-175be17bf275"
TezosChainId = "5649ca42-eb5f-4c0e-ae28-d9a4e77eded3"
NamecoinChainId = "f8b77dc0-46fd-4ea1-9821-587342475869"
SolanaChainId = "64692c23-8971-4cf4-84a7-4dd1271dd887"
NearChainId = "d6ac94f7-c932-4e11-97dd-617867f0669e"
FilecoinChainId = "08285081-e1d8-4be6-9edc-e203afa932da"
MobileCoinChainId = "eea900a8-b327-488c-8d8d-1428702fe240"
PolkadotChainId = "54c61a72-b982-4034-a556-0d99e3c21e39"
KusamaChainId = "9d29e4f6-d67c-4c4b-9525-604b04afbe9f"
AlgorandChainId = "706b6f84-3333-4e55-8e89-275e71ce9803"
AvalancheChainId = "cbc77539-0a20-4666-8c8a-4ded62b36f0a"
XDCChainId = "b12bb04a-1cea-401c-a086-0be61f544889"
AptosChainId = "d2c1c7e1-a1a9-4f88-b282-d93b0a08b42b"
TONChainId = "ef660437-d915-4e27-ad3f-632bfb6ba0ee"
XINAssetId = "c94ac88f-4671-3976-b60a-09064f1811e8"
)
type NetworkChain struct {
Type string `json:"type"`
ChainId string `json:"chain_id"`
Name string `json:"name"`
Symbol string `json:"symbol"`
IconURL string `json:"icon_url"`
ManagedBlockHeight int64 `json:"managed_block_height"`
DepositBlockHeight int64 `json:"deposit_block_height"`
ExternalBlockHeight int64 `json:"external_block_height"`
Threshold int `json:"threshold"`
WithdrawalTimestamp time.Time `json:"withdrawal_timestamp"`
WithdrawalPendingCount int64 `json:"withdrawal_pending_count"`
WithdrawalFee string `json:"withdrawal_fee"`
IsSynchronized bool `json:"is_synchronized"`
}
func ReadNetworkChainById(ctx context.Context, chainId string) (*NetworkChain, error) {
body, err := Request(ctx, "GET", "/network/chains/"+chainId, nil, "")
if err != nil {
return nil, err
}
var resp struct {
Data *NetworkChain `json:"data"`
Error Error `json:"error"`
}
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, err
}
if resp.Error.Code > 0 {
return nil, resp.Error
}
return resp.Data, nil
}
func ReadNetworkChains(ctx context.Context) ([]*NetworkChain, error) {
body, err := Request(ctx, "GET", "/network/chains", nil, "")
if err != nil {
return nil, err
}
var resp struct {
Data []*NetworkChain `json:"data"`
Error Error `json:"error"`
}
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, err
}
if resp.Error.Code > 0 {
return nil, resp.Error
}
return resp.Data, nil
}
func GetChainName(chainId string) string {
switch chainId {
case EOSChainId:
return "EOS"
case RippleChainId:
return "Ripple"
case SiacoinChainId:
return "Siacoin"
case EthereumChainId:
return "Ethereum"
case EthereumClassicChainId:
return "Ethereum Classic"
case BSCChainId:
return "BNB Smart Chain"
case PolygonChainId:
return "Polygon"
case BaseChainId:
return "Base"
case MVMChainId:
return "Mixin Virtual Machine"
case BitcoinChainId:
return "Bitcoin"
case HandshakeChainId:
return "Handshake"
case BitcoinCashChainId:
return "Bitcoin Cash"
case BitcoinSVChainId:
return "Bitcoin SV"
case LitecoinChainId:
return "Litecoin"
case DecredChainId:
return "Decred"
case DogecoinChainId:
return "Dogecoin"
case DashChainId:
return "Dash"
case ZcashChainId:
return "Zcash"
case AvalancheChainId:
return "Avalanche"
case MoneroChainId:
return "Monero"
case NEMChainId:
return "NEM"
case HorizenChainId:
return "Horizen"
case MassGridChainId:
return "MassGrid"
case BytomChainId:
return "Bytom"
case BytomPoSChainId:
return "Bytom"
case TRONChainId:
return "TRON"
case TONChainId:
return "TON"
case StellarChainId:
return "Stellar"
case CosmosChainId:
return "Cosmos"
case StarcoinChainId:
return "Starcoin"
case AkashChainId:
return "Akash"
case BinanceChainId:
return "BNB Beacon Chain"
case BitSharesChainId:
return "Bitshares"
case TezosChainId:
return "Tezos"
case RavencoinChainId:
return "Ravencoin"
case NamecoinChainId:
return "Namecoin"
case NervosChainId:
return "Nervos"
case GrinChainId:
return "Grin"
case VCashChainId:
return "VCash"
case FilecoinChainId:
return "Filecoin"
case PolkadotChainId:
return "Polkadot"
case KusamaChainId:
return "Kusama"
case ArweaveChainId:
return "Arweave"
case MobileCoinChainId:
return "MobileCoin"
case SolanaChainId:
return "Solana"
case NearChainId:
return "NEAR"
case AlgorandChainId:
return "Algorand"
case XDCChainId:
return "XDC Network"
case AptosChainId:
return "Aptos"
default:
return "Not Supported Chain"
}
}
func IsChainId(id string) bool {
return validChainMap[id]
}
var validChainMap = map[string]bool{
BitcoinChainId: true,
BitcoinCashChainId: true,
BitcoinSVChainId: true,
LitecoinChainId: true,
EthereumChainId: true,
EthereumClassicChainId: true,
BSCChainId: true,
PolygonChainId: true,
BaseChainId: true,
MVMChainId: true,
DecredChainId: true,
RippleChainId: true,
SiacoinChainId: true,
EOSChainId: true,
DogecoinChainId: true,
DashChainId: true,
ZcashChainId: true,
NEMChainId: true,
ArweaveChainId: true,
HorizenChainId: true,
TRONChainId: true,
TONChainId: true,
StellarChainId: true,
CosmosChainId: true,
StarcoinChainId: true,
AkashChainId: true,
BinanceChainId: true,
MoneroChainId: true,
BitSharesChainId: true,
RavencoinChainId: true,
HandshakeChainId: true,
NervosChainId: true,
TezosChainId: true,
NamecoinChainId: true,
SolanaChainId: true,
FilecoinChainId: true,
MobileCoinChainId: true,
PolkadotChainId: true,
KusamaChainId: true,
AlgorandChainId: true,
NearChainId: true,
AvalancheChainId: true,
XDCChainId: true,
AptosChainId: true,
MassGridChainId: true,
BytomChainId: true,
BytomPoSChainId: true,
GrinChainId: true,
VCashChainId: true,
}
func GetFullChains() map[string]bool {
return map[string]bool{
BitcoinChainId: true,
BitcoinCashChainId: true,
BitcoinSVChainId: true,
LitecoinChainId: true,
EthereumChainId: true,
EthereumClassicChainId: true,
BSCChainId: true,
PolygonChainId: true,
BaseChainId: true,
MVMChainId: true,
DecredChainId: true,
RippleChainId: true,
SiacoinChainId: true,
EOSChainId: true,
DogecoinChainId: true,
DashChainId: true,
ZcashChainId: true,
NEMChainId: true,
ArweaveChainId: true,
HorizenChainId: true,
TRONChainId: true,
StellarChainId: true,
MassGridChainId: true,
BytomChainId: true,
BytomPoSChainId: true,
CosmosChainId: true,
AkashChainId: true,
BinanceChainId: true,
MoneroChainId: true,
StarcoinChainId: true,
BitSharesChainId: true,
RavencoinChainId: true,
GrinChainId: true,
VCashChainId: true,
HandshakeChainId: true,
NervosChainId: true,
TezosChainId: true,
NamecoinChainId: true,
SolanaChainId: true,
NearChainId: true,
FilecoinChainId: true,
MobileCoinChainId: true,
PolkadotChainId: true,
KusamaChainId: true,
AlgorandChainId: true,
AvalancheChainId: true,
XDCChainId: true,
AptosChainId: true,
TONChainId: true,
}
}