Bitcoin Forum
June 28, 2024, 12:24:52 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: SmartContract ошибка  (Read 127 times)
PayBack420 (OP)
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile
March 21, 2018, 08:15:16 PM
Last edit: March 24, 2018, 04:45:50 AM by PayBack420
 #1

contract MintableToken is TokenERC20, owned  {
  event Mint(address indexed to, uint256 amount);
  event MintFinished();

  bool public mintingFinished = false;


  modifier canMint() {
    require(!mintingFinished);
    _;
  }

  /**
   * @dev Function to mint tokens
   * @param _to The address that will receive the minted tokens.
   * @param _amount The amount of tokens to mint.
   * @return A boolean that indicates if the operation was successful.
   */
  function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
    totalSupply = totalSupply.add(_amount);
    balanceOf[_to] = balanceOf[_to].add(_amount);
    Mint(_to, _amount);
    Transfer(address(0), _to, _amount);
    return true;
  }

  /**
   * @dev Function to stop minting new tokens.
   * @return True if the operation was successful.
   */
  function finishMinting() onlyOwner canMint public returns (bool) {
    mintingFinished = true;
    MintFinished();
    return true;
  }
}

contract MyAdvancedToken is owned, TokenERC20 {

    uint256 public sellPrice;
    uint256 public buyPrice;

    mapping (address => bool) public frozenAccount;

    /* This generates a public event on the blockchain that will notify clients */
    event FrozenFunds(address target, bool frozen);

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function MyAdvancedToken(
        uint256 initialSupply,
        string tokenName,
        string tokenSymbol
    ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {}

    /* Internal transfer, only can be called by this contract */
    function _transfer(address _from, address _to, uint _value) internal {
        require (_to != 0x0);                               // Prevent transfer to 0x0 address. Use burn() instead
        require (balanceOf[_from] >= _value);               // Check if the sender has enough
        require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
        require(!frozenAccount[_from]);                     // Check if sender is frozen
        require(!frozenAccount[_to]);                       // Check if recipient is frozen
        balanceOf[_from] -= _value;                         // Subtract from the sender
        balanceOf[_to] += _value;                           // Add the same to the recipient
        Transfer(_from, _to, _value);
    }

   
    /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
    /// @param target Address to be frozen
    /// @param freeze either to freeze it or not
    function freezeAccount(address target, bool freeze) onlyOwner public {
        frozenAccount[target] = freeze;
        FrozenFunds(target, freeze);
    }

    /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
    /// @param newSellPrice Price the users can sell to the contract
    /// @param newBuyPrice Price users can buy from the contract
    function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public {
        sellPrice = newSellPrice;
        buyPrice = newBuyPrice;
    }

    /// @notice Buy tokens from contract by sending ether
    function buy() payable public {
        uint amount = msg.value / buyPrice;               // calculates the amount
        _transfer(this, msg.sender, amount);              // makes the transfers
    }

    /// @notice Sell `amount` tokens to contract
    /// @param amount amount of tokens to be sold
    function sell(uint256 amount) public {
        require(this.balance >= amount * sellPrice);      // checks if the contract has enough ether to buy
        _transfer(msg.sender, this, amount);              // makes the transfers
        msg.sender.transfer(amount * sellPrice);          // sends ether to the seller. It's important to do this last to avoid recursion attacks
    }
}

contract simpleFairLottery is MyAdvancedToken {
    uint public countTickets = 100;
    uint public JackPot = 0;
    address [100] public tickets;
    uint public ticketPrice = 10;
   
    uint public xPrize = 4;
    uint public lastWinNumber;
   
    function clearTickets()public {
        for (uint i = 0 ; i < countTickets ; i++)
            tickets = 0;
    }
   
   
    function buyTicket(uint ticketNum)public returns (bool succes)  {
        if (  (ticketNum < 0) || (ticketNum >= countTickets)) return false;
        if (balanceOf[msg.sender] < ticketPrice) return false;
        if ( tickets[ticketNum] !=0 ) return false;
        balanceOf[msg.sender] -= ticketPrice;
       
        tickets[ticketNum] = msg.sender;
        return true;
    }

    function play()public onlyOwner {
        lastWinNumber = uint(block.blockhash(block.number-1))%countTickets +1;
        if (tickets[lastWinNumber] !=0 ) {
            balanceOf[tickets[lastWinNumber]] += JackPot;
            JackPot = 0;
        }
       
        uint i1 = lastWinNumber - (lastWinNumber%10);
        for (uint i = i1 ; i < i1 +10 ; i++)
            balanceOf[tickets] += ticketPrice * xPrize;
           
        clearTickets();
    }
   
    function setLotteryParameters(uint newTicketPrice, uint newXprize)public onlyOwner {
        ticketPrice = newTicketPrice;
       
        xPrize = newXprize;
    }
}
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!