radix_transactions/model/v2/
validated_notarized_transaction_v2.rs

1use crate::internal_prelude::*;
2
3#[derive(Debug, Eq, PartialEq, Clone)]
4pub struct ValidatedNotarizedTransactionV2 {
5    pub prepared: PreparedNotarizedTransactionV2,
6    pub total_signature_validations: usize,
7    pub overall_validity_range: OverallValidityRangeV2,
8    pub transaction_intent_info: ValidatedIntentInformationV2,
9    pub non_root_subintents_info: Vec<ValidatedIntentInformationV2>,
10}
11
12#[derive(Debug, Eq, PartialEq, Clone)]
13pub struct ValidatedSignedPartialTransactionV2 {
14    pub prepared: PreparedSignedPartialTransactionV2,
15    pub total_signature_validations: usize,
16    pub overall_validity_range: OverallValidityRangeV2,
17    pub root_subintent_info: ValidatedIntentInformationV2,
18    pub root_subintent_yield_to_parent_count: usize,
19    pub non_root_subintents_info: Vec<ValidatedIntentInformationV2>,
20}
21
22pub struct ValidatedTransactionTreeV2 {
23    pub overall_validity_range: OverallValidityRangeV2,
24    pub total_signature_validations: usize,
25    pub root_intent_info: ValidatedIntentInformationV2,
26    pub root_yield_to_parent_count: usize,
27    pub non_root_subintents_info: Vec<ValidatedIntentInformationV2>,
28}
29
30#[derive(Debug, Eq, PartialEq, Clone)]
31pub struct OverallValidityRangeV2 {
32    pub epoch_range: EpochRange,
33    pub proposer_timestamp_range: ProposerTimestampRange,
34}
35
36#[derive(Debug, Eq, PartialEq, Clone)]
37pub struct ValidatedIntentInformationV2 {
38    pub encoded_instructions: Vec<u8>,
39    pub signer_keys: IndexSet<PublicKey>,
40    pub children_subintent_indices: Vec<SubintentIndex>,
41}
42
43impl HasTransactionIntentHash for ValidatedNotarizedTransactionV2 {
44    fn transaction_intent_hash(&self) -> TransactionIntentHash {
45        self.prepared.transaction_intent_hash()
46    }
47}
48
49impl HasSignedTransactionIntentHash for ValidatedNotarizedTransactionV2 {
50    fn signed_transaction_intent_hash(&self) -> SignedTransactionIntentHash {
51        self.prepared.signed_transaction_intent_hash()
52    }
53}
54
55impl HasNotarizedTransactionHash for ValidatedNotarizedTransactionV2 {
56    fn notarized_transaction_hash(&self) -> NotarizedTransactionHash {
57        self.prepared.notarized_transaction_hash()
58    }
59}
60
61impl HasNonRootSubintentHashes for ValidatedNotarizedTransactionV2 {
62    fn non_root_subintent_hashes(&self) -> Vec<SubintentHash> {
63        self.prepared.non_root_subintent_hashes()
64    }
65}
66
67impl IntoExecutable for ValidatedNotarizedTransactionV2 {
68    type Error = core::convert::Infallible;
69
70    fn into_executable(
71        self,
72        _validator: &TransactionValidator,
73    ) -> Result<ExecutableTransaction, Self::Error> {
74        Ok(self.create_executable())
75    }
76}
77
78impl ValidatedNotarizedTransactionV2 {
79    pub fn hashes(&self) -> UserTransactionHashes {
80        self.prepared.hashes()
81    }
82
83    pub fn create_executable(self) -> ExecutableTransaction {
84        let transaction_intent = self.prepared.signed_intent.transaction_intent;
85        let transaction_intent_hash = transaction_intent.transaction_intent_hash();
86        let transaction_header = transaction_intent.transaction_header.inner;
87        let payload_size = self.prepared.summary.effective_length;
88        let subintents = transaction_intent.non_root_subintents.subintents;
89
90        let mut intent_hash_nullifications =
91            Vec::with_capacity(self.non_root_subintents_info.len() + 1);
92        intent_hash_nullifications.push(
93            IntentHash::from(transaction_intent_hash).to_nullification(
94                transaction_intent
95                    .root_intent_core
96                    .header
97                    .inner
98                    .end_epoch_exclusive,
99            ),
100        );
101        for subintent in subintents.iter() {
102            intent_hash_nullifications.push(
103                IntentHash::from(subintent.subintent_hash())
104                    .to_nullification(subintent.intent_core.header.inner.end_epoch_exclusive),
105            )
106        }
107        let executable_transaction_intent = create_executable_intent(
108            transaction_intent.root_intent_core,
109            self.transaction_intent_info,
110        );
111        let executable_subintents = subintents
112            .into_iter()
113            .zip(self.non_root_subintents_info.into_iter())
114            .map(|(subintent, info)| create_executable_intent(subintent.intent_core, info))
115            .collect();
116
117        ExecutableTransaction::new_v2(
118            executable_transaction_intent,
119            executable_subintents,
120            ExecutionContext {
121                unique_hash: transaction_intent_hash.0,
122                intent_hash_nullifications,
123                payload_size,
124                num_of_signature_validations: self.total_signature_validations,
125                costing_parameters: TransactionCostingParameters {
126                    tip: TipSpecifier::BasisPoints(transaction_header.tip_basis_points),
127                    free_credit_in_xrd: Decimal::ZERO,
128                },
129                pre_allocated_addresses: vec![],
130                disable_limits_and_costing_modules: false,
131                epoch_range: Some(self.overall_validity_range.epoch_range.clone()),
132                proposer_timestamp_range: Some(
133                    self.overall_validity_range.proposer_timestamp_range.clone(),
134                ),
135            },
136        )
137    }
138}
139
140fn create_executable_intent(
141    core: PreparedIntentCoreV2,
142    validated_info: ValidatedIntentInformationV2,
143) -> ExecutableIntent {
144    let signer_keys = validated_info.signer_keys;
145    let auth_zone_init = AuthZoneInit::proofs(AuthAddresses::signer_set(&signer_keys));
146
147    ExecutableIntent {
148        encoded_instructions: validated_info.encoded_instructions,
149        auth_zone_init,
150        references: core.instructions.references,
151        blobs: core.blobs.blobs_by_hash,
152        children_subintent_indices: validated_info.children_subintent_indices,
153    }
154}