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 16, 2023
1 parent e0fba88 commit b6a8e56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 12 additions & 12 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 @@ -914,22 +914,22 @@ pub struct GetInfoResult {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetAddressResult {
#[serde(deserialize_with = "deser_addr_assume_checked")]
address: bitcoin::Address,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetLabelsResult {
pub labels: HashMap<String, String>,
pub address: bitcoin::Address,
pub derivation_index: u32,
}

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 {
&self.address
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetLabelsResult {
pub labels: HashMap<String, String>,
}

#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 res["derivation_index"] < lianad.rpc.getnewaddress()["derivation_index"]


def test_listaddresses(lianad):
Expand Down

0 comments on commit b6a8e56

Please sign in to comment.