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
|
// recovery should be attempted, such as after the wallet's initial
|
||||||
// creation, but before any addresses have been created.
|
// creation, but before any addresses have been created.
|
||||||
RecoveryWindow uint32
|
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
|
// 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.
|
// Try opening the existing wallet with the provided password.
|
||||||
_, err = loader.OpenExistingWallet(password, false)
|
unlockedWallet, err := loader.OpenExistingWallet(password, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Could not open wallet, most likely this means that provided
|
// Could not open wallet, most likely this means that provided
|
||||||
// password was incorrect.
|
// password was incorrect.
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We successfully opened the wallet, but we'll need to unload it to
|
// We successfully opened the wallet and pass the instance back to
|
||||||
// make sure lnd can open it later.
|
// avoid it needing to be unlocked again.
|
||||||
if err := loader.UnloadWallet(); err != nil {
|
|
||||||
// TODO: not return error here?
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
walletUnlockMsg := &WalletUnlockMsg{
|
walletUnlockMsg := &WalletUnlockMsg{
|
||||||
Passphrase: password,
|
Passphrase: password,
|
||||||
RecoveryWindow: recoveryWindow,
|
RecoveryWindow: recoveryWindow,
|
||||||
|
Wallet: unlockedWallet,
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point we was able to open the existing wallet with the
|
// At this point we was able to open the existing wallet with the
|
||||||
|
Loading…
Reference in New Issue
Block a user