@@ -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, 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};
@@ -204,6 +204,47 @@ pub use crate::ln::outbound_payment::{
204
204
};
205
205
use crate::ln::script::ShutdownScript;
206
206
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
+
207
248
/// An input to contribute to a channel's funding transaction either when using the v2 channel
208
249
/// establishment protocol or when splicing.
209
250
#[derive(Clone)]
@@ -4557,14 +4598,13 @@ where
4557
4598
#[cfg(splicing)]
4558
4599
#[rustfmt::skip]
4559
4600
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>,
4563
4603
) -> Result<(), APIError> {
4564
4604
let mut res = Ok(());
4565
4605
PersistenceNotifierGuard::optionally_notify(self, || {
4566
4606
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
4568
4608
);
4569
4609
res = result;
4570
4610
match res {
@@ -4579,8 +4619,7 @@ where
4579
4619
#[cfg(splicing)]
4580
4620
fn internal_splice_channel(
4581
4621
&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>,
4584
4623
) -> Result<(), APIError> {
4585
4624
let per_peer_state = self.per_peer_state.read().unwrap();
4586
4625
@@ -4601,13 +4640,8 @@ where
4601
4640
hash_map::Entry::Occupied(mut chan_phase_entry) => {
4602
4641
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
4603
4642
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)?;
4611
4645
peer_state.pending_msg_events.push(MessageSendEvent::SendSpliceInit {
4612
4646
node_id: *counterparty_node_id,
4613
4647
msg,
0 commit comments