Skip to content

Commit

Permalink
add supply
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones committed Nov 4, 2024
1 parent ff0f73b commit 89c4121
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod MyToken {
#[substorage(v0)]
ownable: OwnableComponent::Storage,
beasts_stats: Map<u256, BeastStats>,
total_supply: u256,
}

#[event]
Expand Down Expand Up @@ -102,12 +103,15 @@ mod MyToken {
fn safe_mint(
ref self: ContractState,
recipient: ContractAddress,
token_id: u256,
beast_stats: BeastStats,
data: Span<felt252>,
) {
self.ownable.assert_only_owner();
self.erc721.safe_mint(recipient, token_id, data);

let total_supply = self.total_supply.read();
let token_id = total_supply + 1;
self.total_supply.write(token_id);

self.erc721.safe_mint(recipient, token_id, array![].span());
self.beasts_stats.entry(token_id).write(BeastStats {
tier: beast_stats.tier,
level: beast_stats.level,
Expand All @@ -121,11 +125,9 @@ mod MyToken {
fn safeMint(
ref self: ContractState,
recipient: ContractAddress,
tokenId: u256,
beast_stats: BeastStats,
data: Span<felt252>,
) {
self.safe_mint(recipient, tokenId, beast_stats, data);
self.safe_mint(recipient, beast_stats);
}

#[external(v0)]
Expand All @@ -143,5 +145,19 @@ mod MyToken {
) -> BeastStats {
self.beasts_stats.entry(tokenId).read()
}

#[external(v0)]
fn total_supply(
self: @ContractState,
) -> u256 {
self.total_supply.read()
}

#[external(v0)]
fn totalSupply(
self: @ContractState,
) -> u256 {
self.total_supply.read()
}
}
}

0 comments on commit 89c4121

Please sign in to comment.