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
use radix_engine_interface::blueprints::resource::*;
use radix_engine_interface::data::scrypto::model::*;
use radix_engine_interface::data::scrypto::{scrypto_decode, scrypto_encode};
use radix_engine_interface::math::Decimal;
use radix_engine_interface::types::*;
use radix_engine_interface::*;
use sbor::rust::collections::IndexSet;
use scrypto::engine::scrypto_env::ScryptoVmV1Api;

pub trait ScryptoAuthZone {
    fn push<P: Into<Proof>>(&self, proof: P);

    fn pop(&self) -> Option<Proof>;

    fn create_proof_of_amount<A: Into<Decimal>>(
        &self,
        amount: A,
        resource_address: ResourceAddress,
    ) -> Proof;

    fn create_proof_of_non_fungibles(
        &self,
        ids: IndexSet<NonFungibleLocalId>,
        resource_address: ResourceAddress,
    ) -> Proof;

    fn create_proof_of_all(&self, resource_address: ResourceAddress) -> Proof;

    fn drop_proofs(&self);

    fn drop_signature_proofs(&self);

    fn drop_regular_proofs(&self);
}

impl ScryptoAuthZone for AuthZoneRef {
    fn push<P: Into<Proof>>(&self, proof: P) {
        let proof: Proof = proof.into();
        ScryptoVmV1Api::object_call(
            &self.0,
            AUTH_ZONE_PUSH_IDENT,
            scrypto_encode(&AuthZonePushInput { proof }).unwrap(),
        );
    }

    fn pop(&self) -> Option<Proof> {
        let rtn = ScryptoVmV1Api::object_call(
            &self.0,
            AUTH_ZONE_POP_IDENT,
            scrypto_encode(&AuthZonePopInput {}).unwrap(),
        );
        scrypto_decode(&rtn).unwrap()
    }

    fn create_proof_of_amount<A: Into<Decimal>>(
        &self,
        amount: A,
        resource_address: ResourceAddress,
    ) -> Proof {
        let rtn = ScryptoVmV1Api::object_call(
            &self.0,
            AUTH_ZONE_CREATE_PROOF_OF_AMOUNT_IDENT,
            scrypto_encode(&AuthZoneCreateProofOfAmountInput {
                resource_address,
                amount: amount.into(),
            })
            .unwrap(),
        );
        scrypto_decode(&rtn).unwrap()
    }

    fn create_proof_of_non_fungibles(
        &self,
        ids: IndexSet<NonFungibleLocalId>,
        resource_address: ResourceAddress,
    ) -> Proof {
        let rtn = ScryptoVmV1Api::object_call(
            &self.0,
            AUTH_ZONE_CREATE_PROOF_OF_NON_FUNGIBLES_IDENT,
            scrypto_encode(&AuthZoneCreateProofOfNonFungiblesInput {
                resource_address,
                ids,
            })
            .unwrap(),
        );
        scrypto_decode(&rtn).unwrap()
    }

    fn create_proof_of_all(&self, resource_address: ResourceAddress) -> Proof {
        let rtn = ScryptoVmV1Api::object_call(
            &self.0,
            AUTH_ZONE_CREATE_PROOF_OF_ALL_IDENT,
            scrypto_encode(&AuthZoneCreateProofOfAllInput { resource_address }).unwrap(),
        );
        scrypto_decode(&rtn).unwrap()
    }

    fn drop_proofs(&self) {
        let rtn = ScryptoVmV1Api::object_call(
            &self.0,
            AUTH_ZONE_DROP_PROOFS_IDENT,
            scrypto_encode(&AuthZoneDropProofsInput {}).unwrap(),
        );
        scrypto_decode(&rtn).unwrap()
    }

    fn drop_signature_proofs(&self) {
        let rtn = ScryptoVmV1Api::object_call(
            &self.0,
            AUTH_ZONE_DROP_SIGNATURE_PROOFS_IDENT,
            scrypto_encode(&AuthZoneDropSignatureProofsInput {}).unwrap(),
        );
        scrypto_decode(&rtn).unwrap()
    }

    fn drop_regular_proofs(&self) {
        let rtn = ScryptoVmV1Api::object_call(
            &self.0,
            AUTH_ZONE_DROP_REGULAR_PROOFS_IDENT,
            scrypto_encode(&AuthZoneDropRegularProofsInput {}).unwrap(),
        );
        scrypto_decode(&rtn).unwrap()
    }
}