From e34b43b938db51c092428b699a05deb258670cb8 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Sat, 7 Nov 2020 00:51:23 +0800 Subject: [PATCH] multi: unify WalletDBName and DefaultDBTimeout in loader --- cmd/dropwtxmgr/main.go | 8 ++------ config.go | 7 ++----- wallet/loader.go | 13 +++++++++---- walletsetup.go | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/cmd/dropwtxmgr/main.go b/cmd/dropwtxmgr/main.go index 72552f3..b474db1 100644 --- a/cmd/dropwtxmgr/main.go +++ b/cmd/dropwtxmgr/main.go @@ -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() { diff --git a/config.go b/config.go index 54575cb..7c80280 100644 --- a/config.go +++ b/config.go @@ -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 " + diff --git a/wallet/loader.go b/wallet/loader.go index c9d48ce..029114c 100644 --- a/wallet/loader.go +++ b/wallet/loader.go @@ -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) } diff --git a/walletsetup.go b/walletsetup.go index 3723abe..c70425e 100644 --- a/walletsetup.go +++ b/walletsetup.go @@ -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.