Skip to content

Commit

Permalink
feat : removed redundant functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun Jangra authored and Arun Jangra committed Jun 25, 2024
1 parent da3f3f5 commit 59ce0a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 84 deletions.
78 changes: 6 additions & 72 deletions crates/orchestrator/src/data_storage/aws_s3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -42,35 +37,18 @@ impl AWSS3 {

#[async_trait]
impl DataStorage for AWSS3 {
async fn get_snos_data_for_block(&self, block_number: u128) -> Result<StarknetOsOutput, Error> {
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<StarknetOsOutput, Error> {
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.");

Ok(json)
}

async fn store_snos_data_for_block(
&self,
block_number: u128,
data: StarknetOsOutput,
) -> Result<usize, Error> {
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<usize, Error> {
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()
Expand All @@ -83,48 +61,4 @@ impl DataStorage for AWSS3 {

Ok(json_data.len())
}

async fn get_kzg_data_for_block(&self, block_number: u128) -> Result<String, Error> {
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<usize, Error> {
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())
}
}
14 changes: 2 additions & 12 deletions crates/orchestrator/src/data_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<StarknetOsOutput, Error>;
async fn store_snos_data_for_block(
&self,
block_number: u128,
data: StarknetOsOutput,
) -> Result<usize, Error>;
async fn get_kzg_data_for_block(&self, block_number: u128) -> Result<String, Error>;
async fn set_kzg_data_for_block(
&self,
block_number: u128,
kzg_proof: &str,
) -> Result<usize, Error>;
async fn get_data_for_block(&self, key: &str) -> Result<StarknetOsOutput, Error>;
async fn put_data_for_block(&self, data: StarknetOsOutput, key: &str) -> Result<usize, Error>;
}

pub trait DataStorageConfig {
Expand Down

0 comments on commit 59ce0a9

Please sign in to comment.