Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds snake case functions #14

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/beasts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -250,38 +259,74 @@ 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
) {
assert(self._isApprovedOrOwner(get_caller_address(), tokenID), 'Unauthorized caller');
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::<felt252> {
assert(self._exists(tokenID), 'Invalid token ID');
let beast = self._beast.read(tokenID);
get_content(beast)
}

fn token_uri(self: @ContractState, tokenID: u256) -> Array::<felt252> {
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);
Expand Down Expand Up @@ -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');
Expand Down
18 changes: 15 additions & 3 deletions src/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,35 @@ trait IBeasts<T> {
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::<felt252>;
fn token_uri(self: @T, tokenID: u256) -> Array::<felt252>;
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::<felt252>;
fn tokenSupply(self: @T) -> u256;
}