bobcat_features/
lib.rs

1pub use bobcat_storage::{const_keccak256_two_off_curve, storage_load, storage_store, U};
2
3#[macro_export]
4macro_rules! bobcat_feature {
5    ($feature_name:ident) => {
6        paste::paste! {
7            #[allow(unused)]
8            #[macro_export]
9            macro_rules! [<IF_FEATURE_ $feature_name:upper>] {
10                ($on_block:block, $off_block:block) => {
11                    if $crate::storage_load(&$crate::const_keccak256_two_off_curve(
12                        b"bobcat.features.",
13                        stringify!($feature_name).as_bytes()
14                    )).is_some() {
15                        $on_block
16                    } else {
17                        $off_block
18                    }
19                };
20            }
21
22            #[allow(unused)]
23            #[macro_export]
24            macro_rules! [<FEATURE_SET_ $feature_name:upper>] {
25                ($value:expr) => {
26                    $crate::storage_store(
27                        &$crate::const_keccak256_two_off_curve(
28                            b"bobcat.features.",
29                            stringify!($feature_name).as_bytes()
30                        ),
31                        &$crate::U::from($value)
32                    )
33                };
34            }
35        }
36    };
37}
38
39#[cfg(all(test, feature = "std"))]
40mod test {
41    bobcat_feature!(test123);
42
43    #[test]
44    fn test_feature() {
45        FEATURE_SET_TEST123!(true);
46        assert!(IF_FEATURE_TEST123!({ true }, { false }));
47    }
48}