diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs index 74520f66..332aaf99 100644 --- a/crates/orchestrator/src/data_storage/aws_s3/mod.rs +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -8,9 +8,6 @@ use aws_sdk_s3::{Client, Error}; pub mod config; -const SNOS_OUTPUT_FILE_NAME: &str = "snos_output.json"; -const KZG_FILE_NAME: &str = "kzg.txt"; - pub struct AWSS3 { client: Client, config: AWSS3Config, @@ -28,9 +25,7 @@ impl AWSS3 { "loaded_from_custom_env", ); let region = Region::new(config.s3_bucket_region.clone().to_string()); - let conf_builder = Builder::new() - .region(region) - .credentials_provider(credentials); + let conf_builder = Builder::new().region(region).credentials_provider(credentials); let conf = conf_builder.build(); // Building AWS S3 config @@ -42,20 +37,9 @@ impl AWSS3 { #[async_trait] impl DataStorage for AWSS3 { - async fn get_snos_data_for_block(&self, block_number: u128) -> Result { - let key = format!("{}/{}", block_number, SNOS_OUTPUT_FILE_NAME); - let response = self - .client - .get_object() - .bucket(self.config.s3_bucket_name.clone()) - .key(key) - .send() - .await?; - let data_stream = response - .body - .collect() - .await - .expect("Failed to convert body into AggregatedBytes."); + async fn get_data_for_block(&self, key: &str) -> Result { + let response = self.client.get_object().bucket(self.config.s3_bucket_name.clone()).key(key).send().await?; + let data_stream = response.body.collect().await.expect("Failed to convert body into AggregatedBytes."); let data_bytes = data_stream.into_bytes(); let json: StarknetOsOutput = serde_json::from_slice(&data_bytes).expect("Failed to convert data_bytes into JSON."); @@ -63,14 +47,8 @@ impl DataStorage for AWSS3 { Ok(json) } - async fn store_snos_data_for_block( - &self, - block_number: u128, - data: StarknetOsOutput, - ) -> Result { - let json_data = - serde_json::to_vec(&data).expect("Failed to convert StarknetOsOutput into JSON."); - let key = format!("{}/{}", block_number, SNOS_OUTPUT_FILE_NAME); + async fn put_data_for_block(&self, data: StarknetOsOutput, key: &str) -> Result { + let json_data = serde_json::to_vec(&data).expect("Failed to convert StarknetOsOutput into JSON."); let byte_stream = ByteStream::from(json_data.clone()); self.client .put_object() @@ -83,48 +61,4 @@ impl DataStorage for AWSS3 { Ok(json_data.len()) } - - async fn get_kzg_data_for_block(&self, block_number: u128) -> Result { - let key = format!("{}/{}", block_number, KZG_FILE_NAME); - let response = self - .client - .get_object() - .bucket(self.config.s3_bucket_name.clone()) - .key(key) - .send() - .await?; - let data_stream = response - .body - .collect() - .await - .expect("Failed to convert body into AggregatedBytes."); - let data_bytes = data_stream.into_bytes(); - - // Convert the bytes to a UTF-8 string - let text = String::from_utf8(data_bytes.to_vec()) - .expect("Failed to convert data_bytes into String."); - - Ok(text) - } - - async fn set_kzg_data_for_block( - &self, - block_number: u128, - kzg_proof: &str, - ) -> Result { - let byte_stream = ByteStream::from(kzg_proof.as_bytes().to_vec()); - let key = format!("{}/{}", block_number, SNOS_OUTPUT_FILE_NAME); - - // Uploading the text file - self.client - .put_object() - .bucket(self.config.s3_bucket_name.clone()) - .key(key) - .body(byte_stream) - .content_type("application/json") - .send() - .await?; - - Ok(kzg_proof.len()) - } } diff --git a/crates/orchestrator/src/data_storage/mod.rs b/crates/orchestrator/src/data_storage/mod.rs index ba1d67a8..2f1d7553 100644 --- a/crates/orchestrator/src/data_storage/mod.rs +++ b/crates/orchestrator/src/data_storage/mod.rs @@ -16,18 +16,8 @@ use mockall::automock; #[automock] #[async_trait] pub trait DataStorage: Send + Sync { - async fn get_snos_data_for_block(&self, block_number: u128) -> Result; - async fn store_snos_data_for_block( - &self, - block_number: u128, - data: StarknetOsOutput, - ) -> Result; - async fn get_kzg_data_for_block(&self, block_number: u128) -> Result; - async fn set_kzg_data_for_block( - &self, - block_number: u128, - kzg_proof: &str, - ) -> Result; + async fn get_data_for_block(&self, key: &str) -> Result; + async fn put_data_for_block(&self, data: StarknetOsOutput, key: &str) -> Result; } pub trait DataStorageConfig {