Skip to content

Commit 49db7b1

Browse files
committed
minor Add optional change destination parameter
1 parent 9a4eabe commit 49db7b1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,9 +2240,12 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
22402240
}
22412241

22422242
impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2243+
/// Prepare and start interactive transaction negotiation.
2244+
/// `change_destination_opt` - Optional destination for optional change; if None, default destination address is used.
22432245
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled
22442246
fn begin_interactive_funding_tx_construction<ES: Deref>(
22452247
&mut self, signer_provider: &SP, entropy_source: &ES, holder_node_id: PublicKey,
2248+
change_destination_opt: Option<ScriptBuf>,
22462249
) -> Result<Option<InteractiveTxMessageSend>, APIError>
22472250
where ES::Target: EntropySource
22482251
{
@@ -2294,10 +2297,15 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22942297
),
22952298
})?;
22962299
if let Some(change_value) = change_value_opt {
2297-
let change_script = signer_provider.get_destination_script(self.context.channel_keys_id).map_err(
2298-
|err| APIError::APIMisuseError {
2299-
err: format!("Failed to get change script as new destination script, {:?}", err),
2300-
})?;
2300+
let change_script = match change_destination_opt {
2301+
Some(script) => script,
2302+
None => {
2303+
signer_provider.get_destination_script(self.context.channel_keys_id).map_err(
2304+
|err| APIError::APIMisuseError {
2305+
err: format!("Failed to get change script as new destination script, {:?}", err),
2306+
})?
2307+
}
2308+
};
23012309
let mut change_output = TxOut {
23022310
value: Amount::from_sat(change_value),
23032311
script_pubkey: change_script,

lightning/src/ln/interactivetxs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,8 @@ pub(super) fn calculate_change_output_value(
17041704
// Note: in case of additional outputs, they will have to be subtracted here
17051705

17061706
let min_contribution_and_fees = our_contribution.saturating_add(fees_sats);
1707-
let min_contribution_and_fees_and_dust = min_contribution_and_fees.saturating_add(holder_dust_limit_satoshis);
1707+
let min_contribution_and_fees_and_dust =
1708+
min_contribution_and_fees.saturating_add(holder_dust_limit_satoshis);
17081709
if total_input_satoshis < min_contribution_and_fees {
17091710
// Not enough to cover contribution plus fees
17101711
Err(AbortReason::InsufficientFees)

0 commit comments

Comments
 (0)