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
use radix_engine_interface::api::ACTOR_REF_AUTH_ZONE;
use radix_engine_interface::blueprints::resource::*;
use radix_engine_interface::data::scrypto::model::*;
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;

use crate::resource::ScryptoAuthZone;

/// Represents the auth zone, which is used by system for checking
/// if this component is allowed to
///
/// 1. Call methods on another component;
/// 2. Access resource system.
pub struct LocalAuthZone {}

impl LocalAuthZone {
    pub fn push<P: Into<Proof>>(proof: P) {
        let proof: Proof = proof.into();
        let node_id = ScryptoVmV1Api::actor_get_object_id(ACTOR_REF_AUTH_ZONE);
        AuthZoneRef(node_id).push(proof)
    }

    pub fn pop() -> Option<Proof> {
        let node_id = ScryptoVmV1Api::actor_get_object_id(ACTOR_REF_AUTH_ZONE);
        AuthZoneRef(node_id).pop()
    }

    pub fn create_proof_of_amount<A: Into<Decimal>>(
        amount: A,
        resource_address: ResourceAddress,
    ) -> Proof {
        let node_id = ScryptoVmV1Api::actor_get_object_id(ACTOR_REF_AUTH_ZONE);
        AuthZoneRef(node_id).create_proof_of_amount(amount, resource_address)
    }

    pub fn create_proof_of_non_fungibles(
        ids: IndexSet<NonFungibleLocalId>,
        resource_address: ResourceAddress,
    ) -> Proof {
        let node_id = ScryptoVmV1Api::actor_get_object_id(ACTOR_REF_AUTH_ZONE);
        AuthZoneRef(node_id).create_proof_of_non_fungibles(ids, resource_address)
    }

    pub fn create_proof_of_all(resource_address: ResourceAddress) -> Proof {
        let node_id = ScryptoVmV1Api::actor_get_object_id(ACTOR_REF_AUTH_ZONE);
        AuthZoneRef(node_id).create_proof_of_all(resource_address)
    }

    pub fn drop_proofs() {
        let node_id = ScryptoVmV1Api::actor_get_object_id(ACTOR_REF_AUTH_ZONE);
        AuthZoneRef(node_id).drop_proofs()
    }

    pub fn drop_signature_proofs() {
        let node_id = ScryptoVmV1Api::actor_get_object_id(ACTOR_REF_AUTH_ZONE);
        AuthZoneRef(node_id).drop_signature_proofs()
    }

    pub fn drop_regular_proofs() {
        let node_id = ScryptoVmV1Api::actor_get_object_id(ACTOR_REF_AUTH_ZONE);
        AuthZoneRef(node_id).drop_regular_proofs()
    }
}