bobcat_features/
lib.rs

1#![no_std]
2
3pub use bobcat_storage::{const_keccak256_two_off_curve, storage_load, storage_store, U};
4
5#[macro_export]
6macro_rules! bobcat_feature {
7    ($feature_name:ident) => {
8        paste::paste! {
9            #[allow(unused)]
10            macro_rules! [<IF_FEATURE_ $feature_name:upper>] {
11                ($on_block:block, $off_block:block) => {
12                    if $crate::storage_load(&$crate::const_keccak256_two_off_curve(
13                        b"bobcat.features.",
14                        stringify!($feature_name).as_bytes()
15                    )).is_some() {
16                        $on_block
17                    } else {
18                        $off_block
19                    }
20                };
21            }
22
23            #[allow(unused)]
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}