Skip to content

Commit

Permalink
Merge pull request #120 from HerodotusDev/hotfix-0.4.0
Browse files Browse the repository at this point in the history
Hotfix 0.4.0
  • Loading branch information
rkdud007 authored Jul 31, 2024
2 parents b568a88 + 6c3a0ff commit b3b8380
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 179 deletions.
143 changes: 14 additions & 129 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ categories = [
]

[workspace.dependencies]
hdp-preprocessor = { version = "0.4.0" }
hdp-processor = { version = "0.4.0" }
hdp-primitives = { version = "0.4.0" }
hdp-provider = { version = "0.4.0" }
hdp-cairo-runner = { version = "0.4.0" }
hdp-preprocessor = { path = "crates/pre-processor" }
hdp-processor = { path = "crates/processor" }
hdp-primitives = { path = "crates/primitives" }
hdp-provider = { path = "crates/provider" }
hdp-cairo-runner = { path = "crates/cairo-runner" }
tokio = { version = "1", features = ["full"] }
tempfile = "3.10.1"
alloy-merkle-tree = { version = "0.6.0" }
Expand All @@ -49,6 +49,7 @@ regex = "1"
starknet = "0.10.0"
starknet-crypto = "0.6.1"
cairo-lang-starknet-classes = "2.6.4"
cairo-vm = "1.0.0-rc6"
futures = "0.3.30"
lazy_static = "1.4.0"
thiserror = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ path = "src/main.rs"

[dependencies]
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
hdp = { version = "0.4.0", default-features = false, features = [
hdp = { path = "../crates/hdp", default-features = false, features = [
"preprocessor",
"processor",
"provider",
Expand Down
6 changes: 5 additions & 1 deletion crates/cairo-runner/src/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ impl DryRunner {

let input_file_path = &NamedTempFile::new()?.path().to_path_buf();
fs::write(input_file_path, input_string).expect("Failed to write input file");
let _ = self._run(input_file_path)?;
let output = self._run(input_file_path)?;
if output.is_empty() {
return Err(CairoRunnerError::CairoRunError);
}

// parse output to return dry run result
let dry_run_result = self.parse_run(&PathBuf::from(DRY_CAIRO_RUN_OUTPUT_FILE))?;
Expand All @@ -73,6 +76,7 @@ impl DryRunner {
/// Parse the output of the dry run command
fn parse_run(&self, input_file_path: &Path) -> Result<DryRunResult, CairoRunnerError> {
let output = fs::read_to_string(input_file_path)?;

let fetch_keys: Vec<DryRunnedModule> = serde_json::from_str(&output)?;
fs::remove_file(input_file_path).expect("Failed to remove input file");
if let Some(ref output_path) = self.output_file_path {
Expand Down
66 changes: 23 additions & 43 deletions crates/pre-processor/src/module_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cairo_lang_starknet_classes::casm_contract_class::{

use hdp_primitives::task::{module::Module, ExtendedModule};
use reqwest::Client;
use serde::Deserialize;
use starknet_crypto::FieldElement;
use std::path::PathBuf;
use thiserror::Error;
Expand Down Expand Up @@ -38,11 +37,6 @@ pub struct ModuleRegistry {
client: Client,
}

#[derive(Deserialize)]
struct GitHubFileResponse {
download_url: String,
}

impl Default for ModuleRegistry {
fn default() -> Self {
Self::new()
Expand Down Expand Up @@ -133,54 +127,40 @@ impl ModuleRegistry {
&self,
program_hash: FieldElement,
) -> Result<CasmContractClass, ModuleRegistryError> {
let program_hash_hex = format!("{:#x}", program_hash);

info!(
"Fetching contract class from module registry... program_hash: {:#?}",
program_hash.to_string()
"Fetching contract class from module registry... program_hash: {}",
program_hash_hex
);

let program_hash_key = program_hash.to_string();
let branch = "dev";
let api_url = format!(
"https://api.github.com/repos/HerodotusDev/hdp/contents/crates/pre-processor/module-registery/{}.json?ref={}",
program_hash_key, branch
"http://program-registery.api.herodotus.cloud/get-program?program_hash={}",
program_hash_hex
);

let response_text = self
let response = self
.client
.get(&api_url)
.header("User-Agent", "request")
.send()
.await
.unwrap()
.text()
.await
.unwrap();

// Try to deserialize the response into GitHubFileResponse
let response: Result<GitHubFileResponse, serde_json::Error> =
serde_json::from_str(&response_text);
let response = match response {
Ok(resp) => resp,
Err(err) => {
eprintln!("Failed to deserialize GitHubFileResponse: {}", err);
return Err(ModuleRegistryError::ClassSourceError("fail".to_string()));
}
};
let download_response = self
.client
.get(&response.download_url)
.send()
.await
.unwrap();

let file_content = download_response.text().await.unwrap();
let casm: CasmContractClass = serde_json::from_str(&file_content)?;

info!(
"Contract class fetched successfully from program_hashh: {:?}",
program_hash
);
Ok(casm)
.expect("response is failed");

// Check if the response status is successful
if response.status().is_success() {
let response_text = response.text().await.expect("cannot get response");
let casm: CasmContractClass = serde_json::from_str(&response_text)?;
info!(
"Contract class fetched successfully from program_hash: {:?}",
program_hash
);
Ok(casm)
} else {
Err(ModuleRegistryError::ClassSourceError(
"Failed to fetch contract class".to_string(),
))
}
}
}

Expand Down

0 comments on commit b3b8380

Please sign in to comment.