casper_executor_wasm_common/
flags.rs

1//! Types that can be safely shared between host and the wasm sdk.
2use bitflags::bitflags;
3
4bitflags! {
5    /// Flags that can be passed as part of returning values.
6    #[repr(transparent)]
7    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
8    pub struct ReturnFlags: u32 {
9        /// If this bit is set, the host should return the value to the caller and all the execution effects are reverted.
10        const REVERT = 0x0000_0001;
11
12        // The source may set any bits.
13        const _ = !0;
14    }
15
16    #[repr(transparent)]
17    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
18    pub struct EntryPointFlags: u32 {
19        const CONSTRUCTOR = 0x0000_0001;
20        const FALLBACK = 0x0000_0002;
21    }
22
23    /// Flags that can be passed as part of calling contracts.
24    #[repr(transparent)]
25    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
26    pub struct CallFlags: u32 {
27        // TODO: This is a placeholder
28    }
29}
30
31impl Default for EntryPointFlags {
32    fn default() -> Self {
33        Self::empty()
34    }
35}
36
37impl Default for CallFlags {
38    fn default() -> Self {
39        Self::empty()
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_return_flags() {
49        assert_eq!(ReturnFlags::empty().bits(), 0x0000_0000);
50        assert_eq!(ReturnFlags::REVERT.bits(), 0x0000_0001);
51    }
52
53    #[test]
54    fn creating_from_invalid_bit_flags_does_not_fail() {
55        let _return_flags = ReturnFlags::from_bits(u32::MAX).unwrap();
56        let _revert = ReturnFlags::from_bits(0x0000_0001).unwrap();
57        let _empty = ReturnFlags::from_bits(0x0000_0000).unwrap();
58    }
59}