pub fn new(
        deposit_input: DepositTxIn,
        unvault_descriptor: &DerivedUnvaultDescriptor,
        cpfp_descriptor: &DerivedCpfpDescriptor,
        lock_time: u32,
    ) -> Result<UnvaultTransaction, TransactionCreationError> {
        // First, create a dummy transaction to get its weight without Witness
        let dummy_unvault_txout = UnvaultTxOut::new(Amount::from_sat(u64::MAX), unvault_descriptor);
        let dummy_cpfp_txout = CpfpTxOut::new(Amount::from_sat(u64::MAX), cpfp_descriptor);
        let dummy_tx = UnvaultTransaction::create_psbt(
            deposit_input.clone(),
            dummy_unvault_txout,
            dummy_cpfp_txout,
            lock_time,
        )
        .global
        .unsigned_tx;

        // The weight of the transaction once signed will be the size of the witness-stripped
        // transaction plus the size of the single input's witness.
        let total_weight = dummy_tx
            .get_weight()
            .checked_add(deposit_input.txout().max_sat_weight())
            .expect("Properly-computed weights cannot overflow");
        let total_weight: u64 = total_weight.try_into().expect("usize in u64");
        let fees = UNVAULT_TX_FEERATE
            .checked_mul(total_weight)
            .expect("Properly-computed weights cannot overflow");
        // Nobody wants to pay 3k€ fees if we had a bug.
        if fees > INSANE_FEES {
            return Err(TransactionCreationError::InsaneFees);
        }

        assert!(
            total_weight <= MAX_STANDARD_TX_WEIGHT as u64,
            "A single input and two outputs"
        );

        // The unvault output value is then equal to the deposit value minus the fees and the CPFP.
        let deposit_value = deposit_input.txout().txout().value;
        if fees + UNVAULT_CPFP_VALUE + DUST_LIMIT > deposit_value {
            return Err(TransactionCreationError::Dust);
        }
        let unvault_value = deposit_value - fees - UNVAULT_CPFP_VALUE; // Arithmetic checked above
        if unvault_value > max_money(Network::Bitcoin) {
            return Err(TransactionCreationError::InsaneAmounts);
        }

        let unvault_txout = UnvaultTxOut::new(Amount::from_sat(unvault_value), unvault_descriptor);
        let cpfp_txout = CpfpTxOut::new(Amount::from_sat(UNVAULT_CPFP_VALUE), cpfp_descriptor);
        Ok(UnvaultTransaction(UnvaultTransaction::create_psbt(
            deposit_input,
            unvault_txout,
            cpfp_txout,
            lock_time,
        )))
    }
/// An unvault transaction always spends one deposit output and contains one CPFP output in
/// addition to the unvault one.
/// It's always created using a fixed feerate and the CPFP output value is fixed as well.
///
/// BIP174 Creator and Updater roles.
An unvault transaction always spends one deposit output and contains one CPFP output in
addition to the unvault one.
It's always created using a fixed feerate and the CPFP output value is fixed as well.

