-
Notifications
You must be signed in to change notification settings - Fork 13
TestToken
woodbaer edited this page Nov 6, 2019
·
2 revisions
pragma solidity ^0.5.0;
import "./RC20.sol";
contract TestToken is ERC20 {
event IncreaseSupply(address indexed addr, uint256 value);
event DecreaseSupply(address indexed addr, uint256 value);
string public name; // Token name
string public symbol; // Token symbol
uint8 public decimals; // Token decimals
uint256 public totalSupply; // Number of tokens
address public owner; // contract owner
// The related value of the contract token passed in when deploying the contract
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _totalSupply) public {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _totalSupply.mul(10 ** uint256(_decimals));
owner = msg.sender;
_balances[owner] = totalSupply;
}
modifier onlyOwner() {
require(owner == msg.sender, "Not the owner operation!");
_;
}
// Increase the number of tokens
function increaseSupply(uint256 addValue) public onlyOwner {
uint256 addSupply = addValue.mul(10 ** uint256(decimals));
totalSupply = totalSupply.add(addSupply);
_balances[owner] = _balances[owner].add(addSupply);
emit IncreaseSupply(owner, addSupply);
}
// Reduce the number of tokens
function decreaseSupply(uint256 subValue) public onlyOwner {
uint256 subSupply = subValue.mul(10 ** uint256(decimals));
_balances[owner] = _balances[owner].sub(subSupply);
totalSupply = totalSupply.sub(subSupply);
emit DecreaseSupply(owner, subSupply);
}
}