-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
233 lines (214 loc) · 6.38 KB
/
config.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
package config
import (
"os"
"time"
"github.com/developertask/multiwallet/cache"
"github.com/developertask/multiwallet/datastore"
"github.com/developertask/wallet-interface"
"github.com/btcsuite/btcd/chaincfg"
"github.com/op/go-logging"
"golang.org/x/net/proxy"
)
const (
EthereumRegistryAddressMainnet = "0x5c69ccf91eab4ef80d9929b3c1b4d5bc03eb0981"
EthereumRegistryAddressRinkeby = "0x5cEF053c7b383f430FC4F4e1ea2F7D31d8e2D16C"
EthereumRegistryAddressRopsten = "0x403d907982474cdd51687b09a8968346159378f3"
)
type Config struct {
// Network parameters. Set mainnet, testnet, or regtest using this.
Params *chaincfg.Params
// Bip39 mnemonic string. If empty a new mnemonic will be created.
Mnemonic string
// The date the wallet was created.
// If before the earliest checkpoint the chain will be synced using the earliest checkpoint.
CreationDate time.Time
// A Tor proxy can be set here causing the wallet will use Tor
Proxy proxy.Dialer
// A logger. You can write the logs to file or stdout or however else you want.
Logger logging.Backend
// Cache is a persistable storage provided by the consumer where the wallet can
// keep state between runtime executions
Cache cache.Cacher
// A list of coin configs. One config should be included for each coin to be used.
Coins []CoinConfig
// Disable the exchange rate functionality in each wallet
DisableExchangeRates bool
}
type CoinConfig struct {
// The type of coin to configure
CoinType wallet.CoinType
// The default fee-per-byte for each level
LowFee uint64
MediumFee uint64
HighFee uint64
// The highest allowable fee-per-byte
MaxFee uint64
// External API to query to look up fees. If this field is nil then the default fees will be used.
// If the API is unreachable then the default fees will likewise be used. If the API returns a fee
// greater than MaxFee then the MaxFee will be used in place. The API response must be formatted as
// { "fastestFee": 40, "halfHourFee": 20, "hourFee": 10 }
FeeAPI string
// The trusted APIs to use for querying for balances and listening to blockchain events.
ClientAPIs []string
// An implementation of the Datastore interface for each desired coin
DB wallet.Datastore
// Custom options for wallet to use
Options map[string]interface{}
}
func NewDefaultConfig(coinTypes map[wallet.CoinType]bool, params *chaincfg.Params) *Config {
cfg := &Config{
Cache: cache.NewMockCacher(),
Params: params,
Logger: logging.NewLogBackend(os.Stdout, "", 0),
}
var testnet bool
if params.Name == chaincfg.TestNet3Params.Name {
testnet = true
}
mockDB := datastore.NewMockMultiwalletDatastore()
if coinTypes[wallet.Bitcoin] {
var apiEndpoints []string
if !testnet {
apiEndpoints = []string{
"https://btc.api.openbazaar.org/api",
// temporarily deprecated Insight endpoints
//"https://btc.bloqapi.net/insight-api",
//"https://btc.insight.openbazaar.org/insight-api",
}
} else {
apiEndpoints = []string{
"https://tbtc.api.openbazaar.org/api",
// temporarily deprecated Insight endpoints
//"https://test-insight.bitpay.com/api",
}
}
feeApi := "https://btc.fees.openbazaar.org"
db, _ := mockDB.GetDatastoreForWallet(wallet.Bitcoin)
btcCfg := CoinConfig{
CoinType: wallet.Bitcoin,
FeeAPI: feeApi,
LowFee: 140,
MediumFee: 160,
HighFee: 180,
MaxFee: 2000,
ClientAPIs: apiEndpoints,
DB: db,
}
cfg.Coins = append(cfg.Coins, btcCfg)
}
if coinTypes[wallet.BitcoinCash] {
var apiEndpoints []string
if !testnet {
apiEndpoints = []string{
"https://bch.api.openbazaar.org/api",
// temporarily deprecated Insight endpoints
//"https://bitcoincash.blockexplorer.com/api",
}
} else {
apiEndpoints = []string{
"https://tbch.api.openbazaar.org/api",
// temporarily deprecated Insight endpoints
//"https://test-bch-insight.bitpay.com/api",
}
}
db, _ := mockDB.GetDatastoreForWallet(wallet.BitcoinCash)
bchCfg := CoinConfig{
CoinType: wallet.BitcoinCash,
FeeAPI: "",
LowFee: 140,
MediumFee: 160,
HighFee: 180,
MaxFee: 2000,
ClientAPIs: apiEndpoints,
DB: db,
}
cfg.Coins = append(cfg.Coins, bchCfg)
}
if coinTypes[wallet.Zcash] {
var apiEndpoints []string
if !testnet {
apiEndpoints = []string{
"https://zec.api.openbazaar.org/api",
// temporarily deprecated Insight endpoints
//"https://zcashnetwork.info/api",
}
} else {
apiEndpoints = []string{
"https://tzec.api.openbazaar.org/api",
// temporarily deprecated Insight endpoints
//"https://explorer.testnet.z.cash/api",
}
}
db, _ := mockDB.GetDatastoreForWallet(wallet.Zcash)
zecCfg := CoinConfig{
CoinType: wallet.Zcash,
FeeAPI: "",
LowFee: 140,
MediumFee: 160,
HighFee: 180,
MaxFee: 2000,
ClientAPIs: apiEndpoints,
DB: db,
}
cfg.Coins = append(cfg.Coins, zecCfg)
}
if coinTypes[wallet.Litecoin] {
var apiEndpoints []string
if !testnet {
apiEndpoints = []string{
"https://ltc.api.openbazaar.org/api",
// temporarily deprecated Insight endpoints
//"https://ltc.coin.space/api",
//"https://ltc.insight.openbazaar.org/insight-lite-api",
}
} else {
apiEndpoints = []string{
"https://tltc.api.openbazaar.org/api",
// temporarily deprecated Insight endpoints
//"https://testnet.litecore.io/api",
}
}
db, _ := mockDB.GetDatastoreForWallet(wallet.Litecoin)
ltcCfg := CoinConfig{
CoinType: wallet.Litecoin,
FeeAPI: "",
LowFee: 140,
MediumFee: 160,
HighFee: 180,
MaxFee: 2000,
ClientAPIs: apiEndpoints,
DB: db,
}
cfg.Coins = append(cfg.Coins, ltcCfg)
}
if coinTypes[wallet.Ethereum] {
var apiEndpoints []string
if !testnet {
apiEndpoints = []string{
"https://mainnet.infura.io",
}
} else {
apiEndpoints = []string{
"https://rinkeby.infura.io",
}
}
db, _ := mockDB.GetDatastoreForWallet(wallet.Ethereum)
ethCfg := CoinConfig{
CoinType: wallet.Ethereum,
FeeAPI: "",
LowFee: 140,
MediumFee: 160,
HighFee: 180,
MaxFee: 2000,
ClientAPIs: apiEndpoints,
DB: db,
Options: map[string]interface{}{
"RegistryAddress": EthereumRegistryAddressMainnet,
"RinkebyRegistryAddress": EthereumRegistryAddressRinkeby,
"RopstenRegistryAddress": EthereumRegistryAddressRopsten,
},
}
cfg.Coins = append(cfg.Coins, ethCfg)
}
return cfg
}