mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
walletunlocker+lnd: move WalletUnlockParams
As a preparation for adding the wallet unlock params to the chain control, we first need to move them out of the main package.
This commit is contained in:
47
lnd.go
47
lnd.go
@@ -314,7 +314,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
walletInitParams = WalletUnlockParams{
|
walletInitParams = walletunlocker.WalletUnlockParams{
|
||||||
// In case we do auto-unlock, we need to be able to send
|
// In case we do auto-unlock, we need to be able to send
|
||||||
// into the channel without blocking so we buffer it.
|
// into the channel without blocking so we buffer it.
|
||||||
MacResponseChan: make(chan []byte, 1),
|
MacResponseChan: make(chan []byte, 1),
|
||||||
@@ -1278,45 +1278,6 @@ func adminPermissions() []bakery.Op {
|
|||||||
return admin
|
return admin
|
||||||
}
|
}
|
||||||
|
|
||||||
// WalletUnlockParams holds the variables used to parameterize the unlocking of
|
|
||||||
// lnd's wallet after it has already been created.
|
|
||||||
type WalletUnlockParams struct {
|
|
||||||
// Password is the public and private wallet passphrase.
|
|
||||||
Password []byte
|
|
||||||
|
|
||||||
// Birthday specifies the approximate time that this wallet was created.
|
|
||||||
// This is used to bound any rescans on startup.
|
|
||||||
Birthday time.Time
|
|
||||||
|
|
||||||
// RecoveryWindow specifies the address lookahead when entering recovery
|
|
||||||
// mode. A recovery will be attempted if this value is non-zero.
|
|
||||||
RecoveryWindow uint32
|
|
||||||
|
|
||||||
// Wallet is the loaded and unlocked Wallet. This is returned
|
|
||||||
// from the unlocker service to avoid it being unlocked twice (once in
|
|
||||||
// the unlocker service to check if the password is correct 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
|
|
||||||
|
|
||||||
// ChansToRestore a set of static channel backups that should be
|
|
||||||
// restored before the main server instance starts up.
|
|
||||||
ChansToRestore walletunlocker.ChannelsToRecover
|
|
||||||
|
|
||||||
// UnloadWallet is a function for unloading the wallet, which should
|
|
||||||
// be called on shutdown.
|
|
||||||
UnloadWallet func() error
|
|
||||||
|
|
||||||
// StatelessInit signals that the user requested the daemon to be
|
|
||||||
// initialized stateless, which means no unencrypted macaroons should be
|
|
||||||
// written to disk.
|
|
||||||
StatelessInit bool
|
|
||||||
|
|
||||||
// MacResponseChan is the channel for sending back the admin macaroon to
|
|
||||||
// the WalletUnlocker service.
|
|
||||||
MacResponseChan chan []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// createWalletUnlockerService creates a WalletUnlockerService from the passed
|
// createWalletUnlockerService creates a WalletUnlockerService from the passed
|
||||||
// config.
|
// config.
|
||||||
func createWalletUnlockerService(cfg *Config) *walletunlocker.UnlockerService {
|
func createWalletUnlockerService(cfg *Config) *walletunlocker.UnlockerService {
|
||||||
@@ -1499,7 +1460,7 @@ func startRestProxy(cfg *Config, rpcServer *rpcServer, restDialOpts []grpc.DialO
|
|||||||
func waitForWalletPassword(cfg *Config,
|
func waitForWalletPassword(cfg *Config,
|
||||||
pwService *walletunlocker.UnlockerService,
|
pwService *walletunlocker.UnlockerService,
|
||||||
loaderOpts []btcwallet.LoaderOption, shutdownChan <-chan struct{}) (
|
loaderOpts []btcwallet.LoaderOption, shutdownChan <-chan struct{}) (
|
||||||
*WalletUnlockParams, error) {
|
*walletunlocker.WalletUnlockParams, error) {
|
||||||
|
|
||||||
// Wait for user to provide the password.
|
// Wait for user to provide the password.
|
||||||
ltndLog.Infof("Waiting for wallet encryption password. Use `lncli " +
|
ltndLog.Infof("Waiting for wallet encryption password. Use `lncli " +
|
||||||
@@ -1591,7 +1552,7 @@ func waitForWalletPassword(cfg *Config,
|
|||||||
"flag for new wallet as it has no effect")
|
"flag for new wallet as it has no effect")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &WalletUnlockParams{
|
return &walletunlocker.WalletUnlockParams{
|
||||||
Password: password,
|
Password: password,
|
||||||
Birthday: birthday,
|
Birthday: birthday,
|
||||||
RecoveryWindow: recoveryWindow,
|
RecoveryWindow: recoveryWindow,
|
||||||
@@ -1616,7 +1577,7 @@ func waitForWalletPassword(cfg *Config,
|
|||||||
"start of lnd")
|
"start of lnd")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &WalletUnlockParams{
|
return &walletunlocker.WalletUnlockParams{
|
||||||
Password: unlockMsg.Passphrase,
|
Password: unlockMsg.Passphrase,
|
||||||
RecoveryWindow: unlockMsg.RecoveryWindow,
|
RecoveryWindow: unlockMsg.RecoveryWindow,
|
||||||
Wallet: unlockMsg.Wallet,
|
Wallet: unlockMsg.Wallet,
|
||||||
|
@@ -27,6 +27,45 @@ var (
|
|||||||
ErrUnlockTimeout = errors.New("got no unlock message before timeout")
|
ErrUnlockTimeout = errors.New("got no unlock message before timeout")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WalletUnlockParams holds the variables used to parameterize the unlocking of
|
||||||
|
// lnd's wallet after it has already been created.
|
||||||
|
type WalletUnlockParams struct {
|
||||||
|
// Password is the public and private wallet passphrase.
|
||||||
|
Password []byte
|
||||||
|
|
||||||
|
// Birthday specifies the approximate time that this wallet was created.
|
||||||
|
// This is used to bound any rescans on startup.
|
||||||
|
Birthday time.Time
|
||||||
|
|
||||||
|
// RecoveryWindow specifies the address lookahead when entering recovery
|
||||||
|
// mode. A recovery will be attempted if this value is non-zero.
|
||||||
|
RecoveryWindow uint32
|
||||||
|
|
||||||
|
// Wallet is the loaded and unlocked Wallet. This is returned
|
||||||
|
// from the unlocker service to avoid it being unlocked twice (once in
|
||||||
|
// the unlocker service to check if the password is correct 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
|
||||||
|
|
||||||
|
// ChansToRestore a set of static channel backups that should be
|
||||||
|
// restored before the main server instance starts up.
|
||||||
|
ChansToRestore ChannelsToRecover
|
||||||
|
|
||||||
|
// UnloadWallet is a function for unloading the wallet, which should
|
||||||
|
// be called on shutdown.
|
||||||
|
UnloadWallet func() error
|
||||||
|
|
||||||
|
// StatelessInit signals that the user requested the daemon to be
|
||||||
|
// initialized stateless, which means no unencrypted macaroons should be
|
||||||
|
// written to disk.
|
||||||
|
StatelessInit bool
|
||||||
|
|
||||||
|
// MacResponseChan is the channel for sending back the admin macaroon to
|
||||||
|
// the WalletUnlocker service.
|
||||||
|
MacResponseChan chan []byte
|
||||||
|
}
|
||||||
|
|
||||||
// ChannelsToRecover wraps any set of packed (serialized+encrypted) channel
|
// ChannelsToRecover wraps any set of packed (serialized+encrypted) channel
|
||||||
// back ups together. These can be passed in when unlocking the wallet, or
|
// back ups together. These can be passed in when unlocking the wallet, or
|
||||||
// creating a new wallet for the first time with an existing seed.
|
// creating a new wallet for the first time with an existing seed.
|
||||||
|
Reference in New Issue
Block a user