radix_engine_interface/object_modules/role_assignment/
invocations.rs

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