-
Notifications
You must be signed in to change notification settings - Fork 15
/
types.go
265 lines (227 loc) · 9.53 KB
/
types.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
package chain
import (
"context"
"math/big"
)
type ChainType string
const (
ICON ChainType = "ICON"
HMNY ChainType = "HMNY"
BSC ChainType = "BSC"
NEAR ChainType = "NEAR"
SNOW ChainType = "SNOW"
)
type ContractName string
const (
BMC ContractName = "BMC"
BMCPeriphery ContractName = "BMCPeriphery"
BTS ContractName = "BTS"
BTSPeriphery ContractName = "BTSPeriphery"
)
type EventLogType string
const (
TransferStart EventLogType = "TransferStart"
TransferReceived EventLogType = "TransferReceived"
TransferEnd EventLogType = "TransferEnd"
AddToBlacklistRequest EventLogType = "AddToBlacklistRequest"
RemoveFromBlacklistRequest EventLogType = "RemoveFromBlacklistRequest"
BlacklistResponse EventLogType = "BlacklistResponse"
TokenLimitRequest EventLogType = "TokenLimitRequest"
TokenLimitResponse EventLogType = "TokenLimitResponse"
FeeGatheringRequest EventLogType = "FeeGatheringRequest"
Message EventLogType = "Message"
)
type CoinBalance struct {
UsableBalance *big.Int
LockedBalance *big.Int
RefundableBalance *big.Int
UserBalance *big.Int
TotalBalance *big.Int // held by BTS + by itself
}
func (cb *CoinBalance) String() string {
return "Usable " + cb.UsableBalance.String() +
" Locked " + cb.LockedBalance.String() + " Refundable " + cb.RefundableBalance.String() +
" UserBalance " + cb.UserBalance.String()
}
type SrcAPI interface {
Transfer(coinName, senderKey, recepientAddress string, amount *big.Int) (txnHash string, err error)
TransferBatch(coinNames []string, senderKey, recepientAddress string, amounts []*big.Int) (txnHash string, err error)
WaitForTxnResult(ctx context.Context, hash string) (txnr *TxnResult, err error)
WatchForTransferStart(requestID uint64, seq int64) error
WatchForTransferEnd(ID uint64, seq int64) error
WatchForFeeGatheringTransferStart(ID uint64, addr string) error
Approve(coinName string, ownerKey string, amount *big.Int) (txnHash string, err error)
GetCoinBalance(coinName string, addr string) (*CoinBalance, error)
Reclaim(coinName string, ownerKey string, amount *big.Int) (txnHash string, err error)
NativeCoin() string
NativeTokens() []string
GetBTPAddress(addr string) string
ChargedGasFee(txnHash string) (*big.Int, error)
SuggestGasPrice() *big.Int
}
type DstAPI interface {
GetCoinBalance(coinName string, addr string) (*CoinBalance, error)
WatchForTransferReceived(requestID uint64, seq int64) error
GetBTPAddress(addr string) string
}
type FullConfigAPI interface {
SetTokenLimit(ownerKey string, coinNames []string, tokenLimits []*big.Int) (txnHash string, err error)
AddBlackListAddress(ownerKey string, net string, addrs []string) (txnHash string, err error)
RemoveBlackListAddress(ownerKey string, net string, addrs []string) (txnHash string, err error)
ChangeRestriction(ownerKey string, enable bool) (txnHash string, err error)
GetTokenLimitStatus(net, coinName string) (response bool, err error)
GetBlackListedUsers(net string, startCursor, endCursor int) (addrs []string, err error)
SetFeeGatheringTerm(ownerKey string, interval uint64) (hash string, err error)
GetFeeGatheringTerm() (interval uint64, err error)
WatchForAddToBlacklistRequest(ID uint64, seq int64) error
WatchForRemoveFromBlacklistRequest(ID uint64, seq int64) error
WatchForSetTokenLmitRequest(ID uint64, seq int64) error
GetConfigRequestEvent(evtType EventLogType, hash string) (*EventLogInfo, error)
WatchForFeeGatheringRequest(ID uint64, addr string) error
IsUserBlackListed(net, addr string) (response bool, err error)
GetTokenLimit(coinName string) (tokenLimit *big.Int, err error)
IsBTSOwner(addr string) (response bool, err error)
// Watch For TokenLimitStart, TokenLimitEnd
}
type StandardConfigAPI interface {
IsUserBlackListed(net, addr string) (response bool, err error)
GetTokenLimit(coinName string) (tokenLimit *big.Int, err error)
IsBTSOwner(addr string) (response bool, err error)
SetFeeRatio(ownerKey string, coinName string, feeNumerator, fixedFee *big.Int) (string, error)
GetFeeRatio(coinName string) (feeNumerator *big.Int, fixedFee *big.Int, err error)
GetAccumulatedFees() (map[string]*big.Int, error)
WatchForBlacklistResponse(ID uint64, seq int64) error
WatchForSetTokenLmitResponse(ID uint64, seq int64) error
}
type TxnResult struct {
StatusCode int
ElInfo []*EventLogInfo
Raw interface{}
}
type ChainAPI interface {
// Subscription
Subscribe(ctx context.Context) (sinkChan chan *EventLogInfo, errChan chan error, err error)
// Account
GetKeyPairs(num int) ([][2]string, error)
GetKeyPairFromKeystore(keystoreFile, secretFile string) (string, string, error)
// Transfer
TransferBatch(coinNames []string, senderKey, recepientAddress string, amounts []*big.Int) (txnHash string, err error)
Transfer(coinName, senderKey, recepientAddress string, amount *big.Int) (txnHash string, err error)
WaitForTxnResult(ctx context.Context, hash string) (txnr *TxnResult, err error)
WatchForTransferStart(ID uint64, seq int64) error
WatchForTransferReceived(ID uint64, seq int64) error
WatchForTransferEnd(ID uint64, seq int64) error
Approve(coinName string, ownerKey string, amount *big.Int) (txnHash string, err error)
GetCoinBalance(coinName string, addr string) (*CoinBalance, error)
Reclaim(coinName string, ownerKey string, amount *big.Int) (txnHash string, err error)
// Query
NativeCoin() string
NativeTokens() []string
GetBTPAddress(addr string) string
ChargedGasFee(txnHash string) (*big.Int, error)
SuggestGasPrice() *big.Int
// Configure
SetTokenLimit(ownerKey string, coinNames []string, tokenLimits []*big.Int) (txnHash string, err error)
AddBlackListAddress(ownerKey string, net string, addrs []string) (txnHash string, err error)
RemoveBlackListAddress(ownerKey string, net string, addrs []string) (txnHash string, err error)
ChangeRestriction(ownerKey string, enable bool) (txnHash string, err error)
GetTokenLimitStatus(net, coinName string) (response bool, err error)
GetBlackListedUsers(net string, startCursor, endCursor int) (addrs []string, err error)
SetFeeGatheringTerm(ownerKey string, interval uint64) (hash string, err error)
GetFeeGatheringTerm() (interval uint64, err error)
WatchForAddToBlacklistRequest(ID uint64, seq int64) error
WatchForRemoveFromBlacklistRequest(ID uint64, seq int64) error
WatchForBlacklistResponse(ID uint64, seq int64) error
WatchForSetTokenLmitRequest(ID uint64, seq int64) error
WatchForSetTokenLmitResponse(ID uint64, seq int64) error
GetConfigRequestEvent(evtType EventLogType, hash string) (*EventLogInfo, error)
WatchForFeeGatheringRequest(ID uint64, addr string) error
WatchForFeeGatheringTransferStart(ID uint64, addr string) error
IsUserBlackListed(net, addr string) (response bool, err error)
GetTokenLimit(coinName string) (tokenLimit *big.Int, err error)
IsBTSOwner(addr string) (response bool, err error)
SetFeeRatio(ownerKey string, coinName string, feeNumerator, fixedFee *big.Int) (string, error)
GetFeeRatio(coinName string) (feeNumerator *big.Int, fixedFee *big.Int, err error)
GetAccumulatedFees() (map[string]*big.Int, error)
}
type Config struct {
Name ChainType `json:"name"`
URL string `json:"url"`
ContractAddresses map[ContractName]string `json:"contract_addresses"`
NativeCoin string `json:"native_coin"`
NativeTokens []string `json:"native_tokens"`
WrappedCoins []string `json:"wrapped_coins"`
GodWalletKeystorePath string `json:"god_wallet_keystore_path"`
GodWalletSecretPath string `json:"god_wallet_secret_path"`
BTSOwnerKeystorePath string `json:"bts_owner_keystore_path"`
BTSOwnerSecretPath string `json:"bts_owner_secret_path"`
NetworkID string `json:"network_id"`
GasLimit map[GasLimitType]uint64 `json:"gas_limit"`
}
type EventLogInfo struct {
PID uint64
ContractAddress string
EventType EventLogType
EventLog interface{}
}
type TransferStartEvent struct {
From string
To string
Sn *big.Int
Assets []AssetTransferDetails
}
type TransferReceivedEvent struct {
From string
To string
Sn *big.Int
Assets []AssetTransferDetails
}
type AssetTransferDetails struct {
Name string
Value *big.Int
Fee *big.Int
}
type TransferEndEvent struct {
From string
Sn *big.Int
Code *big.Int
Response string
}
type BlacklistResponseEvent struct {
Sn *big.Int
Code int64
Msg string
}
type TokenLimitResponseEvent struct {
Sn *big.Int
Code int64
Msg string
}
type AddToBlacklistRequestEvent struct {
Sn *big.Int
Net string
Addrs []string
}
type RemoveFromBlacklistRequestEvent struct {
Sn *big.Int
Net string
Addrs []string
}
type TokenLimitRequestEvent struct {
Sn *big.Int
TokenLimits []*big.Int
CoinNames []string
}
type FeeGatheringRequestEvent struct {
FeeAggregator string
Services []string
}
type GasLimitType string
const (
TransferNativeCoinIntraChainGasLimit GasLimitType = "TransferNativeCoinIntraChainGasLimit"
TransferTokenIntraChainGasLimit GasLimitType = "TransferTokenIntraChainGasLimit"
ApproveTokenInterChainGasLimit GasLimitType = "ApproveTokenInterChainGasLimit"
TransferCoinInterChainGasLimit GasLimitType = "TransferCoinInterChainGasLimit"
TransferBatchCoinInterChainGasLimit GasLimitType = "TransferBatchCoinInterChainGasLimit"
DefaultGasLimit GasLimitType = "DefaultGasLimit"
)