Skip to content

Commit

Permalink
Use internal addresses/LastUnused for change scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Jun 10, 2024
1 parent 7a8053d commit 893172c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ where
Ok(address_info.address)
}

fn get_new_internal_address(&self) -> Result<bitcoin::Address, Error> {
let address_info =
self.inner.lock().unwrap().get_internal_address(AddressIndex::LastUnused)?;
Ok(address_info.address)
}

pub(crate) fn get_balances(
&self, total_anchor_channels_reserve_sats: u64,
) -> Result<(u64, u64), Error> {
Expand Down Expand Up @@ -343,9 +349,10 @@ where

fn get_change_script(&self) -> Result<ScriptBuf, ()> {
let locked_wallet = self.inner.lock().unwrap();
let address_info = locked_wallet.get_address(AddressIndex::LastUnused).map_err(|e| {
log_error!(self.logger, "Failed to retrieve new address from wallet: {}", e);
})?;
let address_info =
locked_wallet.get_internal_address(AddressIndex::LastUnused).map_err(|e| {
log_error!(self.logger, "Failed to retrieve new address from wallet: {}", e);
})?;

Ok(address_info.address.script_pubkey())
}
Expand Down Expand Up @@ -563,7 +570,7 @@ where
L::Target: Logger,
{
fn get_change_destination_script(&self) -> Result<ScriptBuf, ()> {
let address = self.wallet.get_new_address().map_err(|e| {
let address = self.wallet.get_new_internal_address().map_err(|e| {
log_error!(self.logger, "Failed to retrieve new address from wallet: {}", e);
})?;
Ok(address.script_pubkey())
Expand Down

0 comments on commit 893172c

Please sign in to comment.