在 OpenSea 中转移 ERC721 代币时如何执行内部函数?

时间:2021-05-10 00:52:11

标签: ethereum

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract Ticket is ERC721 {
    // Mapping from ticket holder to ticket QR code
    mapping(uint256 => bytes32) private _tokenIdQRcodeMapping;

    // Number of ticket are minted
    uint256 private _ticketCount = 0;

    // Metadata base url
    string private _theBaseURI;
    constructor(string memory __theBaseURI) ERC721("Ticket", "Ticket") {
        _theBaseURI = __theBaseURI;
    }

    // function _baseURI() internal override view returns (string memory) {
    //     return _theBaseURI;
    // }

    // getter
    function getQRcode(uint256 _tokenId) internal view returns (bytes32) {
        return _tokenIdQRcodeMapping[_tokenId];
    }

    function getTicketCount() public view returns (uint256) {
        return _ticketCount;
    }

    /**
    * @dev renew QRcode with token id and new address
    * Requirements:
    *
    * - `tokenId` must not exist.
    * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
    *
    */

    function renewQRcode(uint256 _tokenId, address _newTicketHolder) public{
        require(
            _tokenIdQRcodeMapping[_tokenId] != bytes32(0),
            "token need to exist"
        );
        require(
            _newTicketHolder != address(0),
            "newTicketHolder need to be no null"
        );
        require(
            msg.sender == ownerOf(_tokenId),
            "msg.sender need to be holder to change QRcode"
        );
        _tokenIdQRcodeMapping[_tokenId] = keccak256(
            abi.encodePacked(block.timestamp, _newTicketHolder, _ticketCount)
        );
    }

    /**
    * @dev mint ticket with no args
    * Requirements:
    *
    * - `tokenId` must not exist.
    * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
    *
    */
    function mint() public {
        _safeMint(msg.sender, _ticketCount);
        // add qrcode
        _tokenIdQRcodeMapping[_ticketCount] = keccak256(
            abi.encodePacked(block.timestamp, msg.sender, _ticketCount)
        );
        _ticketCount += 1;
    }
}

开海: https://testnets.opensea.io/assets/0xc0e6c6540ffc11d9e9da78bc0cb280fc70ad4f08/1

以太扫描: https://rinkeby.etherscan.io/token/0xC0E6c6540fFc11D9e9DA78bC0cB280Fc70Ad4f08

问题 1: 我在 Rinkeby 测试网部署了一个票据合约,并将它们放在 opensea 中。但是,当传输成功时,OpenSea 并没有执行传输功能。为什么?

问题 2: 我想在OpenSea 中转移Token 时执行renewQRcode 功能。怎么办?

0 个答案:

没有答案