src/BlockChain/Validators/BlockValidator.cpp
// Validate the coinbase outputs generated by miners.
// Check the sum of coinbase-marked outputs match the sum of coinbase-marked kernels accounting for fees.
Validate the coinbase outputs generated by miners.
Check the sum of coinbase-marked outputs match the sum of coinbase-marked kernels accounting for fees.
Validate the coinbase outputs generated by miners . Check the sum of coinbase - marked outputs match the sum of coinbase - marked kernels accounting for fees .
bool BlockValidator::IsCoinbaseValid(const FullBlock& block) const
{
	const std::vector<TransactionOutput>& blockOutputs = block.GetOutputs();
	std::vector<Commitment> coinbaseCommitments;
	FunctionalUtil::transform_if(
		blockOutputs.cbegin(),
		blockOutputs.cend(),
		std::back_inserter(coinbaseCommitments),
		[](const TransactionOutput& output) { return output.IsCoinbase(); },
		[](const TransactionOutput& output) { return output.GetCommitment(); }
	);
	const std::vector<TransactionKernel>& blockKernels = block.GetKernels();
	std::vector<Commitment> coinbaseKernelExcesses;
	FunctionalUtil::transform_if(
		blockKernels.cbegin(),
		blockKernels.cend(),
		std::back_inserter(coinbaseKernelExcesses),
		[](const TransactionKernel& kernel) { return kernel.IsCoinbase(); },
		[](const TransactionKernel& kernel) { return kernel.GetExcessCommitment(); }
	);
	const uint64_t reward = std::accumulate(
		blockKernels.cbegin(),
		blockKernels.cend(),
		Consensus::REWARD,
		[](uint64_t reward, const TransactionKernel& kernel) { return reward + kernel.GetFee(); }
	);
	const std::vector<Commitment> overCommitment({ Crypto::CommitTransparent(reward) });
	const Commitment outputAdjustedSum = Crypto::AddCommitments(coinbaseCommitments, overCommitment);
	const Commitment kernelSum = Crypto::AddCommitments(coinbaseKernelExcesses, std::vector<Commitment>());
	return kernelSum == outputAdjustedSum;
}
bool BlockValidator :: IsCoinbaseValid ( const FullBlock & block ) const { const std :: vector < TransactionOutput > & blockOutputs = block . GetOutputs ( ) ; std :: vector < Commitment > coinbaseCommitments ; FunctionalUtil :: transform_if ( blockOutputs . cbegin ( ) , blockOutputs . cend ( ) , std :: back_inserter ( coinbaseCommitments ) , [ ] ( const TransactionOutput & output ) { return output . IsCoinbase ( ) ; } , [ ] ( const TransactionOutput & output ) { return output . GetCommitment ( ) ; } ) ; const std :: vector < TransactionKernel > & blockKernels = block . GetKernels ( ) ; std :: vector < Commitment > coinbaseKernelExcesses ; FunctionalUtil :: transform_if ( blockKernels . cbegin ( ) , blockKernels . cend ( ) , std :: back_inserter ( coinbaseKernelExcesses ) , [ ] ( const TransactionKernel & kernel ) { return kernel . IsCoinbase ( ) ; } , [ ] ( const TransactionKernel & kernel ) { return kernel . GetExcessCommitment ( ) ; } ) ; const uint64_t reward = std :: accumulate ( blockKernels . cbegin ( ) , blockKernels . cend ( ) , Consensus :: REWARD , [ ] ( uint64_t reward , const TransactionKernel & kernel ) { return reward + kernel . GetFee ( ) ; } ) ; const std :: vector < Commitment > overCommitment ( { Crypto :: CommitTransparent ( reward ) } ) ; const Commitment outputAdjustedSum = Crypto :: AddCommitments ( coinbaseCommitments , overCommitment ) ; const Commitment kernelSum = Crypto :: AddCommitments ( coinbaseKernelExcesses , std :: vector < Commitment > ( ) ) ; return kernelSum == outputAdjustedSum ; }
Validate the coinbase outputs generated by miners.
Validate the coinbase outputs generated by miners .
// Get Coinbase Output Commitments // Get Coinbase Kernel Commitments // Calculate Block Reward // Verify the kernel sum equals the output sum accounting for block fees.