From 6f984aed1dff0f8b97fc6f63ee01516df40745b6 Mon Sep 17 00:00:00 2001 From: glihm Date: Tue, 9 Jul 2024 16:57:50 -0600 Subject: [PATCH 1/3] fix: ensure overlays can support any resource type --- crates/sozo/ops/src/migration/auto_auth.rs | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/sozo/ops/src/migration/auto_auth.rs b/crates/sozo/ops/src/migration/auto_auth.rs index 5e040f8ea5..7f5ce7227c 100644 --- a/crates/sozo/ops/src/migration/auto_auth.rs +++ b/crates/sozo/ops/src/migration/auto_auth.rs @@ -10,7 +10,7 @@ use starknet::accounts::ConnectedAccount; use super::ui::MigrationUi; use super::MigrationOutput; -use crate::auth::{grant_writer, ResourceType, ResourceWriter}; +use crate::auth::{grant_writer, ResourceWriter}; pub async fn auto_authorize( ws: &Workspace<'_>, @@ -27,7 +27,7 @@ where let ui = ws.config().ui(); ui.print(" "); - ui.print_step(6, "🖋️", "Authorizing Models to Systems (based on overlay)..."); + ui.print_step(6, "🖋️", "Authorizing systems based on overlay..."); ui.print(" "); let new_writers = compute_writers(&ui, local_manifest, migration_output)?; grant_writer(&ui, world, new_writers, *txn_config, default_namespace).await @@ -43,24 +43,31 @@ pub fn compute_writers( // From all the contracts that were migrated successfully. for migrated_contract in migration_output.contracts.iter().flatten() { - // Find that contract from local_manifest based on its name. + // Find that contract from local_manifest based on its tag. let contract = local_contracts .iter() .find(|c| migrated_contract.tag == c.inner.tag) .expect("we know this contract exists"); - ui.print_sub(format!( - "Authorizing {} for Models: {:?}", - contract.inner.tag, contract.inner.writes - )); + // TODO: we may add support for `owns`? - // Read all the models that its supposed to write and collect them in a Vec - // so we can call `grant_writer` on all of them. - for model_tag in &contract.inner.writes { - let resource = ResourceType::from_str(format!("model:{model_tag}").as_str())?; - let tag_or_address = format!("{:#x}", migrated_contract.contract_address); + if !contract.inner.writes.is_empty() { + ui.print_sub(format!( + "Authorizing {} for resources: {:?}", + contract.inner.tag, contract.inner.writes + )); + } + + for tag_with_prefix in &contract.inner.writes { + let resource_type = if tag_with_prefix.contains(':') { + tag_with_prefix.to_string() + } else { + // Default to model if no prefix was given. + format!("m:{}", tag_with_prefix) + }; - res.push(ResourceWriter { resource, tag_or_address }); + let resource = format!("{},{}", resource_type, migrated_contract.contract_address); + res.push(ResourceWriter::from_str(&resource)?); } } From 1003244a8a8ffdd2f4a259b28d9ec6c9959aedca Mon Sep 17 00:00:00 2001 From: glihm Date: Tue, 9 Jul 2024 21:17:54 -0600 Subject: [PATCH 2/3] fix: use contract tag instead of decimal string of the address --- crates/sozo/ops/src/migration/auto_auth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sozo/ops/src/migration/auto_auth.rs b/crates/sozo/ops/src/migration/auto_auth.rs index 7f5ce7227c..270da24a49 100644 --- a/crates/sozo/ops/src/migration/auto_auth.rs +++ b/crates/sozo/ops/src/migration/auto_auth.rs @@ -66,7 +66,7 @@ pub fn compute_writers( format!("m:{}", tag_with_prefix) }; - let resource = format!("{},{}", resource_type, migrated_contract.contract_address); + let resource = format!("{},{}", resource_type, migrated_contract.tag); res.push(ResourceWriter::from_str(&resource)?); } } From ba24b53924e2f5005f793d9ee768ecfabe076fc4 Mon Sep 17 00:00:00 2001 From: glihm Date: Wed, 10 Jul 2024 11:02:07 -0600 Subject: [PATCH 3/3] fix: remove todo --- crates/sozo/ops/src/migration/auto_auth.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/sozo/ops/src/migration/auto_auth.rs b/crates/sozo/ops/src/migration/auto_auth.rs index 270da24a49..54eb7af458 100644 --- a/crates/sozo/ops/src/migration/auto_auth.rs +++ b/crates/sozo/ops/src/migration/auto_auth.rs @@ -49,8 +49,6 @@ pub fn compute_writers( .find(|c| migrated_contract.tag == c.inner.tag) .expect("we know this contract exists"); - // TODO: we may add support for `owns`? - if !contract.inner.writes.is_empty() { ui.print_sub(format!( "Authorizing {} for resources: {:?}",