-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add template quest contract and check is_claimable #61
Merged
b-j-roberts
merged 13 commits into
keep-starknet-strange:main
from
mubarak23:ft_add_template_quest
Apr 23, 2024
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
77e5c00
add template quest contract and check is_claimable
mubarak23 ee63bd4
scrab format
mubarak23 04ff210
move dispachers and reward into a constructor
mubarak23 b0206f0
remove template_store
mubarak23 379108c
make art_peace in storage of type contract address
mubarak23 577dbe1
use component decleration
mubarak23 d906c97
test for test_get_reward
mubarak23 32359bd
test for is_claimable
mubarak23 81102f3
test claim function
mubarak23 9c3d028
Merge branch 'main' into ft_add_template_quest
mubarak23 a9698d3
fix scrap format
mubarak23 5fdb074
Patch tests and template quest storage to remove template store, move…
b-j-roberts a8895cb
Resolve merge conflicts
b-j-roberts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,80 @@ | ||
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>, | ||
template_store: ITemplateStoreDispatcher | ||
} | ||
|
||
#[derive(Drop, Serde)] | ||
pub struct TemplateQuestInitParams { | ||
pub art_peace: ContractAddress, | ||
pub reward: u32, | ||
pub template_store: ContractAddress | ||
mubarak23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState, init_params: TemplateQuestInitParams,) { | ||
self.art_peace.write(IArtPeaceDispatcher { contract_address: init_params.art_peace }); | ||
self.reward.write(init_params.reward); | ||
self | ||
.template_store | ||
.write(ITemplateStoreDispatcher { contract_address: init_params.template_store }); | ||
} | ||
b-j-roberts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
#[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_id = calldata[0]; | ||
|
||
let template = self.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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to store this as a
ContractAddress
and have a separate storage slot forITemplateStoreDispatcher
since you won't be using theIArtPeaceDispatcher
for anything.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean having
art_peace: ContractAddress
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's right