iota_stardust_types/block/
protocol.rs1use alloc::string::String;
7use core::borrow::Borrow;
8
9use packable::{Packable, prefix::StringPrefix};
10
11use super::Error;
12
13pub const PROTOCOL_VERSION: u8 = 2;
15
16#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Packable)]
18#[packable(unpack_error = Error)]
19#[cfg_attr(
20 feature = "serde",
21 derive(serde::Serialize, serde::Deserialize),
22 serde(rename_all = "camelCase")
23)]
24pub struct ProtocolParameters {
25 #[cfg_attr(feature = "serde", serde(rename = "version"))]
27 protocol_version: u8,
28 #[packable(unpack_error_with = |err| Error::InvalidNetworkName(err.into_item_err()))]
30 network_name: StringPrefix<u8>,
31 #[packable(unpack_error_with = |err| Error::InvalidBech32Hrp(format!("{:?}", err.into_item_err())))]
33 bech32_hrp: StringPrefix<u8>,
34 min_pow_score: u32,
36 below_max_depth: u8,
38 rent_byte_cost: u32,
40 rent_byte_factor_data: u8,
42 rent_byte_factor_key: u8,
44 token_supply: u64,
46}
47
48impl Borrow<()> for ProtocolParameters {
51 fn borrow(&self) -> &() {
52 &()
53 }
54}
55
56impl Default for ProtocolParameters {
57 fn default() -> Self {
58 Self {
59 protocol_version: PROTOCOL_VERSION,
60 network_name: StringPrefix::try_from(String::from("shimmer"))
61 .expect("network name should be valid"),
62 bech32_hrp: StringPrefix::try_from(String::from("smr"))
63 .expect("bech32 hrp should be valid"),
64 min_pow_score: 1500,
65 below_max_depth: 15,
66 rent_byte_cost: 100,
67 rent_byte_factor_data: 1,
68 rent_byte_factor_key: 10,
69 token_supply: 1_813_620_509_061_365,
70 }
71 }
72}
73
74impl ProtocolParameters {
75 pub fn protocol_version(&self) -> u8 {
77 self.protocol_version
78 }
79
80 pub fn network_name(&self) -> &str {
82 &self.network_name
83 }
84
85 pub fn bech32_hrp(&self) -> &str {
87 &self.bech32_hrp
88 }
89
90 pub fn min_pow_score(&self) -> u32 {
92 self.min_pow_score
93 }
94
95 pub fn below_max_depth(&self) -> u8 {
97 self.below_max_depth
98 }
99
100 pub fn rent_byte_cost(&self) -> u32 {
102 self.rent_byte_cost
103 }
104
105 pub fn rent_byte_factor_data(&self) -> u8 {
107 self.rent_byte_factor_data
108 }
109
110 pub fn rent_byte_factor_key(&self) -> u8 {
112 self.rent_byte_factor_key
113 }
114
115 pub fn token_supply(&self) -> u64 {
117 self.token_supply
118 }
119}