forked from OpenBazaar/spvwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
72 lines (59 loc) · 1.9 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
package spvwallet
import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/mitchellh/go-homedir"
"github.com/op/go-logging"
"golang.org/x/net/proxy"
"net"
"net/url"
"os"
"path/filepath"
)
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 user-agent that shall be visible to peers
UserAgent string
// Location of the data directory
RepoPath string
// An implementation of the Datastore interface
DB Datastore
// If you wish to connect to a single trusted peer set this. Otherwise leave nil.
TrustedPeer net.Addr
// A Tor proxy can be set here causing the wallet will use Tor
Proxy proxy.Dialer
// 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 url.URL
// A logger. You can write the logs to file or stdout or however else you want.
Logger logging.Backend
}
func NewDefaultConfig() *Config {
repoPath, _ := homedir.Expand(filepath.Join("~", ".spvwallet"))
_, ferr := os.Stat(repoPath)
if os.IsNotExist(ferr) {
os.Mkdir(repoPath, os.ModePerm)
}
feeApi, _ := url.Parse("https://bitcoinfees.21.co/api/v1/fees/recommended")
return &Config{
Params: &chaincfg.MainNetParams,
UserAgent: "spvwallet",
RepoPath: repoPath,
LowFee: 140,
MediumFee: 160,
HighFee: 180,
MaxFee: 2000,
FeeAPI: *feeApi,
Logger: logging.NewLogBackend(os.Stdout, "", 0),
}
}