-
Notifications
You must be signed in to change notification settings - Fork 3
/
bank.go
60 lines (49 loc) · 1.29 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package bank
import (
"context"
"github.com/irisnet/service-sdk-go/codec"
"github.com/irisnet/service-sdk-go/codec/types"
sdk "github.com/irisnet/service-sdk-go/types"
)
type bankClient struct {
sdk.BaseClient
codec.Marshaler
}
func NewClient(bc sdk.BaseClient, cdc codec.Marshaler) BankI {
return bankClient{
BaseClient: bc,
Marshaler: cdc,
}
}
func (b bankClient) Name() string {
return ModuleName
}
func (b bankClient) RegisterInterfaceTypes(registry types.InterfaceRegistry) {
RegisterInterfaces(registry)
}
// QueryAccount returns account information by the specified address
func (b bankClient) QueryAccount(address string) (sdk.BaseAccount, sdk.Error) {
conn, err := b.GenConn()
defer func() { _ = conn.Close() }()
if err != nil {
return sdk.BaseAccount{}, sdk.Wrap(err)
}
account, err := b.BaseClient.QueryAccount(address)
if err != nil {
return sdk.BaseAccount{}, sdk.Wrap(err)
}
addr, err := sdk.AccAddressFromBech32(address)
if err != nil {
return sdk.BaseAccount{}, sdk.Wrap(err)
}
request := &QueryAllBalancesRequest{
Address: addr,
Pagination: nil,
}
balances, err := NewQueryClient(conn).AllBalances(context.Background(), request)
if err != nil {
return sdk.BaseAccount{}, sdk.Wrap(err)
}
account.Coins = balances.Balances
return account, nil
}