diff --git a/.deepsource.toml b/.deepsource.toml deleted file mode 100644 index 029a8db9..00000000 --- a/.deepsource.toml +++ /dev/null @@ -1,7 +0,0 @@ -version = 1 - -[[analyzers]] -name = "rust" - - [analyzers.meta] - msrv = "stable" \ No newline at end of file diff --git a/.env.example b/.env.example index cb7f9cde..02d235e8 100644 --- a/.env.example +++ b/.env.example @@ -13,4 +13,8 @@ MONGODB_CONNECTION_STRING # SQS AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= \ No newline at end of file +AWS_SECRET_ACCESS_KEY= + +# S3 +AWS_S3_BUCKET_NAME= +AWS_S3_BUCKET_REGION= \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 6a78385e..d266015f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,7 +567,7 @@ dependencies = [ "alloy-primitives 0.6.4", "async-trait", "auto_impl", - "elliptic-curve", + "elliptic-curve 0.13.8", "k256", "thiserror", ] @@ -580,7 +580,7 @@ dependencies = [ "alloy-primitives 0.7.6", "async-trait", "auto_impl", - "elliptic-curve", + "elliptic-curve 0.13.8", "k256", "thiserror", ] @@ -1512,6 +1512,7 @@ dependencies = [ "aws-credential-types", "aws-sigv4", "aws-smithy-async", + "aws-smithy-eventstream", "aws-smithy-http", "aws-smithy-runtime-api", "aws-smithy-types", @@ -1526,6 +1527,41 @@ dependencies = [ "uuid 1.8.0", ] +[[package]] +name = "aws-sdk-s3" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ecec5514e9d9c76c5e9489ca65ab9055ae0b3c49da3a1afd452c57cb68734fb" +dependencies = [ + "ahash 0.8.11", + "aws-credential-types", + "aws-runtime", + "aws-sigv4", + "aws-smithy-async", + "aws-smithy-checksums", + "aws-smithy-eventstream", + "aws-smithy-http", + "aws-smithy-json", + "aws-smithy-runtime", + "aws-smithy-runtime-api", + "aws-smithy-types", + "aws-smithy-xml", + "aws-types", + "bytes", + "fastrand 2.1.0", + "hex", + "hmac", + "http 0.2.12", + "http-body 0.4.6", + "lru", + "once_cell", + "percent-encoding", + "regex-lite", + "sha2", + "tracing", + "url", +] + [[package]] name = "aws-sdk-sqs" version = "1.29.1" @@ -1622,20 +1658,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31eed8d45759b2c5fe7fd304dd70739060e9e0de509209036eabea14d0720cce" dependencies = [ "aws-credential-types", + "aws-smithy-eventstream", "aws-smithy-http", "aws-smithy-runtime-api", "aws-smithy-types", "bytes", + "crypto-bigint 0.5.5", "form_urlencoded", "hex", "hmac", "http 0.2.12", "http 1.1.0", "once_cell", + "p256", "percent-encoding", + "ring", "sha2", + "subtle", "time", "tracing", + "zeroize", ] [[package]] @@ -1649,12 +1691,45 @@ dependencies = [ "tokio", ] +[[package]] +name = "aws-smithy-checksums" +version = "0.60.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5b30ea96823b8b25fb6471643a516e1bd475fd5575304e6240aea179f213216" +dependencies = [ + "aws-smithy-http", + "aws-smithy-types", + "bytes", + "crc32c", + "crc32fast", + "hex", + "http 0.2.12", + "http-body 0.4.6", + "md-5", + "pin-project-lite", + "sha1", + "sha2", + "tracing", +] + +[[package]] +name = "aws-smithy-eventstream" +version = "0.60.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6363078f927f612b970edf9d1903ef5cef9a64d1e8423525ebb1f0a1633c858" +dependencies = [ + "aws-smithy-types", + "bytes", + "crc32fast", +] + [[package]] name = "aws-smithy-http" version = "0.60.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a7de001a1b9a25601016d8057ea16e31a45fdca3751304c8edf4ad72e706c08" dependencies = [ + "aws-smithy-eventstream", "aws-smithy-runtime-api", "aws-smithy-types", "bytes", @@ -1690,9 +1765,9 @@ dependencies = [ [[package]] name = "aws-smithy-runtime" -version = "1.5.5" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0d3965f6417a92a6d1009c5958a67042f57e46342afb37ca58f9ad26744ec73" +checksum = "db83b08939838d18e33b5dbaf1a0f048f28c10bd28071ab7ce6f245451855414" dependencies = [ "aws-smithy-async", "aws-smithy-http", @@ -1704,6 +1779,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "http-body 1.0.0", + "httparse", "hyper 0.14.29", "hyper-rustls 0.24.2", "once_cell", @@ -1768,15 +1844,14 @@ dependencies = [ [[package]] name = "aws-types" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f734808d43702a67e57d478a12e227d4d038d0b90c9005a78c87890d3805922" +checksum = "2009a9733865d0ebf428a314440bbe357cc10d0c16d86a8e15d32e9b47c1e80e" dependencies = [ "aws-credential-types", "aws-smithy-async", "aws-smithy-runtime-api", "aws-smithy-types", - "http 0.2.12", "rustc_version 0.4.0", "tracing", ] @@ -1915,6 +1990,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a17bd29f7c70f32e9387f4d4acfa5ea7b7749ef784fb78cf382df97069337b8c" +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + [[package]] name = "base16ct" version = "0.2.0" @@ -2966,8 +3047,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b77c319abfd5219629c45c34c89ba945ed3c5e49fcde9d16b6c3885f118a730" dependencies = [ "const-oid", - "der", - "spki", + "der 0.7.9", + "spki 0.7.3", "x509-cert", ] @@ -3140,6 +3221,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "338089f42c427b86394a5ee60ff321da23a5c89c9d89514c829687b26359fcff" +[[package]] +name = "crc32c" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a47af21622d091a8f0fb295b88bc886ac74efcc613efc19f5d0b21de5c89e47" +dependencies = [ + "rustc_version 0.4.0", +] + [[package]] name = "crc32fast" version = "1.4.2" @@ -3161,6 +3251,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-bigint" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + [[package]] name = "crypto-bigint" version = "0.5.5" @@ -3358,6 +3460,16 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +[[package]] +name = "der" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "der" version = "0.7.9" @@ -3592,18 +3704,30 @@ dependencies = [ "url", ] +[[package]] +name = "ecdsa" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" +dependencies = [ + "der 0.6.1", + "elliptic-curve 0.12.3", + "rfc6979 0.3.1", + "signature 1.6.4", +] + [[package]] name = "ecdsa" version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ - "der", + "der 0.7.9", "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki", + "elliptic-curve 0.13.8", + "rfc6979 0.4.0", + "signature 2.2.0", + "spki 0.7.3", ] [[package]] @@ -3612,21 +3736,41 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +[[package]] +name = "elliptic-curve" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +dependencies = [ + "base16ct 0.1.1", + "crypto-bigint 0.4.9", + "der 0.6.1", + "digest 0.10.7", + "ff 0.12.1", + "generic-array", + "group 0.12.1", + "pkcs8 0.9.0", + "rand_core", + "sec1 0.3.0", + "subtle", + "zeroize", +] + [[package]] name = "elliptic-curve" version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ - "base16ct", - "crypto-bigint", + "base16ct 0.2.0", + "crypto-bigint 0.5.5", "digest 0.10.7", - "ff", + "ff 0.13.0", "generic-array", - "group", - "pkcs8", + "group 0.13.0", + "pkcs8 0.10.2", "rand_core", - "sec1", + "sec1 0.7.3", "subtle", "zeroize", ] @@ -3877,6 +4021,16 @@ dependencies = [ "bytes", ] +[[package]] +name = "ff" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" +dependencies = [ + "rand_core", + "subtle", +] + [[package]] name = "ff" version = "0.13.0" @@ -4292,13 +4446,24 @@ dependencies = [ "utils", ] +[[package]] +name = "group" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +dependencies = [ + "ff 0.12.1", + "rand_core", + "subtle", +] + [[package]] name = "group" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff", + "ff 0.13.0", "rand_core", "subtle", ] @@ -4547,9 +4712,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.4" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -5087,11 +5252,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" dependencies = [ "cfg-if", - "ecdsa", - "elliptic-curve", + "ecdsa 0.16.9", + "elliptic-curve 0.13.8", "once_cell", "sha2", - "signature", + "signature 2.2.0", ] [[package]] @@ -5895,8 +6060,11 @@ dependencies = [ "arc-swap", "async-std", "async-trait", + "aws-config", + "aws-sdk-s3", "axum 0.7.5", "axum-macros", + "bytes", "cairo-vm 1.0.0-rc3", "color-eyre", "da-client-interface", @@ -5957,7 +6125,7 @@ checksum = "df7b60d0b2dcace322e6e8c4499c4c8bdf331c1bae046a54be5e4191c3610286" dependencies = [ "cbc", "cms", - "der", + "der 0.7.9", "des", "hex", "hmac", @@ -5971,6 +6139,17 @@ dependencies = [ "x509-parser", ] +[[package]] +name = "p256" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51f44edd08f51e2ade572f141051021c5af22677e42b7dd28a88155151c33594" +dependencies = [ + "ecdsa 0.14.8", + "elliptic-curve 0.12.3", + "sha2", +] + [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -6335,9 +6514,9 @@ checksum = "695b3df3d3cc1015f12d70235e35b6b79befc5fa7a9b95b951eab1dd07c9efc2" dependencies = [ "cms", "const-oid", - "der", + "der 0.7.9", "digest 0.10.7", - "spki", + "spki 0.7.3", "x509-cert", "zeroize", ] @@ -6350,11 +6529,21 @@ checksum = "e847e2c91a18bfa887dd028ec33f2fe6f25db77db3619024764914affe8b69a6" dependencies = [ "aes", "cbc", - "der", + "der 0.7.9", "pbkdf2 0.12.2", "scrypt 0.11.0", "sha2", - "spki", + "spki 0.7.3", +] + +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der 0.6.1", + "spki 0.6.0", ] [[package]] @@ -6363,8 +6552,8 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der", - "spki", + "der 0.7.9", + "spki 0.7.3", ] [[package]] @@ -6889,6 +7078,17 @@ dependencies = [ "quick-error", ] +[[package]] +name = "rfc6979" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +dependencies = [ + "crypto-bigint 0.4.9", + "hmac", + "zeroize", +] + [[package]] name = "rfc6979" version = "0.4.0" @@ -7409,16 +7609,30 @@ dependencies = [ "untrusted", ] +[[package]] +name = "sec1" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" +dependencies = [ + "base16ct 0.1.1", + "der 0.6.1", + "generic-array", + "pkcs8 0.9.0", + "subtle", + "zeroize", +] + [[package]] name = "sec1" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ - "base16ct", - "der", + "base16ct 0.2.0", + "der 0.7.9", "generic-array", - "pkcs8", + "pkcs8 0.10.2", "subtle", "zeroize", ] @@ -7810,6 +8024,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +dependencies = [ + "digest 0.10.7", + "rand_core", +] + [[package]] name = "signature" version = "2.2.0" @@ -7960,6 +8184,16 @@ dependencies = [ "lock_api", ] +[[package]] +name = "spki" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der 0.6.1", +] + [[package]] name = "spki" version = "0.7.3" @@ -7967,7 +8201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", - "der", + "der 0.7.9", ] [[package]] @@ -8068,13 +8302,13 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3f2175b0b3fc24ff2ec6dc07f5a720498994effca7e78b11a6e1c1bd02cad52" dependencies = [ - "crypto-bigint", + "crypto-bigint 0.5.5", "hex", "hmac", "num-bigint", "num-integer", "num-traits 0.2.19", - "rfc6979", + "rfc6979 0.4.0", "sha2", "starknet-crypto-codegen", "starknet-curve 0.3.0", @@ -8088,13 +8322,13 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e2c30c01e8eb0fc913c4ee3cf676389fffc1d1182bfe5bb9670e4e72e968064" dependencies = [ - "crypto-bigint", + "crypto-bigint 0.5.5", "hex", "hmac", "num-bigint", "num-integer", "num-traits 0.2.19", - "rfc6979", + "rfc6979 0.4.0", "sha2", "starknet-crypto-codegen", "starknet-curve 0.4.2", @@ -8139,7 +8373,7 @@ checksum = "7abf1b44ec5b18d87c1ae5f54590ca9d0699ef4dd5b2ffa66fc97f24613ec585" dependencies = [ "ark-ff 0.4.2", "bigdecimal", - "crypto-bigint", + "crypto-bigint 0.5.5", "getrandom", "hex", "num-bigint", @@ -8207,7 +8441,7 @@ checksum = "8c5eb659e66b56ceafb9025cd601226d8f34d273f1b826cd4053ab6333ff0898" dependencies = [ "async-trait", "auto_impl", - "crypto-bigint", + "crypto-bigint 0.5.5", "eth-keystore", "rand", "starknet-core 0.9.0", @@ -9581,8 +9815,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1301e935010a701ae5f8655edc0ad17c44bad3ac5ce8c39185f75453b720ae94" dependencies = [ "const-oid", - "der", - "spki", + "der 0.7.9", + "spki 0.7.3", ] [[package]] diff --git a/crates/orchestrator/Cargo.toml b/crates/orchestrator/Cargo.toml index 9fbc9155..543f5435 100644 --- a/crates/orchestrator/Cargo.toml +++ b/crates/orchestrator/Cargo.toml @@ -15,8 +15,11 @@ path = "src/main.rs" arc-swap = { workspace = true } async-std = "1.12.0" async-trait = { workspace = true } +aws-config = { version = "1.1.7", features = ["behavior-version-latest"] } +aws-sdk-s3 = { version = "1.38.0", features = ["behavior-version-latest"] } axum = { workspace = true, features = ["macros"] } axum-macros = { workspace = true } +bytes = "1.6.0" cairo-vm = { workspace = true } color-eyre = { workspace = true } da-client-interface = { workspace = true } diff --git a/crates/orchestrator/src/data_storage/aws_s3/config.rs b/crates/orchestrator/src/data_storage/aws_s3/config.rs new file mode 100644 index 00000000..7c41f3c6 --- /dev/null +++ b/crates/orchestrator/src/data_storage/aws_s3/config.rs @@ -0,0 +1,28 @@ +use utils::env_utils::get_env_var_or_panic; + +use crate::data_storage::DataStorageConfig; + +/// Represents AWS S3 config struct with all the necessary variables. +pub struct AWSS3Config { + /// AWS ACCESS KEY ID + pub s3_key_id: String, + /// AWS ACCESS KEY SECRET + pub s3_key_secret: String, + /// S3 Bucket Name + pub s3_bucket_name: String, + /// S3 Bucket region + pub s3_bucket_region: String, +} + +/// Implementation of `DataStorageConfig` for `AWSS3Config` +impl DataStorageConfig for AWSS3Config { + /// To return the config struct by creating it from the environment variables. + fn new_from_env() -> Self { + Self { + s3_key_id: get_env_var_or_panic("AWS_ACCESS_KEY_ID"), + s3_key_secret: get_env_var_or_panic("AWS_SECRET_ACCESS_KEY"), + s3_bucket_name: get_env_var_or_panic("AWS_S3_BUCKET_NAME"), + s3_bucket_region: get_env_var_or_panic("AWS_S3_BUCKET_REGION"), + } + } +} diff --git a/crates/orchestrator/src/data_storage/aws_s3/mod.rs b/crates/orchestrator/src/data_storage/aws_s3/mod.rs new file mode 100644 index 00000000..ab6d90df --- /dev/null +++ b/crates/orchestrator/src/data_storage/aws_s3/mod.rs @@ -0,0 +1,71 @@ +use crate::data_storage::aws_s3::config::AWSS3Config; +use crate::data_storage::DataStorage; +use async_trait::async_trait; +use aws_sdk_s3::config::{Builder, Credentials, Region}; +use aws_sdk_s3::primitives::ByteStream; +use aws_sdk_s3::{Client, Error}; +use bytes::Bytes; + +/// Module for AWS S3 config structs and implementations +pub mod config; + +/// AWSS3 represents AWS S3 client object containing the client and the config itself. +pub struct AWSS3 { + client: Client, + config: AWSS3Config, +} + +/// Implementation for AWS S3 client. Contains the function for : +/// +/// - initializing a new AWS S3 client +impl AWSS3 { + /// Initializes a new AWS S3 client by passing the config + /// and returning it. + #[allow(dead_code)] + pub async fn new(config: AWSS3Config) -> Self { + // AWS cred building + let credentials = Credentials::new( + config.s3_key_id.clone(), + config.s3_key_secret.clone(), + None, + None, + "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 = conf_builder.build(); + + // Building AWS S3 config + let client = Client::from_conf(conf); + + Self { client, config } + } +} + +/// Implementation of `DataStorage` for `AWSS3` +/// contains the function for getting the data and putting the data +/// by taking the key as an argument. +#[async_trait] +impl DataStorage for AWSS3 { + /// Function to get the data from S3 bucket by Key. + async fn get_data(&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(); + Ok(data_bytes) + } + + /// Function to put the data to S3 bucket by Key. + async fn put_data(&self, data: ByteStream, key: &str) -> Result<(), Error> { + self.client + .put_object() + .bucket(self.config.s3_bucket_name.clone()) + .key(key) + .body(data) + .content_type("application/json") + .send() + .await?; + + Ok(()) + } +} diff --git a/crates/orchestrator/src/data_storage/mod.rs b/crates/orchestrator/src/data_storage/mod.rs new file mode 100644 index 00000000..3dbef150 --- /dev/null +++ b/crates/orchestrator/src/data_storage/mod.rs @@ -0,0 +1,30 @@ +mod aws_s3; +mod types; + +use async_trait::async_trait; +use aws_sdk_s3::primitives::ByteStream; +use aws_sdk_s3::Error; +use bytes::Bytes; +use mockall::automock; + +/// DataStorage trait contains the functions used to store and get the data from +/// the cloud provider storage. +/// The proposed storage format is : +/// ----s3 +/// ---- +/// ---- +/// ---- +#[automock] +#[async_trait] +pub trait DataStorage: Send + Sync { + async fn get_data(&self, key: &str) -> Result; + async fn put_data(&self, data: ByteStream, key: &str) -> Result<(), Error>; +} + +/// **DataStorageConfig** : Trait method to represent the config struct needed for +/// initialisation of data storage client +pub trait DataStorageConfig { + /// Get a config file from environment vars in system or + /// dotenv file. + fn new_from_env() -> Self; +} diff --git a/crates/orchestrator/src/data_storage/types.rs b/crates/orchestrator/src/data_storage/types.rs new file mode 100644 index 00000000..0fc1a6fb --- /dev/null +++ b/crates/orchestrator/src/data_storage/types.rs @@ -0,0 +1,42 @@ +use cairo_vm::Felt252; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +/// This struct represents the contract changes that will be in `StarknetOsOutput` +/// as a vector. +#[derive(Debug, Deserialize, Serialize)] +pub struct ContractChanges { + /// The address of the contract. + pub addr: Felt252, + /// The new nonce of the contract (for account contracts). + pub nonce: Felt252, + /// The new class hash (if changed). + pub class_hash: Option, + /// A map from storage key to its new value. + pub storage_changes: HashMap, +} + +/// This struct represents the starknet OS outputs in the json we will get after the run. +#[derive(Debug, Deserialize, Serialize)] +pub struct StarknetOsOutput { + /// The root before. + pub initial_root: Felt252, + /// The root after. + pub final_root: Felt252, + /// The block number. + pub block_number: Felt252, + /// The block hash. + pub block_hash: Felt252, + /// The hash of the OS config. + pub starknet_os_config_hash: Felt252, + /// Whether KZG data availability was used. + pub use_kzg_da: Felt252, + /// Messages from L2 to L1. + pub messages_to_l1: Vec, + /// Messages from L1 to L2. + pub messages_to_l2: Vec, + /// The list of contracts that were changed. + pub contracts: Vec, + /// The list of classes that were declared. A map from class hash to compiled class hash. + pub classes: HashMap, +} diff --git a/crates/orchestrator/src/lib.rs b/crates/orchestrator/src/lib.rs index 4a19222d..109c48ad 100644 --- a/crates/orchestrator/src/lib.rs +++ b/crates/orchestrator/src/lib.rs @@ -2,6 +2,9 @@ pub mod config; /// Controllers for the routes pub mod controllers; +/// Contains the trait that implements the fetching functions +/// for blob and SNOS data from cloud for a particular block. +pub mod data_storage; /// Contains the trait that all database clients must implement pub mod database; /// Contains the trait that all jobs must implement. Also @@ -12,8 +15,7 @@ pub mod jobs; pub mod queue; /// Contains the routes for the service pub mod routes; -/// Contains workers which act like cron jobs -pub mod workers; - #[cfg(test)] mod tests; +/// Contains workers which act like cron jobs +pub mod workers;