mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
multi: allow internal wallet to be watch-only
This commit is contained in:
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ require (
|
|||||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
|
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
|
||||||
github.com/btcsuite/btcutil v1.0.3-0.20210527170813-e2ba6805a890
|
github.com/btcsuite/btcutil v1.0.3-0.20210527170813-e2ba6805a890
|
||||||
github.com/btcsuite/btcutil/psbt v1.0.3-0.20210527170813-e2ba6805a890
|
github.com/btcsuite/btcutil/psbt v1.0.3-0.20210527170813-e2ba6805a890
|
||||||
github.com/btcsuite/btcwallet v0.12.1-0.20210826004415-4ef582f76b02
|
github.com/btcsuite/btcwallet v0.12.1-0.20210916213031-d0868cb9dd94
|
||||||
github.com/btcsuite/btcwallet/wallet/txauthor v1.1.0
|
github.com/btcsuite/btcwallet/wallet/txauthor v1.1.0
|
||||||
github.com/btcsuite/btcwallet/wallet/txrules v1.1.0
|
github.com/btcsuite/btcwallet/wallet/txrules v1.1.0
|
||||||
github.com/btcsuite/btcwallet/wallet/txsizes v1.1.0 // indirect
|
github.com/btcsuite/btcwallet/wallet/txsizes v1.1.0 // indirect
|
||||||
|
4
go.sum
4
go.sum
@@ -91,8 +91,8 @@ github.com/btcsuite/btcutil v1.0.3-0.20210527170813-e2ba6805a890/go.mod h1:0DVlH
|
|||||||
github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:LVveMu4VaNSkIRTZu2+ut0HDBRuYjqGocxDMNS1KuGQ=
|
github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:LVveMu4VaNSkIRTZu2+ut0HDBRuYjqGocxDMNS1KuGQ=
|
||||||
github.com/btcsuite/btcutil/psbt v1.0.3-0.20210527170813-e2ba6805a890 h1:0xUNvvwJ7RjzBs4nCF+YrK28S5P/b4uHkpPxY1ovGY4=
|
github.com/btcsuite/btcutil/psbt v1.0.3-0.20210527170813-e2ba6805a890 h1:0xUNvvwJ7RjzBs4nCF+YrK28S5P/b4uHkpPxY1ovGY4=
|
||||||
github.com/btcsuite/btcutil/psbt v1.0.3-0.20210527170813-e2ba6805a890/go.mod h1:LVveMu4VaNSkIRTZu2+ut0HDBRuYjqGocxDMNS1KuGQ=
|
github.com/btcsuite/btcutil/psbt v1.0.3-0.20210527170813-e2ba6805a890/go.mod h1:LVveMu4VaNSkIRTZu2+ut0HDBRuYjqGocxDMNS1KuGQ=
|
||||||
github.com/btcsuite/btcwallet v0.12.1-0.20210826004415-4ef582f76b02 h1:Q8Scm1SXNRyiXzD3a7O1C6bLFIUxUQSnWAd9aat8Xd0=
|
github.com/btcsuite/btcwallet v0.12.1-0.20210916213031-d0868cb9dd94 h1:Bx+xu606h2sZNn5VaZMWvI0GtlGE+y+dHI4hbL5Ld6k=
|
||||||
github.com/btcsuite/btcwallet v0.12.1-0.20210826004415-4ef582f76b02/go.mod h1:SdqXKJoEEi5LJq6zU67PcKiyqF97AcUOfBfyQHC7rqQ=
|
github.com/btcsuite/btcwallet v0.12.1-0.20210916213031-d0868cb9dd94/go.mod h1:gHFk6GQ4IP/a8z6mfwK85GagUPxvAxCmgFy/whrBXhI=
|
||||||
github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU=
|
github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU=
|
||||||
github.com/btcsuite/btcwallet/wallet/txauthor v1.0.1-0.20210329233242-e0607006dce6/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU=
|
github.com/btcsuite/btcwallet/wallet/txauthor v1.0.1-0.20210329233242-e0607006dce6/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU=
|
||||||
github.com/btcsuite/btcwallet/wallet/txauthor v1.1.0 h1:8pO0pvPX1rFRfRiol4oV6kX7dY5y4chPwhfVwUfvwtk=
|
github.com/btcsuite/btcwallet/wallet/txauthor v1.1.0 h1:8pO0pvPX1rFRfRiol4oV6kX7dY5y4chPwhfVwUfvwtk=
|
||||||
|
@@ -93,7 +93,7 @@ func (b *BtcWalletKeyRing) keyScope() (*waddrmgr.ScopedKeyManager, error) {
|
|||||||
|
|
||||||
// Otherwise, we'll first do a check to ensure that the root manager
|
// Otherwise, we'll first do a check to ensure that the root manager
|
||||||
// isn't locked, as otherwise we won't be able to *use* the scope.
|
// isn't locked, as otherwise we won't be able to *use* the scope.
|
||||||
if b.wallet.Manager.IsLocked() {
|
if !b.wallet.Manager.WatchOnly() && b.wallet.Manager.IsLocked() {
|
||||||
return nil, fmt.Errorf("cannot create BtcWalletKeyRing with " +
|
return nil, fmt.Errorf("cannot create BtcWalletKeyRing with " +
|
||||||
"locked waddrmgr.Manager")
|
"locked waddrmgr.Manager")
|
||||||
}
|
}
|
||||||
@@ -216,10 +216,16 @@ func (b *BtcWalletKeyRing) DeriveKey(keyLoc KeyLocator) (KeyDescriptor, error) {
|
|||||||
|
|
||||||
// If the account doesn't exist, then we may need to create it
|
// If the account doesn't exist, then we may need to create it
|
||||||
// for the first time in order to derive the keys that we
|
// for the first time in order to derive the keys that we
|
||||||
// require.
|
// require. We skip this if we're using a remote signer in which
|
||||||
err = b.createAccountIfNotExists(addrmgrNs, keyLoc.Family, scope)
|
// case we _need_ to create all accounts when creating the
|
||||||
if err != nil {
|
// wallet, so it must exist now.
|
||||||
return err
|
if !b.wallet.Manager.WatchOnly() {
|
||||||
|
err = b.createAccountIfNotExists(
|
||||||
|
addrmgrNs, keyLoc.Family, scope,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
path := waddrmgr.DerivationPath{
|
path := waddrmgr.DerivationPath{
|
||||||
@@ -280,12 +286,16 @@ func (b *BtcWalletKeyRing) DerivePrivKey(keyDesc KeyDescriptor) (
|
|||||||
|
|
||||||
// If the account doesn't exist, then we may need to create it
|
// If the account doesn't exist, then we may need to create it
|
||||||
// for the first time in order to derive the keys that we
|
// for the first time in order to derive the keys that we
|
||||||
// require.
|
// require. We skip this if we're using a remote signer in which
|
||||||
err = b.createAccountIfNotExists(
|
// case we _need_ to create all accounts when creating the
|
||||||
addrmgrNs, keyDesc.Family, scope,
|
// wallet, so it must exist now.
|
||||||
)
|
if !b.wallet.Manager.WatchOnly() {
|
||||||
if err != nil {
|
err = b.createAccountIfNotExists(
|
||||||
return err
|
addrmgrNs, keyDesc.Family, scope,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the public key isn't set or they have a non-zero index,
|
// If the public key isn't set or they have a non-zero index,
|
||||||
|
@@ -291,10 +291,14 @@ func (b *BtcWallet) Start() error {
|
|||||||
// We'll start by unlocking the wallet and ensuring that the KeyScope:
|
// We'll start by unlocking the wallet and ensuring that the KeyScope:
|
||||||
// (1017, 1) exists within the internal waddrmgr. We'll need this in
|
// (1017, 1) exists within the internal waddrmgr. We'll need this in
|
||||||
// order to properly generate the keys required for signing various
|
// order to properly generate the keys required for signing various
|
||||||
// contracts.
|
// contracts. If this is a watch-only wallet, we don't have any private
|
||||||
if err := b.wallet.Unlock(b.cfg.PrivatePass, nil); err != nil {
|
// keys and therefore unlocking is not necessary.
|
||||||
return err
|
if !b.cfg.WatchOnly {
|
||||||
|
if err := b.wallet.Unlock(b.cfg.PrivatePass, nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := b.wallet.Manager.FetchScopedKeyManager(b.chainKeyScope)
|
_, err := b.wallet.Manager.FetchScopedKeyManager(b.chainKeyScope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the scope hasn't yet been created (it wouldn't been
|
// If the scope hasn't yet been created (it wouldn't been
|
||||||
|
@@ -72,6 +72,10 @@ type Config struct {
|
|||||||
// CoinSelectionStrategy is the strategy that is used for selecting
|
// CoinSelectionStrategy is the strategy that is used for selecting
|
||||||
// coins when funding a transaction.
|
// coins when funding a transaction.
|
||||||
CoinSelectionStrategy wallet.CoinSelectionStrategy
|
CoinSelectionStrategy wallet.CoinSelectionStrategy
|
||||||
|
|
||||||
|
// WatchOnly indicates that the wallet was initialized with public key
|
||||||
|
// material only and does not contain any private keys.
|
||||||
|
WatchOnly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkDir returns the directory name of a network directory to hold wallet
|
// NetworkDir returns the directory name of a network directory to hold wallet
|
||||||
|
Reference in New Issue
Block a user