diff --git a/onchain/Scarb.toml b/onchain/Scarb.toml index 99ed1283..b5b37777 100644 --- a/onchain/Scarb.toml +++ b/onchain/Scarb.toml @@ -1,6 +1,7 @@ [package] name = "art_peace" version = "0.1.0" +edition = "2023_11" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html diff --git a/onchain/src/art_peace.cairo b/onchain/src/art_peace.cairo index 288604f8..59336e8d 100644 --- a/onchain/src/art_peace.cairo +++ b/onchain/src/art_peace.cairo @@ -1,10 +1,11 @@ #[starknet::contract] pub mod ArtPeace { use starknet::ContractAddress; + use art_peace::{IArtPeace, Pixel}; - use art_peace::quests::{IQuestDispatcher, IQuestDispatcherTrait}; + use art_peace::quests::interfaces::{IQuestDispatcher, IQuestDispatcherTrait}; use art_peace::templates::component::TemplateStoreComponent; - use art_peace::templates::{ITemplateVerifier, TemplateMetadata}; + use art_peace::templates::interfaces::{ITemplateVerifier, TemplateMetadata}; component!(path: TemplateStoreComponent, storage: templates, event: TemplateEvent); @@ -242,6 +243,7 @@ pub mod ArtPeace { colors.append(self.color_palette.read(i)); i += 1; }; + colors } @@ -285,6 +287,7 @@ pub mod ArtPeace { quests.append(self.daily_quests.read((day_index, i))); i += 1; }; + quests.span() } @@ -297,6 +300,7 @@ pub mod ArtPeace { quests.append(self.daily_quests.read((day, i))); i += 1; }; + quests.span() } @@ -316,6 +320,7 @@ pub mod ArtPeace { quests.append(self.main_quests.read(i)); i += 1; }; + quests.span() } @@ -381,6 +386,7 @@ pub mod ArtPeace { }; i += 1; }; + total } @@ -394,6 +400,7 @@ pub mod ArtPeace { total += self.user_pixels_placed.read((day, user, i)); i += 1; }; + total } diff --git a/onchain/src/interface.cairo b/onchain/src/interface.cairo index 9882ff36..954488ca 100644 --- a/onchain/src/interface.cairo +++ b/onchain/src/interface.cairo @@ -1,9 +1,9 @@ #[derive(Drop, Serde, starknet::Store)] pub struct Pixel { // Color index in the palette - color: u8, + pub color: u8, // The person that placed the pixel - owner: starknet::ContractAddress, + pub owner: starknet::ContractAddress, } // TODO: Tests for all diff --git a/onchain/src/lib.cairo b/onchain/src/lib.cairo index a49dc556..446af8d4 100644 --- a/onchain/src/lib.cairo +++ b/onchain/src/lib.cairo @@ -4,17 +4,18 @@ use art_peace::ArtPeace; use interface::{IArtPeace, IArtPeaceDispatcher, IArtPeaceDispatcherTrait, Pixel}; mod quests { - pub mod interface; + pub mod interfaces; mod pixel_quest; - use interface::{IQuest, QuestClaimed, IQuestDispatcher, IQuestDispatcherTrait}; + use interfaces::{IQuest, IQuestDispatcher, IQuestDispatcherTrait}; + use pixel_quest::PixelQuest::QuestClaimed; } mod templates { - pub mod interface; - mod component; + pub mod interfaces; + pub mod component; - use interface::{ + use interfaces::{ TemplateMetadata, ITemplateVerifier, ITemplateStoreDispatcher, ITemplateStoreDispatcherTrait, ITemplateVerifierDispatcher, ITemplateVerifierDispatcherTrait }; diff --git a/onchain/src/quests/interface.cairo b/onchain/src/quests/interfaces.cairo similarity index 50% rename from onchain/src/quests/interface.cairo rename to onchain/src/quests/interfaces.cairo index 2b0b6862..1d8933c5 100644 --- a/onchain/src/quests/interface.cairo +++ b/onchain/src/quests/interfaces.cairo @@ -1,17 +1,19 @@ use starknet::ContractAddress; -#[derive(Drop, starknet::Event)] -pub struct QuestClaimed { - pub user: ContractAddress, - pub reward: u32, -} - #[starknet::interface] pub trait IQuest { // Return the reward for the quest. fn get_reward(self: @TContractState) -> u32; - // Return if the user can claim the quest. + // Return true if the user can claim the quest. fn is_claimable(self: @TContractState, user: ContractAddress) -> bool; // Claim the quest. fn claim(ref self: TContractState, user: ContractAddress) -> u32; } + +#[starknet::interface] +pub trait IPixelQuest { + fn is_claimed(self: @TContractState, user: starknet::ContractAddress) -> bool; + fn get_pixels_needed(self: @TContractState) -> u32; + fn is_daily(self: @TContractState) -> bool; + fn claim_day(self: @TContractState) -> u32; +} diff --git a/onchain/src/quests/pixel_quest.cairo b/onchain/src/quests/pixel_quest.cairo index efddc53e..00bb64cc 100644 --- a/onchain/src/quests/pixel_quest.cairo +++ b/onchain/src/quests/pixel_quest.cairo @@ -1,17 +1,8 @@ -#[starknet::interface] -trait IPixelQuest { - fn is_claimed(self: @TContractState, user: starknet::ContractAddress) -> bool; - fn get_pixels_needed(self: @TContractState) -> u32; - fn is_daily(self: @TContractState) -> bool; - fn claim_day(self: @TContractState) -> u32; -} - #[starknet::contract] -mod PixelQuest { +pub mod PixelQuest { use starknet::{ContractAddress, get_caller_address}; use art_peace::{IArtPeaceDispatcher, IArtPeaceDispatcherTrait}; - use art_peace::quests::{IQuest, QuestClaimed}; - use super::IPixelQuest; + use art_peace::quests::interfaces::{IQuest, IPixelQuest}; #[storage] struct Storage { @@ -24,6 +15,12 @@ mod PixelQuest { claim_day: u32, } + #[derive(Drop, starknet::Event)] + pub struct QuestClaimed { + pub user: ContractAddress, + pub reward: u32, + } + #[event] #[derive(Drop, starknet::Event)] enum Event { @@ -49,19 +46,19 @@ mod PixelQuest { #[abi(embed_v0)] impl PixelQuestImpl of IPixelQuest { fn is_claimed(self: @ContractState, user: ContractAddress) -> bool { - return self.claimed.read(user); + self.claimed.read(user) } fn get_pixels_needed(self: @ContractState) -> u32 { - return self.pixels_needed.read(); + self.pixels_needed.read() } fn is_daily(self: @ContractState) -> bool { - return self.is_daily.read(); + self.is_daily.read() } fn claim_day(self: @ContractState) -> u32 { - return self.claim_day.read(); + self.claim_day.read() } } @@ -69,14 +66,16 @@ mod PixelQuest { #[abi(embed_v0)] impl PixelQuest of IQuest { fn get_reward(self: @ContractState) -> u32 { - return self.reward.read(); + self.reward.read() } fn is_claimable(self: @ContractState, user: ContractAddress) -> bool { let art_peace = self.art_peace.read(); + if self.claimed.read(user) { return false; } + if self.is_daily.read() { // Daily Pixel Quest let day = art_peace.get_day(); @@ -97,6 +96,7 @@ mod PixelQuest { get_caller_address() == self.art_peace.read().contract_address, 'Only ArtPeace can claim quests' ); + if !self.is_claimable(user) { return 0; } @@ -104,7 +104,8 @@ mod PixelQuest { self.claimed.write(user, true); let reward = self.reward.read(); self.emit(QuestClaimed { user: user, reward: reward }); - return reward; + + reward } } } diff --git a/onchain/src/templates/component.cairo b/onchain/src/templates/component.cairo index f783e886..e159b069 100644 --- a/onchain/src/templates/component.cairo +++ b/onchain/src/templates/component.cairo @@ -1,6 +1,6 @@ #[starknet::component] -mod TemplateStoreComponent { - use art_peace::templates::interface::{ITemplateStore, TemplateMetadata}; +pub mod TemplateStoreComponent { + use art_peace::templates::interfaces::{ITemplateStore, TemplateMetadata}; #[storage] struct Storage { @@ -13,7 +13,7 @@ mod TemplateStoreComponent { #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { TemplateAdded: TemplateAdded, TemplateCompleted: TemplateCompleted, } @@ -37,18 +37,19 @@ mod TemplateStoreComponent { TContractState, +HasComponent > of ITemplateStore> { fn get_templates_count(self: @ComponentState) -> u32 { - return self.templates_count.read(); + self.templates_count.read() } fn get_template( self: @ComponentState, template_id: u32 ) -> TemplateMetadata { - return self.templates.read(template_id); + self.templates.read(template_id) } fn get_template_hash(self: @ComponentState, template_id: u32) -> felt252 { let metadata: TemplateMetadata = self.templates.read(template_id); - return metadata.hash; + + metadata.hash } // TODO: Return idx of the template? @@ -62,7 +63,7 @@ mod TemplateStoreComponent { } fn is_template_complete(self: @ComponentState, template_id: u32) -> bool { - return self.completed_templates.read(template_id); + self.completed_templates.read(template_id) } } } diff --git a/onchain/src/templates/interface.cairo b/onchain/src/templates/interfaces.cairo similarity index 89% rename from onchain/src/templates/interface.cairo rename to onchain/src/templates/interfaces.cairo index 55c1b66d..44b9d7d1 100644 --- a/onchain/src/templates/interface.cairo +++ b/onchain/src/templates/interfaces.cairo @@ -1,11 +1,11 @@ #[derive(Drop, Copy, Serde, starknet::Store)] pub struct TemplateMetadata { - hash: felt252, - position: u128, - width: u128, - height: u128, - reward: u256, - reward_token: starknet::ContractAddress + pub hash: felt252, + pub position: u128, + pub width: u128, + pub height: u128, + pub reward: u256, + pub reward_token: starknet::ContractAddress } #[starknet::interface] diff --git a/onchain/src/tests/art_peace.cairo b/onchain/src/tests/art_peace.cairo index eff84e67..ade9f787 100644 --- a/onchain/src/tests/art_peace.cairo +++ b/onchain/src/tests/art_peace.cairo @@ -1,6 +1,6 @@ use art_peace::{IArtPeaceDispatcher, IArtPeaceDispatcherTrait}; use art_peace::ArtPeace::InitParams; -use art_peace::templates::{ +use art_peace::templates::interfaces::{ ITemplateStoreDispatcher, ITemplateStoreDispatcherTrait, ITemplateVerifierDispatcher, ITemplateVerifierDispatcherTrait, TemplateMetadata };