Skip to content

Commit

Permalink
add voyager interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rjnrohit committed Jul 9, 2024
1 parent e546614 commit a7baf01
Show file tree
Hide file tree
Showing 4 changed files with 1,178 additions and 39 deletions.
98 changes: 59 additions & 39 deletions crates/sncast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,31 @@ fn main() -> Result<()> {

let runtime = Runtime::new().expect("Failed to instantiate Runtime");

if let Commands::Script(script) = &cli.command {
run_script_command(&cli, runtime, script, numbers_format, &output_format)
} else {
let mut config = load_global_config::<CastConfig>(&None, &cli.profile)?;
update_cast_config(&mut config, &cli);
let provider = get_provider(&config.url)?;
runtime.block_on(run_async_command(
cli,
config,
provider,
numbers_format,
output_format,
))
match &cli.command {
Commands::Script(script) => {
run_script_command(&cli, runtime, script, numbers_format, &output_format)
}
Commands::Verify(verify) => {
// run_verify_command(&cli, runtime, verify, numbers_format, &output_format)
runtime.block_on(run_verify_command(
&cli,
verify,
numbers_format,
&output_format,
))
}
_ => {
let mut config = load_global_config::<CastConfig>(&None, &cli.profile)?;
update_cast_config(&mut config, &cli);
let provider = get_provider(&config.url)?;
runtime.block_on(run_async_command(
cli,
config,
provider,
numbers_format,
output_format,
))
}
}
}

Expand Down Expand Up @@ -430,32 +442,7 @@ async fn run_async_command(
print_command_result("tx-status", &mut result, numbers_format, &output_format)?;
Ok(())
}
Commands::Verify(verify) => {
let manifest_path = assert_manifest_path_exists()?;
let package_metadata = get_package_metadata(&manifest_path, &verify.package)?;
let artifacts = build_and_load_artifacts(
&package_metadata,
&BuildConfig {
scarb_toml_path: manifest_path.clone(),
json: cli.json,
profile: cli.profile.unwrap_or("dev".to_string()),
},
)
.expect("Failed to build contract");
let mut result = starknet_commands::verify::verify(
verify.contract_address,
verify.contract_name,
verify.verifier,
verify.network,
verify.confirm_verification,
&package_metadata.manifest_path,
&artifacts,
)
.await;

print_command_result("verify", &mut result, numbers_format, &output_format)?;
Ok(())
}
Commands::Verify(_) => unreachable!(),
Commands::Script(_) => unreachable!(),
}
}
Expand Down Expand Up @@ -536,6 +523,39 @@ fn run_script_command(
Ok(())
}

async fn run_verify_command(
cli: &Cli,
verify: &Verify,
numbers_format: NumbersFormat,
output_format: &OutputFormat,
) -> Result<()> {
let manifest_path = assert_manifest_path_exists()?;
let package_metadata = get_package_metadata(&manifest_path, &verify.package)?;

let artifacts = build_and_load_artifacts(
&package_metadata,
&BuildConfig {
scarb_toml_path: manifest_path.clone(),
json: cli.json,
profile: cli.profile.clone().unwrap_or("dev".to_string()),
},
)
.expect("Failed to build contract");
let mut result = starknet_commands::verify::verify(
verify.contract_address,
verify.contract_name.clone(),
verify.verifier.clone(),
verify.network.clone(),
verify.confirm_verification,
&package_metadata.manifest_path,
&artifacts,
)
.await;

print_command_result("verify", &mut result, numbers_format, &output_format)?;
Ok(())
}

fn update_cast_config(config: &mut CastConfig, cli: &Cli) {
macro_rules! clone_or_else {
($field:expr, $config_field:expr) => {
Expand Down
5 changes: 5 additions & 0 deletions crates/sncast/src/starknet_commands/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,16 @@ impl VerificationInterface for WalnutVerificationInterface {
contract_address: FieldElement,
contract_name: String,
) -> Result<VerifyResponse> {

println!("Verifying contract {contract_name} at address {contract_address}");

// Read all files name along with their contents in a JSON format
// in the workspace dir recursively
// key is the file name and value is the file content
let mut file_data = serde_json::Map::new();

println!("directory: {0}", self.workspace_dir);

// Recursively read files and their contents in workspace directory
for entry in WalkDir::new(self.workspace_dir.clone()).follow_links(true) {
let entry = entry?;
Expand Down
Loading

0 comments on commit a7baf01

Please sign in to comment.