multi: unify WalletDBName and DefaultDBTimeout in loader
This commit is contained in:
parent
1cacaac9ea
commit
e34b43b938
4 changed files with 14 additions and 16 deletions
|
@ -22,10 +22,6 @@ const defaultNet = "mainnet"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
datadir = btcutil.AppDataDir("btcwallet", false)
|
datadir = btcutil.AppDataDir("btcwallet", false)
|
||||||
|
|
||||||
// defaultTimeout is the default timeout value when opening the wallet
|
|
||||||
// database.
|
|
||||||
defaultTimeout = 60 * time.Second
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flags.
|
// Flags.
|
||||||
|
@ -36,8 +32,8 @@ var opts = struct {
|
||||||
Timeout time.Duration `long:"timeout" description:"Timeout value when opening the wallet database"`
|
Timeout time.Duration `long:"timeout" description:"Timeout value when opening the wallet database"`
|
||||||
}{
|
}{
|
||||||
Force: false,
|
Force: false,
|
||||||
DbPath: filepath.Join(datadir, defaultNet, "wallet.db"),
|
DbPath: filepath.Join(datadir, defaultNet, wallet.WalletDBName),
|
||||||
Timeout: defaultTimeout,
|
Timeout: wallet.DefaultDBTimeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -32,9 +32,6 @@ const (
|
||||||
defaultLogFilename = "btcwallet.log"
|
defaultLogFilename = "btcwallet.log"
|
||||||
defaultRPCMaxClients = 10
|
defaultRPCMaxClients = 10
|
||||||
defaultRPCMaxWebsockets = 25
|
defaultRPCMaxWebsockets = 25
|
||||||
|
|
||||||
walletDbName = "wallet.db"
|
|
||||||
defaultDBTimeout = 60 * time.Second
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -275,7 +272,7 @@ func loadConfig() (*config, []string, error) {
|
||||||
MaxPeers: neutrino.MaxPeers,
|
MaxPeers: neutrino.MaxPeers,
|
||||||
BanDuration: neutrino.BanDuration,
|
BanDuration: neutrino.BanDuration,
|
||||||
BanThreshold: neutrino.BanThreshold,
|
BanThreshold: neutrino.BanThreshold,
|
||||||
DBTimeout: defaultDBTimeout,
|
DBTimeout: wallet.DefaultDBTimeout,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pre-parse the command line options to see if an alternative config
|
// Pre-parse the command line options to see if an alternative config
|
||||||
|
@ -418,7 +415,7 @@ func loadConfig() (*config, []string, error) {
|
||||||
|
|
||||||
// Ensure the wallet exists or create it when the create flag is set.
|
// Ensure the wallet exists or create it when the create flag is set.
|
||||||
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
||||||
dbPath := filepath.Join(netDir, walletDbName)
|
dbPath := filepath.Join(netDir, wallet.WalletDBName)
|
||||||
|
|
||||||
if cfg.CreateTemp && cfg.Create {
|
if cfg.CreateTemp && cfg.Create {
|
||||||
err := fmt.Errorf("The flags --create and --createtemp can not " +
|
err := fmt.Errorf("The flags --create and --createtemp can not " +
|
||||||
|
|
|
@ -18,7 +18,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
walletDbName = "wallet.db"
|
// WalletDBName specified the database filename for the wallet.
|
||||||
|
WalletDBName = "wallet.db"
|
||||||
|
|
||||||
|
// DefaultDBTimeout is the default timeout value when opening the wallet
|
||||||
|
// database.
|
||||||
|
DefaultDBTimeout = 60 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -129,7 +134,7 @@ func (l *Loader) createNewWallet(pubPassphrase, privPassphrase,
|
||||||
return nil, ErrLoaded
|
return nil, ErrLoaded
|
||||||
}
|
}
|
||||||
|
|
||||||
dbPath := filepath.Join(l.dbDirPath, walletDbName)
|
dbPath := filepath.Join(l.dbDirPath, WalletDBName)
|
||||||
exists, err := fileExists(dbPath)
|
exists, err := fileExists(dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -198,7 +203,7 @@ func (l *Loader) OpenExistingWallet(pubPassphrase []byte, canConsolePrompt bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the database using the boltdb backend.
|
// Open the database using the boltdb backend.
|
||||||
dbPath := filepath.Join(l.dbDirPath, walletDbName)
|
dbPath := filepath.Join(l.dbDirPath, WalletDBName)
|
||||||
db, err := walletdb.Open("bdb", dbPath, l.noFreelistSync, l.timeout)
|
db, err := walletdb.Open("bdb", dbPath, l.noFreelistSync, l.timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to open database: %v", err)
|
log.Errorf("Failed to open database: %v", err)
|
||||||
|
@ -237,7 +242,7 @@ func (l *Loader) OpenExistingWallet(pubPassphrase []byte, canConsolePrompt bool)
|
||||||
// WalletExists returns whether a file exists at the loader's database path.
|
// WalletExists returns whether a file exists at the loader's database path.
|
||||||
// This may return an error for unexpected I/O failures.
|
// This may return an error for unexpected I/O failures.
|
||||||
func (l *Loader) WalletExists() (bool, error) {
|
func (l *Loader) WalletExists() (bool, error) {
|
||||||
dbPath := filepath.Join(l.dbDirPath, walletDbName)
|
dbPath := filepath.Join(l.dbDirPath, WalletDBName)
|
||||||
return fileExists(dbPath)
|
return fileExists(dbPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,7 @@ func createSimulationWallet(cfg *config) error {
|
||||||
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
|
||||||
|
|
||||||
// Create the wallet.
|
// Create the wallet.
|
||||||
dbPath := filepath.Join(netDir, walletDbName)
|
dbPath := filepath.Join(netDir, wallet.WalletDBName)
|
||||||
fmt.Println("Creating the wallet...")
|
fmt.Println("Creating the wallet...")
|
||||||
|
|
||||||
// Create the wallet database backed by bolt db.
|
// Create the wallet database backed by bolt db.
|
||||||
|
|
Loading…
Reference in a new issue