文件 1 的 3:Context.sol
pragma solidity >=0.6.0 <0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 2 的 3:Ownable.sol
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 3 的 3:ReferralRegistry.sol
pragma solidity =0.6.6;
import "@openzeppelin/contracts/access/Ownable.sol";
contract ReferralRegistry is Ownable {
event ReferralAnchorCreated(address indexed user, address indexed referee);
event ReferralAnchorUpdated(address indexed user, address indexed referee);
event AnchorManagerUpdated(address account, bool isManager);
mapping(address => bool) public isAnchorManager;
mapping(address => address) public referralAnchor;
function createReferralAnchor(address _user, address _referee) external onlyAnchorManager {
require(referralAnchor[_user] == address(0), "ReferralRegistry: ANCHOR_EXISTS");
referralAnchor[_user] = _referee;
emit ReferralAnchorCreated(_user, _referee);
}
function updateReferralAnchor(address _user, address _referee) external onlyOwner {
referralAnchor[_user] = _referee;
emit ReferralAnchorUpdated(_user, _referee);
}
function updateAnchorManager(address _anchorManager, bool _isManager) external onlyOwner {
isAnchorManager[_anchorManager] = _isManager;
emit AnchorManagerUpdated(_anchorManager, _isManager);
}
function getUserReferee(address _user) external view returns (address) {
return referralAnchor[_user];
}
function hasUserReferee(address _user) external view returns (bool) {
return referralAnchor[_user] != address(0);
}
modifier onlyAnchorManager() {
require(isAnchorManager[msg.sender], "ReferralRegistry: FORBIDDEN");
_;
}
}
{
"compilationTarget": {
"contracts/ReferralRegistry.sol": "ReferralRegistry"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isManager","type":"bool"}],"name":"AnchorManagerUpdated","type":"event"},{"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":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"referee","type":"address"}],"name":"ReferralAnchorCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"referee","type":"address"}],"name":"ReferralAnchorUpdated","type":"event"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"address","name":"_referee","type":"address"}],"name":"createReferralAnchor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getUserReferee","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"hasUserReferee","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isAnchorManager","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"referralAnchor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_anchorManager","type":"address"},{"internalType":"bool","name":"_isManager","type":"bool"}],"name":"updateAnchorManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"address","name":"_referee","type":"address"}],"name":"updateReferralAnchor","outputs":[],"stateMutability":"nonpayable","type":"function"}]