radix_transactions/manifest/
manifest_instruction_effects.rs

1use crate::internal_prelude::*;
2
3/// A nicer, grouped representation of a Transaction Instruction
4#[derive(Debug, Clone, Copy)]
5pub enum ManifestInstructionEffect<'a> {
6    CreateBucket {
7        source_amount: BucketSourceAmount<'a>,
8    },
9    CreateProof {
10        source_amount: ProofSourceAmount<'a>,
11    },
12    ConsumeBucket {
13        consumed_bucket: ManifestBucket,
14        destination: BucketDestination<'a>,
15    },
16    ConsumeProof {
17        consumed_proof: ManifestProof,
18        destination: ProofDestination<'a>,
19    },
20    CloneProof {
21        cloned_proof: ManifestProof,
22    },
23    DropManyProofs {
24        drop_all_named_proofs: bool,
25        drop_all_authzone_signature_proofs: bool,
26        drop_all_authzone_non_signature_proofs: bool,
27    },
28    Invocation {
29        kind: InvocationKind<'a>,
30        args: &'a ManifestValue,
31    },
32    CreateAddressAndReservation {
33        package_address: &'a PackageAddress,
34        blueprint_name: &'a str,
35    },
36    ResourceAssertion {
37        assertion: ResourceAssertion<'a>,
38    },
39    Verification {
40        verification: VerificationKind,
41        access_rule: &'a AccessRule,
42    },
43}
44
45#[derive(Debug, Clone, Copy)]
46pub enum InvocationKind<'a> {
47    Method {
48        address: &'a ManifestGlobalAddress,
49        module_id: ModuleId,
50        method: &'a str,
51    },
52    Function {
53        address: &'a ManifestPackageAddress,
54        blueprint: &'a str,
55        function: &'a str,
56    },
57    DirectMethod {
58        address: &'a InternalAddress,
59        method: &'a str,
60    },
61    YieldToParent,
62    YieldToChild {
63        child_index: ManifestNamedIntent,
64    },
65}
66
67#[derive(Debug, Clone, Copy)]
68pub enum VerificationKind {
69    Parent,
70}
71
72#[derive(Debug, Copy, Clone, PartialEq, Eq)]
73pub enum BucketSourceAmount<'a> {
74    AllOnWorktop {
75        resource_address: &'a ResourceAddress,
76    },
77    AmountFromWorktop {
78        resource_address: &'a ResourceAddress,
79        amount: Decimal,
80    },
81    NonFungiblesFromWorktop {
82        resource_address: &'a ResourceAddress,
83        ids: &'a [NonFungibleLocalId],
84    },
85}
86
87impl<'a> BucketSourceAmount<'a> {
88    pub fn resource_address(&self) -> &'a ResourceAddress {
89        match self {
90            Self::AllOnWorktop { resource_address }
91            | Self::AmountFromWorktop {
92                resource_address, ..
93            }
94            | Self::NonFungiblesFromWorktop {
95                resource_address, ..
96            } => resource_address,
97        }
98    }
99}
100
101#[derive(Debug, Copy, Clone, PartialEq, Eq)]
102pub enum ProofSourceAmount<'a> {
103    AuthZonePopLastAddedProof,
104    AuthZoneAllOf {
105        resource_address: &'a ResourceAddress,
106    },
107    AuthZoneAmount {
108        resource_address: &'a ResourceAddress,
109        amount: Decimal,
110    },
111    AuthZoneNonFungibles {
112        resource_address: &'a ResourceAddress,
113        ids: &'a [NonFungibleLocalId],
114    },
115    BucketAllOf {
116        bucket: ManifestBucket,
117    },
118    BucketAmount {
119        bucket: ManifestBucket,
120        amount: Decimal,
121    },
122    BucketNonFungibles {
123        bucket: ManifestBucket,
124        ids: &'a [NonFungibleLocalId],
125    },
126}
127
128impl<'a> ProofSourceAmount<'a> {
129    pub fn proof_kind(&self) -> ProofKind {
130        match self {
131            ProofSourceAmount::AuthZonePopLastAddedProof
132            | ProofSourceAmount::AuthZoneAllOf { .. }
133            | ProofSourceAmount::AuthZoneAmount { .. }
134            | ProofSourceAmount::AuthZoneNonFungibles { .. } => ProofKind::AuthZoneProof,
135            ProofSourceAmount::BucketAllOf { bucket, .. }
136            | ProofSourceAmount::BucketAmount { bucket, .. }
137            | ProofSourceAmount::BucketNonFungibles { bucket, .. } => {
138                ProofKind::BucketProof(*bucket)
139            }
140        }
141    }
142}
143
144#[derive(Debug, Clone, Copy)]
145pub enum BucketDestination<'a> {
146    Worktop,
147    Burned,
148    Invocation(InvocationKind<'a>),
149}
150
151#[derive(Debug, Clone, Copy)]
152pub enum ProofDestination<'a> {
153    AuthZone,
154    Drop,
155    Invocation(InvocationKind<'a>),
156}
157
158#[derive(Debug, Clone, Copy)]
159pub enum AddressReservationDestination<'a> {
160    Invocation(InvocationKind<'a>),
161}
162
163#[derive(Debug, Clone, Copy)]
164pub enum ExpressionDestination<'a> {
165    Invocation(InvocationKind<'a>),
166}
167
168#[derive(Debug, Clone, Copy)]
169pub enum BlobDestination<'a> {
170    Invocation(InvocationKind<'a>),
171}
172
173#[derive(Debug, Clone, Copy)]
174pub enum ResourceAssertion<'a> {
175    Worktop(WorktopAssertion<'a>),
176    NextCall(NextCallAssertion<'a>),
177    Bucket(BucketAssertion<'a>),
178}
179
180#[derive(Debug, Clone, Copy)]
181pub enum WorktopAssertion<'a> {
182    ResourceNonZeroAmount {
183        resource_address: &'a ResourceAddress,
184    },
185    ResourceAtLeastAmount {
186        resource_address: &'a ResourceAddress,
187        amount: Decimal,
188    },
189    ResourceAtLeastNonFungibles {
190        resource_address: &'a ResourceAddress,
191        ids: &'a [NonFungibleLocalId],
192    },
193    ResourcesOnly {
194        constraints: &'a ManifestResourceConstraints,
195    },
196    ResourcesInclude {
197        constraints: &'a ManifestResourceConstraints,
198    },
199}
200
201#[derive(Debug, Clone, Copy)]
202pub enum NextCallAssertion<'a> {
203    ReturnsOnly {
204        constraints: &'a ManifestResourceConstraints,
205    },
206    ReturnsInclude {
207        constraints: &'a ManifestResourceConstraints,
208    },
209}
210
211#[derive(Debug, Clone, Copy)]
212pub enum BucketAssertion<'a> {
213    Contents {
214        bucket: ManifestBucket,
215        constraint: &'a ManifestResourceConstraint,
216    },
217}