Guest User

Untitled

a guest
Mar 6th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. pragma solidity ^0.4.0;
  2.  
  3. /**
  4. * @title Ownable
  5. * @dev The Ownable contract has an owner address, and provides basic authorization control
  6. * functions, this simplifies the implementation of "user permissions".
  7. */
  8. contract Ownable {
  9. address public owner;
  10.  
  11.  
  12. event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
  13.  
  14.  
  15. /**
  16. * @dev The Ownable constructor sets the original `owner` of the contract to the sender
  17. * account.
  18. */
  19. function Ownable() public {
  20. owner = msg.sender;
  21. }
  22.  
  23. /**
  24. * @dev Throws if called by any account other than the owner.
  25. */
  26. modifier onlyOwner() {
  27. require(msg.sender == owner);
  28. _;
  29. }
  30.  
  31. /**
  32. * @dev Allows the current owner to transfer control of the contract to a newOwner.
  33. * @param newOwner The address to transfer ownership to.
  34. */
  35. function transferOwnership(address newOwner) public onlyOwner {
  36. require(newOwner != address(0));
  37. OwnershipTransferred(owner, newOwner);
  38. owner = newOwner;
  39. }
  40.  
  41. }
  42.  
  43.  
  44. contract FredCoin is Ownable {
  45.  
  46. string public name = "FredCoin";
  47. string public symbol = "FRD";
  48.  
  49.  
  50. mapping(address => uint) addressBalance;
  51.  
  52. mapping(address => bool) whitelist;
  53.  
  54. event whitelistAccessAtempt(address indexed _who);
  55. modifier onlyWhitelist{
  56. if(whitelist[msg.sender] == true){
  57. _;
  58. }
  59. else{
  60. whitelistAccessAtempt(msg.sender);
  61. }
  62. }
  63.  
  64. function addWhitelist(address _who) onlyOwner{
  65. whitelist[_who] = true;
  66. }
  67.  
  68.  
  69. uint totalTokenSupply;
  70. uint tokenTransferLimit;
  71.  
  72. function FredCoin(uint _totalSupply, uint _tokenLimit) public{
  73. whitelist[msg.sender] = true;
  74. totalTokenSupply = _totalSupply;
  75. tokenTransferLimit = _tokenLimit;
  76. addressBalance[msg.sender] = 1000;
  77. }
  78.  
  79.  
  80. function totalSupply() constant onlyWhitelist returns (uint totalSupply){
  81. totalSupply = totalTokenSupply;
  82. }
  83. function transferLimit() constant onlyWhitelist returns (uint transferLimit){
  84. transferLimit = tokenTransferLimit;
  85. }
  86. function setTransferLimit (uint _value) onlyOwner{
  87. tokenTransferLimit = _value;
  88. }
  89.  
  90. function balanceOf(address _owner) onlyWhitelist constant returns (uint balance) {
  91. return addressBalance[_owner];
  92. }
  93.  
  94. event NotEnoughFundsTransactionAttempt(address indexed _from, address indexed _to, uint _value);
  95. modifier haveEnoughTokens (address _from, address _to, uint _value){
  96. if(addressBalance[_from] > _value){
  97. _;
  98. }
  99. else{
  100. NotEnoughFundsTransactionAttempt(_from, _to, _value);
  101. }
  102. }
  103.  
  104. event OverflowTransactionAttempt (address indexed _from, address indexed _to, uint _value);
  105. modifier stopOverflow (address _from, address _to, uint _value){
  106. if( addressBalance[_to] < (addressBalance[_to] + _value) ){
  107. _;
  108. }
  109. else{
  110. OverflowTransactionAttempt(_from, _to, _value);
  111. }
  112. }
  113.  
  114. event ExceedTransactionLimit (address indexed _from, address indexed _to, uint _value);
  115. modifier transferLimitExceed (address _from, address _to, uint _value){
  116. if(_value < tokenTransferLimit){
  117. _;
  118. }
  119. else{
  120. ExceedTransactionLimit(_from, _to, _value);
  121. }
  122. }
  123.  
  124. event Transfer(address indexed _from, address indexed _to, uint256 _value);
  125. function transfer(address _to, uint256 _value) onlyWhitelist haveEnoughTokens(msg.sender, _to, _value) stopOverflow(msg.sender, _to, _value) transferLimitExceed(msg.sender, _to, _value) returns (bool success) {
  126.  
  127. addressBalance[msg.sender] = addressBalance[msg.sender] - _value;
  128. addressBalance[_to] = addressBalance[_to] + _value;
  129.  
  130. Transfer(msg.sender, _to, _value);
  131. }
  132.  
  133.  
  134.  
  135. mapping(address => mapping(address => uint)) approved;
  136.  
  137. event Approval(address indexed _owner, address indexed _spender, uint256 _value);
  138. function approve(address _spender, uint256 _value) returns (bool success){
  139. approved[msg.sender][_spender] = _value;
  140. Approval(msg.sender, _spender, _value);
  141. return true;
  142. }
  143.  
  144. function allowance(address _owner, address _spender) constant returns (uint256 remaining){
  145. remaining = approved[_owner][_spender];
  146. }
  147.  
  148. function transferFrom(address _from, address _to, uint256 _value) stopOverflow(_from, _to, _value) haveEnoughTokens(_from, _to, _value) returns (bool success) {
  149. if(allowance(_from, _to) > _value){
  150. addressBalance[_from] = addressBalance[_from] - _value;
  151. addressBalance[_to] = addressBalance[_to] + _value;
  152. Transfer(_from, _to, _value);
  153. return true;
  154. }
  155. return false;
  156. }
  157. }
Add Comment
Please, Sign In to add comment