@@ -30,9 +30,9 @@ use bitcoin::hashes::{Hash, HashEngine, HmacEngine};
3030
3131use bitcoin::secp256k1::Secp256k1;
3232use bitcoin::secp256k1::{PublicKey, SecretKey};
33- #[cfg(splicing)]
34- use bitcoin::ScriptBuf;
3533use bitcoin::{secp256k1, Sequence, SignedAmount, Weight};
34+ #[cfg(splicing)]
35+ use bitcoin::{Amount, ScriptBuf};
3636
3737use crate::blinded_path::message::MessageForwardNode;
3838use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext};
@@ -204,6 +204,47 @@ pub use crate::ln::outbound_payment::{
204204};
205205use crate::ln::script::ShutdownScript;
206206
207+ /// The components of a splice's funding transaction that are contributed by one party.
208+ #[cfg(splicing)]
209+ pub enum SpliceContribution {
210+ /// When funds are added to a channel.
211+ SpliceIn {
212+ /// The amount to contribute to the splice.
213+ value: Amount,
214+
215+ /// The inputs included in the splice's funding transaction to meet the contributed amount.
216+ /// Any excess amount will be sent to a change output.
217+ inputs: Vec<FundingTxInput>,
218+
219+ /// An optional change output script. This will be used if needed or, when not set,
220+ /// generated using [`SignerProvider::get_destination_script`].
221+ change_script: Option<ScriptBuf>,
222+ },
223+ }
224+
225+ #[cfg(splicing)]
226+ impl SpliceContribution {
227+ pub(super) fn value(&self) -> SignedAmount {
228+ match self {
229+ SpliceContribution::SpliceIn { value, .. } => {
230+ value.to_signed().unwrap_or(SignedAmount::MAX)
231+ },
232+ }
233+ }
234+
235+ pub(super) fn inputs(&self) -> &[FundingTxInput] {
236+ match self {
237+ SpliceContribution::SpliceIn { inputs, .. } => &inputs[..],
238+ }
239+ }
240+
241+ pub(super) fn into_tx_parts(self) -> (Vec<FundingTxInput>, Option<ScriptBuf>) {
242+ match self {
243+ SpliceContribution::SpliceIn { inputs, change_script, .. } => (inputs, change_script),
244+ }
245+ }
246+ }
247+
207248/// An input to contribute to a channel's funding transaction either when using the v2 channel
208249/// establishment protocol or when splicing.
209250#[derive(Clone)]
@@ -4557,14 +4598,13 @@ where
45574598 #[cfg(splicing)]
45584599 #[rustfmt::skip]
45594600 pub fn splice_channel(
4560- &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4561- our_funding_inputs: Vec<FundingTxInput>, change_script: Option<ScriptBuf>,
4562- funding_feerate_per_kw: u32, locktime: Option<u32>,
4601+ &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
4602+ contribution: SpliceContribution, funding_feerate_per_kw: u32, locktime: Option<u32>,
45634603 ) -> Result<(), APIError> {
45644604 let mut res = Ok(());
45654605 PersistenceNotifierGuard::optionally_notify(self, || {
45664606 let result = self.internal_splice_channel(
4567- channel_id, counterparty_node_id, our_funding_contribution_satoshis, our_funding_inputs, change_script , funding_feerate_per_kw, locktime
4607+ channel_id, counterparty_node_id, contribution , funding_feerate_per_kw, locktime
45684608 );
45694609 res = result;
45704610 match res {
@@ -4579,8 +4619,7 @@ where
45794619 #[cfg(splicing)]
45804620 fn internal_splice_channel(
45814621 &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
4582- our_funding_contribution_satoshis: i64, our_funding_inputs: Vec<FundingTxInput>,
4583- change_script: Option<ScriptBuf>, funding_feerate_per_kw: u32, locktime: Option<u32>,
4622+ contribution: SpliceContribution, funding_feerate_per_kw: u32, locktime: Option<u32>,
45844623 ) -> Result<(), APIError> {
45854624 let per_peer_state = self.per_peer_state.read().unwrap();
45864625
@@ -4601,13 +4640,8 @@ where
46014640 hash_map::Entry::Occupied(mut chan_phase_entry) => {
46024641 let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
46034642 if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4604- let msg = chan.splice_channel(
4605- our_funding_contribution_satoshis,
4606- our_funding_inputs,
4607- change_script,
4608- funding_feerate_per_kw,
4609- locktime,
4610- )?;
4643+ let msg =
4644+ chan.splice_channel(contribution, funding_feerate_per_kw, locktime)?;
46114645 peer_state.pending_msg_events.push(MessageSendEvent::SendSpliceInit {
46124646 node_id: *counterparty_node_id,
46134647 msg,
0 commit comments