lnwallet+lnrpc: add address index to ListAddresses

For the itest in the next commit we'll need to be able to fetch the
input information for an address over RPC. The only piece missing is the
address' index, which we add in this commit. Everything else should be
derivable from the ListAddresses and ListAccounts calls.
This commit is contained in:
Oliver Gugger
2024-02-06 12:25:59 +01:00
parent fb20cd598e
commit 54fa5805c2
6 changed files with 663 additions and 593 deletions

View File

@@ -815,17 +815,35 @@ func (b *BtcWallet) ListAddresses(name string,
// Hex-encode the compressed public key for custom lnd
// keys, addresses don't make a lot of sense.
pubKey, ok := managedAddr.(waddrmgr.ManagedPubKeyAddress)
if ok && isLndCustom {
var (
pubKey *btcec.PublicKey
derivationPath string
)
pka, ok := managedAddr.(waddrmgr.ManagedPubKeyAddress)
if ok {
pubKey = pka.PubKey()
// There can be an error in two cases: Either
// the address isn't a managed pubkey address,
// which we already checked above, or the
// address is imported in which case we don't
// know the derivation path, and it will just be
// empty anyway.
_, _, derivationPath, _ =
Bip32DerivationFromAddress(pka)
}
if pubKey != nil && isLndCustom {
addressString = hex.EncodeToString(
pubKey.PubKey().SerializeCompressed(),
pubKey.SerializeCompressed(),
)
}
addressProperties[idx] = lnwallet.AddressProperty{
Address: addressString,
Internal: managedAddr.Internal(),
Balance: addressBalance[addressString],
Address: addressString,
Internal: managedAddr.Internal(),
Balance: addressBalance[addressString],
PublicKey: pubKey,
DerivationPath: derivationPath,
}
}