@@ -30,9 +30,9 @@ use bitcoin::hashes::{Hash, HashEngine, HmacEngine};
30
30
31
31
use bitcoin::secp256k1::Secp256k1;
32
32
use bitcoin::secp256k1::{PublicKey, SecretKey};
33
- #[cfg(splicing)]
34
- use bitcoin::ScriptBuf;
35
33
use bitcoin::{secp256k1, Sequence, SignedAmount, TxIn, Weight};
34
+ #[cfg(splicing)]
35
+ use bitcoin::{Amount, ScriptBuf};
36
36
37
37
use crate::blinded_path::message::MessageForwardNode;
38
38
use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext};
@@ -200,6 +200,47 @@ pub use crate::ln::outbound_payment::{
200
200
};
201
201
use crate::ln::script::ShutdownScript;
202
202
203
+ /// The components of a splice's funding transaction that are contributed by one party.
204
+ #[cfg(splicing)]
205
+ pub enum SpliceContribution {
206
+ /// When funds are added to a channel.
207
+ SpliceIn {
208
+ /// The amount to contribute to the splice.
209
+ value: Amount,
210
+
211
+ /// The inputs used to include in the splice's funding transaction used to meet the
212
+ /// contributed amount. Any excess amount will be sent to a change output.
213
+ inputs: Vec<FundingTxInput>,
214
+
215
+ /// An optional change output script. This will be used if needed or, when not set,
216
+ /// generated using `SignerProvider::get_destination_script`.
217
+ change_script: Option<ScriptBuf>,
218
+ },
219
+ }
220
+
221
+ #[cfg(splicing)]
222
+ impl SpliceContribution {
223
+ pub(super) fn value(&self) -> SignedAmount {
224
+ match self {
225
+ SpliceContribution::SpliceIn { value, .. } => {
226
+ value.to_signed().unwrap_or(SignedAmount::MAX)
227
+ },
228
+ }
229
+ }
230
+
231
+ pub(super) fn inputs(&self) -> &[FundingTxInput] {
232
+ match self {
233
+ SpliceContribution::SpliceIn { inputs, .. } => &inputs[..],
234
+ }
235
+ }
236
+
237
+ pub(super) fn into_tx_parts(self) -> (Vec<FundingTxInput>, Option<ScriptBuf>) {
238
+ match self {
239
+ SpliceContribution::SpliceIn { inputs, change_script, .. } => (inputs, change_script),
240
+ }
241
+ }
242
+ }
243
+
203
244
/// An input to contribute to a channel's funding transaction either when using the v2 channel
204
245
/// establishment protocol or when splicing.
205
246
#[derive(Clone)]
@@ -4478,14 +4519,13 @@ where
4478
4519
#[cfg(splicing)]
4479
4520
#[rustfmt::skip]
4480
4521
pub fn splice_channel(
4481
- &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4482
- our_funding_inputs: Vec<FundingTxInput>, change_script: Option<ScriptBuf>,
4483
- funding_feerate_per_kw: u32, locktime: Option<u32>,
4522
+ &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
4523
+ contribution: SpliceContribution, funding_feerate_per_kw: u32, locktime: Option<u32>,
4484
4524
) -> Result<(), APIError> {
4485
4525
let mut res = Ok(());
4486
4526
PersistenceNotifierGuard::optionally_notify(self, || {
4487
4527
let result = self.internal_splice_channel(
4488
- channel_id, counterparty_node_id, our_funding_contribution_satoshis, our_funding_inputs, change_script , funding_feerate_per_kw, locktime
4528
+ channel_id, counterparty_node_id, contribution , funding_feerate_per_kw, locktime
4489
4529
);
4490
4530
res = result;
4491
4531
match res {
@@ -4500,8 +4540,7 @@ where
4500
4540
#[cfg(splicing)]
4501
4541
fn internal_splice_channel(
4502
4542
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
4503
- our_funding_contribution_satoshis: i64, our_funding_inputs: Vec<FundingTxInput>,
4504
- change_script: Option<ScriptBuf>, funding_feerate_per_kw: u32, locktime: Option<u32>,
4543
+ contribution: SpliceContribution, funding_feerate_per_kw: u32, locktime: Option<u32>,
4505
4544
) -> Result<(), APIError> {
4506
4545
let per_peer_state = self.per_peer_state.read().unwrap();
4507
4546
@@ -4522,13 +4561,8 @@ where
4522
4561
hash_map::Entry::Occupied(mut chan_phase_entry) => {
4523
4562
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
4524
4563
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4525
- let msg = chan.splice_channel(
4526
- our_funding_contribution_satoshis,
4527
- our_funding_inputs,
4528
- change_script,
4529
- funding_feerate_per_kw,
4530
- locktime,
4531
- )?;
4564
+ let msg =
4565
+ chan.splice_channel(contribution, funding_feerate_per_kw, locktime)?;
4532
4566
peer_state.pending_msg_events.push(MessageSendEvent::SendSpliceInit {
4533
4567
node_id: *counterparty_node_id,
4534
4568
msg,
0 commit comments