From 26fec210b42ccde7c00b3a7e29b09322c8502062 Mon Sep 17 00:00:00 2001 From: loothero Date: Wed, 8 Nov 2023 23:11:23 +0000 Subject: [PATCH] adds snake case functions --- src/beasts.cairo | 49 ++++++++++++++++++++++++++++++++++++++++++++ src/interfaces.cairo | 18 +++++++++++++--- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/beasts.cairo b/src/beasts.cairo index 4cd0626..3c49d9c 100644 --- a/src/beasts.cairo +++ b/src/beasts.cairo @@ -231,10 +231,19 @@ mod Beasts { self._balances.read(account) } + fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { + assert(!account.is_zero(), 'Invalid account'); + self._balances.read(account) + } + fn ownerOf(self: @ContractState, tokenID: u256) -> ContractAddress { self._ownerOf(tokenID) } + fn owner_of(self: @ContractState, tokenID: u256) -> ContractAddress { + self._ownerOf(tokenID) + } + fn approve(ref self: ContractState, to: ContractAddress, tokenID: u256) { let owner = self._ownerOf(tokenID); @@ -250,17 +259,32 @@ mod Beasts { self._setApprovalForAll(get_caller_address(), operator, approved) } + fn set_approval_for_all(ref self: ContractState, operator: ContractAddress, approved: bool) { + self._setApprovalForAll(get_caller_address(), operator, approved) + } + fn getApproved(self: @ContractState, tokenID: u256) -> ContractAddress { assert(self._exists(tokenID), 'ERC721: invalid token ID'); self._tokenApprovals.read(tokenID) } + fn get_approved(self: @ContractState, tokenID: u256) -> ContractAddress { + assert(self._exists(tokenID), 'ERC721: invalid token ID'); + self._tokenApprovals.read(tokenID) + } + fn isApprovedForAll( self: @ContractState, owner: ContractAddress, operator: ContractAddress ) -> bool { self._operatorApprovals.read((owner, operator)) } + fn is_approved_for_all( + self: @ContractState, owner: ContractAddress, operator: ContractAddress + ) -> bool { + self._operatorApprovals.read((owner, operator)) + } + fn transferFrom( ref self: ContractState, from: ContractAddress, to: ContractAddress, tokenID: u256 ) { @@ -268,20 +292,41 @@ mod Beasts { self._transfer(from, to, tokenID); } + fn transfer_from( + ref self: ContractState, from: ContractAddress, to: ContractAddress, tokenID: u256 + ) { + assert(self._isApprovedOrOwner(get_caller_address(), tokenID), 'Unauthorized caller'); + self._transfer(from, to, tokenID); + } + fn tokenURI(self: @ContractState, tokenID: u256) -> Array:: { assert(self._exists(tokenID), 'Invalid token ID'); let beast = self._beast.read(tokenID); get_content(beast) } + fn token_uri(self: @ContractState, tokenID: u256) -> Array:: { + assert(self._exists(tokenID), 'Invalid token ID'); + let beast = self._beast.read(tokenID); + get_content(beast) + } + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { self._supportsInterface(interfaceId) } + fn supports_interface(self: @ContractState, interfaceId: felt252) -> bool { + self._supportsInterface(interfaceId) + } + fn registerInterface(ref self: ContractState, interface_id: felt252) { self._registerInterface(interface_id); } + fn register_interface(ref self: ContractState, interface_id: felt252) { + self._registerInterface(interface_id); + } + fn setMinter(ref self: ContractState, to: ContractAddress) { self._assertOnlyOwner(); self._whitelist.write(to); @@ -321,6 +366,10 @@ mod Beasts { self._tokenIndex.read() } + fn token_supply(self: @ContractState) -> u256 { + self._tokenIndex.read() + } + fn mintGenesisBeasts(ref self: ContractState, to: ContractAddress) { self._assertOnlyOwner(); assert(self._genesis_mint.read() == false, 'Already minted'); diff --git a/src/interfaces.cairo b/src/interfaces.cairo index 7de45c4..27e4a7d 100644 --- a/src/interfaces.cairo +++ b/src/interfaces.cairo @@ -12,23 +12,35 @@ trait IBeasts { fn name(self: @T) -> felt252; fn symbol(self: @T) -> felt252; fn balanceOf(self: @T, account: ContractAddress) -> u256; + fn balance_of(self: @T, account: ContractAddress) -> u256; fn ownerOf(self: @T, tokenID: u256) -> ContractAddress; + fn owner_of(self: @T, tokenID: u256) -> ContractAddress; fn transferFrom(ref self: T, from: ContractAddress, to: ContractAddress, tokenID: u256); + fn transfer_from(ref self: T, from: ContractAddress, to: ContractAddress, tokenID: u256); fn approve(ref self: T, to: ContractAddress, tokenID: u256); fn setApprovalForAll(ref self: T, operator: ContractAddress, approved: bool); + fn set_approval_for_all(ref self: T, operator: ContractAddress, approved: bool); fn getApproved(self: @T, tokenID: u256) -> ContractAddress; + fn get_approved(self: @T, tokenID: u256) -> ContractAddress; fn isApprovedForAll(self: @T, owner: ContractAddress, operator: ContractAddress) -> bool; + fn is_approved_for_all(self: @T, owner: ContractAddress, operator: ContractAddress) -> bool; + fn tokenURI(self: @T, tokenID: u256) -> Array::; + fn token_uri(self: @T, tokenID: u256) -> Array::; + fn tokenSupply(self: @T) -> u256; + fn token_supply(self: @T) -> u256; // ERC165 fn supportsInterface(self: @T, interfaceId: felt252) -> bool; + fn supports_interface(self: @T, interfaceId: felt252) -> bool; fn registerInterface(ref self: T, interface_id: felt252); + fn register_interface(ref self: T, interface_id: felt252); // Core functions fn mintGenesisBeasts(ref self: T, to: ContractAddress); fn setMinter(ref self: T, to: ContractAddress); fn getMinter(self: @T) -> ContractAddress; - fn mint(ref self: T, to: ContractAddress, beast: u8, prefix: u8, suffix: u8, level: u16, health: u16); + fn mint( + ref self: T, to: ContractAddress, beast: u8, prefix: u8, suffix: u8, level: u16, health: u16 + ); fn isMinted(self: @T, beast: u8, prefix: u8, suffix: u8) -> bool; - fn tokenURI(self: @T, tokenID: u256) -> Array::; - fn tokenSupply(self: @T) -> u256; }