Skip to content

Commit b3b8380

Browse files
authored
Merge pull request #120 from HerodotusDev/hotfix-0.4.0
Hotfix 0.4.0
2 parents b568a88 + 6c3a0ff commit b3b8380

File tree

5 files changed

+49
-179
lines changed

5 files changed

+49
-179
lines changed

Diff for: Cargo.lock

+14-129
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ categories = [
2727
]
2828

2929
[workspace.dependencies]
30-
hdp-preprocessor = { version = "0.4.0" }
31-
hdp-processor = { version = "0.4.0" }
32-
hdp-primitives = { version = "0.4.0" }
33-
hdp-provider = { version = "0.4.0" }
34-
hdp-cairo-runner = { version = "0.4.0" }
30+
hdp-preprocessor = { path = "crates/pre-processor" }
31+
hdp-processor = { path = "crates/processor" }
32+
hdp-primitives = { path = "crates/primitives" }
33+
hdp-provider = { path = "crates/provider" }
34+
hdp-cairo-runner = { path = "crates/cairo-runner" }
3535
tokio = { version = "1", features = ["full"] }
3636
tempfile = "3.10.1"
3737
alloy-merkle-tree = { version = "0.6.0" }
@@ -49,6 +49,7 @@ regex = "1"
4949
starknet = "0.10.0"
5050
starknet-crypto = "0.6.1"
5151
cairo-lang-starknet-classes = "2.6.4"
52+
cairo-vm = "1.0.0-rc6"
5253
futures = "0.3.30"
5354
lazy_static = "1.4.0"
5455
thiserror = "1.0"

Diff for: cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ path = "src/main.rs"
1919

2020
[dependencies]
2121
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
22-
hdp = { version = "0.4.0", default-features = false, features = [
22+
hdp = { path = "../crates/hdp", default-features = false, features = [
2323
"preprocessor",
2424
"processor",
2525
"provider",

Diff for: crates/cairo-runner/src/dry_run.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ impl DryRunner {
6262

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

6770
// parse output to return dry run result
6871
let dry_run_result = self.parse_run(&PathBuf::from(DRY_CAIRO_RUN_OUTPUT_FILE))?;
@@ -73,6 +76,7 @@ impl DryRunner {
7376
/// Parse the output of the dry run command
7477
fn parse_run(&self, input_file_path: &Path) -> Result<DryRunResult, CairoRunnerError> {
7578
let output = fs::read_to_string(input_file_path)?;
79+
7680
let fetch_keys: Vec<DryRunnedModule> = serde_json::from_str(&output)?;
7781
fs::remove_file(input_file_path).expect("Failed to remove input file");
7882
if let Some(ref output_path) = self.output_file_path {

Diff for: crates/pre-processor/src/module_registry.rs

+23-43
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use cairo_lang_starknet_classes::casm_contract_class::{
77

88
use hdp_primitives::task::{module::Module, ExtendedModule};
99
use reqwest::Client;
10-
use serde::Deserialize;
1110
use starknet_crypto::FieldElement;
1211
use std::path::PathBuf;
1312
use thiserror::Error;
@@ -38,11 +37,6 @@ pub struct ModuleRegistry {
3837
client: Client,
3938
}
4039

41-
#[derive(Deserialize)]
42-
struct GitHubFileResponse {
43-
download_url: String,
44-
}
45-
4640
impl Default for ModuleRegistry {
4741
fn default() -> Self {
4842
Self::new()
@@ -133,54 +127,40 @@ impl ModuleRegistry {
133127
&self,
134128
program_hash: FieldElement,
135129
) -> Result<CasmContractClass, ModuleRegistryError> {
130+
let program_hash_hex = format!("{:#x}", program_hash);
131+
136132
info!(
137-
"Fetching contract class from module registry... program_hash: {:#?}",
138-
program_hash.to_string()
133+
"Fetching contract class from module registry... program_hash: {}",
134+
program_hash_hex
139135
);
140136

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

148-
let response_text = self
142+
let response = self
149143
.client
150144
.get(&api_url)
151145
.header("User-Agent", "request")
152146
.send()
153147
.await
154-
.unwrap()
155-
.text()
156-
.await
157-
.unwrap();
158-
159-
// Try to deserialize the response into GitHubFileResponse
160-
let response: Result<GitHubFileResponse, serde_json::Error> =
161-
serde_json::from_str(&response_text);
162-
let response = match response {
163-
Ok(resp) => resp,
164-
Err(err) => {
165-
eprintln!("Failed to deserialize GitHubFileResponse: {}", err);
166-
return Err(ModuleRegistryError::ClassSourceError("fail".to_string()));
167-
}
168-
};
169-
let download_response = self
170-
.client
171-
.get(&response.download_url)
172-
.send()
173-
.await
174-
.unwrap();
175-
176-
let file_content = download_response.text().await.unwrap();
177-
let casm: CasmContractClass = serde_json::from_str(&file_content)?;
178-
179-
info!(
180-
"Contract class fetched successfully from program_hashh: {:?}",
181-
program_hash
182-
);
183-
Ok(casm)
148+
.expect("response is failed");
149+
150+
// Check if the response status is successful
151+
if response.status().is_success() {
152+
let response_text = response.text().await.expect("cannot get response");
153+
let casm: CasmContractClass = serde_json::from_str(&response_text)?;
154+
info!(
155+
"Contract class fetched successfully from program_hash: {:?}",
156+
program_hash
157+
);
158+
Ok(casm)
159+
} else {
160+
Err(ModuleRegistryError::ClassSourceError(
161+
"Failed to fetch contract class".to_string(),
162+
))
163+
}
184164
}
185165
}
186166

0 commit comments

Comments
 (0)