-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank.go
41 lines (31 loc) · 956 Bytes
/
bank.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
package client
import (
"context"
sdktypes "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
// Balance returns balance of a given account for staking denom.
func (cp *ClientProxy) Balance(ctx context.Context, address string, denom string) (sdktypes.Coin, error) {
client := banktypes.NewQueryClient(cp.grpcConn)
req := banktypes.QueryBalanceRequest{
Address: address,
Denom: denom,
}
resp, err := client.Balance(ctx, &req)
if err != nil {
return sdktypes.Coin{}, err
}
return *resp.Balance, nil
}
// Balances returns all balances of a given account.
func (cp *ClientProxy) Balances(ctx context.Context, address string) (sdktypes.Coins, error) {
client := banktypes.NewQueryClient(cp.grpcConn)
req := banktypes.QueryAllBalancesRequest{
Address: address,
}
resp, err := client.AllBalances(ctx, &req)
if err != nil {
return sdktypes.Coins{}, err
}
return resp.Balances, nil
}