๐Ÿ“š - Playerself Registry

Explaining the registry rationale

The Playerself Registry is one of the main and core Playerself contracts, although not having so many code lines. By exploiting his functionalities, we can register which NFTs (whether they are ERC-721 or ERC-1155) can be sold in our PlayerselfAuctions contract.

"Why did you take this approach? Why didn't you leave anyone sell their contracts?"

Those are fairly legitimate questions, and even if our NFTs are completely interoperable with other marketplaces, we didn't feel the need to clunk up our platform with content that may not fit in: our ecosystem is still open to whoever is an active player (fan, content creator, esports player, agencies, etc.) of the gaming entertainment world, but leaving the possibility to everyone, even to who's not part of the community, to list their NFTs didn't really make any sense.

All the products (and services) listed in our marketplace are created by people inside the community that work with us to expand this huge ecosystem that we're trying to build: just reach out to us with your idea and we can work it out!

IPlayerselfRegistry.sol

This is the interface for the PlayerselfRegistry contract; how it works is explained in the following paragraph, where we present the implementation.

IPlayerselfRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

interface IPlayerselfRegistry {

    struct NFT {
        bool enabled;
        bool supportsBatch;
    }

    function isSupported(address addr) external view returns(bool);
    function getNFT(address addr) external view returns (NFT memory);

}

PlayerselfRegistry.sol

This is the implementation of the IPlayerselfRegistry interface.

PlayerselfRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

import "./interfaces/IPlayerselfRegistry.sol";

contract PlayerselfRegistry is IPlayerselfRegistry {
    address private _owner;
    mapping(address => NFT) private _contracts;

    event NFTRegistered(address indexed contractAddress, bool supportsBatch);
    event NFTDisabled(address indexed contractAddress);

    constructor() {
        _owner = msg.sender;
    }

    modifier _onlyOwner() {
        require(msg.sender == _owner, 'Unauthorized.');
        _;
    }

    function setContract(address addr, bool supportsBatch) public _onlyOwner {
        require(addr != address(0), "Invalid address.");
        if (_contracts[addr].enabled) {
            emit NFTDisabled(addr);
        } else {
            emit NFTRegistered(addr, supportsBatch);
        }
        _contracts[addr] = NFT(!_contracts[addr].enabled, supportsBatch);
    }

    function isSupported(address addr) override public view returns (bool) {
        return _contracts[addr].enabled;
    }

    function getNFT(address addr) override public view returns (NFT memory) {
        return _contracts[addr];
    }
}

The contract has, obviously, an owner which is our wallet that deploys this contract; the owner is allowed to call the setContract function to enable/disable an NFT contract address for the PlayerselfAuctions contract.

The NFT struct has also another parameter, "supportsBatch", that allows us to discriminate ERC-1155 from ERC-721; in other words, if the parameter is set as true we will use the common batch transfer functions of the NFT contract; otherwise we'll call the safeTransferFrom.

The isSupported and getNFT methods are pretty self-explainatory: the first returns true if the given address is of a supported NFT contract; the latter returns the NFT struct for the given address.

Last updated