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.

Co-Authored-By: Antoine Poinsot <[email protected]>
  • Loading branch information
edouardparis and darosior committed Nov 16, 2023
1 parent bd71cd6 commit 33384c8
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 @@ -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
Expand Down Expand Up @@ -945,22 +945,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: bip32::ChildNumber,
}

impl GetAddressResult {
pub fn new(address: bitcoin::Address) -> Self {
Self { address }
pub fn new(address: bitcoin::Address, derivation_index: bip32::ChildNumber) -> 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 lianad.rpc.getnewaddress()["derivation_index"] == res["derivation_index"] + 2


def test_listaddresses(lianad):
Expand Down

0 comments on commit 33384c8

Please sign in to comment.