Skip to content

Instantly share code, notes, and snippets.

@iaoedsz2008
Created September 12, 2019 06:37
Show Gist options
  • Save iaoedsz2008/6f83082f944c182236eb6f3e4bfb97ea to your computer and use it in GitHub Desktop.
Save iaoedsz2008/6f83082f944c182236eb6f3e4bfb97ea to your computer and use it in GitHub Desktop.
ERC20 Token
pragma solidity ^0.5.0;
interface IERC20 {
function name () external view returns (string memory);
function symbol () external view returns (string memory);
function decimals () external view returns (uint8 );
function totalSupply () external view returns (uint256);
function balanceOf (address account) external view returns (uint256);
function transfer (address recipient, uint256 amount) external returns (bool);
function allowance (address owner, address spender) external view returns (uint256);
function approve (address spender, uint256 amount) external returns (bool);
function transferFrom (address sender, address recipient, uint256 amount) external returns (bool);
event Transfer (address indexed from, address indexed to, uint256 value);
event Approval (address indexed owner, address indexed spender, uint256 value);
}
contract TOKEN is IERC20 {
string constant NAME = "Tencent QQ Token";
string constant SYMBOL = "QB";
uint8 constant DECIMALS = 10;
uint256 constant UNIT = 10 ** uint256 (DECIMALS);
uint256 constant TOTALSUPPLY = 100 * UNIT;
address private m_owner;
/* user info */
struct user_t {
bool frozen;
uint256 balance;
}
/* user info */
mapping (address => user_t) m_users;
/* get the owner's address */
constructor () public {
m_owner = msg.sender;
user_t storage u = m_users[msg.sender];
u.balance = TOTALSUPPLY;
}
function name () external view returns (string memory) {
return NAME;
}
function symbol () external view returns (string memory) {
return SYMBOL;
}
function decimals () external view returns (uint8) {
return DECIMALS;
}
function totalSupply () external view returns (uint256) {
return TOTALSUPPLY;
}
function balanceOf (address addr) external view returns (uint256) {
user_t storage u = m_users[addr];
return u.balance;
}
function transfer (address recipient, uint256 amount) public returns (bool) {
user_t storage from = m_users[msg.sender];
user_t storage to = m_users[recipient];
require (from.frozen == false);
require (amount >= UNIT);
require (from.balance >= amount);
from.balance -= amount;
to.balance += amount;
emit Transfer (msg.sender, recipient, amount);
return true;
}
function allowance (address owner, address spender) external view returns (uint256) {
return 0;
}
function approve (address spender, uint256 amount) external returns (bool) {
return false;
}
function transferFrom (address sender, address recipient, uint256 amount) external returns (bool) {
return false;
}
/* BEGIN CUSTOM */
function setfrozen (address addr, bool status) public returns (bool) {
require (msg.sender == m_owner);
user_t storage u = m_users[addr];
u.frozen = status;
return true;
}
function frozen (address addr) external view returns (bool) {
require (msg.sender == m_owner);
user_t memory u = m_users[addr];
return u.frozen;
}
/* END CUSTOM*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment