Skip to content

Commit

Permalink
Merge #261: add get raw change address
Browse files Browse the repository at this point in the history
078ae14 get raw change address (thesimplekid)

Pull request description:

ACKs for top commit:
  apoelstra:
    ACK 078ae14
  w0xlt:
    ACK 078ae14

Tree-SHA512: b7ca1c44ef6888caeaa7904c575bb10debc7a965cfba5b27f6bbbcb31239140184e613e755bda8408078f51ee370fb415bcc1bd7a36681ac090e22b4a5f548e0
  • Loading branch information
apoelstra committed Jan 30, 2023
2 parents 9e6dff7 + 078ae14 commit 7e141b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,11 @@ pub trait RpcApi: Sized {
self.call("getnewaddress", &[opt_into_json(label)?, opt_into_json(address_type)?])
}

/// Generate new address for receiving change
fn get_raw_change_address(&self, address_type: Option<json::AddressType>) -> Result<Address> {
self.call("getrawchangeaddress", &[opt_into_json(address_type)?])
}

fn get_address_info(&self, address: &Address) -> Result<json::GetAddressInfoResult> {
self.call("getaddressinfo", &[address.to_string().into()])
}
Expand Down
12 changes: 12 additions & 0 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fn main() {
test_get_mining_info(&cl);
test_get_blockchain_info(&cl);
test_get_new_address(&cl);
test_get_raw_change_address(&cl);
test_dump_private_key(&cl);
test_generate(&cl);
test_get_balance_generate_to_address(&cl);
Expand Down Expand Up @@ -241,6 +242,17 @@ fn test_get_new_address(cl: &Client) {
assert_eq!(addr.address_type(), Some(bitcoin::AddressType::P2sh));
}

fn test_get_raw_change_address(cl: &Client) {
let addr = cl.get_raw_change_address(Some(json::AddressType::Legacy)).unwrap();
assert_eq!(addr.address_type(), Some(bitcoin::AddressType::P2pkh));

let addr = cl.get_raw_change_address(Some(json::AddressType::Bech32)).unwrap();
assert_eq!(addr.address_type(), Some(bitcoin::AddressType::P2wpkh));

let addr = cl.get_raw_change_address(Some(json::AddressType::P2shSegwit)).unwrap();
assert_eq!(addr.address_type(), Some(bitcoin::AddressType::P2sh));
}

fn test_dump_private_key(cl: &Client) {
let addr = cl.get_new_address(None, Some(json::AddressType::Bech32)).unwrap();
let sk = cl.dump_private_key(&addr).unwrap();
Expand Down

0 comments on commit 7e141b6

Please sign in to comment.