pub fn new(
        unvault_input: UnvaultTxIn,
        feebump_input: Option<FeeBumpTxIn>,
        emer_address: EmergencyAddress,
        lock_time: u32,
    ) -> Result<UnvaultEmergencyTransaction, TransactionCreationError> {
        if let Some(ref txin) = feebump_input {
            if txin.txout().txout().value > max_money(Network::Bitcoin) {
                return Err(TransactionCreationError::InsaneAmounts);
            }
        }

        // First, create a dummy transaction to get its weight without Witness. Note that we always
        // account for the weight *without* feebump input. It has to pay for itself.
        let emer_txo = EmergencyTxOut::new(emer_address.clone(), Amount::from_sat(u64::MAX));
        let dummy_tx = UnvaultEmergencyTransaction::create_psbt(
            unvault_input.clone(),
            None,
            emer_txo,
            lock_time,
        )
        .global
        .unsigned_tx;

        // The weight of the unvault emergency transaction without a feebump input is the weight of
        // the witness-stripped transaction plus the weight required to satisfy the unvault txin
        let total_weight = dummy_tx
            .get_weight()
            .checked_add(unvault_input.txout().max_sat_weight())
            .expect("Weight computation bug");
        let total_weight: u64 = total_weight.try_into().expect("usize in u64");
        let fees = EMER_TX_FEERATE
            .checked_mul(total_weight)
            .expect("Weight computation bug");
        // Without the feebump input, it should not be reachable.
        debug_assert!(fees < INSANE_FEES);

        assert!(
            total_weight <= MAX_STANDARD_TX_WEIGHT as u64,
            "At most 2 inputs and a single output"
        );

        // Now, get the emergency output value out of it.
        let deposit_value = unvault_input.txout().txout().value;
        let emer_value = deposit_value
            .checked_sub(fees)
            .expect("We would never create a dust unvault txo");
        assert!(
            emer_value < max_money(Network::Bitcoin),
            "Checked in UnvaultTransaction constructor already"
        );
        let emer_txo = EmergencyTxOut::new(emer_address, Amount::from_sat(emer_value));

        Ok(UnvaultEmergencyTransaction(
            UnvaultEmergencyTransaction::create_psbt(
                unvault_input,
                feebump_input,
                emer_txo,
                lock_time,
            ),
        ))
    }
/// The second emergency transaction always spends an unvault output and pays to the Emergency
/// Script. It may also spend an additional output for fee-bumping.
///
/// BIP174 Creator and Updater roles.
The second emergency transaction always spends an unvault output and pays to the Emergency
Script. It may also spend an additional output for fee-bumping.

BIP174 Creator and Updater roles.
The second emergency transaction always spends an unvault output and pays to the Emergency Script . It may also spend an additional output for fee - bumping . BIP174 Creator and Updater roles .
pub fn new(
        unvault_input: UnvaultTxIn,
        feebump_input: Option<FeeBumpTxIn>,
        emer_address: EmergencyAddress,
        lock_time: u32,
    ) -> Result<UnvaultEmergencyTransaction, TransactionCreationError> {
        if let Some(ref txin) = feebump_input {
            if txin.txout().txout().value > max_money(Network::Bitcoin) {
                return Err(TransactionCreationError::InsaneAmounts);
            }
        }
        // First, create a dummy transaction to get its weight without Witness. Note that we always
        // account for the weight *without* feebump input. It has to pay for itself.
        let emer_txo = EmergencyTxOut::new(emer_address.clone(), Amount::from_sat(u64::MAX));
        let dummy_tx = UnvaultEmergencyTransaction::create_psbt(
            unvault_input.clone(),
            None,
            emer_txo,
            lock_time,
        )
        .global
        .unsigned_tx;
        // The weight of the unvault emergency transaction without a feebump input is the weight of
        // the witness-stripped transaction plus the weight required to satisfy the unvault txin
        let total_weight = dummy_tx
            .get_weight()
            .checked_add(unvault_input.txout().max_sat_weight())
            .expect("Weight computation bug");
        let total_weight: u64 = total_weight.try_into().expect("usize in u64");
        let fees = EMER_TX_FEERATE
            .checked_mul(total_weight)
            .expect("Weight computation bug");
        // Without the feebump input, it should not be reachable.
        debug_assert!(fees < INSANE_FEES);
        assert!(
            total_weight <= MAX_STANDARD_TX_WEIGHT as u64,
            "At most 2 inputs and a single output"
        );
        // Now, get the emergency output value out of it.
        let deposit_value = unvault_input.txout().txout().value;
        let emer_value = deposit_value
            .checked_sub(fees)
            .expect("We would never create a dust unvault txo");
        assert!(
            emer_value < max_money(Network::Bitcoin),
            "Checked in UnvaultTransaction constructor already"
        );
        let emer_txo = EmergencyTxOut::new(emer_address, Amount::from_sat(emer_value));
        Ok(UnvaultEmergencyTransaction(
            UnvaultEmergencyTransaction::create_psbt(
                unvault_input,
                feebump_input,
                emer_txo,
                lock_time,
            ),
        ))
    }
pub fn new ( unvault_input : UnvaultTxIn , feebump_input : Option < FeeBumpTxIn > , emer_address : EmergencyAddress , lock_time : u32 , ) -> Result < UnvaultEmergencyTransaction , TransactionCreationError > { if let Some ( ref txin ) = feebump_input { if txin . txout ( ) . txout ( ) . value > max_money ( Network :: Bitcoin ) { return Err ( TransactionCreationError :: InsaneAmounts ) ; } } // First, create a dummy transaction to get its weight without Witness. Note that we always // account for the weight *without* feebump input. It has to pay for itself. let emer_txo = EmergencyTxOut :: new ( emer_address . clone ( ) , Amount :: from_sat ( u64 :: MAX ) ) ; let dummy_tx = UnvaultEmergencyTransaction :: create_psbt ( unvault_input . clone ( ) , None , emer_txo , lock_time , ) . global . unsigned_tx ; // The weight of the unvault emergency transaction without a feebump input is the weight of // the witness-stripped transaction plus the weight required to satisfy the unvault txin let total_weight = dummy_tx . get_weight ( ) . checked_add ( unvault_input . txout ( ) . max_sat_weight ( ) ) . expect ( " " ) ; let total_weight : u64 = total_weight . try_into ( ) . expect ( " " ) ; let fees = EMER_TX_FEERATE . checked_mul ( total_weight ) . expect ( " " ) ; // Without the feebump input, it should not be reachable. debug_assert ! ( fees INSANE_FEES ) ; assert ! ( total_weight MAX_STANDARD_TX_WEIGHT as u64 " " ) ; // Now, get the emergency output value out of it. let deposit_value = unvault_input . txout ( ) . txout ( ) . value ; let emer_value = deposit_value . checked_sub ( fees ) . expect ( " " ) ; assert ! ( emer_value max_money ( Network Bitcoin ) " " ) ; let emer_txo = EmergencyTxOut :: new ( emer_address , Amount :: from_sat ( emer_value ) ) ; Ok ( UnvaultEmergencyTransaction ( UnvaultEmergencyTransaction :: create_psbt ( unvault_input , feebump_input , emer_txo , lock_time , ) , ) ) }
The second emergency transaction always spends an unvault output and pays to the Emergency
Script.
The second emergency transaction always spends an unvault output and pays to the Emergency Script .
unvault_input
UnvaultTxIn
feebump_input
Option<FeeBumpTxIn>
emer_address
EmergencyAddress
lock_time
u32