Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/dojo-world/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct DeployOutput {
// base class hash at time of deployment
pub base_class_hash: FieldElement,
pub was_upgraded: bool,
pub name: Option<String>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -215,6 +216,7 @@ pub trait Deployable: Declarable + Sync {
declare,
base_class_hash,
was_upgraded,
name: None,
})
}

Expand Down Expand Up @@ -287,6 +289,7 @@ pub trait Deployable: Declarable + Sync {
declare,
base_class_hash: FieldElement::default(),
was_upgraded: false,
name: None,
})
}

Expand Down
37 changes: 21 additions & 16 deletions crates/sozo/ops/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,27 @@ async fn update_manifests_and_abis(
local_manifest.world.inner.block_number = migration_output.world_block_number;
}

let base_class_hash = *local_manifest.base.inner.class_hash();

debug_assert!(local_manifest.contracts.len() == migration_output.contracts.len());

local_manifest.contracts.iter_mut().zip(migration_output.contracts).for_each(
|(local_manifest, contract_output)| {
let salt = generate_salt(&local_manifest.name);
local_manifest.inner.address = Some(get_contract_address(
migration_output.contracts.iter().for_each(|contract_output| {
// ignore failed migration which are represented by None
if let Some(output) = contract_output {
// find the contract in local manifest and update its address and base class hash
let local = local_manifest
.contracts
.iter_mut()
.find(|c| c.name == output.name.as_ref().unwrap())
.expect("contract got migrated, means it should be present here");

let salt = generate_salt(&local.name);
local.inner.address = Some(get_contract_address(
salt,
base_class_hash,
output.base_class_hash,
&[],
migration_output.world_address,
));

if let Some(output) = contract_output {
local_manifest.inner.base_class_hash = output.base_class_hash;
}
},
);
local.inner.base_class_hash = output.base_class_hash;
}
});

// copy abi files from `abi/base` to `abi/deployments/{chain_id}` and update abi path in
// local_manifest
Expand Down Expand Up @@ -612,7 +614,7 @@ where
)
.await
{
Ok(val) => {
Ok(mut val) => {
if let Some(declare) = val.clone().declare {
ui.print_hidden_sub(format!(
"Declare transaction: {:#x}",
Expand All @@ -622,6 +624,7 @@ where

ui.print_hidden_sub(format!("Deploy transaction: {:#x}", val.transaction_hash));

val.name = Some(contract.diff.name.clone());
Ok(ContractDeploymentOutput::Output(val))
}
Err(MigrationError::ContractAlreadyDeployed(contract_address)) => {
Expand Down Expand Up @@ -787,7 +790,7 @@ where
)
.await
{
Ok(output) => {
Ok(mut output) => {
if let Some(ref declare) = output.declare {
ui.print_hidden_sub(format!(
"Declare transaction: {:#x}",
Expand All @@ -813,7 +816,9 @@ where
));
ui.print_sub(format!("Contract address: {:#x}", output.contract_address));
}
let name = contract.diff.name.clone();

output.name = Some(name);
deploy_output.push(Some(output));
}
Err(MigrationError::ContractAlreadyDeployed(contract_address)) => {
Expand Down