You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

76 lines
1.8 KiB

// SPDX-License-Identifier: MIT
pragma solidity 0.8.1;
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Operator is Context, Ownable {
address private _operator;
mapping(address => bool) public miners;
event OperatorTransferred(
address indexed previousOperator,
address indexed newOperator
);
constructor() {
_operator = _msgSender();
emit OperatorTransferred(address(0), _operator);
}
function operator() public view returns (address) {
return _operator;
}
modifier onlyMiner(){
require(miners[msg.sender],"Not miner");
_;
}
modifier onlyOperator() {
require(
_operator == msg.sender,
"operator: caller is not the operator"
);
_;
}
function addMiner(address _miner) public onlyOwner(){
miners[_miner] = true;
}
function removeMiner(address _miner) public onlyOwner(){
miners[_miner] = false;
}
function isOperator() public view returns (bool) {
return _msgSender() == _operator;
}
function transferOperator(address newOperator_) public onlyOwner {
_transferOperator(newOperator_);
}
function _transferOperator(address newOperator_) internal {
require(
newOperator_ != address(0),
"operator: zero address given for new operator"
);
emit OperatorTransferred(address(0), newOperator_);
_operator = newOperator_;
}
receive() external payable{}
function withdraw (uint _amount) external{
require(msg.sender==_operator,"caller is not operator");
payable(msg.sender).transfer(_amount);
}
function getBalance()external view returns(uint){
return address(this).balance;
}
}