Skip to content

Commit

Permalink
feat: add more function to eventNFT (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Immanuelolivia1 authored Dec 1, 2024
1 parent 4b239c9 commit e426af4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
32 changes: 17 additions & 15 deletions src/events/eventnft.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/// @title Event NFT Contract for managing event-specific non-fungible tokens
/// @notice This contract implements functionality for minting and burning event-specific NFTs
/// @dev Implements ERC721 and SRC5 standards using OpenZeppelin components
#[starknet::contract]
pub mod EventNFT {
use starknet::{ContractAddress, get_block_timestamp};
Expand Down Expand Up @@ -31,8 +28,6 @@ pub mod EventNFT {
// *************************************************************************
// EVENTS
// *************************************************************************
/// @notice Events emitted by the contract
/// @dev Combines ERC721 and SRC5 events
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
Expand All @@ -42,8 +37,6 @@ pub mod EventNFT {
SRC5Event: SRC5Component::Event
}

/// @notice Contract storage structure
/// @dev Includes ERC721 and SRC5 storage along with custom mappings
#[storage]
struct Storage {
#[substorage(v0)]
Expand All @@ -56,9 +49,6 @@ pub mod EventNFT {
event_id: u256
}

/// @notice Initializes the EventNFT contract
/// @param event_id The unique identifier for the event this NFT collection represents
/// @dev Sets up the initial state of the contract
#[constructor]
fn constructor(ref self: ContractState, event_id: u256) {
self.event_id.write(event_id);
Expand All @@ -68,8 +58,6 @@ pub mod EventNFT {
impl eventnft of IEventNFT<ContractState> {
/// @notice mints an event NFT
/// @param address address of user trying to mint the event NFT token
/// @return The ID of the newly minted token
/// @dev Reverts if the user already has an NFT from this collection
fn mint_nft(ref self: ContractState, user_address: ContractAddress) -> u256 {
let balance = self.erc721.balance_of(user_address);
assert(balance.is_zero(), ALREADY_MINTED);
Expand All @@ -84,10 +72,24 @@ pub mod EventNFT {
self.last_minted_id.read()
}

fn get_user_token_id(self: @ContractState, user_address: ContractAddress) -> u256 {
self.user_token_id.read(user_address)
}

fn name(self: @ContractState) -> ByteArray {
self.erc721.name()
}

fn symbol(self: @ContractState) -> ByteArray {
self.erc721.symbol()
}

fn token_uri(self: @ContractState, token_id: u256) -> ByteArray {
self.erc721.token_uri(token_id)
}

/// @notice burns a community NFT
/// @param user_address address of user trying to burn the community NFT token
/// @param token_id The ID of the token to burn
/// @dev Reverts if the token doesn't exist or if the user isn't the owner
/// @param address address of user trying to burn the community NFT token
fn burn_nft(ref self: ContractState, user_address: ContractAddress, token_id: u256) {
let user_token_id = self.user_token_id.read(user_address);
assert(user_token_id == token_id, NOT_TOKEN_OWNER);
Expand Down
7 changes: 4 additions & 3 deletions src/interfaces/IEventNFT.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use starknet::ContractAddress;

/// @title Event NFT Interface
/// @notice Interface for minting and burning event-specific NFTs
/// @dev Implements basic NFT functionality for event attendance tracking
#[starknet::interface]
pub trait IEventNFT<TContractState> {
fn mint_nft(ref self: TContractState, user_address: ContractAddress) -> u256;
fn burn_nft(ref self: TContractState, user_address: ContractAddress, token_id: u256);
fn get_user_token_id(self: @TContractState, user_address: ContractAddress) -> u256;
fn name(self: @TContractState) -> ByteArray;
fn symbol(self: @TContractState) -> ByteArray;
fn token_uri(self: @TContractState, token_id: u256) -> ByteArray;
}

0 comments on commit e426af4

Please sign in to comment.