radix_transactions/model/v2/
subintent_manifest_v2.rs

1use super::*;
2use crate::internal_prelude::*;
3
4//=================================================================================
5// NOTE:
6// This isn't actually embedded as a model - it's just a useful model which we use
7// in eg the manifest builder
8//=================================================================================
9
10/// Can be built with a [`ManifestV2Builder`]
11#[derive(Debug, Clone, Default, PartialEq, Eq, ManifestSbor, ScryptoDescribe)]
12pub struct SubintentManifestV2 {
13    pub instructions: Vec<InstructionV2>,
14    pub blobs: IndexMap<Hash, Vec<u8>>,
15    pub children: IndexSet<ChildSubintentSpecifier>,
16    pub object_names: ManifestObjectNames,
17}
18
19impl ReadableManifestBase for SubintentManifestV2 {
20    fn is_subintent(&self) -> bool {
21        true
22    }
23
24    fn get_blobs<'a>(&'a self) -> impl Iterator<Item = (&'a Hash, &'a Vec<u8>)> {
25        self.blobs.iter()
26    }
27
28    fn get_child_subintent_hashes<'a>(
29        &'a self,
30    ) -> impl ExactSizeIterator<Item = &'a ChildSubintentSpecifier> {
31        self.children.iter()
32    }
33
34    fn get_known_object_names_ref(&self) -> ManifestObjectNamesRef {
35        self.object_names.as_ref()
36    }
37}
38
39impl TypedReadableManifest for SubintentManifestV2 {
40    type Instruction = InstructionV2;
41
42    fn get_typed_instructions(&self) -> &[Self::Instruction] {
43        &self.instructions
44    }
45}
46
47impl BuildableManifestWithParent for SubintentManifestV2 {}
48
49impl BuildableManifestSupportingChildren for SubintentManifestV2 {}
50
51impl BuildableManifest for SubintentManifestV2 {
52    fn add_instruction(&mut self, instruction: Self::Instruction) {
53        self.instructions.push(instruction)
54    }
55
56    fn add_blob(&mut self, hash: Hash, content: Vec<u8>) {
57        self.blobs.insert(hash, content);
58    }
59
60    fn set_names(&mut self, names: KnownManifestObjectNames) {
61        self.object_names = names.into()
62    }
63
64    fn add_child_subintent(&mut self, hash: SubintentHash) -> Result<(), ManifestBuildError> {
65        if !self.children.insert(ChildSubintentSpecifier { hash }) {
66            return Err(ManifestBuildError::DuplicateChildSubintentHash);
67        }
68        Ok(())
69    }
70
71    fn default_test_execution_config_type(&self) -> DefaultTestExecutionConfigType {
72        DefaultTestExecutionConfigType::Test
73    }
74
75    fn into_executable_with_proofs(
76        self,
77        _nonce: u32,
78        _initial_proofs: BTreeSet<NonFungibleGlobalId>,
79        _validator: &TransactionValidator,
80    ) -> Result<ExecutableTransaction, String> {
81        Err("A subintent manifest is not executable by itself. See the docs on `TestTransaction::new_v2_builder` for an alternative approach, to wrap the manifest in a parent test transaction.".to_string())
82    }
83}
84
85impl SubintentManifestV2 {
86    pub fn from_intent_core(intent: &IntentCoreV2) -> Self {
87        Self {
88            instructions: intent.instructions.clone().into(),
89            blobs: intent.blobs.clone().into(),
90            children: intent.children.children.clone(),
91            object_names: ManifestObjectNames::Unknown,
92        }
93    }
94
95    pub fn for_intent(self) -> (InstructionsV2, BlobsV1, ChildSubintentSpecifiersV2) {
96        (
97            self.instructions.into(),
98            self.blobs.into(),
99            ChildSubintentSpecifiersV2 {
100                children: self.children,
101            },
102        )
103    }
104
105    pub fn for_intent_with_names(
106        self,
107    ) -> (
108        InstructionsV2,
109        BlobsV1,
110        ChildSubintentSpecifiersV2,
111        ManifestObjectNames,
112    ) {
113        (
114            self.instructions.into(),
115            self.blobs.into(),
116            ChildSubintentSpecifiersV2 {
117                children: self.children,
118            },
119            self.object_names,
120        )
121    }
122}