Created
October 31, 2016 07:44
-
-
Save pavlovdog/d65a0e0b9047a9206b5c34034d7fe910 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 admin { | |
// VARIABLES | |
struct user { | |
address addr; | |
string name; // '$uPeR_p0wner_1999' | |
string desc; // 'CEO & CTO' | |
} | |
user owner; | |
mapping (address => user) adminInfo; | |
mapping (address => bool) isAdmin; | |
function admin (string _name, string _desc) { | |
owner = user({ | |
addr : msg.sender, // msg - дефолтная переменная с информацией о пользователе | |
name : _name, // вызвавшем контракт. msg.sender - его адрес | |
desc : _desc // msg.value - сумма в wei, переданная контракту и т.д. | |
}); | |
isAdmin[msg.sender] = true; | |
adminInfo[msg.sender] = owner; | |
} | |
// EVENTS | |
event adminAdded(address _address, string _name, string _desc); | |
event adminRemoved(address _address, string _name, string _desc); | |
event moneySend(address _address, uint _amount); | |
// FUNCTIONS | |
function addAdmin (address _address, string _name, string _desc) { | |
if (owner.addr != msg.sender || isAdmin[_address]) throw; // Only owner can do this! | |
isAdmin[_address] = true; | |
adminInfo[_address] = user({addr : _address, name : _name, desc : _desc}); | |
adminAdded(_address, _name, _desc); // Call event | |
} | |
function removeAdmin (address _address) { | |
if (owner.addr != msg.sender || !isAdmin[_address]) throw; // Only owner can do this! | |
isAdmin[_address] = false; | |
adminRemoved(_address, adminInfo[_address].name, adminInfo[_address].desc); // Call event | |
delete adminInfo[_address]; | |
} | |
function getMoneyOut(address _receiver, uint _amount) { | |
if (owner.addr != msg.sender || _amount <= 0) throw; | |
_receiver.send(_amount); | |
moneySend(_receiver, _amount); | |
} | |
function killContract () { | |
if (owner.addr != msg.sender) throw; | |
selfdestruct(owner.addr); // Все средства на счету контракта будут переведены на адрес владельца | |
} | |
} | |
contract shop is admin { | |
// VARIABLES | |
uint[] orders; | |
struct Key { | |
string value; | |
address author; | |
} | |
mapping (uint => string) keys; | |
// EVENTS | |
event keyAdded(string _ID, string _name, string _desc); | |
// FUNCTIONS | |
function buyKey(uint _ID) { | |
if (msg.value < 15000000000000000000) throw; | |
orders.push(_ID); | |
} | |
function getKeyByID(uint _ID) returns (string) { | |
if (msg.value < 1000000000000000000) throw; | |
return keys[_ID]; | |
} | |
function addKey(uint _ID, string _key) { | |
if (!isAdmin[msg.sender]) throw; | |
keys[_ID] = Key({}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment