Guest User

Untitled

a guest
Jan 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. pragma solidity ^0.4.16;
  2.  
  3. contract TokenNep {
  4. // Public variables of the token
  5. address public depositor;
  6.  
  7.  
  8. //java code is setup to generate signature for minting so that authority is assured
  9. //for now static authority is established my own address :)
  10.  
  11. address public authority = 0x454dff705e29c3845f13738dd39d3e1db9343ac2;
  12.  
  13. string public name;
  14. string public symbol;
  15. uint8 public decimals = 2;
  16. // 18 decimals is the strongly suggested default, avoid changing it
  17. uint256 public totalSupply;
  18.  
  19. //% fee rate
  20.  
  21. uint public rate = 1;
  22.  
  23. //500 is Rs.5 with two decimal
  24. uint public minFee= 500;
  25.  
  26. //10000 is Rs.100 with two decimal
  27. uint public maxFee = 10000;
  28.  
  29. // This creates an array with all balances
  30. mapping (address => uint256) public balanceOf;
  31.  
  32. // This generates a public event on the blockchain that will notify clients
  33. event Transfer(address indexed from, address indexed to, uint256 value);
  34.  
  35. // This notifies clients about the amount burnt
  36. event Burn(address indexed from, uint256 value);
  37.  
  38.  
  39. //this notifies about mint
  40. event Mint(address indexed by, uint256 value);
  41.  
  42. modifier isDepositor {
  43. require(msg.sender == depositor);
  44. _;
  45. }
  46.  
  47.  
  48. /**
  49. * Constrctor function
  50. *
  51. * Initializes contract with initial supply tokens to the creator of the contract
  52. * fees should consider decimal part as well in this case because fee can be less than Rs.1
  53. */
  54. function TokenNep(
  55. uint256 initialSupply,
  56. string tokenName,
  57. string tokenSymbol
  58. ) public {
  59. totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
  60. balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
  61. name = tokenName; // Set the name for display purposes
  62. symbol = tokenSymbol; // Set the symbol for display purposes
  63. depositor = msg.sender;
  64. }
  65.  
  66. /**
  67. * Internal transfer, only can be called by this contract
  68. */
  69. function _transfer(address _from, address _to, uint _value, uint fee) internal {
  70. // Prevent transfer to 0x0 address. Use burn() instead
  71. require(_to != 0x0);
  72. // Check if the sender has enough
  73. require(balanceOf[_from] >= _value + fee);
  74. // Check for overflows
  75. require(balanceOf[_to] + _value > balanceOf[_to]);
  76. // Save this for an assertion in the future
  77. uint previousBalances = balanceOf[_from] + balanceOf[_to];
  78. // Subtract from the sender
  79. balanceOf[_from] -= (_value + fee );
  80.  
  81. // send fee to deployer
  82. balanceOf[depositor] += fee;
  83.  
  84. // Add the same to the recipient
  85. balanceOf[_to] += _value;
  86. Transfer(_from, _to, _value);
  87. // Asserts are used to use static analysis to find bugs in your code. They should never fail
  88. // if sender is depositor itself then fee is gained by himself so fee substraction and addition results zero fee
  89. if(_from == depositor){
  90. assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
  91.  
  92. }
  93. else{
  94. assert(balanceOf[_from] + balanceOf[_to] + fee == previousBalances);
  95. }
  96. }
  97.  
  98. /**
  99. * Transfer tokens
  100. *
  101. * Send `_value` tokens to `_to` from your account
  102. *
  103. * @param _to The address of the recipient
  104. * @param _value the amount to send
  105. */
  106. function transfer(address _to, uint256 _value) public {
  107. _transfer(msg.sender, _to, _value, _calculateFee(_value));
  108. }
  109.  
  110.  
  111.  
  112. function _calculateFee(uint256 _value) internal returns(uint){
  113.  
  114. uint fee = _value * rate/100;
  115. if(fee > maxFee){
  116. fee = maxFee;
  117. }
  118. else if (fee < minFee){
  119. fee = minFee;
  120. }
  121. return fee;
  122. }
  123.  
  124.  
  125. /**
  126. * Destroy tokens
  127. * can only be done by depositor
  128. *
  129. * Remove `_value` tokens from the system irreversibly
  130. *
  131. * @param _value the amount of money to burn
  132. * _value being the value including two places for decima
  133. */
  134. function burn(uint256 _value) public isDepositor returns (bool success) {
  135. require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
  136. balanceOf[msg.sender] -= _value; // Subtract from the sender
  137. totalSupply -= _value; // Updates totalSupply
  138. Burn(msg.sender, _value);
  139. return true;
  140. }
  141.  
  142.  
  143.  
  144.  
  145. /**
  146. * mint tokens
  147. * can only be done by depositor
  148. *value including the value with two places for decimal
  149. * so if you want to mint Rs.9 it should be 900
  150. * msg hash is like a certificate provided by authority on NRS deposit
  151. * msg hash along with v,r and s should be generated by authority or minting cannot be done
  152. */
  153. function mint(uint256 _value,bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) public isDepositor returns(bool success){
  154. require(ecrecover(msgHash, v, r, s) == authority);
  155. totalSupply += _value;
  156. balanceOf[msg.sender] += _value;
  157. Mint(msg.sender, _value);
  158. return true;
  159. }
  160. }
Add Comment
Please, Sign In to add comment