账户
0xbb...3452
0xbB...3452

0xbB...3452

US$0.00
此合同的源代码已经过验证!
合同元数据
编译器
0.8.26+commit.8a97fa7a
语言
Solidity
合同源代码
文件 1 的 3:Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
合同源代码
文件 2 的 3:MonstroNFTProps.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import "@openzeppelin/contracts/access/Ownable.sol";

/**
 * @title MonstroNFTProps
 * @dev A simplified contract to associate string properties with NFT token IDs.
 */
contract MonstroNFTProps is Ownable {
    struct Property {
        string name;
        mapping(uint256 => string) values; // Maps tokenId to property value
    }

    Property[] public properties; // Array of properties
    mapping(string => uint256) private propertyIndexes; // Maps property names to their index
    mapping(address => bool) private _whitelist; // Whitelist for access control
    address[] private _whitelistedAddresses; // Track all whitelisted addresses

    event PropertyAdded(string name, uint256 index);
    event PropertyUpdated(uint256 tokenId, string propertyName, string value);
    event PropertiesUpdated(uint256 indexed tokenId, string[25] propertyNames, string[25] values);
    event WhitelistUpdated(address account, bool status);

    modifier onlyWhitelisted() {
        require(_whitelist[msg.sender], "Caller is not whitelisted");
        _;
    }

    /**
     * @dev Constructor initializes the owner in the whitelist.
     */
    constructor() Ownable(msg.sender) {
        _whitelist[msg.sender] = true;
        _whitelistedAddresses.push(msg.sender);
    }

    /**
     * @dev Adds a new property.
     * @param propertyName Name of the new property.
     */
    function addProperty(string memory propertyName) external onlyOwner {
        require(propertyIndexes[propertyName] == 0 && (properties.length == 0 || keccak256(bytes(properties[0].name)) != keccak256(bytes(propertyName))), "Property already exists");

        properties.push();
        Property storage newProperty = properties[properties.length - 1];
        newProperty.name = propertyName;
        propertyIndexes[propertyName] = properties.length - 1;

        emit PropertyAdded(propertyName, properties.length - 1);
    }

    /**
     * @dev Sets a single property for a specific NFT token ID.
     * @param tokenId The ID of the NFT.
     * @param propertyName Name of the property.
     * @param value Value to set.
     */
    function setSingleProperty(uint256 tokenId, string memory propertyName, string memory value) external onlyWhitelisted {
        uint256 index = getPropertyIndex(propertyName);
        properties[index].values[tokenId] = value;
        emit PropertyUpdated(tokenId, propertyName, value);
    }

    /**
     * @dev Sets multiple properties for a single NFT.
     * @param tokenId ID of the NFT.
     * @param propertyNames Array of property names.
     * @param values Array of string values for the properties.
     */
    function setMultipleProperties(uint256 tokenId, string[25] memory propertyNames, string[25] memory values) public onlyWhitelisted {
        require(propertyNames.length == values.length, "Arrays length mismatch");

        for (uint256 i = 0; i < propertyNames.length; i++) {
            if (bytes(propertyNames[i]).length > 0) {
                uint256 index = getPropertyIndex(propertyNames[i]);
                properties[index].values[tokenId] = values[i];
                emit PropertyUpdated(tokenId, propertyNames[i], values[i]);
            }
        }

        emit PropertiesUpdated(tokenId, propertyNames, values);
    }

    /**
     * @dev Sets multiple properties across multiple NFTs.
     * @param tokenIds Array of NFT IDs.
     * @param propertyNames Array of property names.
     * @param values Array of arrays, each containing the values for each tokenId.
     */
    function setPropertiesForMultipleNFTs(uint256[] memory tokenIds, string[25] memory propertyNames, string[25][] memory values) external onlyWhitelisted {
        require(tokenIds.length == values.length, "Tokens and values length mismatch");

        for (uint256 i = 0; i < tokenIds.length; i++) {
            setMultipleProperties(tokenIds[i], propertyNames, values[i]);
        }
    }

    /**
     * @dev Gets all properties for a specific token ID.
     * @param tokenId ID of the NFT.
     * @return propertiesArray Array of property names and values.
     */
    function getProperties(uint256 tokenId) public view returns (string[] memory propertiesArray) {
        propertiesArray = new string[](properties.length * 2);

        for (uint256 i = 0; i < properties.length; i++) {
            propertiesArray[i * 2] = properties[i].name;
            propertiesArray[i * 2 + 1] = properties[i].values[tokenId];
        }
    }

    /**
     * @dev Fetches all properties for multiple NFT IDs in a single call.
     * @param tokenIds Array of NFT IDs to fetch properties for.
     * @return results An array where each entry is a list of properties for the respective NFT.
     */
    function getPropertiesForMultipleNFTs(uint256[] memory tokenIds) external view returns (string[][] memory results) {
        results = new string[][](tokenIds.length);

        for (uint256 i = 0; i < tokenIds.length; i++) {
            results[i] = getProperties(tokenIds[i]);
        }
    }

    /**
     * @dev Returns the value of a single property for a given token ID.
     * @param tokenId The ID of the NFT.
     * @param propertyName The name of the property to fetch.
     * @return The value of the property.
     */
    function getSingleProperty(uint256 tokenId, string memory propertyName) external view returns (string memory) {
        uint256 propertyIndex = propertyIndexes[propertyName];
        require(propertyIndex < properties.length && keccak256(bytes(properties[propertyIndex].name)) == keccak256(bytes(propertyName)), "Property does not exist");
        return properties[propertyIndex].values[tokenId];
    }

    /**
     * @dev Helper function to get the index of a property name.
     * @param propertyName Name of the property.
     * @return uint256 Index of the property in the array.
     */
    function getPropertyIndex(string memory propertyName) private view returns (uint256) {
        uint256 index = propertyIndexes[propertyName];
        require(index != 0 || (properties.length > 0 && keccak256(bytes(properties[0].name)) == keccak256(bytes(propertyName))), "Property does not exist");
        return index;
    }

    /**
     * @dev Lists all properties with their names.
     * @return Array of property names.
     */
    function listProperties() external view returns (string[] memory) {
        string[] memory propertyNames = new string[](properties.length);

        for (uint256 i = 0; i < properties.length; i++) {
            propertyNames[i] = properties[i].name;
        }

        return propertyNames;
    }

    /**
     * @dev Lists all whitelisted addresses.
     * @return Array of whitelisted addresses.
     */
    function listWhitelist() external view returns (address[] memory) {
        return _whitelistedAddresses;
    }

    /**
     * @dev Checks if an address is whitelisted.
     * @param account The address to check.
     * @return True if the address is whitelisted, false otherwise.
     */
    function isWhitelisted(address account) public view returns (bool) {
        return _whitelist[account];
    }

    /**
     * @dev Updates the whitelist status of an address.
     * @param account Address to update.
     * @param status Whitelist status (true to whitelist, false to remove).
     */
    function updateWhitelist(address account, bool status) external onlyOwner {
        if (_whitelist[account] != status) {
            _whitelist[account] = status;
            if (status) {
                _whitelistedAddresses.push(account);
            }
            emit WhitelistUpdated(account, status);
        }
    }
}
合同源代码
文件 3 的 3:Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
设置
{
  "compilationTarget": {
    "contracts/MonstroNFTProps.sol": "MonstroNFTProps"
  },
  "evmVersion": "paris",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"string[25]","name":"propertyNames","type":"string[25]"},{"indexed":false,"internalType":"string[25]","name":"values","type":"string[25]"}],"name":"PropertiesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"PropertyAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"string","name":"propertyName","type":"string"},{"indexed":false,"internalType":"string","name":"value","type":"string"}],"name":"PropertyUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"WhitelistUpdated","type":"event"},{"inputs":[{"internalType":"string","name":"propertyName","type":"string"}],"name":"addProperty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getProperties","outputs":[{"internalType":"string[]","name":"propertiesArray","type":"string[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"getPropertiesForMultipleNFTs","outputs":[{"internalType":"string[][]","name":"results","type":"string[][]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"propertyName","type":"string"}],"name":"getSingleProperty","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"listProperties","outputs":[{"internalType":"string[]","name":"","type":"string[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"listWhitelist","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"properties","outputs":[{"internalType":"string","name":"name","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string[25]","name":"propertyNames","type":"string[25]"},{"internalType":"string[25]","name":"values","type":"string[25]"}],"name":"setMultipleProperties","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"internalType":"string[25]","name":"propertyNames","type":"string[25]"},{"internalType":"string[25][]","name":"values","type":"string[25][]"}],"name":"setPropertiesForMultipleNFTs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"propertyName","type":"string"},{"internalType":"string","name":"value","type":"string"}],"name":"setSingleProperty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"updateWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"}]