Add derivation_index to GetAddressResult

The derivation index is required for
for client to derive and verify the address
on hardware wallets.

Co-Authored-By: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
edouardparis 2023-11-15 19:02:51 +01:00 committed by Antoine Poinsot
parent bd71cd646c
commit 33384c89b5
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 14 additions and 12 deletions

View File

@ -306,7 +306,7 @@ impl DaemonControl {
.receive_descriptor()
.derive(index, &self.secp)
.address(self.config.bitcoin_config.network);
GetAddressResult::new(address)
GetAddressResult::new(address, index)
}
/// list addresses
@ -945,7 +945,17 @@ pub struct GetInfoResult {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetAddressResult {
#[serde(deserialize_with = "deser_addr_assume_checked")]
address: bitcoin::Address,
pub address: bitcoin::Address,
pub derivation_index: bip32::ChildNumber,
}
impl GetAddressResult {
pub fn new(address: bitcoin::Address, derivation_index: bip32::ChildNumber) -> Self {
Self {
address,
derivation_index,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -953,16 +963,6 @@ pub struct GetLabelsResult {
pub labels: HashMap<String, String>,
}
impl GetAddressResult {
pub fn new(address: bitcoin::Address) -> Self {
Self { address }
}
pub fn address(&self) -> &bitcoin::Address {
&self.address
}
}
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
pub struct AddressInfo {
index: u32,

View File

@ -35,6 +35,8 @@ def test_getaddress(lianad):
assert "address" in res
# We'll get a new one at every call
assert res["address"] != lianad.rpc.getnewaddress()["address"]
# new address has derivation_index higher than the previous one
assert lianad.rpc.getnewaddress()["derivation_index"] == res["derivation_index"] + 2
def test_listaddresses(lianad):