neo-go/examples/token/token.go
Elizaveta Chichindaeva 28908aa3cf [#2442] English Check
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
2022-05-04 19:48:27 +03:00

63 lines
1.4 KiB
Go

package tokencontract
import (
"github.com/nspcc-dev/neo-go/examples/token/nep17"
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
"github.com/nspcc-dev/neo-go/pkg/interop/util"
)
const (
decimals = 8
multiplier = 100000000
)
var (
owner = util.FromAddress("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB")
token nep17.Token
ctx storage.Context
)
// init initializes Token Interface and storage context for the Smart
// Contract to operate with
func init() {
token = nep17.Token{
Name: "Awesome NEO Token",
Symbol: "ANT",
Decimals: decimals,
Owner: owner,
TotalSupply: 11000000 * multiplier,
CirculationKey: "TokenCirculation",
}
ctx = storage.GetContext()
}
// Symbol returns the token symbol
func Symbol() string {
return token.Symbol
}
// Decimals returns the token decimals
func Decimals() int {
return token.Decimals
}
// TotalSupply returns the token total supply value
func TotalSupply() int {
return token.GetSupply(ctx)
}
// BalanceOf returns the amount of token on the specified address
func BalanceOf(holder interop.Hash160) int {
return token.BalanceOf(ctx, holder)
}
// Transfer token from one user to another
func Transfer(from interop.Hash160, to interop.Hash160, amount int, data interface{}) bool {
return token.Transfer(ctx, from, to, amount, data)
}
// Mint initial supply of tokens
func Mint(to interop.Hash160) bool {
return token.Mint(ctx, to)
}