Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.51 KB | None | 0 0
  1.  
  2. pragma solidity ^0.4.11;
  3.  
  4.  
  5. import "./Owned.sol";
  6.  
  7.  
  8. contract SoupToken is Owned {
  9.  
  10.  
  11.     string public standard = 'SoupToken 30/06';
  12.  
  13.     string public name;
  14.  
  15.     string public symbol;
  16.  
  17.     uint256 public totalSupply;
  18.  
  19.     uint public minBalanceForAccounts = 5 finney;
  20.  
  21.     mapping (address => uint256) public balanceOf;
  22.  
  23.     mapping (uint => address[]) public ordersFor;
  24.  
  25.     event Transfer(address indexed from, address indexed to, uint256 value);
  26.  
  27.     event Burn(address indexed from, uint256 value);
  28.  
  29.     event BurnFrom(address _from, uint256 _value);
  30.  
  31.     event LogDepositReceived(address sender);
  32.  
  33.     function SoupToken(string tokenName, string tokenSymbol) payable {
  34.         name = tokenName;
  35.         // Set the name for display purposes
  36.         symbol = tokenSymbol;
  37.         // Set the symbol for display purposes
  38.     }
  39.  
  40.     function() payable {
  41.         LogDepositReceived(msg.sender);
  42.     }
  43.  
  44.     function mintToken(address target, uint256 mintedAmount) onlyAdmin {
  45.         balanceOf[target] += mintedAmount;
  46.         totalSupply += mintedAmount;
  47.         Transfer(0, owner, mintedAmount);
  48.         Transfer(owner, target, mintedAmount);
  49.         if (target.balance < minBalanceForAccounts) target.transfer(minBalanceForAccounts - target.balance);
  50.     }
  51.  
  52.     function transfer(address _to, uint256 _value){
  53.         if (_to == 0x0) throw;
  54.         // Prevent transfer to 0x0 address. Use burn() instead
  55.         if (balanceOf[msg.sender] < _value) throw;
  56.         // Check if the sender has enough
  57.         if (balanceOf[_to] + _value < balanceOf[_to]) throw;
  58.         // Check for overflows
  59.         balanceOf[msg.sender] -= _value;
  60.         // Subtract from the sender
  61.         balanceOf[_to] += _value;
  62.         // Add the same to the recipient
  63.         Transfer(msg.sender, _to, _value);
  64.         // Notify anyone listening that this transfer took place
  65.     }
  66.  
  67.     function transferFrom(address _from, address _to, uint256 _value) onlyAdmin returns (bool success){
  68.         if (_to == 0x0) throw;
  69.         // Prevent transfer to 0x0 address. Use burn() instead
  70.         if (balanceOf[_from] < _value) throw;
  71.         // Check if the sender has enough
  72.         if (balanceOf[_to] + _value < balanceOf[_to]) throw;
  73.         // Check for overflows
  74.         balanceOf[_from] -= _value;
  75.         // Subtract from the sender
  76.         balanceOf[_to] += _value;
  77.         // Add the same to the recipient
  78.         Transfer(_from, _to, _value);
  79.         return true;
  80.     }
  81.  
  82.     function burnFrom(address _from, uint256 _value) onlyAdmin returns (bool success) {
  83.         if (balanceOf[_from] < _value) throw;
  84.         // Check if the sender has enough
  85.         balanceOf[_from] -= _value;
  86.         // Subtract from the sender
  87.         totalSupply -= _value;
  88.         // Updates totalSupply
  89.         Burn(_from, _value);
  90.         return true;
  91.     }
  92.  
  93.     function checkIfAlreadyOrderedForDay(uint day, address user) internal constant returns (bool){
  94.         var orders = ordersFor[day];
  95.         for (uint i = 0; i < orders.length; i++) {
  96.             if (orders[i] == user) {
  97.                 return true;
  98.             }
  99.         }
  100.         return false;
  101.     }
  102.  
  103.     function findOrderIndexForAddress(uint day, address user) internal constant returns (uint){
  104.         var orders = ordersFor[day];
  105.         for (uint i = 0; i < orders.length; i++) {
  106.             if (orders[i] == user) {
  107.                 return i;
  108.             }
  109.         }
  110.         //this throw will never be reached. This function is only called for users
  111.         //where we absolutely know they are in the list
  112.         throw;
  113.     }
  114.  
  115.     function orderForDays(bool[] weekdays) returns (bool success) {
  116.  
  117.         uint totalOrders = 0;
  118.         for (uint i = 0; i < weekdays.length; i++) {
  119.             var isOrdering = weekdays[i];
  120.             //check if the user already ordered for that day
  121.             if (checkIfAlreadyOrderedForDay(i, msg.sender)) {
  122.                 //if so we remove the order if the user changed his mind
  123.                 if (!isOrdering) {
  124.                     var useridx = findOrderIndexForAddress(i, msg.sender);
  125.                     delete ordersFor[i][useridx];
  126.                 }
  127.                 //if he still wants to buy for the change we dont do anything
  128.             }
  129.             else {
  130.                 if (isOrdering) {
  131.                     //add the user to the list of purchases that day
  132.                     ordersFor[i].push(msg.sender);
  133.                     totalOrders++;
  134.                 }
  135.                 //do nothing otherwise
  136.             }
  137.             // rollback transaction if totalOrders exceeds balance
  138.             if (balanceOf[msg.sender] < totalOrders) {
  139.                 throw;
  140.             }
  141.         }
  142.         return true;
  143.     }
  144.  
  145.     function burnSoupTokensForDay(uint day) onlyAdmin returns (bool success) {
  146.  
  147.         for (uint i = 0; i < ordersFor[day].length; i++) {
  148.             if (ordersFor[day][i] == 0x0) {
  149.                 continue;
  150.             }
  151.             burnFrom(ordersFor[day][i], 1);
  152.             delete ordersFor[day][i];
  153.         }
  154.         return true;
  155.     }
  156.  
  157.     function getOrderAddressesForDay(uint day) constant returns (address[]) {
  158.         return ordersFor[day];
  159.     }
  160.  
  161.     function getAmountOrdersForDay(uint day) constant returns (uint){
  162.         return ordersFor[day].length;
  163.     }
  164.  
  165.     function setMinBalance(uint minimumBalanceInFinney) onlyAdmin {
  166.         minBalanceForAccounts = minimumBalanceInFinney * 1 finney;
  167.     }
  168.  
  169.     function kill() onlyOwner {
  170.         selfdestruct(owner);
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement