pragma solidity ^0.4.23; /** * The owned contract ensures that only the creator of a contract can perform certain tasks. */ contract owned { address public owner; /** * Sets the initator as the owner of the contract */ constructor () { owner = msg.sender; } /** * Checks or make sure that only the owner can call a function with this modifier */ modifier onlyOwner { require (msg.sender == owner); _; } /** * Transfer Ownership to `newOwner` * * @param newOwner The new Owner of the contract */ function transferOwnership (address newOwner) onlyOwner { owner = newOwner; } } /** * Receive message from the owner of balance to spend (approveAndCall) */ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; } /** * The EICToken contract is the Estate Invest Coin based on the ERC20 Token Standard */ contract EICToken is owned { // Public variables of the token string public name = "Estate Invest Coin"; string public symbol = "EIC"; string public standard = "EIC Token v1.0"; uint8 public decimals = 18; uint256 public totalSupply; // Array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // Public event on the blockchain that notify clients event Transfer(address indexed _from, address indexed _to, uint256 _value); // Public event on the blockchain that notify clients event Approval(address indexed _owner, address indexed _spender, uint256 _value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Construktor function * * Initializes contract with initial supply and owner */ constructor (uint256 _initialSupply, address _owner) public { // Update total supply with the decimal amount totalSupply = _initialSupply; // Sets the owner if(_owner != 0) owner = _owner; // Give the owner all the initial tokens balanceOf[owner] = totalSupply; } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check if the sender has enough require(balanceOf[_from] >= _value); // Check for overflows require(balanceOf[_to] + _value >= balanceOf[_to]); // Substract from the sender balanceOf[_from] -= _value; // Add the same to the recipient balanceOf[_to] += _value; // Trigger the Transfer event emit Transfer(_from, _to, _value); } /** * Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public returns (bool success) { _transfer(msg.sender, _to, _value); return true; } /** * Transfer tokens from other address * * Send `_value` tokens to `_to` on behalf of `from` * * @param _from The address of the spender * @param _to The address of the recipient * @param _value The amount to spend */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { // Check if spender has enough require(balanceOf[_from] >= _value); // Check the allowance require(allowance[_from][msg.sender] >= _value); // Substract the amount `_value` from the allowance allowance[_from][msg.sender] -= _value; // Call the internal `_tranfer` function _transfer(_from, _to, _value); return true; } /** * Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { // Check if the allowance is set to 0 OR the allowance is 0 // This makes sure that one can't set a new allowance before setting it again to 0 first require((_value == 0) || (allowance[msg.sender][_spender] == 0)); // Set the allowance allowance[msg.sender][_spender] = _value; // Trigger the Approval event emit Approval(msg.sender, _spender, _value); return true; } /** * Set allowance for other address and notify * * Allows `_spender` to spend no more than `_value` tokens on your behalf * and then ping the contract about it * * @param _spender The address authorized to spend * @param _value The max amount they can spend * @param _extraData Some extra information to send to the approved contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); if(approve(_spender, _value)) { spender.receiveApproval(msg.sender, _value, this, _extraData); return true; } } /** * Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value The amount of money to burn */ function burn(uint256 _value) public returns (bool success) { // Check if the sender has enough require(balanceOf[msg.sender] >= _value); // Substract from the sender balanceOf[msg.sender] -= _value; // Substract from the totalSupply totalSupply -= _value; // Trigger the Burn event emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other account * * Remove `_value` tokens from the system irreversibly on behalf of `_from` * * @param _from The address of the sender * @param _value The amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { // Check if the targeted balance is enough require(balanceOf[_from] >= _value); // Check the allowance require(allowance[_from][msg.sender] >= _value); // Substract from the targeted balance balanceOf[_from] -= _value; // Substract from the sender's allowance allowance[_from][msg.sender] -= _value; // Substract from the totalSupply totalSupply -= _value; // Trigger the burn event emit Burn(_from, _value); return true; } }
0.4.24