Skip to content

Commit

Permalink
display contract addresses in sozo migrate plan (#1926)
Browse files Browse the repository at this point in the history
* draft

* world_addres and contract_address print

* fix

* s

* fix

* world_addres and contract_address print

* fix

* fix

* formatting

* fix implementation and clean up

* revert cargo.lock changes

* clippy lints

* fix CI

* restore unnecessary changes

---------

Co-authored-by: Steven <[email protected]>
Co-authored-by: lambda-0x <[email protected]>
  • Loading branch information
3 people authored May 19, 2024
1 parent 7943970 commit 60e7ded
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
48 changes: 33 additions & 15 deletions crates/sozo/ops/src/migration/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,54 +681,72 @@ where
.await
{
Ok(current_class_hash) if current_class_hash != contract.diff.local_class_hash => {
return format!("upgrade {}", contract.diff.name);
return format!("{}: Upgrade", contract.diff.name);
}
Err(ProviderError::StarknetError(StarknetError::ContractNotFound)) => {
return format!("deploy {}", contract.diff.name);
return format!("{}: Deploy", contract.diff.name);
}
Ok(_) => return "already deployed".to_string(),
Err(_) => return format!("deploy {}", contract.diff.name),
Ok(_) => return "Already Deployed".to_string(),
Err(_) => return format!("{}: Deploy", contract.diff.name),
}
}
}
format!("deploy {}", contract.diff.name)
}

pub async fn print_strategy<P>(ui: &Ui, provider: &P, strategy: &MigrationStrategy)
where
pub async fn print_strategy<P>(
ui: &Ui,
provider: &P,
strategy: &MigrationStrategy,
world_address: FieldElement,
) where
P: Provider + Sync + Send + 'static,
{
ui.print("\n📋 Migration Strategy\n");

ui.print_header(format!("World address: {:#x}", world_address));

ui.print(" ");

if let Some(base) = &strategy.base {
ui.print_header("# Base Contract");
ui.print_sub(format!("declare (class hash: {:#x})\n", base.diff.local_class_hash));
ui.print_sub(format!("Class hash: {:#x}", base.diff.local_class_hash));
}

ui.print(" ");

if let Some(world) = &strategy.world {
ui.print_header("# World");
ui.print_sub(format!("declare (class hash: {:#x})\n", world.diff.local_class_hash));
ui.print_sub(format!("Class hash: {:#x}", world.diff.local_class_hash));
}

ui.print(" ");

if !&strategy.models.is_empty() {
ui.print_header(format!("# Models ({})", &strategy.models.len()));
for m in &strategy.models {
ui.print_sub(format!(
"register {} (class hash: {:#x})",
m.diff.name, m.diff.local_class_hash
));
ui.print(m.diff.name.to_string());
ui.print_sub(format!("Class hash: {:#x}", m.diff.local_class_hash));
}
ui.print(" ");
}

ui.print(" ");

if !&strategy.contracts.is_empty() {
ui.print_header(format!("# Contracts ({})", &strategy.contracts.len()));
for c in &strategy.contracts {
let op_name = get_contract_operation_name(provider, c, strategy.world_address).await;
ui.print_sub(format!("{op_name} (class hash: {:#x})", c.diff.local_class_hash));

ui.print(op_name);
ui.print_sub(format!("Class hash: {:#x}", c.diff.local_class_hash));
let salt = generate_salt(&c.diff.name);
let contract_address =
get_contract_address(salt, c.diff.base_class_hash, &[], world_address);
ui.print_sub(format!("Contract address: {:#x}", contract_address));
}
ui.print(" ");
}

ui.print(" ");
}

#[allow(clippy::too_many_arguments)]
Expand Down
2 changes: 1 addition & 1 deletion crates/sozo/ops/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where
let world_address = strategy.world_address().expect("world address must exist");

if dry_run {
print_strategy(&ui, account.provider(), &strategy).await;
print_strategy(&ui, account.provider(), &strategy, world_address).await;

update_manifests_and_abis(
ws,
Expand Down

0 comments on commit 60e7ded

Please sign in to comment.