From 89c41210147c4517b687dd440ee01ae3bc374a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Pi=C3=B1ones?= Date: Mon, 4 Nov 2024 17:21:40 -0300 Subject: [PATCH] add supply --- src/lib.cairo | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/lib.cairo b/src/lib.cairo index c68f8f8..5527a49 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -48,6 +48,7 @@ mod MyToken { #[substorage(v0)] ownable: OwnableComponent::Storage, beasts_stats: Map, + total_supply: u256, } #[event] @@ -102,12 +103,15 @@ mod MyToken { fn safe_mint( ref self: ContractState, recipient: ContractAddress, - token_id: u256, beast_stats: BeastStats, - data: Span, ) { 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, @@ -121,11 +125,9 @@ mod MyToken { fn safeMint( ref self: ContractState, recipient: ContractAddress, - tokenId: u256, beast_stats: BeastStats, - data: Span, ) { - self.safe_mint(recipient, tokenId, beast_stats, data); + self.safe_mint(recipient, beast_stats); } #[external(v0)] @@ -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() + } } }