-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add template quest contract and check is_claimable
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use art_peace::templates::interfaces::{ | ||
ITemplateStoreDispatcher, ITemplateStoreDispatcherTrait, ITemplateVerifierDispatcher, | ||
ITemplateVerifierDispatcherTrait, TemplateMetadata | ||
}; | ||
|
||
#[starknet::contract] | ||
pub mod TemplateQuest { | ||
use starknet::{ContractAddress, get_caller_address}; | ||
use art_peace::{IArtPeaceDispatcher, IArtPeaceDispatcherTrait}; | ||
use art_peace::quests::{IQuest, QuestClaimed}; | ||
|
||
#[storage] | ||
struct Storage { | ||
art_peace: IArtPeaceDispatcher, | ||
reward: u32, | ||
claimed: LegacyMap<ContractAddress, bool>, | ||
} | ||
|
||
|
||
#[abi(embed_v0)] | ||
impl TemplateQuest of IQuest<ContractState> { | ||
fn get_reward(self: @ContractState) -> u32 { | ||
self.reward.read() | ||
} | ||
|
||
fn is_claimable( | ||
self: @ContractState, user: ContractAddress, calldata: Span<felt252> | ||
) -> bool { | ||
let art_peace = self.art_peace.read(); | ||
|
||
if self.claimed.read(user) { | ||
return false; | ||
} | ||
|
||
let template_store = ITemplateStoreDispatcher { contract_address: art_peace.contract_address }; | ||
|
||
let template_id = calldata[0]; | ||
|
||
let template = template_store.get_template(template_id); | ||
|
||
if template.creator != user { | ||
return false; | ||
} | ||
|
||
return true; | ||
|
||
} | ||
|
||
fn claim(ref self: ContractState, user: ContractAddress, calldata: Span<felt252>) -> u32 { | ||
assert( | ||
get_caller_address() == self.art_peace.read().contract_address, | ||
'Only ArtPeace can claim quests' | ||
); | ||
// TODO: should we revert if the quest is not claimable? | ||
if !self.is_claimable(user, calldata) { | ||
return 0; | ||
} | ||
|
||
self.claimed.write(user, true); | ||
let reward = self.reward.read(); | ||
self.emit(QuestClaimed { user, reward, calldata }); | ||
|
||
reward | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters