编译器
0.5.16+commit.9c3226ce
文件 1 的 2:Ownable.sol
pragma solidity ^0.5.0;
contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 2 的 2:UniverseChart.sol
pragma solidity ^0.5.16;
import "openzeppelin-solidity-2.3.0/contracts/ownership/Ownable.sol";
contract UniverseChart is Ownable {
struct Account {
uint128 id;
uint128 referrerId;
}
uint128 public lastId = 1;
mapping(address => Account) public accounts;
mapping(uint128 => address) public accountIds;
event Register(uint128 id, address user, address referrer);
constructor(address _company) public {
setCompany(_company);
}
function register(address _referrer) external {
require(
accounts[_referrer].id != 0 || _referrer == accountIds[0],
"Invalid referrer address"
);
require(accounts[msg.sender].id == 0, "Account has been registered");
Account memory account =
Account({id: lastId, referrerId: accounts[_referrer].id});
accounts[msg.sender] = account;
accountIds[lastId] = msg.sender;
emit Register(lastId++, msg.sender, _referrer);
}
function setCompany(address _company) public onlyOwner {
require(
_company != accountIds[0],
"You entered the same company address"
);
require(
accounts[_company].id == 0,
"Company was registered on the chart"
);
Account memory account = Account({id: 0, referrerId: 0});
accounts[_company] = account;
accountIds[0] = _company;
}
}
{
"compilationTarget": {
"contracts/5/UniverseChart.sol": "UniverseChart"
},
"evmVersion": "istanbul",
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_company","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"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":false,"internalType":"uint128","name":"id","type":"uint128"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"referrer","type":"address"}],"name":"Register","type":"event"},{"constant":true,"inputs":[{"internalType":"uint128","name":"","type":"uint128"}],"name":"accountIds","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accounts","outputs":[{"internalType":"uint128","name":"id","type":"uint128"},{"internalType":"uint128","name":"referrerId","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastId","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_referrer","type":"address"}],"name":"register","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_company","type":"address"}],"name":"setCompany","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]