@@ -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};
34+ #[cfg(splicing)]
35+ use bitcoin::{Amount, ScriptBuf};
3636
3737use crate::blinded_path::message::MessageForwardNode;
3838use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext};
@@ -202,6 +202,47 @@ pub use crate::ln::outbound_payment::{
202202};
203203use crate::ln::script::ShutdownScript;
204204
205+ /// The components of a splice's funding transaction that are contributed by one party.
206+ #[cfg(splicing)]
207+ pub enum SpliceContribution {
208+ /// When funds are added to a channel.
209+ SpliceIn {
210+ /// The amount to contribute to the splice.
211+ value: Amount,
212+
213+ /// The inputs included in the splice's funding transaction to meet the contributed amount.
214+ /// Any excess amount will be sent to a change output.
215+ inputs: Vec<FundingTxInput>,
216+
217+ /// An optional change output script. This will be used if needed or, when not set,
218+ /// generated using [`SignerProvider::get_destination_script`].
219+ change_script: Option<ScriptBuf>,
220+ },
221+ }
222+
223+ #[cfg(splicing)]
224+ impl SpliceContribution {
225+ pub(super) fn value(&self) -> SignedAmount {
226+ match self {
227+ SpliceContribution::SpliceIn { value, .. } => {
228+ value.to_signed().unwrap_or(SignedAmount::MAX)
229+ },
230+ }
231+ }
232+
233+ pub(super) fn inputs(&self) -> &[FundingTxInput] {
234+ match self {
235+ SpliceContribution::SpliceIn { inputs, .. } => &inputs[..],
236+ }
237+ }
238+
239+ pub(super) fn into_tx_parts(self) -> (Vec<FundingTxInput>, Option<ScriptBuf>) {
240+ match self {
241+ SpliceContribution::SpliceIn { inputs, change_script, .. } => (inputs, change_script),
242+ }
243+ }
244+ }
245+
205246// We hold various information about HTLC relay in the HTLC objects in Channel itself:
206247//
207248// Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should
@@ -4460,14 +4501,13 @@ where
44604501 #[cfg(splicing)]
44614502 #[rustfmt::skip]
44624503 pub fn splice_channel(
4463- &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4464- our_funding_inputs: Vec<FundingTxInput>, change_script: Option<ScriptBuf>,
4465- funding_feerate_per_kw: u32, locktime: Option<u32>,
4504+ &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
4505+ contribution: SpliceContribution, funding_feerate_per_kw: u32, locktime: Option<u32>,
44664506 ) -> Result<(), APIError> {
44674507 let mut res = Ok(());
44684508 PersistenceNotifierGuard::optionally_notify(self, || {
44694509 let result = self.internal_splice_channel(
4470- channel_id, counterparty_node_id, our_funding_contribution_satoshis, our_funding_inputs, change_script , funding_feerate_per_kw, locktime
4510+ channel_id, counterparty_node_id, contribution , funding_feerate_per_kw, locktime
44714511 );
44724512 res = result;
44734513 match res {
@@ -4482,8 +4522,7 @@ where
44824522 #[cfg(splicing)]
44834523 fn internal_splice_channel(
44844524 &self, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
4485- our_funding_contribution_satoshis: i64, our_funding_inputs: Vec<FundingTxInput>,
4486- change_script: Option<ScriptBuf>, funding_feerate_per_kw: u32, locktime: Option<u32>,
4525+ contribution: SpliceContribution, funding_feerate_per_kw: u32, locktime: Option<u32>,
44874526 ) -> Result<(), APIError> {
44884527 let per_peer_state = self.per_peer_state.read().unwrap();
44894528
@@ -4504,13 +4543,8 @@ where
45044543 hash_map::Entry::Occupied(mut chan_phase_entry) => {
45054544 let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
45064545 if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4507- let msg = chan.splice_channel(
4508- our_funding_contribution_satoshis,
4509- our_funding_inputs,
4510- change_script,
4511- funding_feerate_per_kw,
4512- locktime,
4513- )?;
4546+ let msg =
4547+ chan.splice_channel(contribution, funding_feerate_per_kw, locktime)?;
45144548 peer_state.pending_msg_events.push(MessageSendEvent::SendSpliceInit {
45154549 node_id: *counterparty_node_id,
45164550 msg,
0 commit comments