radix_engine/blueprints/resource/auth_zone/
auth_zone_substates.rs1use crate::internal_prelude::*;
2use radix_engine_interface::blueprints::resource::*;
3
4#[derive(Debug, ScryptoSbor, Default)]
5pub struct AuthZone {
6 pub proofs: Vec<Proof>,
7
8 pub simulate_all_proofs_under_resources: BTreeSet<ResourceAddress>,
9 pub implicit_non_fungible_proofs: BTreeSet<NonFungibleGlobalId>,
10
11 pub direct_caller_package_address: Option<PackageAddress>,
12 pub global_caller: Option<(GlobalCaller, Reference)>,
13
14 pub parent: Option<Reference>,
15}
16
17#[derive(ScryptoSbor)]
18#[sbor(type_name = "AuthZone")]
19pub struct GenesisSchemaAuthZone {
22 pub proofs: Vec<Proof>,
23 pub virtual_resources: BTreeSet<ResourceAddress>,
24 pub virtual_non_fungibles: BTreeSet<NonFungibleGlobalId>,
25 pub local_caller_package_address: Option<PackageAddress>,
26 pub global_caller: Option<(GlobalCaller, Reference)>,
27 pub parent: Option<Reference>,
28}
29
30impl AuthZone {
31 pub fn new(
32 proofs: Vec<Proof>,
33 simulate_all_proofs_under_resources: BTreeSet<ResourceAddress>,
34 implicit_non_fungible_proofs: BTreeSet<NonFungibleGlobalId>,
35 direct_caller_package_address: Option<PackageAddress>,
36 global_caller: Option<(GlobalCaller, Reference)>,
37 parent: Option<Reference>,
38 ) -> Self {
39 Self {
40 proofs,
41 simulate_all_proofs_under_resources,
42 implicit_non_fungible_proofs,
43 direct_caller_package_address,
44 global_caller,
45 parent,
46 }
47 }
48
49 pub fn proofs(&self) -> &[Proof] {
50 &self.proofs
51 }
52
53 pub fn simulate_all_proofs_under_resources(&self) -> &BTreeSet<ResourceAddress> {
54 &self.simulate_all_proofs_under_resources
55 }
56
57 pub fn implicit_non_fungible_proofs(&self) -> &BTreeSet<NonFungibleGlobalId> {
58 &self.implicit_non_fungible_proofs
59 }
60
61 pub fn local_implicit_non_fungible_proofs(&self) -> BTreeSet<NonFungibleGlobalId> {
62 let mut local_implicit_non_fungible_proofs = BTreeSet::new();
63
64 if let Some(local_package_address) = self.direct_caller_package_address {
66 let non_fungible_global_id =
67 NonFungibleGlobalId::package_of_direct_caller_badge(local_package_address);
68 local_implicit_non_fungible_proofs.insert(non_fungible_global_id);
69 }
70
71 if let Some((global_caller, _global_caller_reference)) = &self.global_caller {
73 if !global_caller.is_actually_frame_owned() {
74 let non_fungible_global_id =
75 NonFungibleGlobalId::global_caller_badge(global_caller.clone());
76 local_implicit_non_fungible_proofs.insert(non_fungible_global_id);
77 }
78 }
79
80 local_implicit_non_fungible_proofs
81 }
82
83 pub fn push(&mut self, proof: Proof) {
84 self.proofs.push(proof);
85 }
86
87 pub fn pop(&mut self) -> Option<Proof> {
88 self.proofs.pop()
89 }
90
91 pub fn remove_signature_proofs(&mut self) {
92 self.simulate_all_proofs_under_resources
93 .retain(|x| x != &SECP256K1_SIGNATURE_RESOURCE && x != &ED25519_SIGNATURE_RESOURCE);
94 self.implicit_non_fungible_proofs.retain(|x| {
95 x.resource_address() != SECP256K1_SIGNATURE_RESOURCE
96 && x.resource_address() != ED25519_SIGNATURE_RESOURCE
97 });
98 }
99
100 pub fn remove_regular_proofs(&mut self) -> Vec<Proof> {
101 self.proofs.drain(0..).collect()
102 }
103}