diff --git a/Scarb.lock b/Scarb.lock index 3c24d97..ebf1bde 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -10,7 +10,7 @@ dependencies = [ ] [[package]] -name = "arcade_slot" +name = "arcade_trophy" version = "0.0.0" dependencies = [ "dojo", @@ -18,7 +18,7 @@ dependencies = [ ] [[package]] -name = "arcade_trophy" +name = "controller" version = "0.0.0" dependencies = [ "dojo", @@ -45,3 +45,11 @@ dependencies = [ name = "dojo_plugin" version = "2.8.4" source = "git+https://github.com/dojoengine/dojo?tag=v1.0.1#d7335e6f5c76a1dda887ec00c594c2c019b4a05f" + +[[package]] +name = "provider" +version = "0.0.0" +dependencies = [ + "dojo", + "dojo_cairo_test", +] diff --git a/Scarb.toml b/Scarb.toml index 54a029f..808b9a2 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,5 +1,10 @@ [workspace] -members = ["packages/trophy", "packages/registry", "packages/slot"] +members = [ + "packages/trophy", + "packages/registry", + "packages/provider", + "packages/controller", +] description = "Dojo achievement library" homepage = "https://github.com/cartridge-gg/arcade/" cairo-version = "2.8.4" diff --git a/packages/slot/README.md b/packages/controller/README.md similarity index 100% rename from packages/slot/README.md rename to packages/controller/README.md diff --git a/packages/slot/Scarb.toml b/packages/controller/Scarb.toml similarity index 85% rename from packages/slot/Scarb.toml rename to packages/controller/Scarb.toml index a1b34c0..2823fb9 100644 --- a/packages/slot/Scarb.toml +++ b/packages/controller/Scarb.toml @@ -1,5 +1,5 @@ [package] -name = "arcade_slot" +name = "controller" version.workspace = true [dependencies] diff --git a/packages/controller/src/components/controllable.cairo b/packages/controller/src/components/controllable.cairo new file mode 100644 index 0000000..5854165 --- /dev/null +++ b/packages/controller/src/components/controllable.cairo @@ -0,0 +1,31 @@ +#[starknet::component] +mod ControllableComponent { + // Dojo imports + + use dojo::world::WorldStorage; + + // Internal imports + + use controller::store::{Store, StoreTrait}; + use controller::models::account::{Account, AccountTrait, AccountAssert}; + use controller::models::controller::{Controller, ControllerTrait, ControllerAssert}; + use controller::models::member::{Member, MemberTrait, MemberAssert}; + use controller::models::signer::{Signer, SignerTrait, SignerAssert}; + use controller::models::team::{Team, TeamTrait, TeamAssert}; + + // Storage + + #[storage] + struct Storage {} + + // Events + + #[event] + #[derive(Drop, starknet::Event)] + enum Event {} + + #[generate_trait] + impl InternalImpl< + TContractState, +HasComponent + > of InternalTrait {} +} diff --git a/packages/slot/src/constants.cairo b/packages/controller/src/constants.cairo similarity index 100% rename from packages/slot/src/constants.cairo rename to packages/controller/src/constants.cairo diff --git a/packages/slot/src/lib.cairo b/packages/controller/src/lib.cairo similarity index 53% rename from packages/slot/src/lib.cairo rename to packages/controller/src/lib.cairo index 84e65dc..c62d605 100644 --- a/packages/slot/src/lib.cairo +++ b/packages/controller/src/lib.cairo @@ -1,28 +1,20 @@ mod constants; mod store; -mod helpers { - mod json; -} - mod types { mod method; mod role; - mod tier; - mod socials; - mod service; - mod status; - mod metadata; } mod models { mod index; mod account; - mod team; - mod member; mod controller; + mod member; mod signer; - mod deployment; - mod service; - mod game; + mod team; +} + +mod components { + mod controllable; } diff --git a/packages/slot/src/models/account.cairo b/packages/controller/src/models/account.cairo similarity index 90% rename from packages/slot/src/models/account.cairo rename to packages/controller/src/models/account.cairo index ce3ed6b..0eac43e 100644 --- a/packages/slot/src/models/account.cairo +++ b/packages/controller/src/models/account.cairo @@ -1,6 +1,6 @@ // Intenral imports -use arcade_slot::models::index::Account; +use controller::models::index::Account; // Errors @@ -35,13 +35,13 @@ impl AccountImpl of AccountTrait { #[generate_trait] impl AccountAssert of AssertTrait { #[inline] - fn assert_does_not_exist(self: Account) { - assert(self.name == 0, errors::ACCOUNT_ALREADY_EXISTS); + fn assert_does_not_exist(self: @Account) { + assert(self.name == @0, errors::ACCOUNT_ALREADY_EXISTS); } #[inline] - fn assert_does_exist(self: Account) { - assert(self.name != 0, errors::ACCOUNT_NOT_EXIST); + fn assert_does_exist(self: @Account) { + assert(self.name != @0, errors::ACCOUNT_NOT_EXIST); } #[inline] diff --git a/packages/slot/src/models/controller.cairo b/packages/controller/src/models/controller.cairo similarity index 94% rename from packages/slot/src/models/controller.cairo rename to packages/controller/src/models/controller.cairo index 7a8a611..cf43b40 100644 --- a/packages/slot/src/models/controller.cairo +++ b/packages/controller/src/models/controller.cairo @@ -1,6 +1,6 @@ // Intenral imports -use arcade_slot::models::index::Controller; +use controller::models::index::Controller; // Errors @@ -46,13 +46,13 @@ impl ControllerImpl of ControllerTrait { #[generate_trait] impl ControllerAssert of AssertTrait { #[inline] - fn assert_does_not_exist(self: Controller) { - assert(self.account_id == 0, errors::CONTROLLER_ALREADY_EXISTS); + fn assert_does_not_exist(self: @Controller) { + assert(self.account_id == @0, errors::CONTROLLER_ALREADY_EXISTS); } #[inline] - fn assert_does_exist(self: Controller) { - assert(self.account_id != 0, errors::CONTROLLER_NOT_EXIST); + fn assert_does_exist(self: @Controller) { + assert(self.account_id != @0, errors::CONTROLLER_NOT_EXIST); } #[inline] diff --git a/packages/slot/src/models/index.cairo b/packages/controller/src/models/index.cairo similarity index 58% rename from packages/slot/src/models/index.cairo rename to packages/controller/src/models/index.cairo index bb37bca..19673c0 100644 --- a/packages/slot/src/models/index.cairo +++ b/packages/controller/src/models/index.cairo @@ -14,11 +14,15 @@ pub struct Account { #[derive(Clone, Drop, Serde)] #[dojo::model] -pub struct Team { +pub struct Controller { + #[key] + account_id: felt252, #[key] id: felt252, - name: felt252, - description: ByteArray, + signers: u32, + address: felt252, + network: felt252, + constructor_calldata: ByteArray, } #[derive(Copy, Drop, Serde)] @@ -31,19 +35,6 @@ pub struct Member { role: u8, } -#[derive(Clone, Drop, Serde)] -#[dojo::model] -pub struct Controller { - #[key] - account_id: felt252, - #[key] - id: felt252, - signers: u32, - address: felt252, - network: felt252, - constructor_calldata: ByteArray, -} - #[derive(Clone, Drop, Serde)] #[dojo::model] pub struct Signer { @@ -51,45 +42,15 @@ pub struct Signer { account_id: felt252, #[key] controller_id: felt252, - #[key] - id: felt252, method: u8, metadata: ByteArray, } #[derive(Clone, Drop, Serde)] #[dojo::model] -pub struct Deployment { - #[key] - id: felt252, - #[key] - project: felt252, - status: u8, - branch: Option, - service: u8, - tier: u8, - regions: felt252, - auto_upgrade: bool, - config: ByteArray, -} - -#[derive(Copy, Drop, Serde)] -#[dojo::model] -pub struct Service { - #[key] - id: felt252, - version: felt252, - default_version: felt252, -} - -#[derive(Clone, Drop, Serde)] -#[dojo::model] -pub struct Game { +pub struct Team { #[key] id: felt252, name: felt252, - priority: u8, - socials: ByteArray, - metadata: ByteArray, - active: bool, + description: ByteArray, } diff --git a/packages/slot/src/models/member.cairo b/packages/controller/src/models/member.cairo similarity index 88% rename from packages/slot/src/models/member.cairo rename to packages/controller/src/models/member.cairo index f8844c2..77c3010 100644 --- a/packages/slot/src/models/member.cairo +++ b/packages/controller/src/models/member.cairo @@ -1,7 +1,8 @@ // Intenral imports -use arcade_slot::models::index::Member; -use arcade_slot::types::role::Role; +use controller::models::index::Member; +use controller::types::role::Role; + // Errors pub mod errors { @@ -28,13 +29,13 @@ impl MemberImpl of MemberTrait { #[generate_trait] impl MemberAssert of AssertTrait { #[inline] - fn assert_does_not_exist(self: Member) { - assert(self.role == Role::None.into(), errors::MEMBER_ALREADY_EXISTS); + fn assert_does_not_exist(self: @Member) { + assert(self.role == @Role::None.into(), errors::MEMBER_ALREADY_EXISTS); } #[inline] - fn assert_does_exist(self: Member) { - assert(self.role != Role::None.into(), errors::MEMBER_NOT_EXIST); + fn assert_does_exist(self: @Member) { + assert(self.role != @Role::None.into(), errors::MEMBER_NOT_EXIST); } #[inline] diff --git a/packages/slot/src/models/signer.cairo b/packages/controller/src/models/signer.cairo similarity index 71% rename from packages/slot/src/models/signer.cairo rename to packages/controller/src/models/signer.cairo index 3a3128f..bb76e27 100644 --- a/packages/slot/src/models/signer.cairo +++ b/packages/controller/src/models/signer.cairo @@ -1,7 +1,7 @@ // Intenral imports -use arcade_slot::models::index::Signer; -use arcade_slot::types::method::Method; +use controller::models::index::Signer; +use controller::types::method::Method; // Errors @@ -19,23 +19,17 @@ pub mod errors { impl SignerImpl of SignerTrait { #[inline] fn new( - account_id: felt252, - controller_id: felt252, - id: felt252, - method: Method, - metadata: ByteArray, + account_id: felt252, controller_id: felt252, method: Method, metadata: ByteArray, ) -> Signer { // [Check] Inputs SignerAssert::assert_valid_account_id(account_id); SignerAssert::assert_valid_controller_id(controller_id); - SignerAssert::assert_valid_identifier(id); SignerAssert::assert_valid_method(method); // [Return] Signer Signer { account_id: account_id, controller_id: controller_id, - id: id, method: method.into(), metadata: metadata, } @@ -45,18 +39,13 @@ impl SignerImpl of SignerTrait { #[generate_trait] impl SignerAssert of AssertTrait { #[inline] - fn assert_does_not_exist(self: Signer) { - assert(self.account_id == 0, errors::SIGNER_ALREADY_EXISTS); + fn assert_does_not_exist(self: @Signer) { + assert(self.account_id == @0, errors::SIGNER_ALREADY_EXISTS); } #[inline] - fn assert_does_exist(self: Signer) { - assert(self.account_id != 0, errors::SIGNER_NOT_EXIST); - } - - #[inline] - fn assert_valid_identifier(id: felt252) { - assert(id != 0, errors::SIGNER_INVALID_IDENTIFIER); + fn assert_does_exist(self: @Signer) { + assert(self.account_id != @0, errors::SIGNER_NOT_EXIST); } #[inline] @@ -83,15 +72,13 @@ mod tests { // Constants - const IDENTIFIER: felt252 = 'IDENTIFIER'; const ACCOUNT_ID: felt252 = 'ACCOUNT_ID'; const CONTROLLER_ID: felt252 = 'CONTROLLER_ID'; const METHOD: Method = Method::StarknetAccount; #[test] fn test_deployment_new() { - let signer = SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, IDENTIFIER, METHOD, ""); - assert_eq!(signer.id, IDENTIFIER); + let signer = SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, METHOD, ""); assert_eq!(signer.account_id, ACCOUNT_ID); assert_eq!(signer.controller_id, CONTROLLER_ID); assert_eq!(signer.method, METHOD.into()); @@ -100,38 +87,32 @@ mod tests { #[test] fn test_deployment_assert_does_exist() { - let signer = SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, IDENTIFIER, METHOD, ""); + let signer = SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, METHOD, ""); signer.assert_does_exist(); } #[test] #[should_panic(expected: 'Signer: already exists')] fn test_deployment_revert_already_exists() { - let signer = SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, IDENTIFIER, METHOD, ""); + let signer = SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, METHOD, ""); signer.assert_does_not_exist(); } #[test] #[should_panic(expected: 'Signer: invalid account id')] fn test_deployment_revert_invalid_account_id() { - SignerTrait::new(0, CONTROLLER_ID, IDENTIFIER, METHOD, ""); + SignerTrait::new(0, CONTROLLER_ID, METHOD, ""); } #[test] #[should_panic(expected: 'Signer: invalid controller id')] fn test_deployment_revert_invalid_controller_id() { - SignerTrait::new(ACCOUNT_ID, 0, IDENTIFIER, METHOD, ""); - } - - #[test] - #[should_panic(expected: 'Signer: invalid identifier')] - fn test_deployment_revert_invalid_identifier() { - SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, 0, METHOD, ""); + SignerTrait::new(ACCOUNT_ID, 0, METHOD, ""); } #[test] #[should_panic(expected: 'Signer: invalid method')] fn test_deployment_revert_invalid_method() { - SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, IDENTIFIER, Method::None, ""); + SignerTrait::new(ACCOUNT_ID, CONTROLLER_ID, Method::None, ""); } } diff --git a/packages/slot/src/models/team.cairo b/packages/controller/src/models/team.cairo similarity index 88% rename from packages/slot/src/models/team.cairo rename to packages/controller/src/models/team.cairo index 0082070..68586ef 100644 --- a/packages/slot/src/models/team.cairo +++ b/packages/controller/src/models/team.cairo @@ -1,6 +1,6 @@ // Intenral imports -use arcade_slot::models::index::Team; +use controller::models::index::Team; // Errors @@ -26,13 +26,13 @@ impl TeamImpl of TeamTrait { #[generate_trait] impl TeamAssert of AssertTrait { #[inline] - fn assert_does_not_exist(self: Team) { - assert(self.name == 0, errors::TEAM_ALREADY_EXISTS); + fn assert_does_not_exist(self: @Team) { + assert(self.name == @0, errors::TEAM_ALREADY_EXISTS); } #[inline] - fn assert_does_exist(self: Team) { - assert(self.name != 0, errors::TEAM_NOT_EXIST); + fn assert_does_exist(self: @Team) { + assert(self.name != @0, errors::TEAM_NOT_EXIST); } #[inline] diff --git a/packages/controller/src/store.cairo b/packages/controller/src/store.cairo new file mode 100644 index 0000000..96473e7 --- /dev/null +++ b/packages/controller/src/store.cairo @@ -0,0 +1,81 @@ +//! Store struct and component management methods. + +// Starknet imports + +use starknet::SyscallResultTrait; + +// Dojo imports + +use dojo::world::WorldStorage; +use dojo::model::ModelStorage; + +// Models imports + +use controller::models::account::Account; +use controller::models::controller::Controller; +use controller::models::member::Member; +use controller::models::signer::Signer; +use controller::models::team::Team; + + +// Structs + +#[derive(Copy, Drop)] +struct Store { + world: WorldStorage, +} + +// Implementations + +#[generate_trait] +impl StoreImpl of StoreTrait { + #[inline] + fn new(world: WorldStorage) -> Store { + Store { world: world } + } + + #[inline] + fn get_account(self: Store, account_id: felt252) -> Account { + self.world.read_model(account_id) + } + + #[inline] + fn get_controller(self: Store, controller_id: felt252) -> Controller { + self.world.read_model(controller_id) + } + + #[inline] + fn get_member(self: Store, account_id: felt252, team_id: felt252) -> Member { + self.world.read_model((account_id, team_id)) + } + + #[inline] + fn get_signer(self: Store, signer_id: felt252) -> Signer { + self.world.read_model(signer_id) + } + + #[inline] + fn get_team(self: Store, team_id: felt252) -> Team { + self.world.read_model(team_id) + } + + #[inline] + fn set_account(ref self: Store, account: @Account) { + self.world.write_model(account); + } + + #[inline] + fn set_controller(ref self: Store, controller: @Controller) { + self.world.write_model(controller); + } + + #[inline] + fn set_member(ref self: Store, member: @Member) { + self.world.write_model(member); + } + + #[inline] + fn set_team(ref self: Store, team: @Team) { + self.world.write_model(team); + } +} diff --git a/packages/slot/src/types/method.cairo b/packages/controller/src/types/method.cairo similarity index 100% rename from packages/slot/src/types/method.cairo rename to packages/controller/src/types/method.cairo diff --git a/packages/slot/src/types/role.cairo b/packages/controller/src/types/role.cairo similarity index 100% rename from packages/slot/src/types/role.cairo rename to packages/controller/src/types/role.cairo diff --git a/packages/provider/README.md b/packages/provider/README.md new file mode 100644 index 0000000..e69de29 diff --git a/packages/provider/Scarb.toml b/packages/provider/Scarb.toml new file mode 100644 index 0000000..41a1d64 --- /dev/null +++ b/packages/provider/Scarb.toml @@ -0,0 +1,9 @@ +[package] +name = "provider" +version.workspace = true + +[dependencies] +dojo.workspace = true + +[dev-dependencies] +dojo_cairo_test.workspace = true diff --git a/packages/provider/src/components/deployable.cairo b/packages/provider/src/components/deployable.cairo new file mode 100644 index 0000000..1c1f8fb --- /dev/null +++ b/packages/provider/src/components/deployable.cairo @@ -0,0 +1,99 @@ +#[starknet::component] +mod DeployableComponent { + // Dojo imports + + use dojo::world::WorldStorage; + + // Internal imports + + use provider::store::{Store, StoreTrait}; + use provider::models::deployment::{Deployment, DeploymentTrait, DeploymentAssert}; + use provider::models::factory::{Factory, FactoryTrait, FactoryAssert}; + use provider::types::service::{Service, ServiceTrait, SERVICE_COUNT}; + use provider::types::metadata::{Metadata, MetadataTrait}; + use provider::types::socials::{Socials, SocialsTrait}; + use provider::types::status::Status; + use provider::types::tier::Tier; + use provider::helpers::json::JsonifiableTrait; + + // Storage + + #[storage] + struct Storage {} + + // Events + + #[event] + #[derive(Drop, starknet::Event)] + enum Event {} + + #[generate_trait] + impl InternalImpl< + TContractState, +HasComponent + > of InternalTrait { + fn initialize(self: @ComponentState, world: WorldStorage,) { + // [Setup] Datastore + let mut store: Store = StoreTrait::new(world); + // [Effect] Create every service factories + let mut index = SERVICE_COUNT; + while index > 0 { + let service: Service = index.into(); + let version = service.version(); + let factory = FactoryTrait::new(service, version, version); + store.set_factory(@factory); + index -= 1; + } + } + + fn deploy( + self: @ComponentState, + world: WorldStorage, + service: Service, + project: felt252, + tier: Tier, + ) { + // [Setup] Datastore + let mut store: Store = StoreTrait::new(world); + + // [Check] Factory exists + let factory = store.get_factory(service.into()); + factory.assert_does_exist(); + + // [Check] Deployment does not exist + let deployment = store.get_deployment(service.into(), project); + deployment.assert_does_not_exist(); + + // [Effect] Create deployment + let owner = starknet::get_caller_address().into(); + let deployment = DeploymentTrait::new( + service: service, project: project, owner: owner, tier: tier, config: "", + ); + store.set_deployment(@deployment); + } + + fn delete( + self: @ComponentState, + world: WorldStorage, + service: Service, + project: felt252, + ) { + // [Setup] Datastore + let mut store: Store = StoreTrait::new(world); + + // [Check] Factory exists + let factory = store.get_factory(service.into()); + factory.assert_does_exist(); + + // [Check] Deployment exists + let mut deployment = store.get_deployment(service.into(), project); + deployment.assert_does_exist(); + + // [Check] Caller is owner + deployment.assert_is_owner(starknet::get_caller_address().into()); + + // [Effect] Delete deployment + deployment.nullify(); + store.delete_deployment(@deployment); + } + } +} diff --git a/packages/provider/src/constants.cairo b/packages/provider/src/constants.cairo new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/packages/provider/src/constants.cairo @@ -0,0 +1 @@ + diff --git a/packages/provider/src/elements/services/interface.cairo b/packages/provider/src/elements/services/interface.cairo new file mode 100644 index 0000000..00bd093 --- /dev/null +++ b/packages/provider/src/elements/services/interface.cairo @@ -0,0 +1,3 @@ +trait ServiceTrait { + fn version() -> felt252; +} diff --git a/packages/provider/src/elements/services/katana.cairo b/packages/provider/src/elements/services/katana.cairo new file mode 100644 index 0000000..9ba0892 --- /dev/null +++ b/packages/provider/src/elements/services/katana.cairo @@ -0,0 +1,7 @@ +use provider::elements::services::interface::ServiceTrait; + +impl Katana of ServiceTrait { + fn version() -> felt252 { + '1.0.1' + } +} diff --git a/packages/provider/src/elements/services/saya.cairo b/packages/provider/src/elements/services/saya.cairo new file mode 100644 index 0000000..4173f97 --- /dev/null +++ b/packages/provider/src/elements/services/saya.cairo @@ -0,0 +1,7 @@ +use provider::elements::services::interface::ServiceTrait; + +impl Saya of ServiceTrait { + fn version() -> felt252 { + '1.0.1' + } +} diff --git a/packages/provider/src/elements/services/torii.cairo b/packages/provider/src/elements/services/torii.cairo new file mode 100644 index 0000000..3f7cdd7 --- /dev/null +++ b/packages/provider/src/elements/services/torii.cairo @@ -0,0 +1,7 @@ +use provider::elements::services::interface::ServiceTrait; + +impl Torii of ServiceTrait { + fn version() -> felt252 { + '1.0.1' + } +} diff --git a/packages/slot/src/helpers/json.cairo b/packages/provider/src/helpers/json.cairo similarity index 100% rename from packages/slot/src/helpers/json.cairo rename to packages/provider/src/helpers/json.cairo diff --git a/packages/provider/src/lib.cairo b/packages/provider/src/lib.cairo new file mode 100644 index 0000000..7ed7283 --- /dev/null +++ b/packages/provider/src/lib.cairo @@ -0,0 +1,33 @@ +mod constants; +mod store; + +mod helpers { + mod json; +} + +mod elements { + mod services { + mod interface; + mod katana; + mod torii; + mod saya; + } +} + +mod types { + mod tier; + mod socials; + mod service; + mod status; + mod metadata; +} + +mod models { + mod index; + mod deployment; + mod factory; +} + +mod components { + mod deployable; +} diff --git a/packages/slot/src/models/deployment.cairo b/packages/provider/src/models/deployment.cairo similarity index 52% rename from packages/slot/src/models/deployment.cairo rename to packages/provider/src/models/deployment.cairo index 4a1a889..464d6af 100644 --- a/packages/slot/src/models/deployment.cairo +++ b/packages/provider/src/models/deployment.cairo @@ -1,74 +1,66 @@ // Intenral imports -use arcade_slot::models::index::Deployment; -use arcade_slot::types::service::Service; -use arcade_slot::types::status::Status; -use arcade_slot::types::tier::Tier; +use provider::models::index::Deployment; +use provider::types::service::Service; +use provider::types::status::Status; +use provider::types::tier::Tier; // Errors pub mod errors { pub const DEPLOYMENT_ALREADY_EXISTS: felt252 = 'Deployment: already exists'; pub const DEPLOYMENT_NOT_EXIST: felt252 = 'Deployment: does not exist'; - pub const DEPLOYMENT_INVALID_IDENTIFIER: felt252 = 'Deployment: invalid identifier'; + pub const DEPLOYMENT_INVALID_SERVICE: felt252 = 'Deployment: invalid service'; pub const DEPLOYMENT_INVALID_PROJECT: felt252 = 'Deployment: invalid project'; + pub const DEPLOYMENT_INVALID_OWNER: felt252 = 'Deployment: invalid owner'; pub const DEPLOYMENT_INVALID_STATUS: felt252 = 'Deployment: invalid status'; - pub const DEPLOYMENT_INVALID_SERVICE: felt252 = 'Deployment: invalid service'; pub const DEPLOYMENT_INVALID_TIER: felt252 = 'Deployment: invalid tier'; - pub const DEPLOYMENT_INVALID_REGIONS: felt252 = 'Deployment: invalid regions'; + pub const DEPLOYMENT_NOT_OWNER: felt252 = 'Deployment: not owner'; } #[generate_trait] impl DeploymentImpl of DeploymentTrait { #[inline] fn new( - id: felt252, - project: felt252, - status: Status, - branch: Option, - service: Service, - tier: Tier, - regions: felt252, - auto_upgrade: bool, - config: ByteArray, + service: Service, project: felt252, owner: felt252, tier: Tier, config: ByteArray, ) -> Deployment { // [Check] Inputs - DeploymentAssert::assert_valid_identifier(id); - DeploymentAssert::assert_valid_project(project); - DeploymentAssert::assert_valid_status(status); DeploymentAssert::assert_valid_service(service); + DeploymentAssert::assert_valid_project(project); + DeploymentAssert::assert_valid_owner(owner); DeploymentAssert::assert_valid_tier(tier); - DeploymentAssert::assert_valid_regions(regions); // [Return] Deployment Deployment { - id: id, - project: project, - status: status.into(), - branch: branch, service: service.into(), + project: project, + owner: owner, + status: Status::Disabled.into(), tier: tier.into(), - regions: regions, - auto_upgrade: auto_upgrade, config: config, } } + + #[inline] + fn nullify(ref self: Deployment) { + self.owner = 0; + } } #[generate_trait] impl DeploymentAssert of AssertTrait { #[inline] - fn assert_does_not_exist(self: Deployment) { - assert(self.project == 0, errors::DEPLOYMENT_ALREADY_EXISTS); + fn assert_does_not_exist(self: @Deployment) { + assert(self.owner == @0, errors::DEPLOYMENT_ALREADY_EXISTS); } #[inline] - fn assert_does_exist(self: Deployment) { - assert(self.project != 0, errors::DEPLOYMENT_NOT_EXIST); + fn assert_does_exist(self: @Deployment) { + assert(self.owner != @0, errors::DEPLOYMENT_NOT_EXIST); } #[inline] - fn assert_valid_identifier(identifier: felt252) { - assert(identifier != 0, errors::DEPLOYMENT_INVALID_IDENTIFIER); + fn assert_valid_service(service: Service) { + assert(service != Service::None, errors::DEPLOYMENT_INVALID_SERVICE); } #[inline] @@ -77,13 +69,13 @@ impl DeploymentAssert of AssertTrait { } #[inline] - fn assert_valid_status(status: Status) { - assert(status != Status::None, errors::DEPLOYMENT_INVALID_STATUS); + fn assert_valid_owner(owner: felt252) { + assert(owner != 0, errors::DEPLOYMENT_INVALID_OWNER); } #[inline] - fn assert_valid_service(service: Service) { - assert(service != Service::None, errors::DEPLOYMENT_INVALID_SERVICE); + fn assert_valid_status(status: Status) { + assert(status != Status::None, errors::DEPLOYMENT_INVALID_STATUS); } #[inline] @@ -92,8 +84,8 @@ impl DeploymentAssert of AssertTrait { } #[inline] - fn assert_valid_regions(regions: felt252) { - assert(regions != 0, errors::DEPLOYMENT_INVALID_REGIONS); + fn assert_is_owner(self: @Deployment, owner: felt252) { + assert(@owner == self.owner, errors::DEPLOYMENT_NOT_OWNER); } } @@ -105,45 +97,45 @@ mod tests { // Constants - const IDENTIFIER: felt252 = 'ID'; - const PROJECT: felt252 = 'PROJECT'; - const STATUS: Status = Status::Active; - const BRANCH: Option = Option::None; const SERVICE: Service = Service::Katana; + const PROJECT: felt252 = 'PROJECT'; + const OWNER: felt252 = 'OWNER'; const TIER: Tier = Tier::Basic; - const REGIONS: felt252 = 'REGIONS'; - const AUTO_UPGRADE: bool = true; + const NOT_OWNER: felt252 = 'NOT_OWNER'; #[test] fn test_deployment_new() { - let deployment = DeploymentTrait::new( - IDENTIFIER, PROJECT, STATUS, BRANCH, SERVICE, TIER, REGIONS, AUTO_UPGRADE, "" - ); - assert_eq!(deployment.id, IDENTIFIER); - assert_eq!(deployment.project, PROJECT); - assert_eq!(deployment.status, STATUS.into()); - assert_eq!(deployment.branch, BRANCH); + let deployment = DeploymentTrait::new(SERVICE, PROJECT, OWNER, TIER, ""); assert_eq!(deployment.service, SERVICE.into()); + assert_eq!(deployment.project, PROJECT); + assert_eq!(deployment.owner, OWNER); assert_eq!(deployment.tier, TIER.into()); - assert_eq!(deployment.regions, REGIONS); - assert_eq!(deployment.auto_upgrade, AUTO_UPGRADE); assert_eq!(deployment.config, ""); } #[test] fn test_deployment_assert_does_exist() { - let deployment = DeploymentTrait::new( - IDENTIFIER, PROJECT, STATUS, BRANCH, SERVICE, TIER, REGIONS, AUTO_UPGRADE, "" - ); + let deployment = DeploymentTrait::new(SERVICE, PROJECT, OWNER, TIER, ""); deployment.assert_does_exist(); } #[test] #[should_panic(expected: 'Deployment: already exists')] fn test_deployment_revert_already_exists() { - let deployment = DeploymentTrait::new( - IDENTIFIER, PROJECT, STATUS, BRANCH, SERVICE, TIER, REGIONS, AUTO_UPGRADE, "" - ); + let mut deployment = DeploymentTrait::new(SERVICE, PROJECT, OWNER, TIER, ""); deployment.assert_does_not_exist(); } + + #[test] + fn test_deployment_assert_is_owner() { + let deployment = DeploymentTrait::new(SERVICE, PROJECT, OWNER, TIER, ""); + deployment.assert_is_owner(OWNER); + } + + #[test] + #[should_panic(expected: 'Deployment: not owner')] + fn test_deployment_revert_not_owner() { + let deployment = DeploymentTrait::new(SERVICE, PROJECT, OWNER, TIER, ""); + deployment.assert_is_owner(NOT_OWNER); + } } diff --git a/packages/provider/src/models/factory.cairo b/packages/provider/src/models/factory.cairo new file mode 100644 index 0000000..985e54f --- /dev/null +++ b/packages/provider/src/models/factory.cairo @@ -0,0 +1,84 @@ +// Intenral imports + +use provider::models::index::Factory; +use provider::types::service::Service; + +// Errors + +pub mod errors { + pub const SERVICE_ALREADY_EXISTS: felt252 = 'Factory: already exists'; + pub const SERVICE_NOT_EXIST: felt252 = 'Factory: does not exist'; + pub const SERVICE_INVALID_IDENTIFIER: felt252 = 'Factory: invalid identifier'; + pub const SERVICE_INVALID_VERSION: felt252 = 'Factory: invalid version'; +} + +#[generate_trait] +impl FactoryImpl of FactoryTrait { + #[inline] + fn new(service: Service, version: felt252, default_version: felt252,) -> Factory { + // [Check] Inputs + let factory_id: u8 = service.into(); + FactoryAssert::assert_valid_identifier(factory_id); + FactoryAssert::assert_valid_version(version); + FactoryAssert::assert_valid_version(default_version); + // [Return] Factory + Factory { id: factory_id, version: version, default_version: default_version, } + } +} + +#[generate_trait] +impl FactoryAssert of AssertTrait { + #[inline] + fn assert_does_not_exist(self: @Factory) { + assert(self.version == @0, errors::SERVICE_ALREADY_EXISTS); + } + + #[inline] + fn assert_does_exist(self: @Factory) { + assert(self.version != @0, errors::SERVICE_NOT_EXIST); + } + + #[inline] + fn assert_valid_identifier(identifier: u8) { + assert(identifier != 0, errors::SERVICE_INVALID_IDENTIFIER); + } + + #[inline] + fn assert_valid_version(version: felt252) { + assert(version != 0, errors::SERVICE_INVALID_VERSION); + } +} + +#[cfg(test)] +mod tests { + // Local imports + + use super::{Factory, FactoryTrait, FactoryAssert, Service}; + + // Constants + + const SERVICE: Service = Service::Katana; + const VERSION: felt252 = 'VERSION'; + const DEFAULT_VERSION: felt252 = 'DEFAULT'; + + #[test] + fn test_service_new() { + let service = FactoryTrait::new(SERVICE, VERSION, DEFAULT_VERSION); + assert_eq!(service.id, SERVICE.into()); + assert_eq!(service.version, VERSION); + assert_eq!(service.default_version, DEFAULT_VERSION); + } + + #[test] + fn test_service_assert_does_exist() { + let service = FactoryTrait::new(SERVICE, VERSION, DEFAULT_VERSION); + service.assert_does_exist(); + } + + #[test] + #[should_panic(expected: 'Factory: already exists')] + fn test_service_revert_already_exists() { + let service = FactoryTrait::new(SERVICE, VERSION, DEFAULT_VERSION); + service.assert_does_not_exist(); + } +} diff --git a/packages/provider/src/models/game.cairo b/packages/provider/src/models/game.cairo new file mode 100644 index 0000000..dcc6297 --- /dev/null +++ b/packages/provider/src/models/game.cairo @@ -0,0 +1,158 @@ +// Intenral imports + +use provider::models::index::Game; + +// Errors + +pub mod errors { + pub const GAME_ALREADY_EXISTS: felt252 = 'Game: already exists'; + pub const GAME_NOT_EXIST: felt252 = 'Game: does not exist'; + pub const GAME_INVALID_PROJECT: felt252 = 'Game: invalid project'; + pub const GAME_INVALID_OWNER: felt252 = 'Game: invalid owner'; + pub const GAME_INVALID_WORLD: felt252 = 'Game: invalid world'; + pub const GAME_INVALID_NAMESPACE: felt252 = 'Game: invalid namespace'; + pub const GAME_INVALID_NAME: felt252 = 'Game: invalid name'; + pub const GAME_INVALID_PRIORITY: felt252 = 'Game: invalid priority'; +} + +#[generate_trait] +impl GameImpl of GameTrait { + #[inline] + fn new( + project: felt252, + owner: felt252, + world: felt252, + namespace: felt252, + name: felt252, + socials: ByteArray, + metadata: ByteArray, + ) -> Game { + // [Check] Inputs + GameAssert::assert_valid_project(project); + GameAssert::assert_valid_owner(owner); + GameAssert::assert_valid_name(name); + GameAssert::assert_valid_world(world); + GameAssert::assert_valid_namespace(namespace); + // [Return] Game + Game { + project: project, + owner: owner, + world: world, + namespace: namespace, + name: name, + priority: 0, + socials: socials, + metadata: metadata, + active: true, + } + } +} + +#[generate_trait] +impl GameAssert of AssertTrait { + #[inline] + fn assert_does_not_exist(self: @Game) { + assert(self.name == @0, errors::GAME_ALREADY_EXISTS); + } + + #[inline] + fn assert_does_exist(self: @Game) { + assert(self.name != @0, errors::GAME_NOT_EXIST); + } + + #[inline] + fn assert_valid_project(project: felt252) { + assert(project != 0, errors::GAME_INVALID_PROJECT); + } + + #[inline] + fn assert_valid_owner(owner: felt252) { + assert(owner != 0, errors::GAME_INVALID_OWNER); + } + + #[inline] + fn assert_valid_world(world: felt252) { + assert(world != 0, errors::GAME_INVALID_WORLD); + } + + #[inline] + fn assert_valid_namespace(namespace: felt252) { + assert(namespace != 0, errors::GAME_INVALID_NAMESPACE); + } + + #[inline] + fn assert_valid_name(name: felt252) { + assert(name != 0, errors::GAME_INVALID_NAME); + } +} + +#[cfg(test)] +mod tests { + // Local imports + + use super::{Game, GameTrait, GameAssert}; + + // Constants + + const PROJECT: felt252 = 'PROJECT'; + const OWNER: felt252 = 'OWNER'; + const WORLD: felt252 = 'WORLD'; + const NAMESPACE: felt252 = 'NAMESPACE'; + const NAME: felt252 = 'NAME'; + + #[test] + fn test_service_new() { + let service = GameTrait::new(PROJECT, OWNER, WORLD, NAMESPACE, NAME, "", ""); + assert_eq!(service.project, PROJECT); + assert_eq!(service.owner, OWNER); + assert_eq!(service.world, WORLD); + assert_eq!(service.namespace, NAMESPACE); + assert_eq!(service.name, NAME); + assert_eq!(service.socials, ""); + assert_eq!(service.metadata, ""); + assert_eq!(service.active, true); + } + + #[test] + fn test_service_assert_does_exist() { + let service = GameTrait::new(PROJECT, OWNER, WORLD, NAMESPACE, NAME, "", ""); + service.assert_does_exist(); + } + + #[test] + #[should_panic(expected: 'Game: already exists')] + fn test_service_revert_already_exists() { + let service = GameTrait::new(PROJECT, OWNER, WORLD, NAMESPACE, NAME, "", ""); + service.assert_does_not_exist(); + } + + #[test] + #[should_panic(expected: 'Game: invalid project')] + fn test_service_revert_invalid_project() { + GameTrait::new(0, OWNER, WORLD, NAMESPACE, NAME, "", ""); + } + + #[test] + #[should_panic(expected: 'Game: invalid owner')] + fn test_service_revert_invalid_owner() { + GameTrait::new(PROJECT, 0, WORLD, NAMESPACE, NAME, "", ""); + } + + #[test] + #[should_panic(expected: 'Game: invalid world')] + fn test_service_revert_invalid_world() { + GameTrait::new(PROJECT, OWNER, 0, NAMESPACE, NAME, "", ""); + } + + #[test] + #[should_panic(expected: 'Game: invalid namespace')] + fn test_service_revert_invalid_namespace() { + GameTrait::new(PROJECT, OWNER, WORLD, 0, NAME, "", ""); + } + + #[test] + #[should_panic(expected: 'Game: invalid name')] + fn test_service_revert_invalid_name() { + GameTrait::new(PROJECT, OWNER, WORLD, NAMESPACE, 0, "", ""); + } +} diff --git a/packages/provider/src/models/index.cairo b/packages/provider/src/models/index.cairo new file mode 100644 index 0000000..d5586b4 --- /dev/null +++ b/packages/provider/src/models/index.cairo @@ -0,0 +1,38 @@ +//! Models + +#[derive(Clone, Drop, Serde)] +#[dojo::model] +pub struct Deployment { + #[key] + service: u8, + #[key] + project: felt252, + owner: felt252, + status: u8, + tier: u8, + config: ByteArray, +} + +#[derive(Copy, Drop, Serde)] +#[dojo::model] +pub struct Factory { + #[key] + id: u8, + version: felt252, + default_version: felt252, +} + +#[derive(Clone, Drop, Serde)] +#[dojo::model] +pub struct Game { + #[key] + project: felt252, + owner: felt252, + world: felt252, + namespace: felt252, + name: felt252, + priority: u8, + socials: ByteArray, + metadata: ByteArray, + active: bool, +} diff --git a/packages/provider/src/store.cairo b/packages/provider/src/store.cairo new file mode 100644 index 0000000..0d53989 --- /dev/null +++ b/packages/provider/src/store.cairo @@ -0,0 +1,57 @@ +//! Store struct and component management methods. + +// Starknet imports + +use starknet::SyscallResultTrait; + +// Dojo imports + +use dojo::world::WorldStorage; +use dojo::model::ModelStorage; + +// Models imports + +use provider::models::deployment::Deployment; +use provider::models::factory::Factory; + +// Structs + +#[derive(Copy, Drop)] +struct Store { + world: WorldStorage, +} + +// Implementations + +#[generate_trait] +impl StoreImpl of StoreTrait { + #[inline] + fn new(world: WorldStorage) -> Store { + Store { world: world } + } + + #[inline] + fn get_deployment(self: Store, service: u8, project: felt252) -> Deployment { + self.world.read_model((service, project)) + } + + #[inline] + fn get_factory(self: Store, factory_id: u8) -> Factory { + self.world.read_model(factory_id) + } + + #[inline] + fn set_deployment(ref self: Store, deployment: @Deployment) { + self.world.write_model(deployment); + } + + #[inline] + fn set_factory(ref self: Store, factory: @Factory) { + self.world.write_model(factory); + } + + #[inline] + fn delete_deployment(ref self: Store, deployment: @Deployment) { + self.world.erase_model(deployment); + } +} diff --git a/packages/slot/src/types/metadata.cairo b/packages/provider/src/types/metadata.cairo similarity index 58% rename from packages/slot/src/types/metadata.cairo rename to packages/provider/src/types/metadata.cairo index fc841fe..1439ce5 100644 --- a/packages/slot/src/types/metadata.cairo +++ b/packages/provider/src/types/metadata.cairo @@ -1,6 +1,6 @@ // Internal imports -use arcade_slot::helpers::json::{JsonifiableString, JsonifiableTrait}; +use provider::helpers::json::{JsonifiableString, JsonifiableTrait}; // Constants @@ -17,6 +17,41 @@ pub struct Metadata { // Implementations +#[generate_trait] +pub impl MetadataImpl of MetadataTrait { + fn new( + color: Option, + name: Option, + description: Option, + image: Option, + banner: Option + ) -> Metadata { + let color = match color { + Option::Some(color) => color, + Option::None => 0, + }; + let name = match name { + Option::Some(name) => name, + Option::None => "", + }; + let description = match description { + Option::Some(description) => description, + Option::None => "", + }; + let image = match image { + Option::Some(image) => image, + Option::None => "", + }; + let banner = match banner { + Option::Some(banner) => banner, + Option::None => "", + }; + Metadata { + color: color, name: name, description: description, image: image, banner: banner + } + } +} + pub impl MetadataJsonifiable of JsonifiableTrait { fn jsonify(self: Metadata) -> ByteArray { let mut color = ""; diff --git a/packages/slot/src/types/service.cairo b/packages/provider/src/types/service.cairo similarity index 53% rename from packages/slot/src/types/service.cairo rename to packages/provider/src/types/service.cairo index 5fe7d91..4840d1d 100644 --- a/packages/slot/src/types/service.cairo +++ b/packages/provider/src/types/service.cairo @@ -1,3 +1,11 @@ +// Internal imports + +use provider::elements::services; + +// Constants + +pub const SERVICE_COUNT: u8 = 3; + #[derive(Copy, Drop, PartialEq)] pub enum Service { None, @@ -6,13 +14,20 @@ pub enum Service { Saya, } -// Constants - -pub const KATANA: felt252 = 'KATANA'; -pub const TORII: felt252 = 'TORII'; -pub const SAYA: felt252 = 'SAYA'; // Implementations +#[generate_trait] +impl ServiceImpl of ServiceTrait { + fn version(self: Service) -> felt252 { + match self { + Service::None => 0, + Service::Katana => services::katana::Katana::version(), + Service::Torii => services::torii::Torii::version(), + Service::Saya => services::saya::Saya::version(), + } + } +} + impl IntoServiceU8 of core::Into { #[inline] fn into(self: Service) -> u8 { @@ -37,30 +52,3 @@ impl IntoU8Service of core::Into { } } } - -impl IntoServiceFelt252 of core::Into { - #[inline] - fn into(self: Service) -> felt252 { - match self { - Service::None => 0, - Service::Katana => KATANA, - Service::Torii => TORII, - Service::Saya => SAYA, - } - } -} - -impl IntoFelt252Service of core::Into { - #[inline] - fn into(self: felt252) -> Service { - if self == KATANA { - Service::Katana - } else if self == TORII { - Service::Torii - } else if self == SAYA { - Service::Saya - } else { - Service::None - } - } -} diff --git a/packages/slot/src/types/socials.cairo b/packages/provider/src/types/socials.cairo similarity index 54% rename from packages/slot/src/types/socials.cairo rename to packages/provider/src/types/socials.cairo index 66d6ef5..62d7c51 100644 --- a/packages/slot/src/types/socials.cairo +++ b/packages/provider/src/types/socials.cairo @@ -1,6 +1,6 @@ // Internal imports -use arcade_slot::helpers::json::{JsonifiableString, JsonifiableTrait}; +use provider::helpers::json::{JsonifiableString, JsonifiableTrait}; #[derive(Clone, Drop)] pub struct Socials { @@ -13,6 +13,45 @@ pub struct Socials { // Implementations +#[generate_trait] +pub impl SocialsImpl of SocialsTrait { + fn new( + discord: Option, + telegram: Option, + twitter: Option, + youtube: Option, + website: Option + ) -> Socials { + let discord = match discord { + Option::Some(discord) => discord, + Option::None => "", + }; + let telegram = match telegram { + Option::Some(telegram) => telegram, + Option::None => "", + }; + let twitter = match twitter { + Option::Some(twitter) => twitter, + Option::None => "", + }; + let youtube = match youtube { + Option::Some(youtube) => youtube, + Option::None => "", + }; + let website = match website { + Option::Some(website) => website, + Option::None => "", + }; + Socials { + discord: discord, + telegram: telegram, + twitter: twitter, + youtube: youtube, + website: website + } + } +} + pub impl SocialsJsonifiable of JsonifiableTrait { fn jsonify(self: Socials) -> ByteArray { let mut string = "{"; diff --git a/packages/slot/src/types/status.cairo b/packages/provider/src/types/status.cairo similarity index 100% rename from packages/slot/src/types/status.cairo rename to packages/provider/src/types/status.cairo diff --git a/packages/slot/src/types/tier.cairo b/packages/provider/src/types/tier.cairo similarity index 100% rename from packages/slot/src/types/tier.cairo rename to packages/provider/src/types/tier.cairo diff --git a/packages/slot/src/models/game.cairo b/packages/slot/src/models/game.cairo deleted file mode 100644 index e2a918d..0000000 --- a/packages/slot/src/models/game.cairo +++ /dev/null @@ -1,91 +0,0 @@ -// Intenral imports - -use arcade_slot::models::index::Game; - -// Errors - -pub mod errors { - pub const GAME_ALREADY_EXISTS: felt252 = 'Game: already exists'; - pub const GAME_NOT_EXIST: felt252 = 'Game: does not exist'; - pub const GAME_INVALID_IDENTIFIER: felt252 = 'Game: invalid identifier'; - pub const GAME_INVALID_NAME: felt252 = 'Game: invalid name'; - pub const GAME_INVALID_PRIORITY: felt252 = 'Game: invalid priority'; -} - -#[generate_trait] -impl GameImpl of GameTrait { - #[inline] - fn new(id: felt252, name: felt252, socials: ByteArray, metadata: ByteArray,) -> Game { - // [Check] Inputs - GameAssert::assert_valid_identifier(id); - GameAssert::assert_valid_name(name); - // [Return] Game - Game { - id: id, name: name, priority: 0, socials: socials, metadata: metadata, active: true, - } - } -} - -#[generate_trait] -impl GameAssert of AssertTrait { - #[inline] - fn assert_does_not_exist(self: Game) { - assert(self.name == 0, errors::GAME_ALREADY_EXISTS); - } - - #[inline] - fn assert_does_exist(self: Game) { - assert(self.name != 0, errors::GAME_NOT_EXIST); - } - - #[inline] - fn assert_valid_identifier(identifier: felt252) { - assert(identifier != 0, errors::GAME_INVALID_IDENTIFIER); - } - - #[inline] - fn assert_valid_name(name: felt252) { - assert(name != 0, errors::GAME_INVALID_NAME); - } -} - -#[cfg(test)] -mod tests { - // Local imports - - use super::{Game, GameTrait, GameAssert}; - - // Constants - - const IDENTIFIER: felt252 = 'ID'; - const NAME: felt252 = 'NAME'; - - #[test] - fn test_service_new() { - let service = GameTrait::new(IDENTIFIER, NAME, "", ""); - assert_eq!(service.id, IDENTIFIER); - assert_eq!(service.name, NAME); - assert_eq!(service.socials, ""); - assert_eq!(service.metadata, ""); - assert_eq!(service.active, true); - } - - #[test] - fn test_service_assert_does_exist() { - let service = GameTrait::new(IDENTIFIER, NAME, "", ""); - service.assert_does_exist(); - } - - #[test] - #[should_panic(expected: 'Game: already exists')] - fn test_service_revert_already_exists() { - let service = GameTrait::new(IDENTIFIER, NAME, "", ""); - service.assert_does_not_exist(); - } - - #[test] - #[should_panic(expected: 'Game: invalid name')] - fn test_service_revert_invalid_name() { - GameTrait::new(IDENTIFIER, 0, "", ""); - } -} diff --git a/packages/slot/src/models/service.cairo b/packages/slot/src/models/service.cairo deleted file mode 100644 index 3529679..0000000 --- a/packages/slot/src/models/service.cairo +++ /dev/null @@ -1,82 +0,0 @@ -// Intenral imports - -use arcade_slot::models::index::Service; - -// Errors - -pub mod errors { - pub const SERVICE_ALREADY_EXISTS: felt252 = 'Service: already exists'; - pub const SERVICE_NOT_EXIST: felt252 = 'Service: does not exist'; - pub const SERVICE_INVALID_IDENTIFIER: felt252 = 'Service: invalid identifier'; - pub const SERVICE_INVALID_VERSION: felt252 = 'Service: invalid version'; -} - -#[generate_trait] -impl ServiceImpl of ServiceTrait { - #[inline] - fn new(id: felt252, version: felt252, default_version: felt252,) -> Service { - // [Check] Inputs - ServiceAssert::assert_valid_identifier(id); - ServiceAssert::assert_valid_version(version); - ServiceAssert::assert_valid_version(default_version); - // [Return] Service - Service { id: id, version: version, default_version: default_version, } - } -} - -#[generate_trait] -impl ServiceAssert of AssertTrait { - #[inline] - fn assert_does_not_exist(self: Service) { - assert(self.version == 0, errors::SERVICE_ALREADY_EXISTS); - } - - #[inline] - fn assert_does_exist(self: Service) { - assert(self.version != 0, errors::SERVICE_NOT_EXIST); - } - - #[inline] - fn assert_valid_identifier(identifier: felt252) { - assert(identifier != 0, errors::SERVICE_INVALID_IDENTIFIER); - } - - #[inline] - fn assert_valid_version(version: felt252) { - assert(version != 0, errors::SERVICE_INVALID_VERSION); - } -} - -#[cfg(test)] -mod tests { - // Local imports - - use super::{Service, ServiceTrait, ServiceAssert}; - - // Constants - - const IDENTIFIER: felt252 = 'ID'; - const VERSION: felt252 = 'VERSION'; - const DEFAULT_VERSION: felt252 = 'DEFAULT'; - - #[test] - fn test_service_new() { - let service = ServiceTrait::new(IDENTIFIER, VERSION, DEFAULT_VERSION); - assert_eq!(service.id, IDENTIFIER); - assert_eq!(service.version, VERSION); - assert_eq!(service.default_version, DEFAULT_VERSION); - } - - #[test] - fn test_service_assert_does_exist() { - let service = ServiceTrait::new(IDENTIFIER, VERSION, DEFAULT_VERSION); - service.assert_does_exist(); - } - - #[test] - #[should_panic(expected: 'Service: already exists')] - fn test_service_revert_already_exists() { - let service = ServiceTrait::new(IDENTIFIER, VERSION, DEFAULT_VERSION); - service.assert_does_not_exist(); - } -} diff --git a/packages/slot/src/store.cairo b/packages/slot/src/store.cairo deleted file mode 100644 index 023d2f2..0000000 --- a/packages/slot/src/store.cairo +++ /dev/null @@ -1,40 +0,0 @@ -//! Store struct and component management methods. - -// Starknet imports - -use starknet::SyscallResultTrait; - -// Dojo imports - -use dojo::world::WorldStorage; -use dojo::model::ModelStorage; -// Models imports - -use arcade_slot::models::deployment::Deployment; - -// Structs - -#[derive(Copy, Drop)] -struct Store { - world: WorldStorage, -} - -// Implementations - -#[generate_trait] -impl StoreImpl of StoreTrait { - #[inline] - fn new(world: WorldStorage) -> Store { - Store { world: world } - } - - #[inline] - fn get_deployment(self: Store, deployment_id: u32) -> Deployment { - self.world.read_model(deployment_id) - } - - #[inline] - fn set_deployment(ref self: Store, deployment: Deployment) { - self.world.write_model(@deployment); - } -}