You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// SPDX-License-Identifier: GPL-3.0pragma solidity>=0.7.0<0.9.0;
/** A reference implementation of EIP-2135 * * For simplicity, this reference implementation creates a super simple `issueTicket` function without * restriction on who can issue new tickets and under what condition a ticket can be issued. */contractTicket /* isERC2135, ERC721, ERC173, ERC165 */ {
addressprivate issuer;
mapping(uint256=>uint256) private ticketStates; /** 0 = unissued, 1 = issued, unconsumed, 2 = consumed); */mapping(uint256=>address) private ticketHolders;
constructor() {
issuer =msg.sender;
}
/** ERC 2135 */event OnConsumption(uint256_tockenId, address_consumer);
/** ERC 721 */event Transfer(addressindexed_from, addressindexed_to, uint256indexed_tokenId);
function transferFrom(address_from, address_to, uint256_tokenId) externalpayable {
require(_from ==msg.sender, "The sender must be the source of transfer.");
require(_from == ticketHolders[_tokenId], "The sender must hold the ticket.");
require(1== ticketStates[_tokenId], "The ticket must be issued but not consumed.");
ticketHolders[_tokenId] = _to;
emitTransfer(_from, _to, _tokenId);
return;
}
/** * ERC 2135 */function issueTicket(uint256_ticketId, address_receiver) publicreturns (boolsuccess) {
require (msg.sender== issuer, "Only ticket issuer can issue ticket.");
require (ticketStates[_ticketId] ==0, "The ticket address has been issued and not consumed yet, it cannot be issued again."); // ticket needs to be not issued yet;
ticketStates[_ticketId] =1;
ticketHolders[_ticketId] = _receiver;
returntrue;
}
/** * ERC 2135 */function consume(uint256_ticketId) publicreturns (boolsuccess) {
require (ticketHolders[_ticketId] ==msg.sender, "Only the current ticket holder can request to consume a ticket");
require (ticketStates[_ticketId] ==1, "The ticket needs to be issued but not consumed yet.");
ticketStates[_ticketId] =2;
emitOnConsumption(_ticketId, msg.sender);
returntrue;
}
/** * ERC 2135 */function isConsumable(uint256_ticketId) publicviewreturns (boolconsumable) {
return ticketStates[_ticketId] ==1;
}
}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: