registerEvent

This function facilitates the registration of an event within the Decast Gating. It requires several parameters:

  • userAddress: This parameter takes Event Manager Address for event registration.

  • eventId: This parameter serves as the unique identifier for the event, distinguishing it from others within the contract.

  • accessLevels: An array containing the names of different access levels associated with the event, representing various ticket tiers or privileges.

  • ticketPrices: An array containing the corresponding ticket prices for each access level, allowing organizers to set different prices based on access level.

  • whitelist: An array indicating whether each access level requires whitelisting; if an access level requires whitelisting, only specified addresses can purchase tickets for that level.

/**
 * @notice Register an event with the given event ID, ticket prices, access levels, and whitelist.
 * @param userAddress The address of the event manager.
 * @param eventId The unique identifier for the event.
 * @param accessLevels Array of access levels associated with the event.
 * @param ticketPrices Array of ticket prices for different access levels of the event.
 * @param whitelist Array indicating whether each access level requires whitelisting.
 */
function registerEvent(
    address userAddress,
    string calldata eventId,
    string[] calldata accessLevels,
    uint256[] calldata ticketPrices,
    bool[] calldata whitelist
) external onlyOwner {
    // Check if the event ID already exists
    if (getTokenIdsFromEventId(eventId).length > 0 || getAccessLevelsFromEventId(eventId).length > 0) {
        revert DecastGating__EventIdAlreadyExists();
    }

    // Ensure input array lengths match
    if (ticketPrices.length != accessLevels.length || accessLevels.length != whitelist.length) {
        revert DecastGating__UnmatchedArrayLength();
    }

    // Initialize an array to store generated token IDs
    uint256[] memory tokenIdsGeneration = new uint256[](accessLevels.length);

    // Generate token IDs for each access level and perform necessary checks
    for (uint256 i = 0; i < accessLevels.length; ++i) {
        uint256 tokenId = generateTokenId(eventId, userAddress, accessLevels[i]);

        // Check if the generated token ID already exists for the event
        if (checkTokenIdExistsForEventId(eventId, tokenId)) {
            revert DecastGating__TokenIdAlreadyExists();
        }

        tokenIdsGeneration[i] = tokenId;
    }

    // Update storage mappings
    for (uint256 i = 0; i < accessLevels.length; ++i) {
        uint256 tokenId = tokenIdsGeneration[i];

        // Update event-specific mappings
        s_eventIdToTokenIds[eventId].push(tokenId);
        s_eventIdToAccessLevels[eventId].push(accessLevels[i]);
        s_tokenIdToTicketPrice[tokenId] = ticketPrices[i];
        s_tokenIdToWhitelist[tokenId] = whitelist[i];
    }

    // Mint a token for the event manager
    uint256 eventManagerTokenId = getTokenIdOfAnEventManager(eventId);
    _mint(userAddress, eventManagerTokenId, 1, "");
}

Explanation:

The function first checks if the lengths of the input arrays match to ensure consistency in the provided data. If the lengths do not match, indicating inconsistent input, the function reverts the transaction with a custom error message.

Next, the function initializes an array to store the generated token IDs for each access level. It then iterates through each access level, generating a unique token ID using the generateTokenId function. Before generating a token ID, it checks if the generated token ID already exists for the event to prevent duplicates. If a duplicate is found, the function reverts the transaction with an error message indicating that the token ID already exists.

After successfully generating unique token IDs for each access level, the function updates the storage mappings with the event-specific information, including token IDs, access levels, ticket prices, and whitelisting requirements.

Finally, the function mints a token for the event manager using the _mint(ERC1155 inBuilt) function, assigning them the appropriate permissions. If the token IDs are unable to be generated for the given event ID, the function reverts the transaction with an error message indicating the inability to generate token IDs.

Last updated