编译器
0.6.12+commit.27d51765
文件 1 的 5:Context.sol
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
文件 2 的 5:IERC1155Preset.sol
pragma solidity ^0.6.2;
interface IERC1155Preset {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
function supportsInterface(bytes4 interfaceId) external view returns (bool);
function mint(address to, uint256 id, uint256 amount, bytes memory data) external;
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) external;
function getOwnerIdByIndex(address owner, uint256 index) external view returns (uint256);
function getOwnerIdIndex(address owner, uint256 id) external view returns (uint256);
}
文件 3 的 5:IERC20.sol
pragma solidity >=0.6.0 <0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 4 的 5:SafeMath.sol
pragma solidity >=0.6.0 <0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
文件 5 的 5:StrongNFTSeller.sol
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;
import "./interfaces/IERC1155Preset.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/GSN/Context.sol";
contract StrongNFTSeller is Context {
using SafeMath for uint256;
IERC1155Preset public nftToken;
IERC20 public strongToken;
bool public initDone;
address public serviceAdmin;
address public superAdmin;
address payable public feeCollector;
string[] public nftNames;
mapping(string => uint256) public nftLowerBound;
mapping(string => uint256) public nftUpperBound;
mapping(string => uint256) public nftEthValue;
mapping(string => uint256) public nftStrongValue;
mapping(string => uint256) public nftIdCounter;
event Sold(address to, string name, uint256 nftId);
function init(address _nftTokenContract, address _strongTokenContract, address _serviceAdminAddress, address _superAdminAddress, address payable _feeCollectorAddress) public {
require(initDone == false, "init done");
nftToken = IERC1155Preset(_nftTokenContract);
strongToken = IERC20(_strongTokenContract);
serviceAdmin = _serviceAdminAddress;
superAdmin = _superAdminAddress;
feeCollector = _feeCollectorAddress;
initDone = true;
}
function getCurrentNftId(string memory _name) public view returns (uint256) {
return nftIdCounter[_name] > 0 ? nftIdCounter[_name] : nftLowerBound[_name];
}
function getNftNames() public view returns (string[] memory) {
return nftNames;
}
function buyNft(string memory _name) public payable {
uint256 mintNftId = getCurrentNftId(_name);
require(nftEthValue[_name] > 0, "invalid name");
require(mintNftId >= nftLowerBound[_name], "invalid id");
require(mintNftId <= nftUpperBound[_name], "sold out");
require(msg.value >= nftEthValue[_name], "invalid fee");
require(strongToken.balanceOf(_msgSender()) >= nftStrongValue[_name], "insufficient balance");
nftToken.mint(_msgSender(), mintNftId, 1, "");
nftIdCounter[_name] = mintNftId + 1;
feeCollector.transfer(msg.value);
strongToken.transferFrom(_msgSender(), feeCollector, nftStrongValue[_name]);
emit Sold(_msgSender(), _name, mintNftId);
}
function updateNFT(string memory _name, uint256 _lowerBound, uint256 _upperBound, uint256 _ethValue, uint256 _strongValue) public {
require(_msgSender() == serviceAdmin || _msgSender() == superAdmin, "not admin");
bool alreadyExists = false;
for (uint8 i = 0; i < nftNames.length; i++) {
if (keccak256(abi.encode(nftNames[i])) == keccak256(abi.encode(_name))) {
alreadyExists = true;
}
}
if (!alreadyExists) {
nftNames.push(_name);
}
nftLowerBound[_name] = _lowerBound;
nftUpperBound[_name] = _upperBound;
nftEthValue[_name] = _ethValue;
nftStrongValue[_name] = _strongValue;
}
function updatePrice(string memory _name, uint256 _ethValue, uint256 _strongValue) public {
require(_msgSender() == serviceAdmin || _msgSender() == superAdmin, "not admin");
nftEthValue[_name] = _ethValue;
nftStrongValue[_name] = _strongValue;
}
function updateServiceAdmin(address _newServiceAdmin) public {
require(_msgSender() == superAdmin, "not admin");
serviceAdmin = _newServiceAdmin;
}
function updateFeeCollector(address payable _newFeeCollector) public {
require(_newFeeCollector != address(0));
require(_msgSender() == superAdmin);
feeCollector = _newFeeCollector;
}
function updateCounterValue(string memory _name, uint256 _counterValue) public {
require(_msgSender() == serviceAdmin || _msgSender() == superAdmin, "not admin");
nftIdCounter[_name] = _counterValue;
}
}
{
"compilationTarget": {
"contracts/StrongNFTSeller.sol": "StrongNFTSeller"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"uint256","name":"nftId","type":"uint256"}],"name":"Sold","type":"event"},{"inputs":[{"internalType":"string","name":"_name","type":"string"}],"name":"buyNft","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"feeCollector","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"}],"name":"getCurrentNftId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNftNames","outputs":[{"internalType":"string[]","name":"","type":"string[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_nftTokenContract","type":"address"},{"internalType":"address","name":"_strongTokenContract","type":"address"},{"internalType":"address","name":"_serviceAdminAddress","type":"address"},{"internalType":"address","name":"_superAdminAddress","type":"address"},{"internalType":"address payable","name":"_feeCollectorAddress","type":"address"}],"name":"init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initDone","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"nftEthValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"nftIdCounter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"nftLowerBound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"nftNames","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"nftStrongValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nftToken","outputs":[{"internalType":"contract IERC1155Preset","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"nftUpperBound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"serviceAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strongToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"superAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"uint256","name":"_counterValue","type":"uint256"}],"name":"updateCounterValue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_newFeeCollector","type":"address"}],"name":"updateFeeCollector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"uint256","name":"_lowerBound","type":"uint256"},{"internalType":"uint256","name":"_upperBound","type":"uint256"},{"internalType":"uint256","name":"_ethValue","type":"uint256"},{"internalType":"uint256","name":"_strongValue","type":"uint256"}],"name":"updateNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"uint256","name":"_ethValue","type":"uint256"},{"internalType":"uint256","name":"_strongValue","type":"uint256"}],"name":"updatePrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newServiceAdmin","type":"address"}],"name":"updateServiceAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"}]