Merge pull request #823 from nspcc-dev/examples/nep5
examples: add nep5 mint function
This commit is contained in:
commit
c0b5271386
2 changed files with 20 additions and 0 deletions
|
@ -93,3 +93,19 @@ func IsUsableAddress(addr []byte) bool {
|
||||||
|
|
||||||
return false
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -56,6 +56,10 @@ func Main(operation string, args []interface{}) interface{} {
|
||||||
amount := args[2].(int)
|
amount := args[2].(int)
|
||||||
return token.Transfer(ctx, from, to, amount)
|
return token.Transfer(ctx, from, to, amount)
|
||||||
}
|
}
|
||||||
|
if operation == "mint" && CheckArgs(args, 1) {
|
||||||
|
addr := args[0].([]byte)
|
||||||
|
return token.Mint(ctx, addr)
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue