profile.rs (3394B)
1 use serde::{Deserialize, Serialize}; 2 3 use super::{ 4 DEFAULT_TICKET_EXPIRY_WINDOW, DEFAULT_TICKET_MATURITY_DELAY, MAX_BLOCK_BYTES, 5 MAX_BLOCK_TRANSACTIONS, MAX_PENDING_TRANSACTIONS, MINE_DIFFICULTY_BITS, hex_hash, 6 }; 7 8 #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] 9 pub struct LaunchProfile { 10 pub profile_id: String, 11 pub ticket_maturity_delay_heights: u64, 12 #[serde(default = "default_ticket_expiry_window_heights")] 13 pub ticket_expiry_window_heights: u64, 14 #[serde(default = "default_mine_difficulty_bits")] 15 pub mine_difficulty_bits: u32, 16 pub max_pending_transactions: usize, 17 pub max_block_transactions: usize, 18 #[serde(default = "default_max_block_bytes")] 19 pub max_block_bytes: usize, 20 } 21 22 impl Default for LaunchProfile { 23 fn default() -> Self { 24 Self { 25 profile_id: "iuna-devnet-v5".to_string(), 26 ticket_maturity_delay_heights: DEFAULT_TICKET_MATURITY_DELAY, 27 ticket_expiry_window_heights: DEFAULT_TICKET_EXPIRY_WINDOW, 28 mine_difficulty_bits: MINE_DIFFICULTY_BITS, 29 max_pending_transactions: MAX_PENDING_TRANSACTIONS, 30 max_block_transactions: MAX_BLOCK_TRANSACTIONS, 31 max_block_bytes: MAX_BLOCK_BYTES, 32 } 33 } 34 } 35 36 fn default_max_block_bytes() -> usize { 37 MAX_BLOCK_BYTES 38 } 39 40 fn default_ticket_expiry_window_heights() -> u64 { 41 DEFAULT_TICKET_EXPIRY_WINDOW 42 } 43 44 fn default_mine_difficulty_bits() -> u32 { 45 MINE_DIFFICULTY_BITS 46 } 47 48 impl LaunchProfile { 49 pub fn hash(&self) -> String { 50 hex_hash(format!( 51 "iuna-launch-profile:{}:{}:{}:{}:{}:{}:{}", 52 self.profile_id, 53 self.ticket_maturity_delay_heights, 54 self.ticket_expiry_window_heights, 55 self.mine_difficulty_bits, 56 self.max_pending_transactions, 57 self.max_block_transactions, 58 self.max_block_bytes 59 )) 60 } 61 } 62 63 #[derive(Clone, Debug, Eq, PartialEq)] 64 pub struct GenesisBurn { 65 pub from: String, 66 pub amount: u64, 67 } 68 69 impl GenesisBurn { 70 pub fn new(from: impl Into<String>, amount: u64) -> Self { 71 Self { 72 from: from.into(), 73 amount, 74 } 75 } 76 } 77 78 #[cfg(test)] 79 mod tests { 80 use super::{GenesisBurn, LaunchProfile}; 81 use crate::domain::{ 82 DEFAULT_TICKET_EXPIRY_WINDOW, DEFAULT_TICKET_MATURITY_DELAY, MAX_BLOCK_BYTES, 83 MAX_BLOCK_TRANSACTIONS, MAX_PENDING_TRANSACTIONS, MINE_DIFFICULTY_BITS, 84 }; 85 86 #[test] 87 fn default_launch_profile_matches_protocol_defaults() { 88 let profile = LaunchProfile::default(); 89 90 assert_eq!(profile.profile_id, "iuna-devnet-v5"); 91 assert_eq!( 92 profile.ticket_maturity_delay_heights, 93 DEFAULT_TICKET_MATURITY_DELAY 94 ); 95 assert_eq!( 96 profile.ticket_expiry_window_heights, 97 DEFAULT_TICKET_EXPIRY_WINDOW 98 ); 99 assert_eq!(profile.mine_difficulty_bits, MINE_DIFFICULTY_BITS); 100 assert_eq!(profile.max_pending_transactions, MAX_PENDING_TRANSACTIONS); 101 assert_eq!(profile.max_block_transactions, MAX_BLOCK_TRANSACTIONS); 102 assert_eq!(profile.max_block_bytes, MAX_BLOCK_BYTES); 103 } 104 105 #[test] 106 fn genesis_burn_constructor_preserves_fields() { 107 let burn = GenesisBurn::new("alice", 42); 108 109 assert_eq!(burn.from, "alice"); 110 assert_eq!(burn.amount, 42); 111 } 112 }