Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.16;
- contract TokenNep {
- // Public variables of the token
- address public depositor;
- //java code is setup to generate signature for minting so that authority is assured
- //for now static authority is established my own address :)
- address public authority = 0x454dff705e29c3845f13738dd39d3e1db9343ac2;
- string public name;
- string public symbol;
- uint8 public decimals = 2;
- // 18 decimals is the strongly suggested default, avoid changing it
- uint256 public totalSupply;
- //% fee rate
- uint public rate = 1;
- //500 is Rs.5 with two decimal
- uint public minFee= 500;
- //10000 is Rs.100 with two decimal
- uint public maxFee = 10000;
- // This creates an array with all balances
- mapping (address => uint256) public balanceOf;
- // This generates a public event on the blockchain that will notify clients
- event Transfer(address indexed from, address indexed to, uint256 value);
- // This notifies clients about the amount burnt
- event Burn(address indexed from, uint256 value);
- //this notifies about mint
- event Mint(address indexed by, uint256 value);
- modifier isDepositor {
- require(msg.sender == depositor);
- _;
- }
- /**
- * Constrctor function
- *
- * Initializes contract with initial supply tokens to the creator of the contract
- * fees should consider decimal part as well in this case because fee can be less than Rs.1
- */
- function TokenNep(
- uint256 initialSupply,
- string tokenName,
- string tokenSymbol
- ) public {
- totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
- balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
- name = tokenName; // Set the name for display purposes
- symbol = tokenSymbol; // Set the symbol for display purposes
- depositor = msg.sender;
- }
- /**
- * Internal transfer, only can be called by this contract
- */
- function _transfer(address _from, address _to, uint _value, uint fee) internal {
- // Prevent transfer to 0x0 address. Use burn() instead
- require(_to != 0x0);
- // Check if the sender has enough
- require(balanceOf[_from] >= _value + fee);
- // Check for overflows
- require(balanceOf[_to] + _value > balanceOf[_to]);
- // Save this for an assertion in the future
- uint previousBalances = balanceOf[_from] + balanceOf[_to];
- // Subtract from the sender
- balanceOf[_from] -= (_value + fee );
- // send fee to deployer
- balanceOf[depositor] += fee;
- // Add the same to the recipient
- balanceOf[_to] += _value;
- Transfer(_from, _to, _value);
- // Asserts are used to use static analysis to find bugs in your code. They should never fail
- // if sender is depositor itself then fee is gained by himself so fee substraction and addition results zero fee
- if(_from == depositor){
- assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
- }
- else{
- assert(balanceOf[_from] + balanceOf[_to] + fee == previousBalances);
- }
- }
- /**
- * Transfer tokens
- *
- * Send `_value` tokens to `_to` from your account
- *
- * @param _to The address of the recipient
- * @param _value the amount to send
- */
- function transfer(address _to, uint256 _value) public {
- _transfer(msg.sender, _to, _value, _calculateFee(_value));
- }
- function _calculateFee(uint256 _value) internal returns(uint){
- uint fee = _value * rate/100;
- if(fee > maxFee){
- fee = maxFee;
- }
- else if (fee < minFee){
- fee = minFee;
- }
- return fee;
- }
- /**
- * Destroy tokens
- * can only be done by depositor
- *
- * Remove `_value` tokens from the system irreversibly
- *
- * @param _value the amount of money to burn
- * _value being the value including two places for decima
- */
- function burn(uint256 _value) public isDepositor returns (bool success) {
- require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
- balanceOf[msg.sender] -= _value; // Subtract from the sender
- totalSupply -= _value; // Updates totalSupply
- Burn(msg.sender, _value);
- return true;
- }
- /**
- * mint tokens
- * can only be done by depositor
- *value including the value with two places for decimal
- * so if you want to mint Rs.9 it should be 900
- * msg hash is like a certificate provided by authority on NRS deposit
- * msg hash along with v,r and s should be generated by authority or minting cannot be done
- */
- function mint(uint256 _value,bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) public isDepositor returns(bool success){
- require(ecrecover(msgHash, v, r, s) == authority);
- totalSupply += _value;
- balanceOf[msg.sender] += _value;
- Mint(msg.sender, _value);
- return true;
- }
- }
Add Comment
Please, Sign In to add comment