radix_engine_interface/object_modules/role_assignment/
invocations.rs

1use crate::api::ModuleId;
2use crate::blueprints::resource::*;
3
4use radix_common::prelude::*;
5use sbor::rust::fmt::Debug;
6
7pub const ROLE_ASSIGNMENT_BLUEPRINT: &str = "RoleAssignment";
8
9pub const ROLE_ASSIGNMENT_CREATE_IDENT: &str = "create";
10
11#[cfg_attr(
12    feature = "fuzzing",
13    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
14)]
15#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestEncode, ManifestCategorize)]
16pub struct RoleAssignmentCreateInput {
17    pub owner_role: OwnerRoleEntry,
18    pub roles: IndexMap<ModuleId, RoleAssignmentInit>,
19}
20
21#[cfg_attr(
22    feature = "fuzzing",
23    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
24)]
25#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
26pub struct RoleAssignmentCreateManifestInput {
27    pub owner_role: ManifestOwnerRoleEntry,
28    pub roles: IndexMap<ModuleId, ManifestRoleAssignmentInit>,
29}
30
31pub type RoleAssignmentCreateOutput = Own;
32
33pub const ROLE_ASSIGNMENT_SET_IDENT: &str = "set";
34
35#[cfg_attr(
36    feature = "fuzzing",
37    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
38)]
39#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestEncode, ManifestCategorize)]
40pub struct RoleAssignmentSetInput {
41    pub module: ModuleId,
42    pub role_key: RoleKey,
43    pub rule: AccessRule,
44}
45
46#[cfg_attr(
47    feature = "fuzzing",
48    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
49)]
50#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
51pub struct RoleAssignmentSetManifestInput {
52    pub module: ModuleId,
53    pub role_key: RoleKey,
54    pub rule: ManifestAccessRule,
55}
56
57pub type RoleAssignmentSetOutput = ();
58
59pub const ROLE_ASSIGNMENT_SET_OWNER_IDENT: &str = "set_owner";
60
61#[cfg_attr(
62    feature = "fuzzing",
63    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
64)]
65#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestEncode, ManifestCategorize)]
66pub struct RoleAssignmentSetOwnerInput {
67    pub rule: AccessRule,
68}
69
70#[cfg_attr(
71    feature = "fuzzing",
72    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
73)]
74#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
75pub struct RoleAssignmentSetOwnerManifestInput {
76    pub rule: ManifestAccessRule,
77}
78
79pub type RoleAssignmentSetOwnerOutput = ();
80
81pub const ROLE_ASSIGNMENT_LOCK_OWNER_IDENT: &str = "lock_owner";
82
83#[cfg_attr(
84    feature = "fuzzing",
85    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
86)]
87#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoSbor)]
88pub struct RoleAssignmentLockOwnerInput {}
89
90pub type RoleAssignmentLockOwnerManifestInput = RoleAssignmentLockOwnerInput;
91
92pub type RoleAssignmentLockOwnerOutput = ();
93
94pub const ROLE_ASSIGNMENT_GET_IDENT: &str = "get";
95
96#[cfg_attr(
97    feature = "fuzzing",
98    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
99)]
100#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoSbor)]
101pub struct RoleAssignmentGetInput {
102    pub module: ModuleId,
103    pub role_key: RoleKey,
104}
105
106pub type RoleAssignmentGetManifestInput = RoleAssignmentGetInput;
107
108pub type RoleAssignmentGetOutput = Option<AccessRule>;
109
110// Part of the Bottlenose protocol update with the role assignment blueprint extension.
111pub const ROLE_ASSIGNMENT_GET_OWNER_ROLE_IDENT: &str = "get_owner_role";
112
113#[cfg_attr(
114    feature = "fuzzing",
115    derive(::arbitrary::Arbitrary, ::serde::Serialize, ::serde::Deserialize)
116)]
117#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoSbor)]
118pub struct RoleAssignmentGetOwnerRoleInput;
119
120pub type RoleAssignmentGetOwnerRoleManifestInput = RoleAssignmentGetOwnerRoleInput;
121
122pub type RoleAssignmentGetOwnerRoleOutput = OwnerRoleEntry;
123
124pub trait ToRoleEntry {
125    fn to_role_entry(self) -> Option<AccessRule>;
126}
127
128impl ToRoleEntry for AccessRule {
129    fn to_role_entry(self) -> Option<AccessRule> {
130        Some(self)
131    }
132}
133
134#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor)]
135pub enum FallToOwner {
136    OWNER,
137}
138
139impl ToRoleEntry for FallToOwner {
140    fn to_role_entry(self) -> Option<AccessRule> {
141        match self {
142            FallToOwner::OWNER => None,
143        }
144    }
145}
146
147impl ToRoleEntry for Option<AccessRule> {
148    fn to_role_entry(self) -> Option<AccessRule> {
149        self
150    }
151}
152
153pub type RoleDefinition = Option<AccessRule>;
154pub type ManifestRoleDefinition = Option<ManifestAccessRule>;
155
156#[macro_export]
157macro_rules! internal_roles {
158    ($role_struct:ident, $($role:ident => $rule:expr;)* ) => ({
159        let method_roles = $crate::internal_roles_struct!($role_struct, $($role => $rule;)*);
160
161        let mut roles = $crate::blueprints::resource::RoleAssignmentInit::new();
162        for (name, entry) in method_roles.list() {
163            roles.define_role(name, entry);
164        }
165
166        roles
167    });
168}
169
170#[macro_export]
171macro_rules! internal_roles_struct {
172    ($role_struct:ident, $($role:ident => $rule:expr;)* ) => ({
173        $role_struct::<$crate::object_modules::role_assignment::RoleDefinition> {
174            $(
175                $role: {
176                    $crate::role_definition_entry!($rule)
177                }
178            ),*
179        }
180    });
181}
182
183#[macro_export]
184macro_rules! role_definition_entry {
185    ($rule:expr) => {{
186        $crate::object_modules::role_assignment::ToRoleEntry::to_role_entry($rule)
187    }};
188}
189
190#[macro_export]
191macro_rules! roles_init_set_entry {
192    ($roles:expr, $key:expr, $value:expr) => {{
193        $roles.define_role($key, $value);
194    }};
195}
196
197#[macro_export]
198macro_rules! roles_init {
199    () => ({
200        RoleAssignmentInit::new()
201    });
202    ( $($key:expr => $value:expr;)* ) => ({
203        let mut roles_init = RoleAssignmentInit::new();
204        $(
205            $crate::roles_init_set_entry!(roles_init, $key, $value);
206        )*
207        roles_init
208    });
209}