Skip to content

Commit c5e3102

Browse files
committed
minor Add optional change destination parameter
1 parent 8b25a0a commit c5e3102

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
@@ -2237,9 +2237,12 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
22372237
}
22382238

22392239
impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2240+
/// Prepare and start interactive transaction negotiation.
2241+
/// `change_destination_opt` - Optional destination for optional change; if None, default destination address is used.
22402242
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled
22412243
fn begin_interactive_funding_tx_construction<ES: Deref>(
22422244
&mut self, signer_provider: &SP, entropy_source: &ES, holder_node_id: PublicKey,
2245+
change_destination_opt: Option<ScriptBuf>,
22432246
) -> Result<Option<InteractiveTxMessageSend>, APIError>
22442247
where ES::Target: EntropySource
22452248
{
@@ -2291,10 +2294,15 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22912294
),
22922295
})?;
22932296
if let Some(change_value) = change_value_opt {
2294-
let change_script = signer_provider.get_destination_script(self.context.channel_keys_id).map_err(
2295-
|err| APIError::APIMisuseError {
2296-
err: format!("Failed to get change script as new destination script, {:?}", err),
2297-
})?;
2297+
let change_script = match change_destination_opt {
2298+
Some(script) => script,
2299+
None => {
2300+
signer_provider.get_destination_script(self.context.channel_keys_id).map_err(
2301+
|err| APIError::APIMisuseError {
2302+
err: format!("Failed to get change script as new destination script, {:?}", err),
2303+
})?
2304+
}
2305+
};
22982306
let mut change_output = TxOut {
22992307
value: Amount::from_sat(change_value),
23002308
script_pubkey: change_script,

lightning/src/ln/interactivetxs.rs

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

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

0 commit comments

Comments
 (0)