radix_transactions/model/v1/
preview_transaction.rs

1use crate::internal_prelude::*;
2
3#[derive(Debug, Clone, Sbor, PartialEq, Eq, Default)]
4pub struct PreviewFlags {
5    pub use_free_credit: bool,
6    pub assume_all_signature_proofs: bool,
7    pub skip_epoch_check: bool,
8    pub disable_auth: bool,
9}
10
11#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
12pub struct PreviewIntentV1 {
13    pub intent: IntentV1,
14    pub signer_public_keys: Vec<PublicKey>,
15    pub flags: PreviewFlags,
16}
17
18pub struct ValidatedPreviewIntent {
19    pub intent: PreparedIntentV1,
20    pub encoded_instructions: Vec<u8>,
21    pub signer_public_keys: Vec<PublicKey>,
22    pub flags: PreviewFlags,
23}
24
25#[allow(deprecated)]
26impl ValidatedPreviewIntent {
27    pub fn create_executable(self) -> ExecutableTransaction {
28        let intent = self.intent;
29        let flags = self.flags;
30
31        let mut simulate_every_proof_under_resources = BTreeSet::new();
32        if flags.assume_all_signature_proofs {
33            simulate_every_proof_under_resources.insert(SECP256K1_SIGNATURE_RESOURCE);
34            simulate_every_proof_under_resources.insert(ED25519_SIGNATURE_RESOURCE);
35        }
36
37        let header = &intent.header.inner;
38        let fee_payment = TransactionCostingParameters {
39            tip: TipSpecifier::Percentage(header.tip_percentage),
40            free_credit_in_xrd: if flags.use_free_credit {
41                Decimal::try_from(PREVIEW_CREDIT_IN_XRD).unwrap()
42            } else {
43                Decimal::ZERO
44            },
45        };
46
47        let mut initial_proofs = AuthAddresses::signer_set(&self.signer_public_keys);
48        if header.notary_is_signatory {
49            initial_proofs.insert(NonFungibleGlobalId::from_public_key(
50                &header.notary_public_key,
51            ));
52        }
53
54        let intent_hash = intent.transaction_intent_hash();
55
56        let nullification = if flags.skip_epoch_check {
57            IntentHashNullification::SimulatedTransactionIntent {
58                simulated: SimulatedTransactionIntentNullification,
59            }
60        } else {
61            IntentHashNullification::TransactionIntent {
62                intent_hash,
63                expiry_epoch: intent.header.inner.end_epoch_exclusive,
64            }
65        };
66
67        ExecutableTransaction::new_v1(
68            self.encoded_instructions,
69            AuthZoneInit::new(initial_proofs, simulate_every_proof_under_resources),
70            intent.instructions.references,
71            intent.blobs.blobs_by_hash,
72            ExecutionContext {
73                unique_hash: intent_hash.0,
74                intent_hash_nullifications: vec![nullification],
75                epoch_range: if flags.skip_epoch_check {
76                    None
77                } else {
78                    Some(EpochRange {
79                        start_epoch_inclusive: intent.header.inner.start_epoch_inclusive,
80                        end_epoch_exclusive: intent.header.inner.end_epoch_exclusive,
81                    })
82                },
83                payload_size: intent.summary.effective_length,
84                num_of_signature_validations: 0, // Accounted for by tests in `common_transformation_costs.rs`.
85                costing_parameters: fee_payment,
86                pre_allocated_addresses: vec![],
87                disable_limits_and_costing_modules: false,
88                proposer_timestamp_range: None,
89            },
90        )
91    }
92}