Created
October 20, 2018 07:17
-
-
Save yhuag/477264e0be4cfa7a084ae94c7373accb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Ownable { | |
address public owner; | |
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
/** | |
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
* account. | |
*/ | |
function Ownable() public { | |
owner = msg.sender; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
/** | |
* @dev Allows the current owner to transfer control of the contract to a newOwner. | |
* @param newOwner The address to transfer ownership to. | |
*/ | |
function transferOwnership(address newOwner) public onlyOwner { | |
require(newOwner != address(0)); | |
OwnershipTransferred(owner, newOwner); | |
owner = newOwner; | |
} | |
} | |
contract Freezable is Ownable { | |
event AccountFrozen(address indexed token_owner); | |
event AccountReleased(address indexed token_owner); | |
event FreezingAgentChanged(address indexed addr, bool state); | |
// freeze status of addresses | |
mapping(address=>bool) public addressFreezeStatus; | |
// agents who have privilege to freeze | |
mapping (address => bool) freezingAgents; | |
/** | |
* @dev Modifier to make a function callable only when the address is frozen. | |
*/ | |
modifier whenFrozen(address target) { | |
require(addressFreezeStatus[target] == true); | |
_; | |
} | |
/** | |
* @dev Modifier to make a function callable only when the address is not frozen. | |
*/ | |
modifier whenNotFrozen(address target) { | |
require(addressFreezeStatus[target] == false); | |
_; | |
} | |
/** | |
* @dev Modifier to make a function callable only by owner or freezing agent | |
*/ | |
modifier onlyOwnerOrFreezingAgent() { | |
require((msg.sender == owner ) || (freezingAgents[msg.sender] == true)); | |
_; | |
} | |
/** | |
* @dev Function to freeze an account from transactions | |
*/ | |
function freeze(address target) public onlyOwnerOrFreezingAgent whenNotFrozen(target) returns (bool) { | |
addressFreezeStatus[target] = true; | |
AccountFrozen(target); | |
return true; | |
} | |
/** | |
* @dev Function to release an account form frozen state | |
*/ | |
function release(address target) public onlyOwnerOrFreezingAgent whenFrozen(target) returns (bool) { | |
addressFreezeStatus[target] = false; | |
AccountReleased(target); | |
return true; | |
} | |
/** | |
* @dev Function to allow a contract to freeze addresses | |
*/ | |
function setFreezeAgent(address addr, bool state) public onlyOwner { | |
freezingAgents[addr] = state; | |
FreezingAgentChanged(addr, state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment