radix_native_sdk/resource/
auth_zone.rs

1use radix_common::data::scrypto::model::*;
2use radix_common::data::scrypto::{scrypto_decode, scrypto_encode};
3use radix_common::math::Decimal;
4use radix_engine_interface::api::*;
5use radix_engine_interface::blueprints::resource::*;
6use radix_engine_interface::types::*;
7use sbor::rust::collections::IndexSet;
8use sbor::rust::vec::Vec;
9
10pub trait NativeAuthZone {
11    fn drain<Y: SystemApi<E>, E: SystemApiError>(&self, api: &mut Y) -> Result<Vec<Proof>, E>;
12
13    fn drop_proofs<Y: SystemApi<E>, E: SystemApiError>(&self, api: &mut Y) -> Result<(), E>;
14
15    fn drop_regular_proofs<Y: SystemApi<E>, E: SystemApiError>(&self, api: &mut Y)
16        -> Result<(), E>;
17
18    fn drop_signature_proofs<Y: SystemApi<E>, E: SystemApiError>(
19        &self,
20        api: &mut Y,
21    ) -> Result<(), E>;
22
23    fn pop<Y: SystemApi<E>, E: SystemApiError>(&self, api: &mut Y) -> Result<Option<Proof>, E>;
24
25    fn create_proof_of_amount<Y: SystemApi<E>, E: SystemApiError>(
26        &self,
27        amount: Decimal,
28        resource_address: ResourceAddress,
29        api: &mut Y,
30    ) -> Result<Proof, E>;
31
32    fn create_proof_of_non_fungibles<Y: SystemApi<E>, E: SystemApiError>(
33        &self,
34        ids: &IndexSet<NonFungibleLocalId>,
35        resource_address: ResourceAddress,
36        api: &mut Y,
37    ) -> Result<Proof, E>;
38
39    fn create_proof_of_all<Y: SystemApi<E>, E: SystemApiError>(
40        &self,
41        resource_address: ResourceAddress,
42        api: &mut Y,
43    ) -> Result<Proof, E>;
44
45    fn push<Y: SystemApi<E>, E: SystemApiError, P: Into<Proof>>(
46        &self,
47        proof: P,
48        api: &mut Y,
49    ) -> Result<(), E>;
50}
51
52impl NativeAuthZone for AuthZoneRef {
53    fn drain<Y: SystemApi<E>, E: SystemApiError>(&self, api: &mut Y) -> Result<Vec<Proof>, E> {
54        let rtn = api.call_method(
55            &self.0,
56            AUTH_ZONE_DRAIN_IDENT,
57            scrypto_encode(&AuthZoneDrainInput {}).unwrap(),
58        )?;
59        Ok(scrypto_decode(&rtn).unwrap())
60    }
61
62    fn drop_proofs<Y: SystemApi<E>, E: SystemApiError>(&self, api: &mut Y) -> Result<(), E> {
63        let rtn = api.call_method(
64            &self.0,
65            AUTH_ZONE_DROP_PROOFS_IDENT,
66            scrypto_encode(&AuthZoneDropProofsInput {}).unwrap(),
67        )?;
68        let _: () = scrypto_decode(&rtn).unwrap();
69        Ok(())
70    }
71
72    fn drop_regular_proofs<Y: SystemApi<E>, E: SystemApiError>(
73        &self,
74        api: &mut Y,
75    ) -> Result<(), E> {
76        let rtn = api.call_method(
77            &self.0,
78            AUTH_ZONE_DROP_REGULAR_PROOFS_IDENT,
79            scrypto_encode(&AuthZoneDropRegularProofsInput {}).unwrap(),
80        )?;
81        let _: () = scrypto_decode(&rtn).unwrap();
82        Ok(())
83    }
84
85    fn drop_signature_proofs<Y: SystemApi<E>, E: SystemApiError>(
86        &self,
87        api: &mut Y,
88    ) -> Result<(), E> {
89        let rtn = api.call_method(
90            &self.0,
91            AUTH_ZONE_DROP_SIGNATURE_PROOFS_IDENT,
92            scrypto_encode(&AuthZoneDropSignatureProofsInput {}).unwrap(),
93        )?;
94        let _: () = scrypto_decode(&rtn).unwrap();
95        Ok(())
96    }
97
98    fn pop<Y: SystemApi<E>, E: SystemApiError>(&self, api: &mut Y) -> Result<Option<Proof>, E> {
99        let rtn = api.call_method(
100            &self.0,
101            AUTH_ZONE_POP_IDENT,
102            scrypto_encode(&AuthZonePopInput {}).unwrap(),
103        )?;
104
105        Ok(scrypto_decode(&rtn).unwrap())
106    }
107
108    fn create_proof_of_amount<Y: SystemApi<E>, E: SystemApiError>(
109        &self,
110        amount: Decimal,
111        resource_address: ResourceAddress,
112        api: &mut Y,
113    ) -> Result<Proof, E> {
114        let rtn = api.call_method(
115            &self.0,
116            AUTH_ZONE_CREATE_PROOF_OF_AMOUNT_IDENT,
117            scrypto_encode(&AuthZoneCreateProofOfAmountInput {
118                resource_address,
119                amount,
120            })
121            .unwrap(),
122        )?;
123
124        Ok(scrypto_decode(&rtn).unwrap())
125    }
126
127    fn create_proof_of_non_fungibles<Y: SystemApi<E>, E: SystemApiError>(
128        &self,
129        ids: &IndexSet<NonFungibleLocalId>,
130        resource_address: ResourceAddress,
131        api: &mut Y,
132    ) -> Result<Proof, E> {
133        let rtn = api.call_method(
134            &self.0,
135            AUTH_ZONE_CREATE_PROOF_OF_NON_FUNGIBLES_IDENT,
136            scrypto_encode(&AuthZoneCreateProofOfNonFungiblesInput {
137                resource_address,
138                ids: ids.clone(),
139            })
140            .unwrap(),
141        )?;
142
143        Ok(scrypto_decode(&rtn).unwrap())
144    }
145
146    fn create_proof_of_all<Y: SystemApi<E>, E: SystemApiError>(
147        &self,
148        resource_address: ResourceAddress,
149        api: &mut Y,
150    ) -> Result<Proof, E> {
151        let rtn = api.call_method(
152            &self.0,
153            AUTH_ZONE_CREATE_PROOF_OF_ALL_IDENT,
154            scrypto_encode(&AuthZoneCreateProofOfAllInput { resource_address }).unwrap(),
155        )?;
156
157        Ok(scrypto_decode(&rtn).unwrap())
158    }
159
160    fn push<Y: SystemApi<E>, E: SystemApiError, P: Into<Proof>>(
161        &self,
162        proof: P,
163        api: &mut Y,
164    ) -> Result<(), E> {
165        let proof: Proof = proof.into();
166
167        let _rtn = api.call_method(
168            &self.0,
169            AUTH_ZONE_PUSH_IDENT,
170            scrypto_encode(&AuthZonePushInput { proof }).unwrap(),
171        )?;
172
173        Ok(())
174    }
175}