src/transactions/types.rs
The halving calculator
pub const REWARDS_TYPE: u8 = 1;
pub const BLOCKS_PER_HALVING: u32 = 8400000;
pub fn calculate_block_reward(block_height: u32) -> u64 {
let halving_count = block_height / BLOCKS_PER_HALVING as u32;
let base_reward = 41666666666; // Represents 416.66666666 * 100000000
let reward: u64;
if halving_count == 0 {
reward = base_reward;
} else {
reward = base_reward / (2u64.pow(halving_count));
}
reward
}
src/transactions/types.rs
The Reward transaction (commonly called the Coinbase Transaction in other chains)
#[derive(Debug, Serialize, Deserialize, Clone)] // 142 bytes
pub struct RewardsTransaction {
pub txtype: u8, // 1 byte txtype should be 1
pub timestamp: u32, // 4 bytes time of block mine
pub value: u64, // 8 bytes reward for mining
pub receiver: String, // 33 bytes miner wallet address
pub hash: String, // 32 bytes hash of transaction
pub signature: String, // 64 bytes signature of hash
}