radix_common/types/
royalty_amount.rs

1use crate::internal_prelude::*;
2
3#[cfg_attr(
4    feature = "fuzzing",
5    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
6)]
7#[derive(
8    Debug, Clone, Copy, PartialEq, Eq, ManifestSbor, ScryptoCategorize, ScryptoEncode, ScryptoDecode,
9)]
10pub enum RoyaltyAmount {
11    Free,
12    Xrd(Decimal),
13    Usd(Decimal),
14}
15
16impl Describe<ScryptoCustomTypeKind> for RoyaltyAmount {
17    const TYPE_ID: RustTypeId =
18        RustTypeId::WellKnown(well_known_scrypto_custom_types::ROYALTY_AMOUNT_TYPE);
19
20    fn type_data() -> ScryptoTypeData<RustTypeId> {
21        well_known_scrypto_custom_types::royalty_amount_type_data()
22    }
23}
24
25impl RoyaltyAmount {
26    pub fn is_zero(&self) -> bool {
27        match self {
28            RoyaltyAmount::Xrd(x) => x.is_zero(),
29            RoyaltyAmount::Usd(x) => x.is_zero(),
30            RoyaltyAmount::Free => true,
31        }
32    }
33
34    pub fn is_non_zero(&self) -> bool {
35        !self.is_zero()
36    }
37
38    pub fn is_negative(&self) -> bool {
39        match self {
40            Self::Free => false,
41            Self::Usd(amount) | Self::Xrd(amount) => amount.is_negative(),
42        }
43    }
44}