Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Stratis.SmartContracts;
- using Stratis.SmartContracts.Token;
- /// <summary>
- /// Implementation of a standard token contract for the Stratis Platform.
- /// DISCLAIMER: For demonstration purposes only.
- /// </summary>
- public class StandardToken : SmartContract, IStandardToken
- {
- /// <summary>
- /// Constructor used to create a new instance of the token. Assigns the total token supply to the creator of the contract.
- /// </summary>
- /// <param name="smartContractState">The execution state for the contract.</param>
- /// <param name="totalSupply">The total token supply.</param>
- public StandardToken(ISmartContractState smartContractState, uint totalSupply)
- : base(smartContractState)
- {
- this.TotalSupply = totalSupply;
- this.SetBalance(Message.Sender, totalSupply);
- }
- ...
- /// <inheritdoc />
- public bool Transfer(Address to, uint amount)
- {
- if (amount == 0)
- {
- Log(new TransferLog { From = Message.Sender, To = to, Amount = 0 });
- return true;
- }
- uint senderBalance = GetBalance(Message.Sender);
- if (senderBalance < amount)
- {
- return false;
- }
- uint toBalance = GetBalance(to);
- SetBalance(Message.Sender, senderBalance - amount);
- SetBalance(to, checked(toBalance + amount));
- Log(new TransferLog { From = Message.Sender, To = to, Amount = amount });
- return true;
- }
- ...
- }
Add Comment
Please, Sign In to add comment