-
Notifications
You must be signed in to change notification settings - Fork 4
/
balance.go
49 lines (41 loc) · 1.45 KB
/
balance.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
package imx
import (
"context"
"github.com/immutable/imx-core-sdk-golang/imx/api"
)
/*
GetBalance Fetches the token balances of the user
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@param owner Address of the owner/user
@param tokenAddress Token address
@return Balance
*/
func (c *Client) GetBalance(ctx context.Context, owner, tokenAddress string) (*api.Balance, error) {
response, httpResponse, err := c.BalancesAPI.GetBalance(ctx, owner, tokenAddress).Execute()
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}
/*
NewListBalancesRequest Creates a new ApiListBalancesRequest object with required params.
@param ctx context.Context - for cancellation, deadlines, tracing, etc or context.Background().
@return ApiListBalancesRequest
*/
func (c *Client) NewListBalancesRequest(ctx context.Context, owner string) api.ApiListBalancesRequest {
return c.BalancesAPI.ListBalances(ctx, owner)
}
/*
ListBalances Get a list of balances for given user
@param req the api request struct with all params populated to make the request
@return ListBalancesResponse
*/
func (c *Client) ListBalances(req *api.ApiListBalancesRequest) (*api.ListBalancesResponse, error) {
response, httpResponse, err := c.BalancesAPI.ListBalancesExecute(*req)
defer httpResponse.Body.Close()
if err != nil {
return nil, NewIMXError(httpResponse, err)
}
return response, nil
}