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:
parent
6289a2fb84
commit
d8ce90306d
@ -80,21 +80,33 @@ 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
|
|
||||||
// DB itself.
|
|
||||||
wallet, err = loader.OpenExistingWallet(pubPass, false)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
if err != nil {
|
||||||
|
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.
|
||||||
db := wallet.Database()
|
db := wallet.Database()
|
||||||
|
Loading…
Reference in New Issue
Block a user