wallet: use db timeout in loader
This commit is contained in:
parent
368301866e
commit
86bc349c6e
3 changed files with 16 additions and 5 deletions
|
@ -10,6 +10,10 @@ import (
|
||||||
"github.com/btcsuite/btcutil/hdkeychain"
|
"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.
|
// testWallet creates a test wallet and unlocks it.
|
||||||
func testWallet(t *testing.T) (*Wallet, func()) {
|
func testWallet(t *testing.T) (*Wallet, func()) {
|
||||||
// Set up a wallet.
|
// Set up a wallet.
|
||||||
|
@ -32,7 +36,9 @@ func testWallet(t *testing.T) (*Wallet, func()) {
|
||||||
pubPass := []byte("hello")
|
pubPass := []byte("hello")
|
||||||
privPass := []byte("world")
|
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())
|
w, err := loader.CreateNewWallet(pubPass, privPass, seed, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create wallet: %v", err)
|
t.Fatalf("unable to create wallet: %v", err)
|
||||||
|
|
|
@ -47,6 +47,7 @@ type Loader struct {
|
||||||
chainParams *chaincfg.Params
|
chainParams *chaincfg.Params
|
||||||
dbDirPath string
|
dbDirPath string
|
||||||
noFreelistSync bool
|
noFreelistSync bool
|
||||||
|
timeout time.Duration
|
||||||
recoveryWindow uint32
|
recoveryWindow uint32
|
||||||
wallet *Wallet
|
wallet *Wallet
|
||||||
db walletdb.DB
|
db walletdb.DB
|
||||||
|
@ -57,12 +58,14 @@ type Loader struct {
|
||||||
// recovery window is non-zero, the wallet will attempt to recovery addresses
|
// recovery window is non-zero, the wallet will attempt to recovery addresses
|
||||||
// starting from the last SyncedTo height.
|
// starting from the last SyncedTo height.
|
||||||
func NewLoader(chainParams *chaincfg.Params, dbDirPath string,
|
func NewLoader(chainParams *chaincfg.Params, dbDirPath string,
|
||||||
noFreelistSync bool, recoveryWindow uint32) *Loader {
|
noFreelistSync bool, timeout time.Duration,
|
||||||
|
recoveryWindow uint32) *Loader {
|
||||||
|
|
||||||
return &Loader{
|
return &Loader{
|
||||||
chainParams: chainParams,
|
chainParams: chainParams,
|
||||||
dbDirPath: dbDirPath,
|
dbDirPath: dbDirPath,
|
||||||
noFreelistSync: noFreelistSync,
|
noFreelistSync: noFreelistSync,
|
||||||
|
timeout: timeout,
|
||||||
recoveryWindow: recoveryWindow,
|
recoveryWindow: recoveryWindow,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +143,7 @@ func (l *Loader) createNewWallet(pubPassphrase, privPassphrase,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
db, err := walletdb.Create("bdb", dbPath, l.noFreelistSync)
|
db, err := walletdb.Create("bdb", dbPath, l.noFreelistSync, l.timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -196,7 +199,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)
|
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)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -26,7 +26,9 @@ func TestCreateWatchingOnly(t *testing.T) {
|
||||||
|
|
||||||
pubPass := []byte("hello")
|
pubPass := []byte("hello")
|
||||||
|
|
||||||
loader := NewLoader(&chaincfg.TestNet3Params, dir, true, 250)
|
loader := NewLoader(
|
||||||
|
&chaincfg.TestNet3Params, dir, true, defaultDBTimeout, 250,
|
||||||
|
)
|
||||||
_, err = loader.CreateNewWatchingOnlyWallet(pubPass, time.Now())
|
_, err = loader.CreateNewWatchingOnlyWallet(pubPass, time.Now())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create wallet: %v", err)
|
t.Fatalf("unable to create wallet: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue