SHARE
TWEET

Smart Contract

a guest Mar 22nd, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.4.18;
  2. contract Present
  3. {
  4.     event PresentCallExecuted(bool result, int amount );
  5.     event DistrubuteCallExecuted(address addressReceiver);
  6.    
  7.     struct Receiver
  8.     {
  9.         address receiverAddress;
  10.         bool    claimed;
  11.         uint    percentDone;
  12.         bytes32 token;
  13.     }
  14.    
  15.     Receiver[] public presents;
  16.     address giver;
  17.    
  18.     function Present()  public
  19.     {
  20.         giver = msg.sender;
  21.     }
  22.    
  23.     function () payable public
  24.     { }
  25.    
  26.     modifier IsGiver()
  27.     {
  28.         require(giver == msg.sender);
  29.         _;
  30.     }
  31.    
  32.     function addPresent(string claimToken) public IsGiver() returns(bool)
  33.     {
  34.         for (uint8 index = 0; index < presents.length; index++)
  35.         {
  36.             if (presents[index].token == keccak256(claimToken))
  37.             {
  38.                 return false;
  39.             }
  40.         }
  41.        
  42.         // token was not present continue
  43.         var newReceiverOfPresents = Receiver(
  44.             {
  45.                 receiverAddress: 0,
  46.                 claimed : false,
  47.                 percentDone : 0,
  48.                 token : keccak256(claimToken)
  49.             });
  50.         presents.push(newReceiverOfPresents);
  51.        
  52.         PresentCallExecuted(true, 1);
  53.         return true;
  54.     }
  55.    
  56.    
  57.     function claimPresent(string claimToken, address receiver) public IsGiver() returns(bool)
  58.     {
  59.         for (uint8 index = 0; index < presents.length; index++)
  60.         {
  61.             if (presents[index].token == keccak256(claimToken) &&
  62.                 presents[index].claimed == false)
  63.             {
  64.                 presents[index].claimed = true;
  65.                 presents[index].percentDone = 0;
  66.                 presents[index].receiverAddress = receiver;
  67.                 PresentCallExecuted(true, 1);
  68.                 return true;
  69.             }
  70.         }
  71.         PresentCallExecuted(false, 0);
  72.         return false;
  73.     }
  74.    
  75.     function distrubute() public payable IsGiver()
  76.     {
  77.             for (uint8 index = 0; index < presents.length; index++)
  78.             {
  79.                 if (presents[index].claimed &&
  80.                     presents[index].percentDone <= 100)
  81.                 {
  82.                     presents[index].percentDone += 34;
  83.                     transferThirdPercentageOfPresent(presents[index].receiverAddress);
  84.                     //distrubuted.push();
  85.                     DistrubuteCallExecuted(presents[index].receiverAddress);
  86.                 }
  87.             }
  88.     }
  89.    
  90.     function getPresentCount() public view returns(uint256)
  91.     {
  92.        return presents.length;
  93.     }
  94.    
  95.     function checkBalance() public view returns(uint256)
  96.     {
  97.        return this.balance;
  98.     }
  99.    
  100.     function transferThirdPercentageOfPresent(address receiver) private
  101.     {
  102.         receiver.transfer(15 finney);
  103.     }
  104.    
  105.     function kill() public
  106.     {
  107.         if (msg.sender == giver)
  108.         {
  109.             selfdestruct(giver);
  110.         }
  111.     }
  112. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top