@@ -10015,35 +10015,41 @@ where
1001510015 /// - `our_funding_inputs`: the inputs we contribute to the new funding transaction.
1001610016 /// Includes the witness weight for this input (e.g. P2WPKH_WITNESS_WEIGHT=109 for typical P2WPKH inputs).
1001710017 #[cfg(splicing)]
10018- #[rustfmt::skip]
10019- pub fn splice_channel( &mut self, our_funding_contribution_satoshis: i64,
10020- our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
10021- funding_feerate_per_kw: u32, locktime: u32,
10018+ pub fn splice_channel(
10019+ &mut self, our_funding_contribution_satoshis: i64,
10020+ our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, funding_feerate_per_kw: u32,
10021+ locktime: u32,
1002210022 ) -> Result<msgs::SpliceInit, APIError> {
1002310023 // Check if a splice has been initiated already.
1002410024 // Note: only a single outstanding splice is supported (per spec)
1002510025 if let Some(pending_splice) = &self.pending_splice {
10026- return Err(APIError::APIMisuseError { err: format!(
10026+ return Err(APIError::APIMisuseError {
10027+ err: format!(
1002710028 "Channel {} cannot be spliced, as it has already a splice pending (contribution {})",
1002810029 self.context.channel_id(),
1002910030 pending_splice.our_funding_contribution,
10030- )});
10031+ ),
10032+ });
1003110033 }
1003210034
1003310035 if !self.context.is_live() {
10034- return Err(APIError::APIMisuseError { err: format!(
10035- "Channel {} cannot be spliced, as channel is not live",
10036- self.context.channel_id()
10037- )});
10036+ return Err(APIError::APIMisuseError {
10037+ err: format!(
10038+ "Channel {} cannot be spliced, as channel is not live",
10039+ self.context.channel_id()
10040+ ),
10041+ });
1003810042 }
1003910043
1004010044 // TODO(splicing): check for quiescence
1004110045
1004210046 if our_funding_contribution_satoshis < 0 {
10043- return Err(APIError::APIMisuseError { err: format!(
10047+ return Err(APIError::APIMisuseError {
10048+ err: format!(
1004410049 "TODO(splicing): Splice-out not supported, only splice in; channel ID {}, contribution {}",
1004510050 self.context.channel_id(), our_funding_contribution_satoshis,
10046- )});
10051+ ),
10052+ });
1004710053 }
1004810054
1004910055 // TODO(splicing): Once splice-out is supported, check that channel balance does not go below 0
@@ -10053,20 +10059,30 @@ where
1005310059 // (Cannot test for miminum required post-splice channel value)
1005410060
1005510061 // Check that inputs are sufficient to cover our contribution.
10056- let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, true, funding_feerate_per_kw)
10057- .map_err(|err| APIError::APIMisuseError { err: format!(
10062+ let _fee = check_v2_funding_inputs_sufficient(
10063+ our_funding_contribution_satoshis,
10064+ &our_funding_inputs,
10065+ true,
10066+ true,
10067+ funding_feerate_per_kw,
10068+ )
10069+ .map_err(|err| APIError::APIMisuseError {
10070+ err: format!(
1005810071 "Insufficient inputs for splicing; channel ID {}, err {}",
10059- self.context.channel_id(), err,
10060- )})?;
10072+ self.context.channel_id(),
10073+ err,
10074+ ),
10075+ })?;
1006110076 // Convert inputs
1006210077 let mut funding_inputs = Vec::new();
1006310078 for (tx_in, tx, _w) in our_funding_inputs.into_iter() {
10064- let tx16 = TransactionU16LenLimited::new(tx.clone()).map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction")})?;
10079+ let tx16 = TransactionU16LenLimited::new(tx.clone())
10080+ .map_err(|_e| APIError::APIMisuseError { err: format!("Too large transaction") })?;
1006510081 funding_inputs.push((tx_in.clone(), tx16));
1006610082 }
1006710083
1006810084 let funding_negotiation_context = FundingNegotiationContext {
10069- our_funding_satoshis: 0, // set at later phase
10085+ our_funding_satoshis: 0, // set at later phase
1007010086 their_funding_satoshis: None, // set at later phase
1007110087 funding_tx_locktime: LockTime::from_consensus(locktime),
1007210088 funding_feerate_sat_per_1000_weight: funding_feerate_per_kw,
@@ -10082,7 +10098,11 @@ where
1008210098 received_funding_txid: None,
1008310099 });
1008410100
10085- let msg = self.get_splice_init(our_funding_contribution_satoshis, funding_feerate_per_kw, locktime);
10101+ let msg = self.get_splice_init(
10102+ our_funding_contribution_satoshis,
10103+ funding_feerate_per_kw,
10104+ locktime,
10105+ );
1008610106 Ok(msg)
1008710107 }
1008810108
0 commit comments