BIP174 Creator and Updater roles.
An unvault transaction always spends one deposit output and contains one CPFP output in addition to the unvault one . It ' s always created using a fixed feerate and the CPFP output value is fixed as well . BIP174 Creator and Updater roles .
pub fn new(
        deposit_input: DepositTxIn,
        unvault_descriptor: &DerivedUnvaultDescriptor,
        cpfp_descriptor: &DerivedCpfpDescriptor,
        lock_time: u32,
    ) -> Result<UnvaultTransaction, TransactionCreationError> {
        // First, create a dummy transaction to get its weight without Witness
        let dummy_unvault_txout = UnvaultTxOut::new(Amount::from_sat(u64::MAX), unvault_descriptor);
        let dummy_cpfp_txout = CpfpTxOut::new(Amount::from_sat(u64::MAX), cpfp_descriptor);
        let dummy_tx = UnvaultTransaction::create_psbt(
            deposit_input.clone(),
            dummy_unvault_txout,
            dummy_cpfp_txout,
            lock_time,
        )
        .global
        .unsigned_tx;
        // The weight of the transaction once signed will be the size of the witness-stripped
        // transaction plus the size of the single input's witness.
        let total_weight = dummy_tx
            .get_weight()
            .checked_add(deposit_input.txout().max_sat_weight())
            .expect("Properly-computed weights cannot overflow");
        let total_weight: u64 = total_weight.try_into().expect("usize in u64");
        let fees = UNVAULT_TX_FEERATE
            .checked_mul(total_weight)
            .expect("Properly-computed weights cannot overflow");
        // Nobody wants to pay 3k€ fees if we had a bug.
        if fees > INSANE_FEES {
            return Err(TransactionCreationError::InsaneFees);
        }
        assert!(
            total_weight <= MAX_STANDARD_TX_WEIGHT as u64,
            "A single input and two outputs"
        );
        // The unvault output value is then equal to the deposit value minus the fees and the CPFP.
        let deposit_value = deposit_input.txout().txout().value;
        if fees + UNVAULT_CPFP_VALUE + DUST_LIMIT > deposit_value {
            return Err(TransactionCreationError::Dust);
        }
        let unvault_value = deposit_value - fees - UNVAULT_CPFP_VALUE; // Arithmetic checked above
        if unvault_value > max_money(Network::Bitcoin) {
            return Err(TransactionCreationError::InsaneAmounts);
        }
        let unvault_txout = UnvaultTxOut::new(Amount::from_sat(unvault_value), unvault_descriptor);
        let cpfp_txout = CpfpTxOut::new(Amount::from_sat(UNVAULT_CPFP_VALUE), cpfp_descriptor);
        Ok(UnvaultTransaction(UnvaultTransaction::create_psbt(
            deposit_input,
            unvault_txout,
            cpfp_txout,
            lock_time,
        )))
    }
pub fn new ( deposit_input : DepositTxIn , unvault_descriptor : & DerivedUnvaultDescriptor , cpfp_descriptor : & DerivedCpfpDescriptor , lock_time : u32 , ) -> Result < UnvaultTransaction , TransactionCreationError > { // First, create a dummy transaction to get its weight without Witness let dummy_unvault_txout = UnvaultTxOut :: new ( Amount :: from_sat ( u64 :: MAX ) , unvault_descriptor ) ; let dummy_cpfp_txout = CpfpTxOut :: new ( Amount :: from_sat ( u64 :: MAX ) , cpfp_descriptor ) ; let dummy_tx = UnvaultTransaction :: create_psbt ( deposit_input . clone ( ) , dummy_unvault_txout , dummy_cpfp_txout , lock_time , ) . global . unsigned_tx ; // The weight of the transaction once signed will be the size of the witness-stripped // transaction plus the size of the single input's witness. let total_weight = dummy_tx . get_weight ( ) . checked_add ( deposit_input . txout ( ) . max_sat_weight ( ) ) . expect ( " " ) ; let total_weight : u64 = total_weight . try_into ( ) . expect ( " " ) ; let fees = UNVAULT_TX_FEERATE . checked_mul ( total_weight ) . expect ( " " ) ; // Nobody wants to pay 3k€ fees if we had a bug. if fees > INSANE_FEES { return Err ( TransactionCreationError :: InsaneFees ) ; } assert ! ( total_weight MAX_STANDARD_TX_WEIGHT as u64 " " ) ; // The unvault output value is then equal to the deposit value minus the fees and the CPFP. let deposit_value = deposit_input . txout ( ) . txout ( ) . value ; if fees + UNVAULT_CPFP_VALUE + DUST_LIMIT > deposit_value { return Err ( TransactionCreationError :: Dust ) ; } let unvault_value = deposit_value - fees - UNVAULT_CPFP_VALUE ; // Arithmetic checked above if unvault_value > max_money ( Network :: Bitcoin ) { return Err ( TransactionCreationError :: InsaneAmounts ) ; } let unvault_txout = UnvaultTxOut :: new ( Amount :: from_sat ( unvault_value ) , unvault_descriptor ) ; let cpfp_txout = CpfpTxOut :: new ( Amount :: from_sat ( UNVAULT_CPFP_VALUE ) , cpfp_descriptor ) ; Ok ( UnvaultTransaction ( UnvaultTransaction :: create_psbt ( deposit_input , unvault_txout , cpfp_txout , lock_time , ) ) ) }
An unvault transaction always spends one deposit output and contains one CPFP output in
addition to the unvault one.
An unvault transaction always spends one deposit output and contains one CPFP output in addition to the unvault one .
deposit_input
DepositTxIn
unvault_descriptor
&DerivedUnvaultDescriptor
cpfp_descriptor
&DerivedCpfpDescriptor
lock_time
u32