From c84c33d39877d42c56869e35de4672a159f3e19a Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 3 Apr 2020 12:26:13 +0300 Subject: [PATCH] examples: add nep5 mint function Add Mint(...) to NEP5 for initial tokens supply. --- examples/token/nep5/nep5.go | 16 ++++++++++++++++ examples/token/token.go | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/examples/token/nep5/nep5.go b/examples/token/nep5/nep5.go index f16abd38c..96a465b6d 100644 --- a/examples/token/nep5/nep5.go +++ b/examples/token/nep5/nep5.go @@ -93,3 +93,19 @@ func IsUsableAddress(addr []byte) bool { return false } + +// Mint initial supply of tokens. +func (t Token) Mint(ctx storage.Context, to []byte) bool { + if !IsUsableAddress(t.Owner) { + return false + } + minted := storage.Get(ctx, []byte("minted")).(bool) + if minted { + return false + } + + storage.Put(ctx, to, t.TotalSupply) + storage.Put(ctx, []byte("minted"), true) + runtime.Notify("transfer", "", to, t.TotalSupply) + return true +} diff --git a/examples/token/token.go b/examples/token/token.go index 51f045f81..d4b78c2d2 100644 --- a/examples/token/token.go +++ b/examples/token/token.go @@ -56,6 +56,10 @@ func Main(operation string, args []interface{}) interface{} { amount := args[2].(int) return token.Transfer(ctx, from, to, amount) } + if operation == "mint" && CheckArgs(args, 1) { + addr := args[0].([]byte) + return token.Mint(ctx, addr) + } return true }