From 6159feda34be304d5691098188eea196caf613ad Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 20 Sep 2024 11:51:52 +0400 Subject: [PATCH 1/2] Multi-class verification via single API request --- crates/sozo/walnut/src/verification.rs | 55 +++++++++----------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/crates/sozo/walnut/src/verification.rs b/crates/sozo/walnut/src/verification.rs index 9c987e9990..b803038cfc 100644 --- a/crates/sozo/walnut/src/verification.rs +++ b/crates/sozo/walnut/src/verification.rs @@ -5,7 +5,6 @@ use std::path::Path; use console::{pad_str, Alignment, Style, StyledObject}; use dojo_world::metadata::get_default_namespace_from_ws; use dojo_world::migration::strategy::MigrationStrategy; -use futures::future::join_all; use reqwest::StatusCode; use scarb::core::Workspace; use serde::Serialize; @@ -61,50 +60,32 @@ pub async fn walnut_verify_migration_strategy( // Collect source code let source_code = collect_source_code(root_dir)?; - // Prepare verification payloads - let mut verification_tasks = Vec::new(); - let mut class_tags = Vec::new(); + let mut class_names = Vec::new(); + let mut class_hashes = Vec::new(); for contract_migration in &migration_strategy.contracts { let class_name = get_class_name_from_artifact_path( &contract_migration.artifact_path, &default_namespace, )?; - let verification_payload = VerificationPayload { - class_name: class_name.clone(), - class_hash: contract_migration.diff.local_class_hash.to_hex_string(), - rpc_url: rpc_url.clone(), - source_code: source_code.clone(), - }; - class_tags.push(contract_migration.diff.tag.clone()); - verification_tasks.push(verify_class(verification_payload, &api_url, &api_key)); + class_names.push(class_name); + class_hashes.push(contract_migration.diff.local_class_hash.to_hex_string()); } for class_migration in &migration_strategy.models { let class_name = get_class_name_from_artifact_path(&class_migration.artifact_path, &default_namespace)?; - let verification_payload = VerificationPayload { - class_name: class_name.clone(), - class_hash: class_migration.diff.local_class_hash.to_hex_string(), - rpc_url: rpc_url.clone(), - source_code: source_code.clone(), - }; - class_tags.push(class_migration.diff.tag.clone()); - verification_tasks.push(verify_class(verification_payload, &api_url, &api_key)); + class_names.push(class_name); + class_hashes.push(class_migration.diff.local_class_hash.to_hex_string()); } - // Run all verification tasks - let results = join_all(verification_tasks).await; + let verification_payload = + VerificationPayload { class_names, class_hashes, rpc_url, source_code }; - for (i, result) in results.into_iter().enumerate() { - match result { - Ok(message) => { - ui.print(subtitle(format!("{}: {}", class_tags[i], message))); - } - Err(e) => { - ui.print(subtitle(format!("{}: {}", class_tags[i], e))); - } - } + // Send verification request + match verify_classes(verification_payload, &api_url, &api_key).await { + Ok(message) => ui.print(subtitle(message)), + Err(e) => ui.print(subtitle(e.to_string())), } Ok(()) @@ -118,18 +99,18 @@ fn get_class_name_from_artifact_path(path: &Path, namespace: &str) -> Result, + /// The hashes of the Sierra classes. + pub class_hashes: Vec, + /// The RPC URL of the network where these classes are declared (can only be a hosted network). pub rpc_url: String, /// JSON that contains a map where the key is the path to the file and the value is the content /// of the file. It should contain all files required to build the Dojo project with Sozo. pub source_code: Value, } -async fn verify_class( +async fn verify_classes( payload: VerificationPayload, api_url: &str, api_key: &str, From a8e1048d7e6f1e0e9f104b42eecd663bf503e849 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 20 Sep 2024 12:02:50 +0400 Subject: [PATCH 2/2] Remove futures dependency --- Cargo.lock | 1 - crates/sozo/walnut/Cargo.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb7394efc4..1dc3eee7f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13107,7 +13107,6 @@ dependencies = [ "anyhow", "console", "dojo-world", - "futures", "reqwest 0.12.5", "scarb", "scarb-ui", diff --git a/crates/sozo/walnut/Cargo.toml b/crates/sozo/walnut/Cargo.toml index 8fb55d68fe..82dfb5325f 100644 --- a/crates/sozo/walnut/Cargo.toml +++ b/crates/sozo/walnut/Cargo.toml @@ -9,7 +9,6 @@ version.workspace = true anyhow.workspace = true console.workspace = true dojo-world = { workspace = true, features = [ "contracts", "metadata", "migration" ] } -futures.workspace = true reqwest.workspace = true scarb.workspace = true scarb-ui.workspace = true