Guest User

Untitled

a guest
Oct 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using Stratis.SmartContracts;
  2. using Stratis.SmartContracts.Token;
  3.  
  4. /// <summary>
  5. /// Implementation of a standard token contract for the Stratis Platform.
  6. /// DISCLAIMER: For demonstration purposes only.
  7. /// </summary>
  8. public class StandardToken : SmartContract, IStandardToken
  9. {
  10. /// <summary>
  11. /// Constructor used to create a new instance of the token. Assigns the total token supply to the creator of the contract.
  12. /// </summary>
  13. /// <param name="smartContractState">The execution state for the contract.</param>
  14. /// <param name="totalSupply">The total token supply.</param>
  15. public StandardToken(ISmartContractState smartContractState, uint totalSupply)
  16. : base(smartContractState)
  17. {
  18. this.TotalSupply = totalSupply;
  19. this.SetBalance(Message.Sender, totalSupply);
  20. }
  21.  
  22. ...
  23.  
  24. /// <inheritdoc />
  25. public bool Transfer(Address to, uint amount)
  26. {
  27. if (amount == 0)
  28. {
  29. Log(new TransferLog { From = Message.Sender, To = to, Amount = 0 });
  30.  
  31. return true;
  32. }
  33.  
  34. uint senderBalance = GetBalance(Message.Sender);
  35.  
  36. if (senderBalance < amount)
  37. {
  38. return false;
  39. }
  40.  
  41. uint toBalance = GetBalance(to);
  42.  
  43. SetBalance(Message.Sender, senderBalance - amount);
  44.  
  45. SetBalance(to, checked(toBalance + amount));
  46.  
  47. Log(new TransferLog { From = Message.Sender, To = to, Amount = amount });
  48.  
  49. return true;
  50. }
  51. ...
  52. }
Add Comment
Please, Sign In to add comment