mintTicket
This function enables the minting of tickets for specified recipients, events, access levels, and ticket amounts. It takes four parameters:
_to
: An array containing the addresses of recipients for whom tickets are to be minted._eventIds
: An array containing the unique identifiers for the events for which tickets are to be minted._accessLevels
: An array containing the access levels associated with the tickets being minted._amounts
: An array containing the amounts of tickets to be minted for each recipient.
// Some code
```remix-solidity
/**
MintTicket: Mint tickets for the specified recipients, events, access levels, and amounts.
@param _to: Array of recipient addresses for whom tickets are to be minted.
@param _eventIds: Array of event IDs for which tickets are to be minted.
@param _accessLevels: Array of access levels for the tickets being minted.
@param _amounts: Array of amounts of tickets to be minted for each recipient.
Format: to, eventIds, accessLevels, amounts
*/
function mintTicket(
address[] calldata _to,
string[] calldata _eventIds,
string[] calldata _accessLevels,
uint256[] calldata _amounts
) public nonReentrant {
// Check if the lengths of input arrays match
if (!checkLengths(_to, _eventIds, _accessLevels, _amounts))
revert DecastGating__UnmatchedArrayLength();
// Iterate through each recipient
for (uint256 i = 0; i < _to.length; ++i) {
// Get the token ID for the specified event and access level
uint256 _tokenId = getTokenIdOfAccessLevel(
_eventIds[i],
_accessLevels[i]
);
// Check if the ticket price is greater than 0, indicating a paid ticket
if (getTicketPriceFromTokenId(_tokenId) > 0)
revert DecastGating__PaidTicket();
// Check if the recipient address is valid
if (_to[i] == address(0))
revert DecastGating__InvalidInputAddress();
// Check if the amount of tickets is valid
if (_amounts[i] <= 0) revert DecastGating__InvalidInputAmount();
// Check if the token ID exists for the specified event
if (!checkTokenIdExistsForEventId(_eventIds[i], _tokenId))
revert DecastGating__TokenIdDoesNotExists();
// Mint the ticket
_mintTicket(_eventIds[i], _to[i], _tokenId, _amounts[i]);
}
}
```
Explanation:
The function begins by checking if the lengths of the input arrays match using the checkLengths
function. If the lengths do not match, indicating inconsistent input, the function reverts the transaction with a custom error message.
Next, the function iterates through each recipient address in the _to
array. For each recipient, it retrieves the corresponding token ID for the specified event and access level using the getTokenIdOfAccessLevel
function. It then checks if the ticket price associated with the token ID is greater than 0, which indicates a paid ticket. If a paid ticket is found, the function reverts the transaction with an error message indicating that paid tickets cannot be minted using this function.
Subsequently, the function verifies the validity of the recipient address, ensuring it is not a null address. It also checks if the amount of tickets to be minted is greater than 0, preventing the minting of invalid amounts. Additionally, it confirms whether the token ID exists for the specified event. If the token ID does not exist, indicating an invalid event or access level combination, the function reverts the transaction with an appropriate error message.
Finally, if all checks pass, the function calls the _mintTicket
internal function to mint the specified amount of tickets for the recipient, event, and access level.
Last updated