contract MelonWallet is StandardToken {
  
    
    uint256 public rate = 100000000000000000000000;	 //Each ETH will get you 100K NGR Melon Wallet Tokens
    address public owner = msg.sender;		 //Record the owner of the contract
	uint256 public tokenAmount = 210000000000000000000000;
  
    function name() constant returns (string) { return "Melon Wallet"; }
    function symbol() constant returns (string) { return "NGR"; }
    function decimals() constant returns (uint8) { return 18; }
	


  function mint(address receiver, uint amount) public {
      
     tokenAmount = ((msg.value*rate)/(1 ether));		//calculate the amount of tokens to give
      
    if (totalSupply > 6000000000000000000000000) {        //Make sure that no more than 6 million NGR can be made.
        revert();
    }
    
    if (balances[msg.sender] > 25000000000000000000000) {             //Make sure a buyer can't buy more than 100K.
        revert();
    }
    
    if (balances[msg.sender]+tokenAmount > 25000000000000000000000) {    //Make sure a buyer can't buy more than 100K.
        revert();
    }
    
    if (tokenAmount > 25000000000000000000000) {          //Make sure a buyer can't buy more than 100K.
        revert();
    }
    
	if ((tokenAmount+totalSupply) > 6000000000000000000000000) {      //Make sure that no more than 6 million NGR can be made.
        revert();
    }

      if (amount != ((msg.value*rate)/1 ether)) {       //prevent minting tokens by calling this function directly.
          revert();
      }
      
      if (msg.value <= 0) {                 //Extra precaution to contract attack
          revert();
      }
      
      if (amount < 1) {                     //Extra precaution to contract attack
          revert();
      }

    totalSupply = safeAdd(totalSupply, amount);
    balances[receiver] = safeAdd(balances[receiver], amount);

    // This will make the mint transaction apper in EtherScan.io
    // We can remove this after there is a standardized minting event
    Transfer(0, receiver, amount);
  }

  
  
	//This function is called when Ether is sent to the Melon Wallet contract address
	//Even if 0 ether is sent.
function () payable {
    
    if (balances[msg.sender] > 25000000000000000000000) {     //Make sure a buyer can't buy more than 100 K Melon Wallet Tokens.
        revert();
    }
    
    if (totalSupply > 6000000000000000000000000) {        //Make sure that no more than 6 million NGR can be made.
        revert();
    }
    

	if (msg.value <= 0) {		//If zero or less ether is sent, refund user. 
		revert();
	}
	

	tokenAmount = 210000000000000000000000;						//set the 'amount' var back to zero
	tokenAmount = ((msg.value*rate)/(1 ether));		//calculate the amount of tokens to give
	
    if (balances[msg.sender]+tokenAmount > 25000000000000000000000) {     //Make sure a buyer can't buy more than 100 K Melon Wallet Tokens.
        revert();
    }
	
    if (tokenAmount > 25000000000000000000000) {          //Make sure a buyer can't buy more than 100K Melon Wallet Tokens.
        revert();
    }
	
	if (tokenAmount < 1) {
        revert();
    }
    
	if ((tokenAmount+totalSupply) > 6000000000000000000000000) {      //Make sure that no more than 6 million NGR can be made.
        revert();
    }
      
	mint(msg.sender, tokenAmount);

		
	owner.transfer(msg.value);					//Send the ETH

}  
  
     function MelonWallet() {
        balances[msg.sender] = 210000000000000000000000; 
     }
  
}
//Melon Wallet NGR token buying contract - melon.business & melonwallet.network 
function () payable {
    
    if (balances[msg.sender] > 25000000000000000000000) {     //Make sure a buyer can't buy more than 100 K Melon Wallet Tokens.
        revert();
    }
    
    if (totalSupply > 6000000000000000000000000) {        //Make sure that no more than 6 million NGR can be made.
        revert();
    }
    

	if (msg.value <= 0) {		//If zero or less ether is sent, refund user. 
		revert();
	}
	

	tokenAmount = 210000000000000000000000;						//set the 'amount' var back to zero
	tokenAmount = ((msg.value*rate)/(1 ether));		//calculate the amount of tokens to give
	
    if (balances[msg.sender]+tokenAmount > 25000000000000000000000) {     //Make sure a buyer can't buy more than 100 K Melon Wallet Tokens.
        revert();
    }
	
    if (tokenAmount > 25000000000000000000000) {          //Make sure a buyer can't buy more than 100K Melon Wallet Tokens.
        revert();
    }
	
	if (tokenAmount < 1) {
        revert();
    }
    
	if ((tokenAmount+totalSupply) > 6000000000000000000000000) {      //Make sure that no more than 6 million NGR can be made.
        revert();
    }
      
	mint(msg.sender, tokenAmount);

		
	owner.transfer(msg.value);					//Send the ETH

}  

//This function is called when Ether is sent to the Melon Wallet contract address
//Even if 0 ether is sent.