From efa36ce8f2d6099c8dfe67b4c360ee745096e4d5 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 16 Mar 2022 15:11:13 +0100 Subject: [PATCH] lntest+lnwallet: add AddressInfo to WalletController We need to be able to query the watch-only wallet about a public key when trying to sign with a key that we don't know the family or index of. The easiest way to do that is to leverage the wallet's address index to query the derivation path for a public key. To give the RPC wallet access to that functionality, we need to expose the method on the WalletController interface. --- lntest/mock/walletcontroller.go | 7 +++++++ lnwallet/btcwallet/btcwallet.go | 10 ++++++++++ lnwallet/interface.go | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/lntest/mock/walletcontroller.go b/lntest/mock/walletcontroller.go index 431c9f885..7dc79e2cc 100644 --- a/lntest/mock/walletcontroller.go +++ b/lntest/mock/walletcontroller.go @@ -90,6 +90,13 @@ func (w *WalletController) IsOurAddress(btcutil.Address) bool { return false } +// AddressInfo currently returns a dummy value. +func (w *WalletController) AddressInfo( + btcutil.Address) (waddrmgr.ManagedAddress, error) { + + return nil, nil +} + // ListAccounts currently returns a dummy value. func (w *WalletController) ListAccounts(string, *waddrmgr.KeyScope) ([]*waddrmgr.AccountProperties, error) { diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index a8f44a71e..d6a63b0b8 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -543,6 +543,16 @@ func (b *BtcWallet) IsOurAddress(a btcutil.Address) bool { return result && (err == nil) } +// AddressInfo returns the information about an address, if it's known to this +// wallet. +// +// NOTE: This is a part of the WalletController interface. +func (b *BtcWallet) AddressInfo(a btcutil.Address) (waddrmgr.ManagedAddress, + error) { + + return b.wallet.AddressInfo(a) +} + // ListAccounts retrieves all accounts belonging to the wallet by default. A // name and key scope filter can be provided to filter through all of the wallet // accounts and return only those matching. diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 5475ad62f..f91b1ae81 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -216,6 +216,10 @@ type WalletController interface { // IsOurAddress checks if the passed address belongs to this wallet IsOurAddress(a btcutil.Address) bool + // AddressInfo returns the information about an address, if it's known + // to this wallet. + AddressInfo(a btcutil.Address) (waddrmgr.ManagedAddress, error) + // ListAccounts retrieves all accounts belonging to the wallet by // default. A name and key scope filter can be provided to filter // through all of the wallet accounts and return only those matching.