-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
129 lines (107 loc) · 3.11 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
package client
import (
"net"
"net/url"
"os"
"path/filepath"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"golang.org/x/net/proxy"
"github.com/dev-warrior777/go-electrum-client/electrumx"
"github.com/dev-warrior777/go-electrum-client/wallet"
)
const (
appName = "goele"
DbTypeBolt = "bbolt"
DbTypeSqlite = "sqlite"
)
type ClientConfig struct {
// The blockchain, Bitcoin, Dash, etc
Chain wallet.CoinType
// Network parameters. Set mainnet, testnet using this.
Params *chaincfg.Params
// Store the seed in encrypted storage
StoreEncSeed bool
// The user-agent that shall be visible to the network
UserAgent string
// Location of the data directory
DataDir string
// Database implementation type (bbolt or sqlite)
DbType string
// An implementation of the Datastore interface
DB wallet.Datastore
// If you wish to connect to a single trusted electrumX peer server set this.
// SingleNode servers will error if not provided. MultiNode not yet impl.
TrustedPeer net.Addr
// A Tor proxy can be set here. TODO:
Proxy proxy.Dialer
// The default fee-per-byte for each level
LowFee int64
MediumFee int64
HighFee int64
// The highest allowable fee-per-byte
MaxFee int64
// 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 url.URL
// Disable the exchange rate provider
DisableExchangeRates bool
// If not testing do not overwrite existing wallet files
Testing bool
// Test RPC server
RPCTestPort int
}
func NewDefaultConfig() *ClientConfig {
return &ClientConfig{
Chain: wallet.Bitcoin,
Params: &chaincfg.MainNetParams,
UserAgent: appName,
DataDir: btcutil.AppDataDir(appName, false),
DbType: DbTypeBolt,
DB: nil, // concrete impl
DisableExchangeRates: true,
RPCTestPort: 8888,
}
}
func (cc *ClientConfig) MakeWalletConfig() *wallet.WalletConfig {
wc := wallet.WalletConfig{
Chain: cc.Chain,
Params: cc.Params,
StoreEncSeed: cc.StoreEncSeed,
DataDir: cc.DataDir,
DbType: cc.DbType,
DB: cc.DB,
LowFee: cc.LowFee,
MediumFee: cc.MediumFee,
HighFee: cc.HighFee,
MaxFee: cc.MaxFee,
Testing: cc.Testing,
}
return &wc
}
func (cc *ClientConfig) MakeNodeConfig() *electrumx.NodeConfig {
nc := electrumx.NodeConfig{
Chain: cc.Chain,
Params: cc.Params,
UserAgent: cc.UserAgent,
DataDir: cc.DataDir,
TrustedPeer: cc.TrustedPeer,
Proxy: cc.Proxy,
Testing: cc.Testing,
}
return &nc
}
func GetConfigPath() (string, error) {
userCfgDir, err := os.UserConfigDir()
if err != nil {
return "", err
}
appPath := filepath.Join(userCfgDir, appName)
err = os.MkdirAll(appPath, os.ModeDir|0777)
if err != nil {
return "", err
}
return appPath, nil
}