Skip to content

Commit

Permalink
Improve hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
gianalarcon committed Aug 26, 2024
1 parent 6271a7e commit eee45b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion packages/snfoundry/contracts/src/YourCollectible.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod YourCollectible {
component!(path: CounterComponent, storage: token_id_counter, event: CounterEvent);
component!(path: ERC721EnumerableComponent, storage: enumerable, event: EnumerableEvent);

// Expose entrypoints
#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
#[abi(embed_v0)]
Expand All @@ -39,6 +40,7 @@ mod YourCollectible {
impl ERC721EnumerableImpl =
ERC721EnumerableComponent::ERC721EnumerableImpl<ContractState>;

// Use internal implementations but do not expose them
impl ERC721InternalImpl = ERC721Component::InternalImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

Expand Down Expand Up @@ -154,7 +156,7 @@ mod YourCollectible {
token_id: u256,
auth: ContractAddress
) {
let mut counter_component = get_dep_component_mut!(ref self, Counter);
let counter_component = get_dep_component!(@self, Counter);
let token_id_counter = counter_component.current();
let mut enumerable_component = get_dep_component_mut!(ref self, ERC721Enumerable);
if (token_id == token_id_counter) { // `Mint Token` case: Add token to `all_tokens` enumerable component
Expand Down
8 changes: 4 additions & 4 deletions packages/snfoundry/contracts/src/components/Counter.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[starknet::interface]
pub trait ICounter<T> {
fn current(self: @T) -> u256;
fn increment(ref self: T);
fn decrement(ref self: T);
pub trait ICounter<TState> {
fn current(self: @TState) -> u256;
fn increment(ref self: TState);
fn decrement(ref self: TState);
}

#[starknet::component]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use starknet::ContractAddress;

#[starknet::interface]
pub trait IERC721Enumerable<T> {
fn token_of_owner_by_index(self: @T, owner: ContractAddress, index: u256) -> u256;
fn total_supply(self: @T) -> u256;
pub trait IERC721Enumerable<TState> {
fn token_of_owner_by_index(self: @TState, owner: ContractAddress, index: u256) -> u256;
fn total_supply(self: @TState) -> u256;
}

#[starknet::component]
Expand Down

0 comments on commit eee45b4

Please sign in to comment.