radix_transactions/model/v2/
transaction_intent_v2.rs

1use super::*;
2use crate::internal_prelude::*;
3
4//=================================================================================
5// NOTE:
6// See versioned.rs for tests and a demonstration for the calculation of hashes etc
7//=================================================================================
8
9/// This is the root intent of a [`NotarizedTransactionV2`].
10///
11/// It may have 0 or more [`SubintentV2`] children, which themselves may have children...
12/// This forms an intent tree, which is subject to a depth limit, and a limit on the
13/// total number of intents.
14///
15/// All the subintent descendents are flattened and are stored in the `non_root_subintents`
16/// field. To be valid, these intents must form a tree, with the transaction intent at its root.
17/// There are a few reasons for the flattening:
18/// * It means the models have a fixed depth, allowing avoiding recursion.
19/// * It aligns with the runtime model.
20/// * It allows the signatures to be attached in one layer as per the [`SignedTransactionIntentV2`].
21///
22/// ## Similar models
23///
24///  A [`PartialTransactionV2`] is a similar structure for a partial subtree
25/// of a transaction, but with a subintent root. Whilst useful for constructing a
26/// transaction, it doesn't appear under a [`NotarizedTransactionV2`] because the subintents
27/// get flattened.
28#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
29pub struct TransactionIntentV2 {
30    pub transaction_header: TransactionHeaderV2,
31    pub root_intent_core: IntentCoreV2,
32    pub non_root_subintents: NonRootSubintentsV2,
33}
34
35define_transaction_payload!(
36    TransactionIntentV2,
37    RawTransactionIntent,
38    PreparedTransactionIntentV2 {
39        transaction_header: PreparedTransactionHeaderV2,
40        root_intent_core: PreparedIntentCoreV2,
41        non_root_subintents: PreparedNonRootSubintentsV2,
42    },
43    TransactionDiscriminator::V2TransactionIntent,
44);
45
46impl HasTransactionIntentHash for PreparedTransactionIntentV2 {
47    fn transaction_intent_hash(&self) -> TransactionIntentHash {
48        TransactionIntentHash::from_hash(self.summary.hash)
49    }
50}
51
52impl HasNonRootSubintentHashes for PreparedTransactionIntentV2 {
53    fn non_root_subintent_hashes(&self) -> Vec<SubintentHash> {
54        self.non_root_subintents.non_root_subintent_hashes()
55    }
56}