Skip to content

Commit

Permalink
Add derivation_index to GetAddressResult
Browse files Browse the repository at this point in the history
The derivation index is required for
for client to derive and verify the address
on hardware wallets.
  • Loading branch information
edouardparis committed Nov 15, 2023
1 parent e0fba88 commit 5927c22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl DaemonControl {
.receive_descriptor()
.derive(index, &self.secp)
.address(self.config.bitcoin_config.network);
GetAddressResult::new(address)
GetAddressResult::new(address, index.into())
}

/// list addresses
Expand Down Expand Up @@ -915,6 +915,7 @@ pub struct GetInfoResult {
pub struct GetAddressResult {
#[serde(deserialize_with = "deser_addr_assume_checked")]
address: bitcoin::Address,
derivation_index: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -923,8 +924,11 @@ pub struct GetLabelsResult {
}

impl GetAddressResult {
pub fn new(address: bitcoin::Address) -> Self {
Self { address }
pub fn new(address: bitcoin::Address, derivation_index: u32) -> Self {
Self {
address,
derivation_index,
}
}

pub fn address(&self) -> &bitcoin::Address {
Expand Down
1 change: 1 addition & 0 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_getaddress(lianad):
assert "address" in res
# We'll get a new one at every call
assert res["address"] != lianad.rpc.getnewaddress()["address"]
assert res["derivation_index"] > lianad.rpc.getnewaddress()["derivation_index"]


def test_listaddresses(lianad):
Expand Down

0 comments on commit 5927c22

Please sign in to comment.