lnwallet/btcwallet: during initial creation catch the case of an existing wallet

In this commit, due to the recent changes within lnd itself, it may be
possible that a wallet already exists when the wallet has been signaled
to be created. As a result, *always* open the wallet ourselves, but
allow an existing wallet to already be in place.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-01 20:50:58 -08:00
parent 6289a2fb84
commit d8ce90306d
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
1 changed files with 21 additions and 9 deletions

View File

@ -80,20 +80,32 @@ func New(cfg Config) (*BtcWallet, error) {
var wallet *base.Wallet var wallet *base.Wallet
if !walletExists { if !walletExists {
// Wallet has never been created, perform initial set up. // Wallet has never been created, perform initial set up.
wallet, err = loader.CreateNewWallet(pubPass, cfg.PrivatePass, wallet, err = loader.CreateNewWallet(
cfg.HdSeed) pubPass, cfg.PrivatePass, cfg.HdSeed,
if err != nil { )
switch {
// If the wallet already exists, then we'll ignore this error
// and proceed directly to opening the wallet.
case err == base.ErrExists:
// Otherwise, there's a greater error here, and we'll return
// early.
case err != nil:
return nil, err return nil, err
} }
} else {
// Wallet has been created and been initialized at this point, if err := loader.UnloadWallet(); err != nil {
// open it along with all the required DB namespaces, and the return nil, err
// DB itself. }
}
// Wallet has been created and been initialized at this point, open it
// along with all the required DB namepsaces, and the DB itself.
wallet, err = loader.OpenExistingWallet(pubPass, false) wallet, err = loader.OpenExistingWallet(pubPass, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
// Create a bucket within the wallet's database dedicated to storing // Create a bucket within the wallet's database dedicated to storing
// our LN specific data. // our LN specific data.