2019-09-03 15:00:10 +00:00
|
|
|
package tokencontract
|
2018-08-22 16:23:19 +00:00
|
|
|
|
|
|
|
import (
|
2019-08-15 16:41:51 +00:00
|
|
|
"github.com/CityOfZion/neo-go/examples/token/nep5"
|
2018-08-22 16:23:19 +00:00
|
|
|
|
2019-08-15 16:41:51 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/interop/storage"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/interop/util"
|
2018-08-22 16:23:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
decimals = 8
|
|
|
|
multiplier = 100000000
|
|
|
|
)
|
|
|
|
|
|
|
|
var owner = util.FromAddress("AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y")
|
|
|
|
|
|
|
|
// CreateToken initializes the Token Interface for the Smart Contract to operate with
|
2018-08-22 16:49:30 +00:00
|
|
|
func CreateToken() nep5.Token {
|
|
|
|
return nep5.Token{
|
2018-08-22 16:23:19 +00:00
|
|
|
Name: "Awesome NEO Token",
|
|
|
|
Symbol: "ANT",
|
|
|
|
Decimals: decimals,
|
|
|
|
Owner: owner,
|
|
|
|
TotalSupply: 11000000 * multiplier,
|
|
|
|
CirculationKey: "TokenCirculation",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Main function = contract entry
|
|
|
|
func Main(operation string, args []interface{}) interface{} {
|
|
|
|
token := CreateToken()
|
|
|
|
|
|
|
|
if operation == "name" {
|
|
|
|
return token.Name
|
|
|
|
}
|
|
|
|
if operation == "symbol" {
|
|
|
|
return token.Symbol
|
|
|
|
}
|
|
|
|
if operation == "decimals" {
|
|
|
|
return token.Decimals
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following operations need ctx
|
|
|
|
ctx := storage.GetContext()
|
|
|
|
|
|
|
|
if operation == "totalSupply" {
|
|
|
|
return token.GetSupply(ctx)
|
|
|
|
}
|
|
|
|
if operation == "balanceOf" {
|
|
|
|
hodler := args[0].([]byte)
|
|
|
|
return token.BalanceOf(ctx, hodler)
|
|
|
|
}
|
|
|
|
if operation == "transfer" && CheckArgs(args, 3) {
|
|
|
|
from := args[0].([]byte)
|
|
|
|
to := args[1].([]byte)
|
|
|
|
amount := args[2].(int)
|
|
|
|
return token.Transfer(ctx, from, to, amount)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// CheckArgs checks args array against a length indicator
|
|
|
|
func CheckArgs(args []interface{}, length int) bool {
|
|
|
|
if len(args) == length {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|