Created
December 16, 2017 01:57
-
-
Save blueplanet/b8339281509eb765530f39e297919d92 to your computer and use it in GitHub Desktop.
仮想仔猫に対する記事から分かったブロックチェーン・スマートコントラクトに対する誤解 ref: https://qiita.com/blueplanet/items/d1f493cb82af3d7438ff
This file contains hidden or 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
イーサリアム上で運営されるため、ゲーム運営会社が突然閉鎖してもトークンとよばれる一種の仮想通貨である仮想子猫は生き続けることだ。 |
This file contains hidden or 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
仮想子猫経済は非中央集権化されており、開発チームでも悪意をもって操作できない。 |
This file contains hidden or 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 KittyAccessControl { | |
// This facet controls access control for CryptoKitties. There are four roles managed here: | |
// | |
// - The CEO: The CEO can reassign other roles and change the addresses of our dependent smart | |
// contracts. It is also the only role that can unpause the smart contract. It is initially | |
// set to the address that created the smart contract in the KittyCore constructor. | |
// | |
// - The CFO: The CFO can withdraw funds from KittyCore and its auction contracts. | |
// | |
// - The COO: The COO can release gen0 kitties to auction, and mint promo cats. | |
// | |
// It should be noted that these roles are distinct without overlap in their access abilities, the | |
// abilities listed for each role above are exhaustive. In particular, while the CEO can assign any | |
// address to any role, the CEO address itself doesn't have the ability to act in those roles. This | |
// restriction is intentional so that we aren't tempted to use the CEO address frequently out of | |
// convenience. The less we use an address, the less likely it is that we somehow compromise the | |
// account. | |
/// @dev Emited when contract is upgraded - See README.md for updgrade plan | |
event ContractUpgrade(address newContract); | |
// The addresses of the accounts (or contracts) that can execute actions within each roles. | |
address public ceoAddress; | |
address public cfoAddress; | |
address public cooAddress; | |
// @dev Keeps track whether the contract is paused. When that is true, most actions are blocked | |
bool public paused = false; | |
/// @dev Access modifier for CEO-only functionality | |
modifier onlyCEO() { | |
require(msg.sender == ceoAddress); | |
_; | |
} | |
/// @dev Access modifier for CFO-only functionality | |
modifier onlyCFO() { | |
require(msg.sender == cfoAddress); | |
_; | |
} | |
/// @dev Access modifier for COO-only functionality | |
modifier onlyCOO() { | |
require(msg.sender == cooAddress); | |
_; | |
} | |
modifier onlyCLevel() { | |
require( | |
msg.sender == cooAddress || | |
msg.sender == ceoAddress || | |
msg.sender == cfoAddress | |
); | |
_; | |
} | |
/// @dev Assigns a new address to act as the CEO. Only available to the current CEO. | |
/// @param _newCEO The address of the new CEO | |
function setCEO(address _newCEO) external onlyCEO { | |
require(_newCEO != address(0)); | |
ceoAddress = _newCEO; | |
} | |
/// @dev Assigns a new address to act as the CFO. Only available to the current CEO. | |
/// @param _newCFO The address of the new CFO | |
function setCFO(address _newCFO) external onlyCEO { | |
require(_newCFO != address(0)); | |
cfoAddress = _newCFO; | |
} | |
/// @dev Assigns a new address to act as the COO. Only available to the current CEO. | |
/// @param _newCOO The address of the new COO | |
function setCOO(address _newCOO) external onlyCEO { | |
require(_newCOO != address(0)); | |
cooAddress = _newCOO; | |
} | |
/*** Pausable functionality adapted from OpenZeppelin ***/ | |
/// @dev Modifier to allow actions only when the contract IS NOT paused | |
modifier whenNotPaused() { | |
require(!paused); | |
_; | |
} | |
/// @dev Modifier to allow actions only when the contract IS paused | |
modifier whenPaused { | |
require(paused); | |
_; | |
} | |
/// @dev Called by any "C-level" role to pause the contract. Used only when | |
/// a bug or exploit is detected and we need to limit damage. | |
function pause() external onlyCLevel whenNotPaused { | |
paused = true; | |
} | |
/// @dev Unpauses the smart contract. Can only be called by the CEO, since | |
/// one reason we may pause the contract is when CFO or COO accounts are | |
/// compromised. | |
/// @notice This is public rather than external so it can be called by | |
/// derived contracts. | |
function unpause() public onlyCEO whenPaused { | |
// can't unpause if contract was upgraded | |
paused = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment