2019-09-03 15:00:10 +00:00
|
|
|
package tokencontract
|
2018-08-22 16:23:19 +00:00
|
|
|
|
|
|
|
import (
|
2020-11-24 08:14:25 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/examples/token/nep17"
|
2020-08-28 07:47:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
2018-08-22 16:23:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
decimals = 8
|
|
|
|
multiplier = 100000000
|
|
|
|
)
|
|
|
|
|
2020-08-10 10:42:02 +00:00
|
|
|
var (
|
|
|
|
owner = util.FromAddress("NULwe3UAHckN2fzNdcVg31tDiaYtMDwANt")
|
2020-11-24 08:14:25 +00:00
|
|
|
token nep17.Token
|
2020-08-10 10:42:02 +00:00
|
|
|
ctx storage.Context
|
|
|
|
)
|
2018-08-22 16:23:19 +00:00
|
|
|
|
2020-08-10 10:42:02 +00:00
|
|
|
// init initializes the Token Interface and storage context for the Smart
|
|
|
|
// Contract to operate with
|
|
|
|
func init() {
|
2020-11-24 08:14:25 +00:00
|
|
|
token = nep17.Token{
|
2018-08-22 16:23:19 +00:00
|
|
|
Name: "Awesome NEO Token",
|
|
|
|
Symbol: "ANT",
|
|
|
|
Decimals: decimals,
|
|
|
|
Owner: owner,
|
|
|
|
TotalSupply: 11000000 * multiplier,
|
|
|
|
CirculationKey: "TokenCirculation",
|
|
|
|
}
|
2020-08-10 10:42:02 +00:00
|
|
|
ctx = storage.GetContext()
|
2018-08-22 16:23:19 +00:00
|
|
|
}
|
2020-07-03 11:53:29 +00:00
|
|
|
|
|
|
|
// Symbol returns the token symbol
|
|
|
|
func Symbol() string {
|
2020-08-10 10:42:02 +00:00
|
|
|
return token.Symbol
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decimals returns the token decimals
|
|
|
|
func Decimals() int {
|
2020-08-10 10:42:02 +00:00
|
|
|
return token.Decimals
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TotalSupply returns the token total supply value
|
2020-08-10 10:42:02 +00:00
|
|
|
func TotalSupply() int {
|
|
|
|
return token.GetSupply(ctx)
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BalanceOf returns the amount of token on the specified address
|
2020-11-24 10:38:24 +00:00
|
|
|
func BalanceOf(holder interop.Hash160) int {
|
2020-08-10 10:42:02 +00:00
|
|
|
return token.BalanceOf(ctx, holder)
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transfer token from one user to another
|
2020-11-19 15:01:42 +00:00
|
|
|
func Transfer(from interop.Hash160, to interop.Hash160, amount int, data interface{}) bool {
|
|
|
|
return token.Transfer(ctx, from, to, amount, data)
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mint initial supply of tokens
|
2020-11-24 10:38:24 +00:00
|
|
|
func Mint(to interop.Hash160) bool {
|
2020-08-10 10:42:02 +00:00
|
|
|
return token.Mint(ctx, to)
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|