diff --git a/dlc/src/lib.rs b/dlc/src/lib.rs index de20a6d7..53e3f04a 100644 --- a/dlc/src/lib.rs +++ b/dlc/src/lib.rs @@ -302,10 +302,14 @@ impl PartyParams { let this_party_fund_base_weight = (FUND_TX_BASE_WEIGHT as f32 * fee_multiplier) as usize; let fund_weight_without_change = checked_add!( - this_party_fund_base_weight, - inputs_weight + dbg!(this_party_fund_base_weight), + dbg!(inputs_weight) )?; - let fund_fee_without_change = util::tx_weight_to_fee(fund_weight_without_change, fee_rate_per_vb)?; + let fund_fee_without_change = if inputs_weight > 0 { + util::tx_weight_to_fee(fund_weight_without_change, fee_rate_per_vb)? + } else { + 0 + }; // Base weight (nLocktime, nVersion, funding input ...) is distributed // among parties independently of output types @@ -321,13 +325,13 @@ impl PartyParams { (FeeConfig::EvenSplit, _) => output_spk_fee, (FeeConfig::AllOffer, false) | (FeeConfig::AllAccept, true) => 0, }; - let cet_or_refund_base_fee = util::weight_to_fee(this_party_cet_base_weight, fee_rate_per_vb)?; - let cet_or_refund_fee = checked_add!(cet_or_refund_base_fee, output_spk_fee)?; + let cet_or_refund_base_fee = util::weight_to_fee(dbg!(this_party_cet_base_weight), fee_rate_per_vb)?; + let cet_or_refund_fee = checked_add!(dbg!(cet_or_refund_base_fee), dbg!(output_spk_fee))?; - let extra_fee = (extra_fee as f32 * fee_multiplier) as u64; + let extra_fee = (extra_fee as f32 * dbg!(fee_multiplier)) as u64; let required_input_funds = - checked_add!(self.collateral, fund_fee_without_change, cet_or_refund_fee, extra_fee)?; + checked_add!(self.collateral, dbg!(fund_fee_without_change), dbg!(cet_or_refund_fee), dbg!(extra_fee))?; if self.input_amount < required_input_funds { return Err( @@ -375,14 +379,14 @@ impl PartyParams { } }; - let fund_fee = fund_fee_without_change + change_fee; + let fund_fee = dbg!(fund_fee_without_change) + dbg!(change_fee); let change_output = TxOut { - value: change_amount, + value: dbg!(change_amount), script_pubkey: self.change_script_pubkey.clone(), }; - Ok((change_output, fund_fee, cet_or_refund_fee)) + Ok((change_output, dbg!(fund_fee), dbg!(cet_or_refund_fee))) } fn get_unsigned_tx_inputs_and_serial_ids(&self, sequence: Sequence) -> (Vec, Vec) { @@ -485,7 +489,7 @@ pub(crate) fn create_fund_transaction_with_fees( // transaction (for DLC channels) and a CET or refund transaction. assert_eq!( fund_output_value, - total_collateral + offer_cet_fee + accept_cet_fee + offer_extra_fee + accept_extra_fee + total_collateral + offer_cet_fee + dbg!(accept_cet_fee) + offer_extra_fee + dbg!(accept_extra_fee) ); // The sum of the inputs provided by both parties have to cover: the fund output; all the change