@@ -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};
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};
@@ -202,6 +202,47 @@ pub use crate::ln::outbound_payment::{
202
202
};
203
203
use crate::ln::script::ShutdownScript;
204
204
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
+
205
246
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
206
247
//
207
248
// Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should
@@ -4460,14 +4501,13 @@ where
4460
4501
#[cfg(splicing)]
4461
4502
#[rustfmt::skip]
4462
4503
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>,
4466
4506
) -> Result<(), APIError> {
4467
4507
let mut res = Ok(());
4468
4508
PersistenceNotifierGuard::optionally_notify(self, || {
4469
4509
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
4471
4511
);
4472
4512
res = result;
4473
4513
match res {
@@ -4482,8 +4522,7 @@ where
4482
4522
#[cfg(splicing)]
4483
4523
fn internal_splice_channel(
4484
4524
&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>,
4487
4526
) -> Result<(), APIError> {
4488
4527
let per_peer_state = self.per_peer_state.read().unwrap();
4489
4528
@@ -4504,13 +4543,8 @@ where
4504
4543
hash_map::Entry::Occupied(mut chan_phase_entry) => {
4505
4544
let locktime = locktime.unwrap_or_else(|| self.current_best_block().height);
4506
4545
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)?;
4514
4548
peer_state.pending_msg_events.push(MessageSendEvent::SendSpliceInit {
4515
4549
node_id: *counterparty_node_id,
4516
4550
msg,
0 commit comments