-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
356 additions
and
141 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
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
File renamed without changes.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "arcade_trophy" | ||
name = "achievement" | ||
version.workspace = true | ||
|
||
[dependencies] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#[starknet::component] | ||
mod PinnableComponent { | ||
// Core imports | ||
|
||
use core::debug::PrintTrait; | ||
|
||
// Dojo imports | ||
|
||
use dojo::world::WorldStorage; | ||
|
||
// Internal imports | ||
|
||
use achievement::store::{Store, StoreTrait}; | ||
|
||
// Errors | ||
|
||
mod errors {} | ||
|
||
// Storage | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
// Events | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event {} | ||
|
||
#[generate_trait] | ||
impl InternalImpl< | ||
TContractState, +HasComponent<TContractState> | ||
> of InternalTrait<TContractState> { | ||
fn pin( | ||
self: @ComponentState<TContractState>, | ||
world: WorldStorage, | ||
player_id: felt252, | ||
achievement_id: felt252, | ||
) { | ||
// [Setup] Store | ||
let store: Store = StoreTrait::new(world); | ||
|
||
// [Event] Emit achievement creation | ||
let time = starknet::get_block_timestamp(); | ||
store.pin(player_id, achievement_id, time); | ||
} | ||
|
||
fn unpin( | ||
self: @ComponentState<TContractState>, | ||
world: WorldStorage, | ||
player_id: felt252, | ||
achievement_id: felt252, | ||
) { | ||
let store: Store = StoreTrait::new(world); | ||
store.unpin(player_id, achievement_id); | ||
} | ||
} | ||
} |
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
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,57 @@ | ||
// Internal imports | ||
|
||
use achievement::events::index::TrophyPinning; | ||
|
||
// Errors | ||
|
||
pub mod errors { | ||
pub const PINNING_INVALID_ID: felt252 = 'Pinning: invalid id'; | ||
} | ||
|
||
// Implementations | ||
|
||
#[generate_trait] | ||
impl PinningImpl of PinningTrait { | ||
#[inline] | ||
fn new(player_id: felt252, achievement_id: felt252, time: u64) -> TrophyPinning { | ||
// [Check] Inputs | ||
PinningAssert::assert_valid_id(achievement_id); | ||
// [Return] Pinning | ||
TrophyPinning { player_id, achievement_id, time } | ||
} | ||
} | ||
|
||
#[generate_trait] | ||
impl PinningAssert of AssertTrait { | ||
#[inline] | ||
fn assert_valid_id(achievement_id: felt252) { | ||
assert(achievement_id != 0, errors::PINNING_INVALID_ID); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
// Local imports | ||
|
||
use super::PinningTrait; | ||
|
||
// Constants | ||
|
||
const PLAYER_ID: felt252 = 'PLAYER'; | ||
const ACHIEVEMENT_ID: felt252 = 'ACHIEVEMENT'; | ||
const TIME: u64 = 1000000000; | ||
|
||
#[test] | ||
fn test_pinning_new() { | ||
let pinning = PinningTrait::new(PLAYER_ID, ACHIEVEMENT_ID, TIME,); | ||
assert_eq!(pinning.player_id, PLAYER_ID); | ||
assert_eq!(pinning.achievement_id, ACHIEVEMENT_ID); | ||
assert_eq!(pinning.time, TIME); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: ('Pinning: invalid id',))] | ||
fn test_pinning_new_invalid_id() { | ||
PinningTrait::new(PLAYER_ID, 0, TIME); | ||
} | ||
} |
Oops, something went wrong.