X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fpackage.rs;h=dbf46298888ce20a8225c6a11bd88e1394c2552e;hb=60f3c0a206bfdc851400bce7753db688b01b094e;hp=b135db5c07ff86cb6e9c4cdedcf111f4e1df8d11;hpb=d7027c2d5b6546f7709ccd033a35feac6de1c690;p=rust-lightning diff --git a/lightning/src/chain/package.rs b/lightning/src/chain/package.rs index b135db5c..dbf46298 100644 --- a/lightning/src/chain/package.rs +++ b/lightning/src/chain/package.rs @@ -26,6 +26,8 @@ use crate::ln::chan_utils; use crate::ln::msgs::DecodeError; use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT}; use crate::chain::keysinterface::Sign; +#[cfg(anchors)] +use crate::chain::onchaintx::ExternalHTLCClaim; use crate::chain::onchaintx::OnchainTxHandler; use crate::util::logger::Logger; use crate::util::ser::{Readable, Writer, Writeable}; @@ -448,8 +450,13 @@ impl PackageSolvingData { } fn get_finalized_tx(&self, outpoint: &BitcoinOutPoint, onchain_handler: &mut OnchainTxHandler) -> Option { match self { - PackageSolvingData::HolderHTLCOutput(ref outp) => { return onchain_handler.get_fully_signed_htlc_tx(outpoint, &outp.preimage); } - PackageSolvingData::HolderFundingOutput(ref outp) => { return Some(onchain_handler.get_fully_signed_holder_tx(&outp.funding_redeemscript)); } + PackageSolvingData::HolderHTLCOutput(ref outp) => { + debug_assert!(!outp.opt_anchors()); + return onchain_handler.get_fully_signed_htlc_tx(outpoint, &outp.preimage); + } + PackageSolvingData::HolderFundingOutput(ref outp) => { + return Some(onchain_handler.get_fully_signed_holder_tx(&outp.funding_redeemscript)); + } _ => { panic!("API Error!"); } } } @@ -649,6 +656,25 @@ impl PackageTemplate { let output_weight = (8 + 1 + destination_script.len()) * WITNESS_SCALE_FACTOR; inputs_weight + witnesses_weight + transaction_weight + output_weight } + #[cfg(anchors)] + pub(crate) fn construct_malleable_package_with_external_funding( + &self, onchain_handler: &mut OnchainTxHandler, + ) -> Option> { + debug_assert!(self.requires_external_funding()); + let mut htlcs: Option> = None; + for (previous_output, input) in &self.inputs { + match input { + PackageSolvingData::HolderHTLCOutput(ref outp) => { + debug_assert!(outp.opt_anchors()); + onchain_handler.generate_external_htlc_claim(&previous_output, &outp.preimage).map(|htlc| { + htlcs.get_or_insert_with(|| Vec::with_capacity(self.inputs.len())).push(htlc); + }); + } + _ => debug_assert!(false, "Expected HolderHTLCOutputs to not be aggregated with other input types"), + } + } + htlcs + } pub(crate) fn finalize_malleable_package( &self, onchain_handler: &mut OnchainTxHandler, value: u64, destination_script: Script, logger: &L ) -> Option where L::Target: Logger {