Skip to content

Commit 54fa580

Browse files
committed
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.
1 parent fb20cd5 commit 54fa580

File tree

6 files changed

+659
-589
lines changed

6 files changed

+659
-589
lines changed

lnrpc/walletrpc/walletkit.pb.go

Lines changed: 604 additions & 580 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/walletrpc/walletkit.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,13 @@ message AddressProperty {
517517

518518
// The balance of the address.
519519
int64 balance = 3;
520+
521+
// The full derivation path of the address. This will be empty for imported
522+
// addresses.
523+
string derivation_path = 4;
524+
525+
// The public key of the address. This will be empty for imported addresses.
526+
bytes public_key = 5;
520527
}
521528

522529
message AccountWithAddresses {

lnrpc/walletrpc/walletkit.swagger.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,15 @@
13171317
"type": "string",
13181318
"format": "int64",
13191319
"description": "The balance of the address."
1320+
},
1321+
"derivation_path": {
1322+
"type": "string",
1323+
"description": "The full derivation path of the address. This will be empty for imported\naddresses."
1324+
},
1325+
"public_key": {
1326+
"type": "string",
1327+
"format": "byte",
1328+
"description": "The public key of the address. This will be empty for imported addresses."
13201329
}
13211330
}
13221331
},

lnrpc/walletrpc/walletkit_server.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,10 +2054,16 @@ func marshalWalletAddressList(w *WalletKit, account *waddrmgr.AccountProperties,
20542054

20552055
addresses := make([]*AddressProperty, len(addressList))
20562056
for idx, addr := range addressList {
2057+
var pubKeyBytes []byte
2058+
if addr.PublicKey != nil {
2059+
pubKeyBytes = addr.PublicKey.SerializeCompressed()
2060+
}
20572061
addresses[idx] = &AddressProperty{
2058-
Address: addr.Address,
2059-
IsInternal: addr.Internal,
2060-
Balance: int64(addr.Balance),
2062+
Address: addr.Address,
2063+
IsInternal: addr.Internal,
2064+
Balance: int64(addr.Balance),
2065+
DerivationPath: addr.DerivationPath,
2066+
PublicKey: pubKeyBytes,
20612067
}
20622068
}
20632069

lnwallet/btcwallet/btcwallet.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,17 +815,35 @@ func (b *BtcWallet) ListAddresses(name string,
815815

816816
// Hex-encode the compressed public key for custom lnd
817817
// keys, addresses don't make a lot of sense.
818-
pubKey, ok := managedAddr.(waddrmgr.ManagedPubKeyAddress)
819-
if ok && isLndCustom {
818+
var (
819+
pubKey *btcec.PublicKey
820+
derivationPath string
821+
)
822+
pka, ok := managedAddr.(waddrmgr.ManagedPubKeyAddress)
823+
if ok {
824+
pubKey = pka.PubKey()
825+
826+
// There can be an error in two cases: Either
827+
// the address isn't a managed pubkey address,
828+
// which we already checked above, or the
829+
// address is imported in which case we don't
830+
// know the derivation path, and it will just be
831+
// empty anyway.
832+
_, _, derivationPath, _ =
833+
Bip32DerivationFromAddress(pka)
834+
}
835+
if pubKey != nil && isLndCustom {
820836
addressString = hex.EncodeToString(
821-
pubKey.PubKey().SerializeCompressed(),
837+
pubKey.SerializeCompressed(),
822838
)
823839
}
824840

825841
addressProperties[idx] = lnwallet.AddressProperty{
826-
Address: addressString,
827-
Internal: managedAddr.Internal(),
828-
Balance: addressBalance[addressString],
842+
Address: addressString,
843+
Internal: managedAddr.Internal(),
844+
Balance: addressBalance[addressString],
845+
PublicKey: pubKey,
846+
DerivationPath: derivationPath,
829847
}
830848
}
831849

lnwallet/interface.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ type AddressProperty struct {
9696

9797
// Balance returns the total balance of an address.
9898
Balance btcutil.Amount
99+
100+
// DerivationPath is the derivation path of the address.
101+
DerivationPath string
102+
103+
// PublicKey is the public key of the address.
104+
PublicKey *btcec.PublicKey
99105
}
100106

101107
// AccountIdentifier contains information to uniquely identify an account.

0 commit comments

Comments
 (0)