@@ -49,6 +49,25 @@ impl PreComputeApp {
4949}
5050
5151impl PreComputeAppTrait for PreComputeApp {
52+ /// Runs the complete pre-compute pipeline.
53+ ///
54+ /// This method orchestrates the entire pre-compute process:
55+ /// 1. Reads configuration arguments
56+ /// 2. Validates the output folder exists
57+ /// 3. Downloads and decrypts the dataset (if required)
58+ /// 4. Downloads all input files
59+ ///
60+ /// # Returns
61+ ///
62+ /// - `Ok(())` if all operations completed successfully
63+ /// - `Err(ReplicateStatusCause)` if any step failed
64+ ///
65+ /// # Example
66+ ///
67+ /// ```rust
68+ /// let mut app = PreComputeApp::new("task_id".to_string());
69+ /// app.run()?;
70+ /// ```
5271 fn run ( & mut self ) -> Result < ( ) , ReplicateStatusCause > {
5372 self . pre_compute_args = PreComputeArgs :: read_args ( ) ?;
5473 self . check_output_folder ( ) ?;
@@ -61,23 +80,6 @@ impl PreComputeAppTrait for PreComputeApp {
6180 Ok ( ( ) )
6281 }
6382
64- /// Checks whether the output folder specified in `pre_compute_args` exists.
65- ///
66- /// # Returns
67- ///
68- /// - `Ok(())` if the output directory (`output_dir`) exists.
69- /// - `Err(ReplicateStatusCause::PreComputeOutputFolderNotFound)` if the directory does not exist,
70- /// or if `pre_compute_args` is missing.
71- ///
72- /// # Example
73- ///
74- /// ```
75- /// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
76- ///
77- /// let mut pre_compute_app = PreComputeApp::new("0x123456789abcdef".to_string());
78- ///
79- /// pre_compute_app.check_output_folder();
80- /// ```
8183 fn check_output_folder ( & self ) -> Result < ( ) , ReplicateStatusCause > {
8284 let output_dir: & str = & self . pre_compute_args . output_dir ;
8385 let chain_task_id: & str = & self . chain_task_id ;
@@ -93,31 +95,6 @@ impl PreComputeAppTrait for PreComputeApp {
9395 Err ( ReplicateStatusCause :: PreComputeOutputFolderNotFound )
9496 }
9597
96- /// Downloads the input files listed in `pre_compute_args.input_files` to the specified `output_dir`.
97- ///
98- /// Each URL is hashed (SHA-256) to generate a unique local filename.
99- /// If any download fails, the function returns an error.
100- ///
101- /// # Returns
102- ///
103- /// - `Ok(())` if all files are downloaded successfully.
104- /// - `Err(ReplicateStatusCause::PreComputeInputFileDownloadFailed)` if any file fails to download.
105- ///
106- /// # Panics
107- ///
108- /// This function panics if:
109- /// - `pre_compute_args` is `None`.
110- /// - `chain_task_id` is `None`.
111- ///
112- /// # Example
113- ///
114- /// ```
115- /// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
116- ///
117- /// let mut pre_compute_app = PreComputeApp::new("0x123456789abcdef".to_string());
118- ///
119- /// pre_compute_app.download_input_files().unwrap();
120- /// ```
12198 fn download_input_files ( & self ) -> Result < ( ) , ReplicateStatusCause > {
12299 let args = & self . pre_compute_args ;
123100 let chain_task_id: & str = & self . chain_task_id ;
@@ -133,23 +110,6 @@ impl PreComputeAppTrait for PreComputeApp {
133110 Ok ( ( ) )
134111 }
135112
136- /// Downloads the encrypted dataset file from a URL or IPFS multi-address, and verifies its checksum.
137- ///
138- /// # Returns
139- ///
140- /// * `Ok(Vec<u8>)` containing the dataset's encrypted content if download and verification succeed.
141- /// * `Err(ReplicateStatusCause::PreComputeDatasetDownloadFailed)` if the download fails or inputs are missing.
142- /// * `Err(ReplicateStatusCause::PreComputeInvalidDatasetChecksum)` if checksum validation fails.
143- ///
144- /// # Example
145- ///
146- /// ```
147- /// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
148- ///
149- /// let mut app = PreComputeApp::new("0x123456789abcdef".to_string());
150- ///
151- /// app.download_encrypted_dataset();
152- /// ```
153113 fn download_encrypted_dataset ( & self ) -> Result < Vec < u8 > , ReplicateStatusCause > {
154114 let args = & self . pre_compute_args ;
155115 let chain_task_id = & self . chain_task_id ;
@@ -192,30 +152,6 @@ impl PreComputeAppTrait for PreComputeApp {
192152 Ok ( encrypted_content)
193153 }
194154
195- /// Decrypts the provided encrypted dataset bytes using AES-CBC.
196- ///
197- /// The first 16 bytes of `encrypted_content` are treated as the IV.
198- /// The rest is the ciphertext. The decryption key is decoded from a Base64 string.
199- ///
200- /// # Arguments
201- ///
202- /// * `encrypted_content` - Full encrypted dataset, including the IV prefix.
203- ///
204- /// # Returns
205- ///
206- /// * `Ok(Vec<u8>)` containing the plaintext dataset if decryption succeeds.
207- /// * `Err(ReplicateStatusCause::PreComputeDatasetDecryptionFailed)` if the key is missing, decoding fails, or decryption fails.
208- ///
209- /// # Example
210- ///
211- /// ```
212- /// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
213- ///
214- /// let mut app = PreComputeApp::new("0x123456789abcdef".to_string());
215- ///
216- /// let encrypted = vec![/* ... */];
217- /// let decrypted = app.decrypt_dataset(&encrypted);
218- /// ```
219155 fn decrypt_dataset ( & self , encrypted_content : & [ u8 ] ) -> Result < Vec < u8 > , ReplicateStatusCause > {
220156 let base64_key: & str = & self . pre_compute_args . encrypted_dataset_base64_key ;
221157
@@ -236,29 +172,6 @@ impl PreComputeAppTrait for PreComputeApp {
236172 . map_err ( |_| ReplicateStatusCause :: PreComputeDatasetDecryptionFailed )
237173 }
238174
239- /// Saves the decrypted (plain) dataset to disk in the configured output directory.
240- ///
241- /// The output filename is taken from `pre_compute_args.plain_dataset_filename`.
242- ///
243- /// # Arguments
244- ///
245- /// * `plain_dataset` - The dataset content to write to a file.
246- ///
247- /// # Returns
248- ///
249- /// * `Ok(())` if the file is successfully saved.
250- /// * `Err(ReplicateStatusCause::PreComputeSavingPlainDatasetFailed)` if the path is invalid or write fails.
251- ///
252- /// # Example
253- ///
254- /// ```
255- /// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
256- ///
257- /// let mut app = PreComputeApp::new("0x123456789abcdef".to_string());
258- ///
259- /// let plain_data = vec![/* ... */];
260- /// app.save_plain_dataset_file(&plain_data);
261- /// ```
262175 fn save_plain_dataset_file ( & self , plain_dataset : & [ u8 ] ) -> Result < ( ) , ReplicateStatusCause > {
263176 let chain_task_id: & str = & self . chain_task_id ;
264177 let args = & self . pre_compute_args ;
0 commit comments