walletunlocker: pass unlocked wallet back to lnd to avoid double unlock
This commit is contained in:
parent
7303a65ad1
commit
cd8a21c4b8
@ -52,6 +52,13 @@ type WalletUnlockMsg struct {
|
||||
// recovery should be attempted, such as after the wallet's initial
|
||||
// creation, but before any addresses have been created.
|
||||
RecoveryWindow uint32
|
||||
|
||||
// Wallet is the loaded and unlocked Wallet. This is returned
|
||||
// through the channel to avoid it being unlocked twice (once to check
|
||||
// if the password is correct, here in the WalletUnlocker and again
|
||||
// later when lnd actually uses it). Because unlocking involves scrypt
|
||||
// which is resource intensive, we want to avoid doing it twice.
|
||||
Wallet *wallet.Wallet
|
||||
}
|
||||
|
||||
// UnlockerService implements the WalletUnlocker service used to provide lnd
|
||||
@ -255,23 +262,19 @@ func (u *UnlockerService) UnlockWallet(ctx context.Context,
|
||||
}
|
||||
|
||||
// Try opening the existing wallet with the provided password.
|
||||
_, err = loader.OpenExistingWallet(password, false)
|
||||
unlockedWallet, err := loader.OpenExistingWallet(password, false)
|
||||
if err != nil {
|
||||
// Could not open wallet, most likely this means that provided
|
||||
// password was incorrect.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// We successfully opened the wallet, but we'll need to unload it to
|
||||
// make sure lnd can open it later.
|
||||
if err := loader.UnloadWallet(); err != nil {
|
||||
// TODO: not return error here?
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// We successfully opened the wallet and pass the instance back to
|
||||
// avoid it needing to be unlocked again.
|
||||
walletUnlockMsg := &WalletUnlockMsg{
|
||||
Passphrase: password,
|
||||
RecoveryWindow: recoveryWindow,
|
||||
Wallet: unlockedWallet,
|
||||
}
|
||||
|
||||
// At this point we was able to open the existing wallet with the
|
||||
|
Loading…
Reference in New Issue
Block a user