Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.18;
- contract Present
- {
- event PresentCallExecuted(bool result, int amount );
- event DistrubuteCallExecuted(address addressReceiver);
- struct Receiver
- {
- address receiverAddress;
- bool claimed;
- uint percentDone;
- bytes32 token;
- }
- Receiver[] public presents;
- address giver;
- function Present() public
- {
- giver = msg.sender;
- }
- function () payable public
- { }
- modifier IsGiver()
- {
- require(giver == msg.sender);
- _;
- }
- function addPresent(string claimToken) public IsGiver() returns(bool)
- {
- for (uint8 index = 0; index < presents.length; index++)
- {
- if (presents[index].token == keccak256(claimToken))
- {
- return false;
- }
- }
- // token was not present continue
- var newReceiverOfPresents = Receiver(
- {
- receiverAddress: 0,
- claimed : false,
- percentDone : 0,
- token : keccak256(claimToken)
- });
- presents.push(newReceiverOfPresents);
- PresentCallExecuted(true, 1);
- return true;
- }
- function claimPresent(string claimToken, address receiver) public IsGiver() returns(bool)
- {
- for (uint8 index = 0; index < presents.length; index++)
- {
- if (presents[index].token == keccak256(claimToken) &&
- presents[index].claimed == false)
- {
- presents[index].claimed = true;
- presents[index].percentDone = 0;
- presents[index].receiverAddress = receiver;
- PresentCallExecuted(true, 1);
- return true;
- }
- }
- PresentCallExecuted(false, 0);
- return false;
- }
- function distrubute() public payable IsGiver()
- {
- for (uint8 index = 0; index < presents.length; index++)
- {
- if (presents[index].claimed &&
- presents[index].percentDone <= 100)
- {
- presents[index].percentDone += 34;
- transferThirdPercentageOfPresent(presents[index].receiverAddress);
- //distrubuted.push();
- DistrubuteCallExecuted(presents[index].receiverAddress);
- }
- }
- }
- function getPresentCount() public view returns(uint256)
- {
- return presents.length;
- }
- function checkBalance() public view returns(uint256)
- {
- return this.balance;
- }
- function transferThirdPercentageOfPresent(address receiver) private
- {
- receiver.transfer(15 finney);
- }
- function kill() public
- {
- if (msg.sender == giver)
- {
- selfdestruct(giver);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement