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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use crate::api::ModuleId;
use crate::blueprints::resource::*;
use crate::*;
#[cfg(feature = "radix_engine_fuzzing")]
use arbitrary::Arbitrary;
use radix_engine_common::data::scrypto::model::Own;
use sbor::rust::fmt::Debug;
use sbor::rust::prelude::*;

pub const ROLE_ASSIGNMENT_BLUEPRINT: &str = "RoleAssignment";

pub const ROLE_ASSIGNMENT_CREATE_IDENT: &str = "create";

#[cfg_attr(
    feature = "radix_engine_fuzzing",
    derive(Arbitrary, serde::Serialize, serde::Deserialize)
)]
#[derive(
    Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestCategorize, ManifestEncode, ManifestDecode,
)]
pub struct RoleAssignmentCreateInput {
    pub owner_role: OwnerRoleEntry,
    pub roles: IndexMap<ModuleId, RoleAssignmentInit>,
}

pub type RoleAssignmentCreateOutput = Own;

pub const ROLE_ASSIGNMENT_SET_IDENT: &str = "set";

#[cfg_attr(
    feature = "radix_engine_fuzzing",
    derive(Arbitrary, serde::Serialize, serde::Deserialize)
)]
#[derive(
    Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestCategorize, ManifestEncode, ManifestDecode,
)]
pub struct RoleAssignmentSetInput {
    pub module: ModuleId,
    pub role_key: RoleKey,
    pub rule: AccessRule,
}

pub type RoleAssignmentSetOutput = ();

pub const ROLE_ASSIGNMENT_SET_OWNER_IDENT: &str = "set_owner";

#[cfg_attr(
    feature = "radix_engine_fuzzing",
    derive(Arbitrary, serde::Serialize, serde::Deserialize)
)]
#[derive(
    Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestCategorize, ManifestEncode, ManifestDecode,
)]
pub struct RoleAssignmentSetOwnerInput {
    pub rule: AccessRule,
}

pub type RoleAssignmentSetOwnerOutput = ();

pub const ROLE_ASSIGNMENT_LOCK_OWNER_IDENT: &str = "lock_owner";

#[cfg_attr(
    feature = "radix_engine_fuzzing",
    derive(Arbitrary, serde::Serialize, serde::Deserialize)
)]
#[derive(
    Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestCategorize, ManifestEncode, ManifestDecode,
)]
pub struct RoleAssignmentLockOwnerInput {}

pub type RoleAssingmentLockOwnerOutput = ();

pub const ROLE_ASSIGNMENT_GET_IDENT: &str = "get";

#[cfg_attr(
    feature = "radix_engine_fuzzing",
    derive(Arbitrary, serde::Serialize, serde::Deserialize)
)]
#[derive(
    Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestCategorize, ManifestEncode, ManifestDecode,
)]
pub struct RoleAssignmentGetInput {
    pub module: ModuleId,
    pub role_key: RoleKey,
}

pub type RoleAssignmentGetOutput = Option<AccessRule>;

pub trait ToRoleEntry {
    fn to_role_entry(self) -> Option<AccessRule>;
}

impl ToRoleEntry for AccessRule {
    fn to_role_entry(self) -> Option<AccessRule> {
        Some(self)
    }
}

#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor)]
pub enum FallToOwner {
    OWNER,
}

impl ToRoleEntry for FallToOwner {
    fn to_role_entry(self) -> Option<AccessRule> {
        match self {
            FallToOwner::OWNER => None,
        }
    }
}

impl ToRoleEntry for Option<AccessRule> {
    fn to_role_entry(self) -> Option<AccessRule> {
        self
    }
}

pub type RoleDefinition = Option<AccessRule>;

#[macro_export]
macro_rules! internal_roles {
    ($role_struct:ident, $($role:ident => $rule:expr;)* ) => ({
        let method_roles = $crate::internal_roles_struct!($role_struct, $($role => $rule;)*);

        let mut roles = $crate::blueprints::resource::RoleAssignmentInit::new();
        for (name, entry) in method_roles.list() {
            roles.define_role(name, entry);
        }

        roles
    });
}

#[macro_export]
macro_rules! internal_roles_struct {
    ($role_struct:ident, $($role:ident => $rule:expr;)* ) => ({
        $role_struct::<$crate::api::node_modules::auth::RoleDefinition> {
            $(
                $role: {
                    $crate::role_definition_entry!($rule)
                }
            ),*
        }
    });
}

#[macro_export]
macro_rules! role_definition_entry {
    ($rule:expr) => {{
        $crate::api::node_modules::auth::ToRoleEntry::to_role_entry($rule)
    }};
}

#[macro_export]
macro_rules! roles_init_set_entry {
    ($roles:expr, $key:expr, $value:expr) => {{
        $roles.define_role($key, $value);
    }};
}

#[macro_export]
macro_rules! roles_init {
    () => ({
        RoleAssignmentInit::new()
    });
    ( $($key:expr => $value:expr;)* ) => ({
        let mut roles_init = RoleAssignmentInit::new();
        $(
            $crate::roles_init_set_entry!(roles_init, $key, $value);
        )*
        roles_init
    });
}