1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
| pragma solidity ^0.4.18;
// ---------------------------------------------------------------------------- // '' token contract // // 部署地址 : // 標志 : LOVE // 名字 : LOVE TOKEN // 總供應量 100000000000000000000000000 // 精度 : 18
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // SafeMath安全庫 // ---------------------------------------------------------------------------- contract SafeMath { function safeAdd(uint a, uint b) public pure returns (uint c) { c = a + b; require(c >= a); } function safeSub(uint a, uint b) public pure returns (uint c) { require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0); c = a / b; } }
// ---------------------------------------------------------------------------- // ERC20 代幣標準 // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md // ---------------------------------------------------------------------------- contract ERC20Interface { //總發行數量 function totalSupply() public constant returns (uint); //查詢數量 function balanceOf(address tokenOwner) public constant returns (uint balance); //查詢授權數量 function allowance(address tokenOwner, address spender) public constant returns (uint remaining); //轉賬 function transfer(address to, uint tokens) public returns (bool success); //授權 function approve(address spender, uint tokens) public returns (bool success); //授權轉賬 function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens); event Approval(address indexed tokenOwner, address indexed spender, uint tokens); }
// ---------------------------------------------------------------------------- // 所有者合約 // ---------------------------------------------------------------------------- contract Owned { address public owner; address public newOwner;
event OwnershipTransferred(address indexed _from, address indexed _to);
function Owned() public { owner = msg.sender; }
modifier onlyOwner { require(msg.sender == owner); _; }
function transferOwnership(address _newOwner) public onlyOwner { newOwner = _newOwner; } function acceptOwnership() public { require(msg.sender == newOwner); OwnershipTransferred(owner, newOwner); owner = newOwner; newOwner = address(0); } }
// ---------------------------------------------------------------------------- // ERC20代幣,增加標志、名字、精度 // 代幣轉移 // ---------------------------------------------------------------------------- contract LOVEToken is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply;
mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------ // 構造函數 // ------------------------------------------------------------------------ function LOVEToken() public { symbol = "LOVER"; name = "LOVER Token"; decimals = 18; _totalSupply = 100000000000000000000000000;
balances[0x6AFe57C1F589C4744ab9FF4ac8899080695a6f5e] = _totalSupply;
Transfer(address(0), 0x6AFe57C1F589C4744ab9FF4ac8899080695a6f5e, _totalSupply); }
// ------------------------------------------------------------------------ // 總供應量 // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; }
// ------------------------------------------------------------------------ // 得到資金的數量 // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; }
// ------------------------------------------------------------------------ // 轉賬從代幣擁有者的賬戶到其他賬戶 // - 所有者的賬戶必須有充足的資金去轉賬 // - 0值的轉賬也是被允許的 // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; }
// ------------------------------------------------------------------------ // 授權 // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; }
// ------------------------------------------------------------------------ // 和approve連接在一起 // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; }
// ------------------------------------------------------------------------ // 返回授權數量 // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; }
// ------------------------------------------------------------------------ // 合約不接受以太幣 // ------------------------------------------------------------------------ function () public payable { revert(); }
// ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens //所有者能夠轉移任何ERC20代幣的接口 // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
|