Skip to content

Commit

Permalink
Light refactoring
Browse files Browse the repository at this point in the history
- isMinted() doesn't need reference to contract state
- Use 'minter' instead of allowlist since there will only be one address
- Remove owner as a valid minter as this isn't expectted
- Change mintGenesis to mintGenesisBeasts to be more descriptive
  • Loading branch information
loothero committed Sep 23, 2023
1 parent 05ee567 commit fb9efb3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
12 changes: 5 additions & 7 deletions src/beasts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,16 @@ mod Beasts {
self._registerInterface(interface_id);
}

fn whitelist(ref self: ContractState, to: ContractAddress) {
fn setMinter(ref self: ContractState, to: ContractAddress) {
self._assertOnlyOwner();
self._whitelist.write(to);
}

fn getWhitelist(self: @ContractState) -> ContractAddress {
fn getMinter(self: @ContractState) -> ContractAddress {
return self._whitelist.read();
}

fn isMinted(ref self: ContractState, beast: u8, prefix: u8, suffix: u8) -> bool {
fn isMinted(self: @ContractState, beast: u8, prefix: u8, suffix: u8) -> bool {
self._minted.read(get_hash(beast, prefix, suffix))
}

Expand All @@ -304,9 +304,7 @@ mod Beasts {
) {
assert(!to.is_zero(), 'Invalid receiver');
let caller: ContractAddress = get_caller_address();
assert(
caller == self.owner() || caller == self.getWhitelist(), 'Not owner or whitelist'
);
assert(caller == self.getMinter(), 'Not authorized to mint');
assert(!self.isMinted(beast, prefix, suffix), 'Already minted');
let current: u256 = self._tokenIndex.read();

Expand All @@ -321,7 +319,7 @@ mod Beasts {
self._tokenIndex.read()
}

fn mintGenesis(ref self: ContractState, to: ContractAddress) {
fn mintGenesisBeasts(ref self: ContractState, to: ContractAddress) {
self._assertOnlyOwner();

let mut id = 1;
Expand Down
10 changes: 5 additions & 5 deletions src/interfaces.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use starknet::ContractAddress;

// LeetLoot interface
// contract interface
#[starknet::interface]
trait IBeasts<T> {
// Ownership
Expand All @@ -24,11 +24,11 @@ trait IBeasts<T> {
fn registerInterface(ref self: T, interface_id: felt252);

// Core functions
fn whitelist(ref self: T, to: ContractAddress);
fn getWhitelist(self: @T) -> ContractAddress;
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);
fn isMinted(ref self: T, beast: u8, prefix: u8, suffix: u8) -> bool;
fn isMinted(self: @T, beast: u8, prefix: u8, suffix: u8) -> bool;
fn tokenURI(self: @T, tokenID: u256) -> Array::<felt252>;
fn tokenSupply(self: @T) -> u256;
fn mintGenesis(ref self: T, to: ContractAddress);
}
2 changes: 1 addition & 1 deletion src/tests/deploy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod tests {
let contract = deploy();
let owner = contract.owner();

contract.mintGenesis(owner);
contract.mintGenesisBeasts(owner);
assert(starknet::get_caller_address() == owner, 'Wrong caller');
assert(contract.tokenSupply() == 75, 'Wrong supply');
}
Expand Down

0 comments on commit fb9efb3

Please sign in to comment.