iota_stardust_types/block/output/
treasury.rs1use crate::block::Error;
5
6#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, packable::Packable)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[packable(unpack_error = Error)]
10pub struct TreasuryOutput {
11 amount: u64,
12}
13
14impl TreasuryOutput {
15 pub const KIND: u8 = 2;
18
19 pub fn new(amount: u64, token_supply: u64) -> Result<Self, Error> {
21 verify_amount(&amount, &token_supply)?;
22
23 Ok(Self { amount })
24 }
25
26 #[inline(always)]
28 pub fn amount(&self) -> u64 {
29 self.amount
30 }
31}
32
33fn verify_amount(amount: &u64, token_supply: &u64) -> Result<(), Error> {
34 if amount > token_supply {
35 Err(Error::InvalidTreasuryOutputAmount(*amount))
36 } else {
37 Ok(())
38 }
39}