-
Notifications
You must be signed in to change notification settings - Fork 1
/
token.go
112 lines (100 loc) · 3.14 KB
/
token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package embedded
import (
"math/big"
"github.com/zenon-network/go-zenon/chain/nom"
"github.com/zenon-network/go-zenon/common"
"github.com/zenon-network/go-zenon/common/types"
"github.com/zenon-network/go-zenon/rpc/api"
"github.com/zenon-network/go-zenon/rpc/api/embedded"
"github.com/zenon-network/go-zenon/rpc/server"
"github.com/zenon-network/go-zenon/vm/constants"
"github.com/zenon-network/go-zenon/vm/embedded/definition"
)
type TokenApi struct {
client *server.Client
}
func NewTokenApi(client *server.Client) *TokenApi {
return &TokenApi{
client: client,
}
}
func (ta *TokenApi) GetAll(pageIndex, pageSize uint32) (*embedded.TokenList, error) {
ans := new(embedded.TokenList)
if err := ta.client.Call(ans, "embedded.token.getAll", pageIndex, pageSize); err != nil {
return nil, err
}
return ans, nil
}
func (ta *TokenApi) GetByOwner(address types.Address, pageIndex, pageSize uint32) (*embedded.TokenList, error) {
ans := new(embedded.TokenList)
if err := ta.client.Call(ans, "embedded.token.getByOwner", address, pageIndex, pageSize); err != nil {
return nil, err
}
return ans, nil
}
func (ta *TokenApi) GetByZts(zts types.ZenonTokenStandard) (*api.Token, error) {
ans := new(api.Token)
if err := ta.client.Call(ans, "embedded.token.getByZts", zts.String()); err != nil {
return nil, err
}
return ans, nil
}
// Contract calls
func (ta *TokenApi) IssueToken(tokenName, tokenSymbol, tokenDomain string, totalSupply, maxSupply *big.Int, decimals uint8, isMintable, isBurnable, isUtility bool) *nom.AccountBlock {
return &nom.AccountBlock{
BlockType: nom.BlockTypeUserSend,
ToAddress: types.TokenContract,
TokenStandard: types.ZnnTokenStandard,
Amount: constants.TokenIssueAmount,
Data: definition.ABIToken.PackMethodPanic(
definition.IssueMethodName,
tokenName,
tokenSymbol,
tokenDomain,
totalSupply,
maxSupply,
decimals,
isMintable,
isBurnable,
isUtility,
),
}
}
func (ta *TokenApi) Mint(tokenStandard types.ZenonTokenStandard, amount *big.Int, receiver types.Address) *nom.AccountBlock {
return &nom.AccountBlock{
BlockType: nom.BlockTypeUserSend,
ToAddress: types.TokenContract,
TokenStandard: types.ZnnTokenStandard,
Amount: common.Big0,
Data: definition.ABIToken.PackMethodPanic(
definition.MintMethodName,
tokenStandard,
amount,
receiver,
),
}
}
func (ta *TokenApi) Burn(tokenStandard types.ZenonTokenStandard, amount *big.Int) *nom.AccountBlock {
return &nom.AccountBlock{
BlockType: nom.BlockTypeUserSend,
ToAddress: types.TokenContract,
TokenStandard: tokenStandard,
Amount: amount,
Data: definition.ABIToken.PackMethodPanic(definition.BurnMethodName),
}
}
func (ta *TokenApi) UpdateToken(tokenStandard types.ZenonTokenStandard, owner types.Address, isMintable, isBurnable bool) *nom.AccountBlock {
return &nom.AccountBlock{
BlockType: nom.BlockTypeUserSend,
ToAddress: types.TokenContract,
TokenStandard: types.ZnnTokenStandard,
Amount: common.Big0,
Data: definition.ABIToken.PackMethodPanic(
definition.UpdateTokenMethodName,
tokenStandard,
owner,
isMintable,
isBurnable,
),
}
}