Created
October 24, 2018 03:55
-
-
Save yhuag/2f203b12660c75757b25f2be7d1e972f to your computer and use it in GitHub Desktop.
Tested Freezable Contract
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
pragma solidity ^0.4.25; | |
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 _account); | |
event AccountReleased(address indexed _account); | |
// freeze status of addresses | |
mapping(address=>bool) public frozenAccounts; | |
/** | |
* @dev Modifier to make a function callable only when the address is frozen. | |
*/ | |
modifier whenAccountFrozen(address _account) { | |
require(frozenAccounts[_account] == true); | |
_; | |
} | |
/** | |
* @dev Modifier to make a function callable only when the address is not frozen. | |
*/ | |
modifier whenAccountNotFrozen(address _account) { | |
require(frozenAccounts[_account] == false); | |
_; | |
} | |
/** | |
* @dev Function to freeze an account from transactions | |
*/ | |
function freeze(address _account) public onlyOwner whenAccountNotFrozen(_account) returns (bool) { | |
frozenAccounts[_account] = true; | |
emit AccountFrozen(_account); | |
return true; | |
} | |
/** | |
* @dev Function to release an account form frozen state | |
*/ | |
function release(address _account) public onlyOwner whenAccountFrozen(_account) returns (bool) { | |
frozenAccounts[_account] = false; | |
emit AccountReleased(_account); | |
return true; | |
} | |
} | |
contract Test is Freezable { | |
bool value = false; | |
function toggleBool() public whenAccountNotFrozen(msg.sender) returns (bool) { | |
value = !value; | |
return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment