1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#[macro_export]
macro_rules! event_schema {
    ($aggregator: ident, [$($event_type: ty),* $(,)?]) => {
        {
            let mut event_schema = sbor::rust::collections::index_map_new();
            $(
                event_schema.insert(
                    <$event_type as radix_engine_interface::traits::ScryptoEvent>::EVENT_NAME.to_string(),
                    TypeRef::Static($aggregator.add_child_type_and_descendents::<$event_type>()),
                );
            )*
            radix_engine_interface::schema::BlueprintEventSchemaInit {
                event_schema
            }
        }
    };
}

#[macro_export]
macro_rules! add_role {
    ($roles:expr, $role:expr) => {{
        $roles.insert(
            $role.into(),
            radix_engine_interface::blueprints::resource::RoleList::none(),
        );
    }};
    ($roles:expr, $role:expr => updaters: $updaters:expr) => {{
        $roles.insert($role.into(), $updaters.into());
    }};
}

#[macro_export]
macro_rules! method_auth_template {
    () => ({
        let methods: IndexMap<radix_engine_interface::blueprints::resource::MethodKey, radix_engine_interface::blueprints::resource::MethodAccessibility>
            = index_map_new();
        methods
    });
    ($($method:expr => $entry:expr;)*) => ({
        let mut methods: IndexMap<radix_engine_interface::blueprints::resource::MethodKey, radix_engine_interface::blueprints::resource::MethodAccessibility>
            = index_map_new();
        $(
            methods.insert($method.into(), $entry.into());
        )*
        methods
    });
}

#[macro_export]
macro_rules! roles_template {
    () => ({
        radix_engine_interface::blueprints::package::StaticRoleDefinition {
            roles: radix_engine_interface::blueprints::package::RoleSpecification::Normal(index_map_new()),
            methods: index_map_new(),
        }
    });
    (
        roles { $($role:expr $( => updaters: $updaters:expr)?;)* },
        methods { $($method:expr => $entry:expr; )* }
    ) => ({
        let mut methods: IndexMap<radix_engine_interface::blueprints::resource::MethodKey, radix_engine_interface::blueprints::resource::MethodAccessibility>
            = index_map_new();
        $(
            methods.insert($method.into(), $entry.into());
        )*

        let mut roles: IndexMap<radix_engine_interface::blueprints::resource::RoleKey, radix_engine_interface::blueprints::resource::RoleList> = index_map_new();
        $(
            crate::add_role!(roles, $role $( => updaters: $updaters)?);
        )*

        radix_engine_interface::blueprints::package::StaticRoleDefinition {
            roles: radix_engine_interface::blueprints::package::RoleSpecification::Normal(roles),
            methods,
        }
    });
    ( methods { $($method:expr => $entry:expr;)* }) => ({
        let mut methods: IndexMap<radix_engine_interface::blueprints::resource::MethodKey, radix_engine_interface::blueprints::resource::MethodAccessibility>
            = index_map_new();
        $(
            methods.insert($method.into(), $entry.into());
        )*

        radix_engine_interface::blueprints::package::StaticRoleDefinition {
            roles: radix_engine_interface::blueprints::package::RoleSpecification::Normal(index_map_new()),
            methods,
        }
    });
}