diff --git a/wallet/example_test.go b/wallet/example_test.go index c6d1b82..5b29d2e 100644 --- a/wallet/example_test.go +++ b/wallet/example_test.go @@ -10,6 +10,10 @@ import ( "github.com/btcsuite/btcutil/hdkeychain" ) +// defaultDBTimeout specifies the timeout value when opening the wallet +// database. +var defaultDBTimeout = 10 * time.Second + // testWallet creates a test wallet and unlocks it. func testWallet(t *testing.T) (*Wallet, func()) { // Set up a wallet. @@ -32,7 +36,9 @@ func testWallet(t *testing.T) (*Wallet, func()) { pubPass := []byte("hello") privPass := []byte("world") - loader := NewLoader(&chaincfg.TestNet3Params, dir, true, 250) + loader := NewLoader( + &chaincfg.TestNet3Params, dir, true, defaultDBTimeout, 250, + ) w, err := loader.CreateNewWallet(pubPass, privPass, seed, time.Now()) if err != nil { t.Fatalf("unable to create wallet: %v", err) diff --git a/wallet/loader.go b/wallet/loader.go index 17f761f..c9d48ce 100644 --- a/wallet/loader.go +++ b/wallet/loader.go @@ -47,6 +47,7 @@ type Loader struct { chainParams *chaincfg.Params dbDirPath string noFreelistSync bool + timeout time.Duration recoveryWindow uint32 wallet *Wallet db walletdb.DB @@ -57,12 +58,14 @@ type Loader struct { // recovery window is non-zero, the wallet will attempt to recovery addresses // starting from the last SyncedTo height. func NewLoader(chainParams *chaincfg.Params, dbDirPath string, - noFreelistSync bool, recoveryWindow uint32) *Loader { + noFreelistSync bool, timeout time.Duration, + recoveryWindow uint32) *Loader { return &Loader{ chainParams: chainParams, dbDirPath: dbDirPath, noFreelistSync: noFreelistSync, + timeout: timeout, recoveryWindow: recoveryWindow, } } @@ -140,7 +143,7 @@ func (l *Loader) createNewWallet(pubPassphrase, privPassphrase, if err != nil { return nil, err } - db, err := walletdb.Create("bdb", dbPath, l.noFreelistSync) + db, err := walletdb.Create("bdb", dbPath, l.noFreelistSync, l.timeout) if err != nil { return nil, err } @@ -196,7 +199,7 @@ func (l *Loader) OpenExistingWallet(pubPassphrase []byte, canConsolePrompt bool) // Open the database using the boltdb backend. dbPath := filepath.Join(l.dbDirPath, walletDbName) - db, err := walletdb.Open("bdb", dbPath, l.noFreelistSync) + db, err := walletdb.Open("bdb", dbPath, l.noFreelistSync, l.timeout) if err != nil { log.Errorf("Failed to open database: %v", err) return nil, err diff --git a/wallet/watchingonly_test.go b/wallet/watchingonly_test.go index f7846b1..64a72b0 100644 --- a/wallet/watchingonly_test.go +++ b/wallet/watchingonly_test.go @@ -26,7 +26,9 @@ func TestCreateWatchingOnly(t *testing.T) { pubPass := []byte("hello") - loader := NewLoader(&chaincfg.TestNet3Params, dir, true, 250) + loader := NewLoader( + &chaincfg.TestNet3Params, dir, true, defaultDBTimeout, 250, + ) _, err = loader.CreateNewWatchingOnlyWallet(pubPass, time.Now()) if err != nil { t.Fatalf("unable to create wallet: %v", err)