pragma solidity ^0.4.16;
//Base class of token-owner
contract Ownable {
address public owner; //owner's address
function Ownable() public
{
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/*
* Funtion: Transfer owner's authority
* Type:Public and onlyOwner
* Parameters:
@newOwner: address of newOwner
*/
function transferOwnership(address newOwner) onlyOwner public{
if (newOwner != address(0)) {
owner = newOwner;
}
}
function kill() onlyOwner public{
selfdestruct(owner);
}
}
//Announcement of an interface for recipient approving
interface tokenRecipient {
function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData)public;
}
contract BITStationERC20 is Ownable{
//===================public variables definition start==================
string public name; //Name of your Token
string public symbol; //Symbol of your Token
uint8 public decimals; //Decimals of your Token
uint256 public totalSupply; //Maximum amount of Token supplies
//define dictionaries of balance
mapping (address => uint256) public balanceOf; //Announce the dictionary of account's balance
mapping (address => mapping (address => uint256)) public allowance; //Announce the dictionary of account's available balance
//===================public variables definition end==================
//===================events definition start==================
event Transfer(address indexed from, address indexed to, uint256 value); //Event on blockchain which notify client
//===================events definition end==================
//===================Contract Initialization Sequence Definition start===================
function BITStationERC20 () public {
decimals=7; //Assignment of Token's decimals
totalSupply = 12000000000 * 10 ** uint256(decimals); //Assignment of Token's total supply with decimals
balanceOf[owner] = totalSupply; //Assignment of Token's creator initial tokens
name = "BitStation"; //Set the name of Token
symbol = "BSTN"; //Set the symbol of Token
}
//===================Contract Initialization Sequence definition end===================
//===================Contract behavior & funtions definition start===================
/*
* Funtion: Transfer funtions
* Type:Internal
* Parameters:
@_from: address of sender's account
@_to: address of recipient's account
@_value:transaction amount
*/
function _transfer(address _from, address _to, uint _value) internal {
//Fault-tolerant processing
require(_to != 0x0); //
require(balanceOf[_from] >= _value);
require(balanceOf[_to] + _value > balanceOf[_to]);
//Execute transaction
uint previousBalances = balanceOf[_from] + balanceOf[_to];
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
Transfer(_from, _to, _value);
//Verify transaction
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
/*
* Funtion: Transfer tokens
* Type:Public
* Parameters:
@_to: address of recipient's account
@_value:transaction amount
*/
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
/*
* Funtion: Transfer tokens from other address
* Type:Public
* Parameters:
@_from: address of sender's account
@_to: address of recipient's account
@_value:transaction amount
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_value <= allowance[_from][msg.sender]); //Allowance verification
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
/*
* Funtion: Approve usable amount for an account
* Type:Public
* Parameters:
@_spender: address of spender's account
@_value: approve amount
*/
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowance[msg.sender][_spender] = _value;
return true;
}
/*
* Funtion: Approve usable amount for other address and then notify the contract
* Type:Public
* Parameters:
@_spender: address of other account
@_value: approve amount
@_extraData:additional 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;
}
}
/*
* Funtion: Transfer owner's authority and account balance
* Type:Public and onlyOwner
* Parameters:
@newOwner: address of newOwner
*/
function transferOwnershipWithBalance(address newOwner) onlyOwner public{
if (newOwner != address(0)) {
_transfer(owner,newOwner,balanceOf[owner]);
owner = newOwner;
}
}
//===================Contract behavior & funtions definition end===================
}
{
"compilationTarget": {
"BITStationERC20.sol": "BITStationERC20"
},
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnershipWithBalance","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]