pub fn check_coinbase_output(
        &self,
        reward: MicroTari,
        coinbase_lock_height: u64,
        factories: &CryptoFactories,
        height: u64,
    ) -> Result<(), TransactionError>
    {
        let mut coinbase_utxo = None;
        let mut coinbase_kernel = None;
        let mut coinbase_counter = 0; // there should be exactly 1 coinbase
        for utxo in self.outputs() {
            if utxo.features.flags.contains(OutputFlags::COINBASE_OUTPUT) {
                coinbase_counter += 1;
                if utxo.features.maturity < (height + coinbase_lock_height) {
                    warn!(target: LOG_TARGET, "Coinbase {} found with maturity set too low", utxo);
                    return Err(TransactionError::InvalidCoinbaseMaturity);
                }
                coinbase_utxo = Some(utxo.clone());
            }
        }
        if coinbase_counter != 1 {
            warn!(
                target: LOG_TARGET,
                "{} coinbases found in body. Only a single coinbase is permitted.", coinbase_counter,
            );
            return Err(TransactionError::InvalidCoinbaseCount);
        }

        let mut coinbase_counter = 0; // there should be exactly 1 coinbase kernel as well
        for kernel in self.kernels() {
            if kernel.features.contains(KernelFeatures::COINBASE_KERNEL) {
                coinbase_counter += 1;
                coinbase_kernel = Some(kernel.clone());
            }
        }
        if coinbase_counter != 1 {
            warn!(
                target: LOG_TARGET,
                "{} coinbase kernels found in body. Only a single coinbase kernel is permitted.", coinbase_counter,
            );
            return Err(TransactionError::InvalidCoinbaseCount);
        }
        // Unwrap used here are fine as they should have an amount in them by here. If the coinbase's are missing the
        // counters should be 0 and the fn should have returned an error by now.
        let utxo = coinbase_utxo.unwrap();
        let rhs =
            &coinbase_kernel.unwrap().excess + &factories.commitment.commit_value(&BlindingFactor::default(), reward.0);
        if rhs != utxo.commitment {
            warn!(target: LOG_TARGET, "Coinbase {} amount validation failed", utxo);
            return Err(TransactionError::InvalidCoinbase);
        }
        Ok(())
    }
/// Run through the outputs of the block and check that
/// 1. There is exactly ONE coinbase output
/// 1. The output's maturity is correctly set
/// 1. The amount is correct.
Run through the outputs of the block and check that
1. There is exactly ONE coinbase output
1. The output's maturity is correctly set
1. The amount is correct.
Run through the outputs of the block and check that 1 . There is exactly ONE coinbase output 1 . The output ' s maturity is correctly set 1 . The amount is correct .
pub fn check_coinbase_output(
        &self,
        reward: MicroTari,
        coinbase_lock_height: u64,
        factories: &CryptoFactories,
        height: u64,
    ) -> Result<(), TransactionError>
    {
        let mut coinbase_utxo = None;
        let mut coinbase_kernel = None;
        let mut coinbase_counter = 0; // there should be exactly 1 coinbase
        for utxo in self.outputs() {
            if utxo.features.flags.contains(OutputFlags::COINBASE_OUTPUT) {
                coinbase_counter += 1;
                if utxo.features.maturity < (height + coinbase_lock_height) {
                    warn!(target: LOG_TARGET, "Coinbase {} found with maturity set too low", utxo);
                    return Err(TransactionError::InvalidCoinbaseMaturity);
                }
                coinbase_utxo = Some(utxo.clone());
            }
        }
        if coinbase_counter != 1 {
            warn!(
                target: LOG_TARGET,
                "{} coinbases found in body. Only a single coinbase is permitted.", coinbase_counter,
            );
            return Err(TransactionError::InvalidCoinbaseCount);
        }
        let mut coinbase_counter = 0; // there should be exactly 1 coinbase kernel as well
        for kernel in self.kernels() {
            if kernel.features.contains(KernelFeatures::COINBASE_KERNEL) {
                coinbase_counter += 1;
                coinbase_kernel = Some(kernel.clone());
            }
        }
        if coinbase_counter != 1 {
            warn!(
                target: LOG_TARGET,
                "{} coinbase kernels found in body. Only a single coinbase kernel is permitted.", coinbase_counter,
            );
            return Err(TransactionError::InvalidCoinbaseCount);
        }
        // Unwrap used here are fine as they should have an amount in them by here. If the coinbase's are missing the
        // counters should be 0 and the fn should have returned an error by now.
        let utxo = coinbase_utxo.unwrap();
        let rhs =
            &coinbase_kernel.unwrap().excess + &factories.commitment.commit_value(&BlindingFactor::default(), reward.0);
        if rhs != utxo.commitment {
            warn!(target: LOG_TARGET, "Coinbase {} amount validation failed", utxo);
            return Err(TransactionError::InvalidCoinbase);
        }
        Ok(())
    }
pub fn check_coinbase_output ( & self , reward : MicroTari , coinbase_lock_height : u64 , factories : & CryptoFactories , height : u64 , ) -> Result < ( ) , TransactionError > { let mut coinbase_utxo = None ; let mut coinbase_kernel = None ; let mut coinbase_counter = 0 ; // there should be exactly 1 coinbase for utxo in self . outputs ( ) { if utxo . features . flags . contains ( OutputFlags :: COINBASE_OUTPUT ) { coinbase_counter += 1 ; if utxo . features . maturity < ( height + coinbase_lock_height ) { warn ! ( target LOG_TARGET " " utxo ) ; return Err ( TransactionError :: InvalidCoinbaseMaturity ) ; } coinbase_utxo = Some ( utxo . clone ( ) ) ; } } if coinbase_counter != 1 { warn ! ( target LOG_TARGET " " coinbase_counter ) ; return Err ( TransactionError :: InvalidCoinbaseCount ) ; } let mut coinbase_counter = 0 ; // there should be exactly 1 coinbase kernel as well for kernel in self . kernels ( ) { if kernel . features . contains ( KernelFeatures :: COINBASE_KERNEL ) { coinbase_counter += 1 ; coinbase_kernel = Some ( kernel . clone ( ) ) ; } } if coinbase_counter != 1 { warn ! ( target LOG_TARGET " " coinbase_counter ) ; return Err ( TransactionError :: InvalidCoinbaseCount ) ; } // Unwrap used here are fine as they should have an amount in them by here. If the coinbase's are missing the // counters should be 0 and the fn should have returned an error by now. let utxo = coinbase_utxo . unwrap ( ) ; let rhs = & coinbase_kernel . unwrap ( ) . excess + & factories . commitment . commit_value ( & BlindingFactor :: default ( ) , reward . 0 ) ; if rhs != utxo . commitment { warn ! ( target LOG_TARGET " " utxo ) ; return Err ( TransactionError :: InvalidCoinbase ) ; } Ok ( ( ) ) }
Run through the outputs of the block and check that
1.
Run through the outputs of the block and check that 1 .
&self
reward
MicroTari
coinbase_lock_height
u64
factories
&CryptoFactories
height
u64
&self
reward
MicroTari
coinbase_lock_height
u64
factories
&CryptoFactories
height
u64