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:
6 files changed
+663
-593
No files matched your search
+608
-584
File diff suppressed because it is too large.
Load diff
@@ -517,6 +517,13 @@ message AddressProperty {
|
||||
|
||||
// The balance of the address.
|
||||
int64 balance = 3;
|
||||
|
||||
// The full derivation path of the address. This will be empty for imported
|
||||
// addresses.
|
||||
string derivation_path = 4;
|
||||
|
||||
// The public key of the address. This will be empty for imported addresses.
|
||||
bytes public_key = 5;
|
||||
}
|
||||
|
||||
message AccountWithAddresses {
|
||||
|
||||
@@ -1317,6 +1317,15 @@
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The balance of the address."
|
||||
},
|
||||
"derivation_path": {
|
||||
"type": "string",
|
||||
"description": "The full derivation path of the address. This will be empty for imported\naddresses."
|
||||
},
|
||||
"public_key": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "The public key of the address. This will be empty for imported addresses."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -2054,10 +2054,16 @@ func marshalWalletAddressList(w *WalletKit, account *waddrmgr.AccountProperties,
|
||||
|
||||
addresses := make([]*AddressProperty, len(addressList))
|
||||
for idx, addr := range addressList {
|
||||
var pubKeyBytes []byte
|
||||
if addr.PublicKey != nil {
|
||||
pubKeyBytes = addr.PublicKey.SerializeCompressed()
|
||||
}
|
||||
addresses[idx] = &AddressProperty{
|
||||
Address: addr.Address,
|
||||
IsInternal: addr.Internal,
|
||||
Balance: int64(addr.Balance),
|
||||
Address: addr.Address,
|
||||
IsInternal: addr.Internal,
|
||||
Balance: int64(addr.Balance),
|
||||
DerivationPath: addr.DerivationPath,
|
||||
PublicKey: pubKeyBytes,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,12 @@ type AddressProperty struct {
|
||||
|
||||
// Balance returns the total balance of an address.
|
||||
Balance btcutil.Amount
|
||||
|
||||
// DerivationPath is the derivation path of the address.
|
||||
DerivationPath string
|
||||
|
||||
// PublicKey is the public key of the address.
|
||||
PublicKey *btcec.PublicKey
|
||||
}
|
||||
|
||||
// AccountIdentifier contains information to uniquely identify an account.
|
||||
|
||||
Reference in new issue
Block a user