multi: unify WalletDBName and DefaultDBTimeout in loader

This commit is contained in:
yyforyongyu 2020-11-07 00:51:23 +08:00
parent 1cacaac9ea
commit e34b43b938
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
4 changed files with 14 additions and 16 deletions

View file

@ -22,10 +22,6 @@ const defaultNet = "mainnet"
var (
datadir = btcutil.AppDataDir("btcwallet", false)
// defaultTimeout is the default timeout value when opening the wallet
// database.
defaultTimeout = 60 * time.Second
)
// Flags.
@ -36,8 +32,8 @@ var opts = struct {
Timeout time.Duration `long:"timeout" description:"Timeout value when opening the wallet database"`
}{
Force: false,
DbPath: filepath.Join(datadir, defaultNet, "wallet.db"),
Timeout: defaultTimeout,
DbPath: filepath.Join(datadir, defaultNet, wallet.WalletDBName),
Timeout: wallet.DefaultDBTimeout,
}
func init() {

View file

@ -32,9 +32,6 @@ const (
defaultLogFilename = "btcwallet.log"
defaultRPCMaxClients = 10
defaultRPCMaxWebsockets = 25
walletDbName = "wallet.db"
defaultDBTimeout = 60 * time.Second
)
var (
@ -275,7 +272,7 @@ func loadConfig() (*config, []string, error) {
MaxPeers: neutrino.MaxPeers,
BanDuration: neutrino.BanDuration,
BanThreshold: neutrino.BanThreshold,
DBTimeout: defaultDBTimeout,
DBTimeout: wallet.DefaultDBTimeout,
}
// 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.
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
dbPath := filepath.Join(netDir, walletDbName)
dbPath := filepath.Join(netDir, wallet.WalletDBName)
if cfg.CreateTemp && cfg.Create {
err := fmt.Errorf("The flags --create and --createtemp can not " +

View file

@ -18,7 +18,12 @@ import (
)
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 (
@ -129,7 +134,7 @@ func (l *Loader) createNewWallet(pubPassphrase, privPassphrase,
return nil, ErrLoaded
}
dbPath := filepath.Join(l.dbDirPath, walletDbName)
dbPath := filepath.Join(l.dbDirPath, WalletDBName)
exists, err := fileExists(dbPath)
if err != nil {
return nil, err
@ -198,7 +203,7 @@ func (l *Loader) OpenExistingWallet(pubPassphrase []byte, canConsolePrompt bool)
}
// 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)
if err != nil {
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.
// This may return an error for unexpected I/O failures.
func (l *Loader) WalletExists() (bool, error) {
dbPath := filepath.Join(l.dbDirPath, walletDbName)
dbPath := filepath.Join(l.dbDirPath, WalletDBName)
return fileExists(dbPath)
}

View file

@ -217,7 +217,7 @@ func createSimulationWallet(cfg *config) error {
netDir := networkDir(cfg.AppDataDir.Value, activeNet.Params)
// Create the wallet.
dbPath := filepath.Join(netDir, walletDbName)
dbPath := filepath.Join(netDir, wallet.WalletDBName)
fmt.Println("Creating the wallet...")
// Create the wallet database backed by bolt db.