radix_transactions/model/v1/
system_transaction.rs1use crate::internal_prelude::*;
2
3#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
4pub struct SystemTransactionV1 {
5 pub instructions: InstructionsV1,
6 pub blobs: BlobsV1,
7 pub pre_allocated_addresses: Vec<PreAllocatedAddress>,
8 pub hash_for_execution: Hash,
9}
10
11impl SystemTransactionV1 {
12 pub fn with_proofs_ref(
13 &self,
14 initial_proofs: BTreeSet<NonFungibleGlobalId>,
15 ) -> SystemTransactionV1WithProofs {
16 SystemTransactionV1WithProofs {
17 initial_proofs,
18 transaction: Cow::Borrowed(self),
19 }
20 }
21
22 pub fn with_proofs(
23 self,
24 initial_proofs: BTreeSet<NonFungibleGlobalId>,
25 ) -> SystemTransactionV1WithProofs<'static> {
26 SystemTransactionV1WithProofs {
27 initial_proofs,
28 transaction: Cow::Owned(self),
29 }
30 }
31}
32
33pub struct SystemTransactionV1WithProofs<'a> {
37 initial_proofs: BTreeSet<NonFungibleGlobalId>,
38 transaction: Cow<'a, SystemTransactionV1>,
39}
40
41impl<'a> IntoExecutable for SystemTransactionV1WithProofs<'a> {
42 type Error = PrepareError;
43
44 fn into_executable(
45 self,
46 validator: &TransactionValidator,
47 ) -> Result<ExecutableTransaction, Self::Error> {
48 let executable = self
49 .transaction
50 .prepare(validator.preparation_settings())?
51 .create_executable(self.initial_proofs);
52 Ok(executable)
53 }
54}
55
56#[allow(deprecated)]
57type PreparedPreAllocatedAddresses = SummarizedRawFullValue<Vec<PreAllocatedAddress>>;
58type PreparedHash = RawHash;
59
60impl TransactionPayload for SystemTransactionV1 {
61 type Prepared = PreparedSystemTransactionV1;
62 type Raw = RawSystemTransaction;
63}
64
65pub struct PreparedSystemTransactionV1 {
66 pub encoded_instructions: Vec<u8>,
67 pub references: IndexSet<Reference>,
68 pub blobs: PreparedBlobsV1,
69 pub pre_allocated_addresses: PreparedPreAllocatedAddresses,
70 pub hash_for_execution: PreparedHash,
71 pub summary: Summary,
72}
73
74impl_has_summary!(PreparedSystemTransactionV1);
75
76impl HasSystemTransactionHash for PreparedSystemTransactionV1 {
77 fn system_transaction_hash(&self) -> SystemTransactionHash {
78 SystemTransactionHash::from_hash(self.summary.hash)
79 }
80}
81
82#[allow(deprecated)]
83impl PreparedTransaction for PreparedSystemTransactionV1 {
84 type Raw = RawSystemTransaction;
85
86 fn prepare_from_transaction_enum(
87 decoder: &mut TransactionDecoder,
88 ) -> Result<Self, PrepareError> {
89 let ((prepared_instructions, blobs, pre_allocated_addresses, hash_for_execution), summary) =
90 ConcatenatedDigest::prepare_transaction_payload::<(
91 PreparedInstructionsV1,
92 PreparedBlobsV1,
93 PreparedPreAllocatedAddresses,
94 PreparedHash,
95 )>(
96 decoder,
97 TransactionDiscriminator::V1System,
98 ExpectedHeaderKind::EnumWithValueKind,
99 )?;
100 Ok(Self {
101 encoded_instructions: manifest_encode(&prepared_instructions.inner.0)?,
102 references: prepared_instructions.references,
103 blobs,
104 pre_allocated_addresses,
105 hash_for_execution,
106 summary,
107 })
108 }
109}
110
111#[allow(deprecated)]
112impl TransactionPreparableFromValue for PreparedSystemTransactionV1 {
113 fn prepare_from_value(decoder: &mut TransactionDecoder) -> Result<Self, PrepareError> {
114 let ((prepared_instructions, blobs, pre_allocated_addresses, hash_for_execution), summary) =
115 ConcatenatedDigest::prepare_transaction_payload::<(
116 PreparedInstructionsV1,
117 PreparedBlobsV1,
118 PreparedPreAllocatedAddresses,
119 PreparedHash,
120 )>(
121 decoder,
122 TransactionDiscriminator::V1System,
123 ExpectedHeaderKind::TupleWithValueKind,
124 )?;
125 Ok(Self {
126 encoded_instructions: manifest_encode(&prepared_instructions.inner.0)?,
127 references: prepared_instructions.references,
128 blobs,
129 pre_allocated_addresses,
130 hash_for_execution,
131 summary,
132 })
133 }
134}
135
136#[allow(deprecated)]
137impl PreparedSystemTransactionV1 {
138 pub fn create_executable(
139 self,
140 initial_proofs: BTreeSet<NonFungibleGlobalId>,
141 ) -> ExecutableTransaction {
142 ExecutableTransaction::new_v1(
143 self.encoded_instructions,
144 AuthZoneInit::proofs(initial_proofs),
145 self.references,
146 self.blobs.blobs_by_hash,
147 ExecutionContext {
148 unique_hash: self.hash_for_execution.hash,
149 intent_hash_nullifications: vec![],
150 epoch_range: None,
151 payload_size: 0,
152 num_of_signature_validations: 0,
153 costing_parameters: TransactionCostingParameters {
154 tip: TipSpecifier::None,
155 free_credit_in_xrd: Decimal::ZERO,
156 },
157 pre_allocated_addresses: self.pre_allocated_addresses.inner,
158 disable_limits_and_costing_modules: true,
159 proposer_timestamp_range: None,
160 },
161 )
162 }
163}