neoneo-go/examples/token/token.go

68 lines
1.4 KiB
Go
Raw Normal View History

package tokencontract
import (
"github.com/nspcc-dev/neo-go/examples/token/nep5"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
"github.com/nspcc-dev/neo-go/pkg/interop/util"
)
const (
decimals = 8
multiplier = 100000000
)
2020-08-10 10:42:02 +00:00
var (
owner = util.FromAddress("NULwe3UAHckN2fzNdcVg31tDiaYtMDwANt")
token nep5.Token
ctx storage.Context
)
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() {
token = nep5.Token{
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()
}
// Name returns the token name
func Name() string {
2020-08-10 10:42:02 +00:00
return token.Name
}
// Symbol returns the token symbol
func Symbol() string {
2020-08-10 10:42:02 +00:00
return token.Symbol
}
// Decimals returns the token decimals
func Decimals() int {
2020-08-10 10:42:02 +00:00
return token.Decimals
}
// TotalSupply returns the token total supply value
2020-08-10 10:42:02 +00:00
func TotalSupply() int {
return token.GetSupply(ctx)
}
// BalanceOf returns the amount of token on the specified address
func BalanceOf(holder []byte) interface{} {
2020-08-10 10:42:02 +00:00
return token.BalanceOf(ctx, holder)
}
// Transfer token from one user to another
func Transfer(from []byte, to []byte, amount int) bool {
2020-08-10 10:42:02 +00:00
return token.Transfer(ctx, from, to, amount)
}
// Mint initial supply of tokens
func Mint(to []byte) bool {
2020-08-10 10:42:02 +00:00
return token.Mint(ctx, to)
}