lnd
lnd copied to clipboard
lnrpc+lnwallet: adds listaddresses RPC
Change Description
Related: #2498
Command: lncli wallet addresses list --account_name "default"
Steps to Test
Steps for reviewers to follow to test the change.
Pull Request Checklist
Testing
- [ ] Your PR passes all CI checks.
- [ ] Tests covering the positive and negative (error paths) are included.
- [ ] Bug fixes contain tests triggering the bug to prevent regressions.
Code Style and Documentation
- [x] The change obeys the Code Documentation and Commenting guidelines, and lines wrap at 80.
- [x] Commits follow the Ideal Git Commit Structure.
- [ ] Any new logging statements use an appropriate subsystem and logging level.
- [ ] There is a change description in the release notes, or
[skip ci]
in the commit message for small changes.
📝 Please see our Contribution Guidelines for further guidance.
Here's the diff I'm proposing:
diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go
index 14f9e3d7d..58db4322e 100644
--- a/lnwallet/btcwallet/btcwallet.go
+++ b/lnwallet/btcwallet/btcwallet.go
@@ -739,29 +739,48 @@ func (b *BtcWallet) ListAddresses(name string) (
}
for _, accntDetails := range accounts {
+ scopedMgr, err := b.wallet.Manager.FetchScopedKeyManager(
+ accntDetails.KeyScope,
+ )
+ if err != nil {
+ return nil, err
+ }
+
// Retrieve all addresses of an account.
- addresses, err := b.wallet.AccountAddresses(accntDetails.AccountNumber)
+ var managedAddrs []waddrmgr.ManagedAddress
+ err = walletdb.View(
+ b.wallet.Database(), func(tx walletdb.ReadTx) error {
+ addrmgrNs := tx.ReadBucket(waddrmgrNamespaceKey)
+ return scopedMgr.ForEachAccountAddress(
+ addrmgrNs, accntDetails.AccountNumber,
+ func(a waddrmgr.ManagedAddress) error {
+ managedAddrs = append(
+ managedAddrs, a,
+ )
+
+ return nil
+ },
+ )
+ },
+ )
if err != nil {
return nil, err
}
// Only consider those accounts which have addresses.
- if len(addresses) == 0 {
+ if len(managedAddrs) == 0 {
continue
}
- addressProperties := make([]lnwallet.AddressProperty, len(addresses))
-
- for idx, address := range addresses {
- addressInfo, err := b.wallet.AddressInfo(address)
- if err != nil {
- return nil, err
- }
-
- addressString := address.String()
+ addressProperties := make(
+ []lnwallet.AddressProperty, len(managedAddrs),
+ )
+ for idx, managedAddr := range managedAddrs {
+ addr := managedAddr.Address()
+ addressString := addr.String()
addressProperties[idx] = lnwallet.AddressProperty{
Address: addressString,
- Internal: addressInfo.Internal(),
+ Internal: managedAddr.Internal(),
Balance: addressBalance[addressString],
}
}
needs rebase
@bhandras: review reminder