lnwallet: use the wallet interface
This commit is contained in:
3 files changed
+25
-19
No files matched your search
+10
-6
@@ -48,7 +48,7 @@ type BtcWalletKeyRing struct {
|
|||||||
// wallet is a pointer to the active instance of the btcwallet core.
|
// wallet is a pointer to the active instance of the btcwallet core.
|
||||||
// This is required as we'll need to manually open database
|
// This is required as we'll need to manually open database
|
||||||
// transactions in order to derive addresses and lookup relevant keys
|
// transactions in order to derive addresses and lookup relevant keys
|
||||||
wallet *wallet.Wallet
|
wallet wallet.Interface
|
||||||
|
|
||||||
// chainKeyScope defines the purpose and coin type to be used when generating
|
// chainKeyScope defines the purpose and coin type to be used when generating
|
||||||
// keys for this keyring.
|
// keys for this keyring.
|
||||||
@@ -64,7 +64,7 @@ type BtcWalletKeyRing struct {
|
|||||||
//
|
//
|
||||||
// NOTE: The passed waddrmgr.Manager MUST be unlocked in order for the keychain
|
// NOTE: The passed waddrmgr.Manager MUST be unlocked in order for the keychain
|
||||||
// to function.
|
// to function.
|
||||||
func NewBtcWalletKeyRing(w *wallet.Wallet, coinType uint32) SecretKeyRing {
|
func NewBtcWalletKeyRing(w wallet.Interface, coinType uint32) SecretKeyRing {
|
||||||
// Construct the key scope that will be used within the waddrmgr to
|
// Construct the key scope that will be used within the waddrmgr to
|
||||||
// create an HD chain for deriving all of our required keys. A different
|
// create an HD chain for deriving all of our required keys. A different
|
||||||
// scope is used for each specific coin type.
|
// scope is used for each specific coin type.
|
||||||
@@ -92,14 +92,18 @@ 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.WatchOnly() && b.wallet.Manager.IsLocked() {
|
if !b.wallet.AddrManager().WatchOnly() &&
|
||||||
|
b.wallet.AddrManager().IsLocked() {
|
||||||
|
|
||||||
return nil, fmt.Errorf("cannot create BtcWalletKeyRing with " +
|
return nil, fmt.Errorf("cannot create BtcWalletKeyRing with " +
|
||||||
"locked waddrmgr.Manager")
|
"locked waddrmgr.Manager")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the manager is indeed unlocked, then we'll fetch the scope, cache
|
// If the manager is indeed unlocked, then we'll fetch the scope, cache
|
||||||
// it, and return to the caller.
|
// it, and return to the caller.
|
||||||
lnScope, err := b.wallet.Manager.FetchScopedKeyManager(b.chainKeyScope)
|
lnScope, err := b.wallet.AddrManager().FetchScopedKeyManager(
|
||||||
|
b.chainKeyScope,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -218,7 +222,7 @@ func (b *BtcWalletKeyRing) DeriveKey(keyLoc KeyLocator) (KeyDescriptor, error) {
|
|||||||
// require. We skip this if we're using a remote signer in which
|
// require. We skip this if we're using a remote signer in which
|
||||||
// case we _need_ to create all accounts when creating the
|
// case we _need_ to create all accounts when creating the
|
||||||
// wallet, so it must exist now.
|
// wallet, so it must exist now.
|
||||||
if !b.wallet.Manager.WatchOnly() {
|
if !b.wallet.AddrManager().WatchOnly() {
|
||||||
err = b.createAccountIfNotExists(
|
err = b.createAccountIfNotExists(
|
||||||
addrmgrNs, keyLoc.Family, scope,
|
addrmgrNs, keyLoc.Family, scope,
|
||||||
)
|
)
|
||||||
@@ -288,7 +292,7 @@ func (b *BtcWalletKeyRing) DerivePrivKey(keyDesc KeyDescriptor) (
|
|||||||
// require. We skip this if we're using a remote signer in which
|
// require. We skip this if we're using a remote signer in which
|
||||||
// case we _need_ to create all accounts when creating the
|
// case we _need_ to create all accounts when creating the
|
||||||
// wallet, so it must exist now.
|
// wallet, so it must exist now.
|
||||||
if !b.wallet.Manager.WatchOnly() {
|
if !b.wallet.AddrManager().WatchOnly() {
|
||||||
err = b.createAccountIfNotExists(
|
err = b.createAccountIfNotExists(
|
||||||
addrmgrNs, keyDesc.Family, scope,
|
addrmgrNs, keyDesc.Family, scope,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ var (
|
|||||||
// operate.
|
// operate.
|
||||||
type BtcWallet struct {
|
type BtcWallet struct {
|
||||||
// wallet is an active instance of btcwallet.
|
// wallet is an active instance of btcwallet.
|
||||||
wallet *base.Wallet
|
wallet base.Interface
|
||||||
|
|
||||||
chain chain.Interface
|
chain chain.Interface
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ func (b *BtcWallet) BackEnd() string {
|
|||||||
|
|
||||||
// InternalWallet returns a pointer to the internal base wallet which is the
|
// InternalWallet returns a pointer to the internal base wallet which is the
|
||||||
// core of btcwallet.
|
// core of btcwallet.
|
||||||
func (b *BtcWallet) InternalWallet() *base.Wallet {
|
func (b *BtcWallet) InternalWallet() base.Interface {
|
||||||
return b.wallet
|
return b.wallet
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ func (b *BtcWallet) InternalWallet() *base.Wallet {
|
|||||||
func (b *BtcWallet) Start() error {
|
func (b *BtcWallet) Start() error {
|
||||||
// Is the wallet (according to its database) currently watch-only
|
// Is the wallet (according to its database) currently watch-only
|
||||||
// already? If it is, we won't need to convert it later.
|
// already? If it is, we won't need to convert it later.
|
||||||
walletIsWatchOnly := b.wallet.Manager.WatchOnly()
|
walletIsWatchOnly := b.wallet.AddrManager().WatchOnly()
|
||||||
|
|
||||||
// If the wallet is watch-only, but we don't expect it to be, then we
|
// If the wallet is watch-only, but we don't expect it to be, then we
|
||||||
// are in an unexpected state and cannot continue.
|
// are in an unexpected state and cannot continue.
|
||||||
@@ -335,7 +335,7 @@ func (b *BtcWallet) Start() error {
|
|||||||
// created correctly for new wallets. Existing wallets don't
|
// created correctly for new wallets. Existing wallets don't
|
||||||
// automatically add them, we need to do that manually now.
|
// automatically add them, we need to do that manually now.
|
||||||
for _, scope := range LndDefaultKeyScopes {
|
for _, scope := range LndDefaultKeyScopes {
|
||||||
_, err := b.wallet.Manager.FetchScopedKeyManager(scope)
|
_, err := b.wallet.AddrManager().FetchScopedKeyManager(scope)
|
||||||
if waddrmgr.IsError(err, waddrmgr.ErrScopeNotFound) {
|
if waddrmgr.IsError(err, waddrmgr.ErrScopeNotFound) {
|
||||||
// The default scope wasn't found, that probably means
|
// The default scope wasn't found, that probably means
|
||||||
// it was added recently and older wallets don't know it
|
// it was added recently and older wallets don't know it
|
||||||
@@ -348,7 +348,9 @@ func (b *BtcWallet) Start() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scope, err := b.wallet.Manager.FetchScopedKeyManager(b.chainKeyScope)
|
scope, err := b.wallet.AddrManager().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
|
||||||
// loaded by default if it was), then we'll manually create the
|
// loaded by default if it was), then we'll manually create the
|
||||||
@@ -1291,7 +1293,7 @@ func (b *BtcWallet) GetTransactionDetails(
|
|||||||
|
|
||||||
// Grab the best block the wallet knows of, we'll use this to calculate
|
// Grab the best block the wallet knows of, we'll use this to calculate
|
||||||
// # of confirmations shortly below.
|
// # of confirmations shortly below.
|
||||||
bestBlock := b.wallet.Manager.SyncedTo()
|
bestBlock := b.wallet.SyncedTo()
|
||||||
currentHeight := bestBlock.Height
|
currentHeight := bestBlock.Height
|
||||||
tx, err := b.wallet.GetTransaction(*txHash)
|
tx, err := b.wallet.GetTransaction(*txHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1481,7 +1483,7 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
|
|||||||
|
|
||||||
// Grab the best block the wallet knows of, we'll use this to calculate
|
// Grab the best block the wallet knows of, we'll use this to calculate
|
||||||
// # of confirmations shortly below.
|
// # of confirmations shortly below.
|
||||||
bestBlock := b.wallet.Manager.SyncedTo()
|
bestBlock := b.wallet.SyncedTo()
|
||||||
currentHeight := bestBlock.Height
|
currentHeight := bestBlock.Height
|
||||||
|
|
||||||
// We'll attempt to find all transactions from start to end height.
|
// We'll attempt to find all transactions from start to end height.
|
||||||
@@ -1554,7 +1556,7 @@ type txSubscriptionClient struct {
|
|||||||
confirmed chan *lnwallet.TransactionDetail
|
confirmed chan *lnwallet.TransactionDetail
|
||||||
unconfirmed chan *lnwallet.TransactionDetail
|
unconfirmed chan *lnwallet.TransactionDetail
|
||||||
|
|
||||||
w *base.Wallet
|
w base.Interface
|
||||||
|
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
@@ -1597,7 +1599,7 @@ out:
|
|||||||
select {
|
select {
|
||||||
case txNtfn := <-t.txClient.C:
|
case txNtfn := <-t.txClient.C:
|
||||||
// TODO(roasbeef): handle detached blocks
|
// TODO(roasbeef): handle detached blocks
|
||||||
currentHeight := t.w.Manager.SyncedTo().Height
|
currentHeight := t.w.SyncedTo().Height
|
||||||
|
|
||||||
// Launch a goroutine to re-package and send
|
// Launch a goroutine to re-package and send
|
||||||
// notifications for any newly confirmed transactions.
|
// notifications for any newly confirmed transactions.
|
||||||
@@ -1653,7 +1655,7 @@ out:
|
|||||||
//
|
//
|
||||||
// This is a part of the WalletController interface.
|
// This is a part of the WalletController interface.
|
||||||
func (b *BtcWallet) SubscribeTransactions() (lnwallet.TransactionSubscription, error) {
|
func (b *BtcWallet) SubscribeTransactions() (lnwallet.TransactionSubscription, error) {
|
||||||
walletClient := b.wallet.NtfnServer.TransactionNotifications()
|
walletClient := b.wallet.NotificationServer().TransactionNotifications()
|
||||||
|
|
||||||
txClient := &txSubscriptionClient{
|
txClient := &txSubscriptionClient{
|
||||||
txClient: walletClient,
|
txClient: walletClient,
|
||||||
@@ -1674,7 +1676,7 @@ func (b *BtcWallet) SubscribeTransactions() (lnwallet.TransactionSubscription, e
|
|||||||
// This is a part of the WalletController interface.
|
// This is a part of the WalletController interface.
|
||||||
func (b *BtcWallet) IsSynced() (bool, int64, error) {
|
func (b *BtcWallet) IsSynced() (bool, int64, error) {
|
||||||
// Grab the best chain state the wallet is currently aware of.
|
// Grab the best chain state the wallet is currently aware of.
|
||||||
syncState := b.wallet.Manager.SyncedTo()
|
syncState := b.wallet.SyncedTo()
|
||||||
|
|
||||||
// We'll also extract the current best wallet timestamp so the caller
|
// We'll also extract the current best wallet timestamp so the caller
|
||||||
// can get an idea of where we are in the sync timeline.
|
// can get an idea of where we are in the sync timeline.
|
||||||
@@ -1752,7 +1754,7 @@ func (b *BtcWallet) GetRecoveryInfo() (bool, float64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Grab the best chain state the wallet is currently aware of.
|
// Grab the best chain state the wallet is currently aware of.
|
||||||
syncState := b.wallet.Manager.SyncedTo()
|
syncState := b.wallet.SyncedTo()
|
||||||
|
|
||||||
// Next, query the chain backend to grab the info about the tip of the
|
// Next, query the chain backend to grab the info about the tip of the
|
||||||
// main chain.
|
// main chain.
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ func TestScriptImport(t *testing.T) {
|
|||||||
require.Equal(t, firstAddressTaproot, firstDerivedAddr.String())
|
require.Equal(t, firstAddressTaproot, firstDerivedAddr.String())
|
||||||
|
|
||||||
scope := waddrmgr.KeyScopeBIP0086
|
scope := waddrmgr.KeyScopeBIP0086
|
||||||
_, err = w.InternalWallet().Manager.FetchScopedKeyManager(scope)
|
_, err = w.InternalWallet().AddrManager().FetchScopedKeyManager(scope)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Let's create a taproot script output now. This is a hash lock with a
|
// Let's create a taproot script output now. This is a hash lock with a
|
||||||
|
|||||||
Reference in new issue
Block a user