From 087715cb203ed7946f32d2a1f40039989e7ccef6 Mon Sep 17 00:00:00 2001 From: glihm Date: Mon, 14 Oct 2024 10:19:13 -0600 Subject: [PATCH] fix: remove unused files --- crates/compiler/src/compiler/manifest.rs | 235 ------------------ .../src/contract/base_contract.cairo | 39 --- crates/contracts/src/world/config.cairo | 133 ---------- crates/contracts/src/world/update.cairo | 33 --- 4 files changed, 440 deletions(-) delete mode 100644 crates/compiler/src/compiler/manifest.rs delete mode 100644 crates/contracts/src/contract/base_contract.cairo delete mode 100644 crates/contracts/src/world/config.cairo delete mode 100644 crates/contracts/src/world/update.cairo diff --git a/crates/compiler/src/compiler/manifest.rs b/crates/compiler/src/compiler/manifest.rs deleted file mode 100644 index c0a3370..0000000 --- a/crates/compiler/src/compiler/manifest.rs +++ /dev/null @@ -1,235 +0,0 @@ -//! Manifests generated by the compiler. -//! -//! The manifests files contains metadata about -//! the contracts being compiled, since in Dojo -//! every resource is represented as a starknet contract. - -use std::io::{Read, Write}; - -use anyhow::Result; -use dojo_types::naming; -use scarb::core::Workspace; -use serde::{Deserialize, Serialize}; -use serde_with::serde_as; -use starknet::core::serde::unsigned_field_element::UfeHex; -use starknet::core::types::Felt; - -use crate::scarb_extensions::{FilesystemExt, WorkspaceExt}; -use crate::{ - BASE_CONTRACT_TAG, CAIRO_PATH_SEPARATOR, CONTRACTS_DIR, MODELS_DIR, WORLD_CONTRACT_TAG, -}; - -const TOML_EXTENSION: &str = "toml"; - -/// Represents a member of a struct. -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub struct Member { - // Name of the member. - pub name: String, - // Type of the member. - #[serde(rename = "type")] - pub ty: String, - // Whether the member is a key. - pub key: bool, -} - -/// Represents the contract of a dojo contract. -#[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize)] -#[cfg_attr(test, derive(PartialEq))] -#[serde(tag = "kind", rename = "DojoContract")] -pub struct ContractManifest { - #[serde_as(as = "UfeHex")] - pub class_hash: Felt, - pub qualified_path: String, - pub tag: String, - pub systems: Vec, -} - -/// Represents the contract of a dojo model. -#[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize)] -#[cfg_attr(test, derive(PartialEq))] -#[serde(tag = "kind", rename = "DojoModel")] -pub struct ModelManifest { - #[serde_as(as = "UfeHex")] - pub class_hash: Felt, - pub qualified_path: String, - pub tag: String, - pub members: Vec, -} - -/// Represents a starknet contract. -#[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize)] -#[cfg_attr(test, derive(PartialEq))] -#[serde(tag = "kind", rename = "StarknetContract")] -pub struct StarknetContractManifest { - #[serde_as(as = "UfeHex")] - pub class_hash: Felt, - pub qualified_path: String, - pub name: String, -} - -/// An abstract representation of the manifest files combined. -/// -/// An [`AbstractBaseManifest`] internalizes the workspace reference -/// to automatically provide the paths to the manifest files based on the -/// workspace configuration. -#[derive(Clone, Debug)] -pub struct AbstractBaseManifest<'w> { - workspace: &'w Workspace<'w>, - pub world: StarknetContractManifest, - pub base: StarknetContractManifest, - pub contracts: Vec, - pub models: Vec, - pub sn_contracts: Vec, -} - -impl<'w> AbstractBaseManifest<'w> { - /// Creates a new abstract base manifest. - pub fn new(workspace: &'w Workspace) -> Self { - Self { - workspace, - world: StarknetContractManifest::default(), - base: StarknetContractManifest::default(), - contracts: vec![], - models: vec![], - sn_contracts: vec![], - } - } - - pub fn read(&mut self) -> Result<()> { - let base_dir = self.workspace.dojo_base_manfiests_dir_profile(); - - let contracts_dir = base_dir.child(CONTRACTS_DIR); - for file_name in contracts_dir.list_files()? { - let mut file = contracts_dir.open_ro( - &file_name, - &format!("contract manifest for `{}`", &file_name), - self.workspace.config(), - )?; - let mut contract_str = String::new(); - file.read_to_string(&mut contract_str)?; - self.contracts.push(toml::from_str(&contract_str)?); - } - - let models_dir = base_dir.child(MODELS_DIR); - for file_name in models_dir.list_files()? { - let mut file = models_dir.open_ro( - &file_name, - &format!("model manifest for `{}`", &file_name), - self.workspace.config(), - )?; - let mut model_str = String::new(); - file.read_to_string(&mut model_str)?; - self.models.push(toml::from_str(&model_str)?); - } - - for file_name in base_dir.list_files()? { - let mut file = base_dir.open_ro( - &file_name, - &format!("starknet contract manifest for `{}`", &file_name), - self.workspace.config(), - )?; - let mut sn_contract_str = String::new(); - file.read_to_string(&mut sn_contract_str)?; - - if file_name == format!("{}.toml", naming::get_filename_from_tag(WORLD_CONTRACT_TAG)) { - self.world = toml::from_str(&sn_contract_str)?; - } else if file_name - == format!("{}.toml", naming::get_filename_from_tag(BASE_CONTRACT_TAG)) - { - self.base = toml::from_str(&sn_contract_str)?; - } else { - self.sn_contracts.push(toml::from_str(&sn_contract_str)?); - } - } - - Ok(()) - } - - /// Writes the manifest to the given path. - /// - /// # Arguments - /// - /// * `path` - The path to write the manifest files to. - pub fn write(&self) -> Result<()> { - let base_dir = self.workspace.dojo_base_manfiests_dir_profile(); - - let world = toml::to_string(&self.world)?; - - let mut file = base_dir.create_rw( - format!("{}.toml", naming::get_filename_from_tag(WORLD_CONTRACT_TAG)), - &format!("world manifest"), - self.workspace.config(), - )?; - - file.write(world.as_bytes())?; - - let base = toml::to_string(&self.base)?; - - let mut file = base_dir.create_rw( - format!("{}.toml", naming::get_filename_from_tag(BASE_CONTRACT_TAG)), - &format!("base manifest"), - self.workspace.config(), - )?; - - file.write(base.as_bytes())?; - - let contracts_dir = base_dir.child(CONTRACTS_DIR); - let models_dir = base_dir.child(MODELS_DIR); - - for contract in &self.contracts { - let name = format!( - "{}.{}", - naming::get_filename_from_tag(&contract.tag), - TOML_EXTENSION - ); - - let mut file = contracts_dir.create_rw( - name, - &format!("contract manifest for `{}`", contract.qualified_path), - self.workspace.config(), - )?; - - file.write(toml::to_string(contract)?.as_bytes())?; - } - - for model in &self.models { - let name = format!( - "{}.{}", - naming::get_filename_from_tag(&model.tag), - TOML_EXTENSION - ); - - let mut file = models_dir.create_rw( - name, - &format!("model manifest for `{}`", model.qualified_path), - self.workspace.config(), - )?; - - file.write(toml::to_string(model)?.as_bytes())?; - } - - for sn_contract in &self.sn_contracts { - let name = format!( - "{}.{}", - sn_contract - .qualified_path - .replace(CAIRO_PATH_SEPARATOR, "_"), - TOML_EXTENSION - ); - - let mut file = base_dir.create_rw( - name, - &format!("starknet contract manifest for `{}`", sn_contract.name), - self.workspace.config(), - )?; - - file.write(toml::to_string(sn_contract)?.as_bytes())?; - } - - Ok(()) - } -} diff --git a/crates/contracts/src/contract/base_contract.cairo b/crates/contracts/src/contract/base_contract.cairo deleted file mode 100644 index ef478ab..0000000 --- a/crates/contracts/src/contract/base_contract.cairo +++ /dev/null @@ -1,39 +0,0 @@ -#[starknet::contract] -pub mod base { - use starknet::get_caller_address; - use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; - - use dojo::contract::upgradeable::upgradeable as upgradeable_component; - use dojo::world::{IWorldProvider, IWorldDispatcher}; - - component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent); - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - #[flat] - UpgradeableEvent: upgradeable_component::Event - } - - #[storage] - struct Storage { - world_dispatcher: IWorldDispatcher, - #[substorage(v0)] - upgradeable: upgradeable_component::Storage, - } - - #[constructor] - fn constructor(ref self: ContractState) { - self.world_dispatcher.write(IWorldDispatcher { contract_address: get_caller_address() }); - } - - #[abi(embed_v0)] - impl WorldProviderImpl of IWorldProvider { - fn world(self: @ContractState) -> IWorldDispatcher { - self.world_dispatcher.read() - } - } - - #[abi(embed_v0)] - impl UpgradableImpl = upgradeable_component::UpgradableImpl; -} diff --git a/crates/contracts/src/world/config.cairo b/crates/contracts/src/world/config.cairo deleted file mode 100644 index 88115eb..0000000 --- a/crates/contracts/src/world/config.cairo +++ /dev/null @@ -1,133 +0,0 @@ -use starknet::ContractAddress; - -pub mod errors { - pub const INVALID_CALLER: felt252 = 'Config: not owner or operator'; - pub const ALREADY_REGISTERED: felt252 = 'Config: already operator'; - pub const NOT_OPERATOR: felt252 = 'Config: not operator'; -} - -#[starknet::interface] -pub trait IConfig { - /// Sets the information of the program that generates the - /// state transition trace (namely DojoOS). - /// - /// # Arguments - /// - /// * `program_hash` - The program hash. - fn set_differ_program_hash(ref self: T, program_hash: felt252); - fn set_merger_program_hash(ref self: T, program_hash: felt252); - - /// Gets the information of the program that generates the - /// state transition trace (namely DojoOS). - /// - /// # Returns - /// - /// The program hash and its configuration hash. - fn get_differ_program_hash(self: @T) -> felt252; - fn get_merger_program_hash(self: @T) -> felt252; - - /// Sets the facts registry contract address, which is already - /// initialized with the verifier information. - /// - /// # Arguments - /// - /// * `address` - The facts registry contract's address. - fn set_facts_registry(ref self: T, address: ContractAddress); - - /// Gets the facts registry contract address. - /// - /// # Returns - /// - /// The contract address of the facts registry. - fn get_facts_registry(self: @T) -> ContractAddress; -} - -#[starknet::component] -pub mod Config { - use starknet::ContractAddress; - use starknet::get_caller_address; - use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; - - use super::errors; - use super::IConfig; - - #[event] - #[derive(Drop, starknet::Event, Debug, PartialEq)] - pub enum Event { - DifferProgramHashUpdate: DifferProgramHashUpdate, - MergerProgramHashUpdate: MergerProgramHashUpdate, - FactsRegistryUpdate: FactsRegistryUpdate - } - - #[derive(Drop, starknet::Event, Debug, PartialEq)] - pub struct DifferProgramHashUpdate { - pub program_hash: felt252, - } - - #[derive(Drop, starknet::Event, Debug, PartialEq)] - pub struct MergerProgramHashUpdate { - pub program_hash: felt252, - } - - #[derive(Drop, starknet::Event, Debug, PartialEq)] - pub struct FactsRegistryUpdate { - pub address: ContractAddress - } - - #[storage] - pub struct Storage { - differ_program_hash: felt252, - merger_program_hash: felt252, - facts_registry: ContractAddress, - owner: ContractAddress - } - - #[generate_trait] - pub impl InternalImpl< - TContractState, +HasComponent - > of InternalTrait { - fn initializer(ref self: ComponentState, owner: ContractAddress) { - self.owner.write(owner); - } - } - - #[embeddable_as(ConfigImpl)] - impl Config< - TContractState, +HasComponent - > of IConfig> { - fn set_differ_program_hash( - ref self: ComponentState, program_hash: felt252 - ) { - assert(get_caller_address() == self.owner.read(), errors::INVALID_CALLER); - self.differ_program_hash.write(program_hash); - self.emit(DifferProgramHashUpdate { program_hash }); - } - - fn set_merger_program_hash( - ref self: ComponentState, program_hash: felt252 - ) { - assert(get_caller_address() == self.owner.read(), errors::INVALID_CALLER); - self.merger_program_hash.write(program_hash); - self.emit(MergerProgramHashUpdate { program_hash }); - } - - fn get_differ_program_hash(self: @ComponentState) -> felt252 { - self.differ_program_hash.read() - } - - fn get_merger_program_hash(self: @ComponentState) -> felt252 { - self.merger_program_hash.read() - } - - fn set_facts_registry(ref self: ComponentState, address: ContractAddress) { - assert(get_caller_address() == self.owner.read(), errors::INVALID_CALLER); - self.facts_registry.write(address); - self.emit(FactsRegistryUpdate { address: address }); - } - - fn get_facts_registry(self: @ComponentState) -> ContractAddress { - self.facts_registry.read() - } - } -} - diff --git a/crates/contracts/src/world/update.cairo b/crates/contracts/src/world/update.cairo deleted file mode 100644 index a156a08..0000000 --- a/crates/contracts/src/world/update.cairo +++ /dev/null @@ -1,33 +0,0 @@ -#[derive(Drop, Serde)] -pub struct StorageUpdate { - pub key: felt252, - pub value: felt252, -} - -#[derive(Drop, Serde)] -pub struct ProgramOutput { - pub prev_state_root: felt252, - pub new_state_root: felt252, - pub block_number: felt252, - pub block_hash: felt252, - pub config_hash: felt252, - pub world_da_hash: felt252, - pub message_to_starknet_segment: Span, - pub message_to_appchain_segment: Span, -} - -#[starknet::interface] -pub trait IUpgradeableState { - fn upgrade_state( - ref self: TContractState, - new_state: Span, - program_output: ProgramOutput, - program_hash: felt252 - ); -} - -#[starknet::interface] -pub trait IFactRegistry { - fn is_valid(self: @TContractState, fact: felt252) -> bool; -} -