Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/payment/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ impl OnchainPayment {
Ok(funding_address)
}

/// Retrieve the next unused on-chain/funding address.
pub fn next_address(&self) -> Result<Address, Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing this API will be super confusing, IMO, as it will be entirely unclear which variant to use. And we intentionally only expose APIs that advance the descriptor index to avoid address reuse.

let funding_address = self.wallet.get_next_address()?;
log_info!(self.logger, "Generated next funding address: {}", funding_address);
Ok(funding_address)
}

/// Send an on-chain payment to the given address.
///
/// This will respect any on-chain reserve we need to keep, i.e., won't allow to cut into
Expand Down
12 changes: 12 additions & 0 deletions src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,18 @@ impl Wallet {
Ok(address_info.address)
}

pub(crate) fn get_next_address(&self) -> Result<bitcoin::Address, Error> {
let mut locked_wallet = self.inner.lock().unwrap();
let mut locked_persister = self.persister.lock().unwrap();

let address_info = locked_wallet.next_unused_address(KeychainKind::External);
locked_wallet.persist(&mut locked_persister).map_err(|e| {
log_error!(self.logger, "Failed to persist wallet: {}", e);
Error::PersistenceFailed
})?;
Ok(address_info.address)
}

pub(crate) fn get_new_internal_address(&self) -> Result<bitcoin::Address, Error> {
let mut locked_wallet = self.inner.lock().unwrap();
let mut locked_persister = self.persister.lock().unwrap();
Expand Down
Loading