-
Notifications
You must be signed in to change notification settings - Fork 4
/
tokens.go
93 lines (80 loc) · 2.42 KB
/
tokens.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
package imx
import (
"context"
"github.com/immutable/imx-core-sdk-golang/imx/api"
)
const (
ETHTokenType = "ETH"
ERC20TokenType = "ERC20"
ERC721TokenType = "ERC721"
)
func s(constant string) *string {
return &constant
}
// SignableETHToken returns a new ETH type token.
// https://docs.x.immutable.com/docs/token-data-object#type-eth
func SignableETHToken() api.SignableToken {
return api.SignableToken{
Data: map[string]interface{}{
"decimals": 18,
},
Type: s(ETHTokenType),
}
}
// SignableERC20Token returns a new ERC20 type token.
// https://docs.x.immutable.com/docs/token-data-object#type-erc20
func SignableERC20Token(decimals int, tokenAddress string) api.SignableToken {
return api.SignableToken{
Data: map[string]interface{}{
"decimals": decimals,
"token_address": tokenAddress,
},
Type: s(ERC20TokenType),
}
}
// SignableERC721Token returns a new ERC721 type token.
// https://docs.x.immutable.com/docs/token-data-object#type-erc721
func SignableERC721Token(tokenID, tokenAddress string) api.SignableToken {
return api.SignableToken{
Data: map[string]interface{}{
"token_id": tokenID,
"token_address": tokenAddress,
},
Type: s(ERC721TokenType),
}
}
/*
GetToken Get details of a token with the given ID
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@param id Token ID
@return TokenDetails
*/
func (c *Client) GetToken(ctx context.Context, id string) (*api.TokenDetails, error) {
response, httpResponse, err := c.TokensAPI.GetToken(ctx, id).Execute()
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}
/*
NewListTokensRequest Creates a new ApiListTokensRequest object with required params.
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@return ApiListTokensRequest
*/
func (c *Client) NewListTokensRequest(ctx context.Context) api.ApiListTokensRequest {
return c.TokensAPI.ListTokens(ctx)
}
/*
ListTokens Gets a list of tokens
@param req the api request struct with all params populated to make the request
@return ListTokensResponse
*/
func (c *Client) ListTokens(req *api.ApiListTokensRequest) (*api.ListTokensResponse, error) {
response, httpResponse, err := c.TokensAPI.ListTokensExecute(*req)
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}