Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3. contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
  4.  
  5. /// @title ICONOMI Daa token
  6. contract DaaToken {
  7. //
  8. // events
  9. //
  10. // ERC20 events
  11. event Transfer(address indexed _from, address indexed _to, uint256 _value);
  12. event Approval(address indexed _owner, address indexed _spender, uint256 _value);
  13.  
  14. // mint/burn events
  15. event Mint(address indexed _to, uint256 _amount, uint256 _newTotalSupply);
  16. event Burn(address indexed _from, uint256 _amount, uint256 _newTotalSupply);
  17.  
  18. // admin events
  19. event BlockLockSet(uint256 _value);
  20. event NewOwner(address _newOwner);
  21. event NewMinter(address _minter);
  22.  
  23. modifier onlyOwner {
  24. if (msg.sender == owner) {
  25. _;
  26. }
  27. }
  28.  
  29. modifier minterOrOwner {
  30. if (msg.sender == minter || msg.sender == owner) {
  31. _;
  32. }
  33. }
  34.  
  35. modifier blockLock(address _sender) {
  36. if (!isLocked() || _sender == owner) {
  37. _;
  38. }
  39. }
  40.  
  41. modifier validTransfer(address _from, address _to, uint256 _amount) {
  42. if (isTransferValid(_from, _to, _amount)) {
  43. _;
  44. }
  45. }
  46.  
  47. uint256 public totalSupply;
  48. string public name;
  49. uint8 public decimals;
  50. string public symbol;
  51. string public version = '0.0.1';
  52. address public owner;
  53. address public minter;
  54. uint256 public lockedUntilBlock;
  55.  
  56. constructor(string _tokenName, uint8 _decimalUnits, string _tokenSymbol, uint256 _lockedUntilBlock)
  57. public
  58. {
  59.  
  60. name = _tokenName;
  61. decimals = _decimalUnits;
  62. symbol = _tokenSymbol;
  63. lockedUntilBlock = _lockedUntilBlock;
  64. owner = msg.sender;
  65. }
  66.  
  67. function transfer(address _to, uint256 _value)
  68. public
  69. blockLock(msg.sender)
  70. validTransfer(msg.sender, _to, _value)
  71. returns (bool success)
  72. {
  73.  
  74. // transfer tokens
  75. balances[msg.sender] -= _value;
  76. balances[_to] += _value;
  77.  
  78. emit Transfer(msg.sender, _to, _value);
  79. return true;
  80. }
  81.  
  82. function approve(address _spender, uint256 _value)
  83. public
  84. returns (bool success)
  85. {
  86. allowed[msg.sender][_spender] = _value;
  87. emit Approval(msg.sender, _spender, _value);
  88. return true;
  89. }
  90.  
  91. function transferFrom(address _from, address _to, uint256 _value)
  92. public
  93. blockLock(_from)
  94. validTransfer(_from, _to, _value)
  95. returns (bool success)
  96. {
  97.  
  98. // check sufficient allowance
  99. if (_value > allowed[_from][msg.sender]) {
  100. return false;
  101. }
  102.  
  103. // transfer tokens
  104. balances[_from] -= _value;
  105. balances[_to] += _value;
  106. allowed[_from][msg.sender] -= _value;
  107.  
  108. emit Transfer(_from, _to, _value);
  109. return true;
  110. }
  111.  
  112. function approveAndCall(address _spender, uint256 _value, bytes _extraData)
  113. public
  114. returns (bool success)
  115. {
  116. if (approve(_spender, _value)) {
  117. tokenRecipient(_spender).receiveApproval(msg.sender, _value, this, _extraData);
  118. return true;
  119. }
  120. }
  121.  
  122. /// @notice Mint new tokens. Can only be called by minter or owner
  123. function mint(address _to, uint256 _value)
  124. public
  125. minterOrOwner
  126. blockLock(msg.sender)
  127. returns (bool success)
  128. {
  129. // ensure _value is greater than zero and
  130. // doesn't overflow
  131. if (totalSupply + _value <= totalSupply) {
  132. return false;
  133. }
  134.  
  135. balances[_to] += _value;
  136. totalSupply += _value;
  137.  
  138. emit Mint(_to, _value, totalSupply);
  139. emit Transfer(0x0, _to, _value);
  140.  
  141. return true;
  142. }
  143.  
  144. /// @notice Burn tokens. Can be called by any account
  145. function burn(uint256 _value)
  146. public
  147. blockLock(msg.sender)
  148. returns (bool success)
  149. {
  150. if (_value == 0 || _value > balances[msg.sender]) {
  151. return false;
  152. }
  153.  
  154. balances[msg.sender] -= _value;
  155. totalSupply -= _value;
  156.  
  157. emit Burn(msg.sender, _value, totalSupply);
  158. emit Transfer(msg.sender, 0x0, _value);
  159.  
  160. return true;
  161. }
  162.  
  163. /// @notice Set block lock. Until that block (exclusive) transfers are disallowed
  164. function setBlockLock(uint256 _lockedUntilBlock)
  165. public
  166. onlyOwner
  167. returns (bool success)
  168. {
  169. lockedUntilBlock = _lockedUntilBlock;
  170. emit BlockLockSet(_lockedUntilBlock);
  171. return true;
  172. }
  173.  
  174. /// @notice Replace current owner with new one
  175. function replaceOwner(address _newOwner)
  176. public
  177. onlyOwner
  178. returns (bool success)
  179. {
  180. owner = _newOwner;
  181. emit NewOwner(_newOwner);
  182. return true;
  183. }
  184.  
  185. /// @notice Set account that can mint new tokens
  186. function setMinter(address _newMinter)
  187. public
  188. onlyOwner
  189. returns (bool success)
  190. {
  191. minter = _newMinter;
  192. emit NewMinter(_newMinter);
  193. return true;
  194. }
  195.  
  196. function balanceOf(address _owner)
  197. public
  198. constant
  199. returns (uint256 balance)
  200. {
  201. return balances[_owner];
  202. }
  203.  
  204. function allowance(address _owner, address _spender)
  205. public
  206. constant
  207. returns (uint256 remaining)
  208. {
  209. return allowed[_owner][_spender];
  210. }
  211.  
  212. /// @notice Are transfers currently disallowed
  213. function isLocked()
  214. public
  215. constant
  216. returns (bool success)
  217. {
  218. return lockedUntilBlock > block.number;
  219. }
  220.  
  221. /// @dev Checks if transfer parameters are valid
  222. function isTransferValid(address _from, address _to, uint256 _amount)
  223. private
  224. constant
  225. returns (bool isValid)
  226. {
  227. return balances[_from] >= _amount && // sufficient balance
  228. _amount > 0 && // amount is positive
  229. _to != address(this) && // prevent sending tokens to contract
  230. _to != 0x0 // prevent sending token to 0x0 address
  231. ;
  232. }
  233.  
  234. mapping (address => uint256) balances;
  235. mapping (address => mapping (address => uint256)) allowed;
  236. }
Add Comment
Please, Sign In to add comment