Skip to content

Commit

Permalink
Merge #818: Add derivation_index to GetAddressResult
Browse files Browse the repository at this point in the history
33384c8 Add derivation_index to GetAddressResult (edouardparis)

Pull request description:

  My bad, i pushed my fixes in a rush in #815 and wrecked the PR.

ACKs for top commit:
  darosior:
    ACK 33384c8

Tree-SHA512: 5f18506a84ff10fbe13757c2522b11a7ec005243f8698425f1d761d4b36378c256150d3d8337fefc1938232990004bbd629878b42b032b1dd0349d593a39386d
  • Loading branch information
darosior committed Nov 16, 2023
2 parents bd71cd6 + 33384c8 commit 514535d
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 514535d

Please sign in to comment.