-
Notifications
You must be signed in to change notification settings - Fork 80
/
config.go
105 lines (86 loc) · 2.69 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
package spvwallet
import (
"github.com/OpenBazaar/wallet-interface"
"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"
"runtime"
"time"
)
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
// 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 wallet.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
// Disable the exchange rate provider
DisableExchangeRates bool
}
func NewDefaultConfig() *Config {
repoPath, _ := getRepoPath()
_, 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),
}
}
func getRepoPath() (string, error) {
// Set default base path and directory name
path := "~"
directoryName := "spvwallet"
// Override OS-specific names
switch runtime.GOOS {
case "linux":
directoryName = ".spvwallet"
case "darwin":
path = "~/Library/Application Support"
}
// Join the path and directory name, then expand the home path
fullPath, err := homedir.Expand(filepath.Join(path, directoryName))
if err != nil {
return "", err
}
// Return the shortest lexical representation of the path
return filepath.Clean(fullPath), nil
}