@@ -4,10 +4,7 @@ import (
4
4
"context"
5
5
"fmt"
6
6
7
- "cosmossdk.io/math"
8
7
sdkmath "cosmossdk.io/math"
9
- "google.golang.org/grpc"
10
- "google.golang.org/grpc/credentials/insecure"
11
8
12
9
"github.com/cosmos/cosmos-sdk/types"
13
10
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
@@ -25,7 +22,7 @@ func (tn *ChainNode) BankSend(ctx context.Context, keyName string, amount ibc.Wa
25
22
}
26
23
27
24
// BankMultiSend sends an amount of token from one account to multiple accounts.
28
- func (tn * ChainNode ) BankMultiSend (ctx context.Context , keyName string , addresses []string , amount math .Int , denom string ) error {
25
+ func (tn * ChainNode ) BankMultiSend (ctx context.Context , keyName string , addresses []string , amount sdkmath .Int , denom string ) error {
29
26
cmd := append ([]string {"bank" , "multi-send" , keyName }, addresses ... )
30
27
cmd = append (cmd , fmt .Sprintf ("%s%s" , amount , denom ))
31
28
@@ -36,15 +33,7 @@ func (tn *ChainNode) BankMultiSend(ctx context.Context, keyName string, addresse
36
33
// GetBalance fetches the current balance for a specific account address and denom.
37
34
// Implements Chain interface
38
35
func (c * CosmosChain ) GetBalance (ctx context.Context , address string , denom string ) (sdkmath.Int , error ) {
39
- grpcConn , err := grpc .Dial (
40
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
41
- )
42
- if err != nil {
43
- return sdkmath.Int {}, err
44
- }
45
- defer grpcConn .Close ()
46
-
47
- res , err := banktypes .NewQueryClient (grpcConn ).Balance (ctx , & banktypes.QueryBalanceRequest {Address : address , Denom : denom })
36
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).Balance (ctx , & banktypes.QueryBalanceRequest {Address : address , Denom : denom })
48
37
return res .Balance .Amount , err
49
38
}
50
39
@@ -55,151 +44,63 @@ func (c *CosmosChain) BankGetBalance(ctx context.Context, address string, denom
55
44
56
45
// AllBalances fetches an account address's balance for all denoms it holds
57
46
func (c * CosmosChain ) BankAllBalances (ctx context.Context , address string ) (types.Coins , error ) {
58
- grpcConn , err := grpc .Dial (
59
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
60
- )
61
- if err != nil {
62
- return nil , err
63
- }
64
- defer grpcConn .Close ()
65
-
66
- res , err := banktypes .NewQueryClient (grpcConn ).AllBalances (ctx , & banktypes.QueryAllBalancesRequest {Address : address })
47
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).AllBalances (ctx , & banktypes.QueryAllBalancesRequest {Address : address })
67
48
return res .GetBalances (), err
68
49
}
69
50
70
51
// BankDenomMetadata fetches the metadata of a specific coin denomination
71
52
func (c * CosmosChain ) BankDenomMetadata (ctx context.Context , denom string ) (* banktypes.Metadata , error ) {
72
- grpcConn , err := grpc .Dial (
73
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
74
- )
75
- if err != nil {
76
- return nil , err
77
- }
78
- defer grpcConn .Close ()
79
-
80
- res , err := banktypes .NewQueryClient (grpcConn ).DenomMetadata (ctx , & banktypes.QueryDenomMetadataRequest {Denom : denom })
53
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).DenomMetadata (ctx , & banktypes.QueryDenomMetadataRequest {Denom : denom })
81
54
return & res .Metadata , err
82
55
}
83
56
84
57
func (c * CosmosChain ) BankQueryDenomMetadataByQueryString (ctx context.Context , denom string ) (* banktypes.Metadata , error ) {
85
- grpcConn , err := grpc .Dial (
86
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
87
- )
88
- if err != nil {
89
- return nil , err
90
- }
91
- defer grpcConn .Close ()
92
-
93
- res , err := banktypes .NewQueryClient (grpcConn ).DenomMetadataByQueryString (ctx , & banktypes.QueryDenomMetadataByQueryStringRequest {Denom : denom })
58
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).DenomMetadataByQueryString (ctx , & banktypes.QueryDenomMetadataByQueryStringRequest {Denom : denom })
94
59
return & res .Metadata , err
95
60
}
96
61
97
62
func (c * CosmosChain ) BankQueryDenomOwners (ctx context.Context , denom string ) ([]* banktypes.DenomOwner , error ) {
98
- grpcConn , err := grpc .Dial (
99
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
100
- )
101
- if err != nil {
102
- return nil , err
103
- }
104
- defer grpcConn .Close ()
105
-
106
- res , err := banktypes .NewQueryClient (grpcConn ).DenomOwners (ctx , & banktypes.QueryDenomOwnersRequest {Denom : denom })
63
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).DenomOwners (ctx , & banktypes.QueryDenomOwnersRequest {Denom : denom })
107
64
return res .DenomOwners , err
108
65
}
109
66
110
67
func (c * CosmosChain ) BankQueryDenomsMetadata (ctx context.Context ) ([]banktypes.Metadata , error ) {
111
- grpcConn , err := grpc .Dial (
112
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
113
- )
114
- if err != nil {
115
- return nil , err
116
- }
117
- defer grpcConn .Close ()
118
-
119
- res , err := banktypes .NewQueryClient (grpcConn ).DenomsMetadata (ctx , & banktypes.QueryDenomsMetadataRequest {})
68
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).DenomsMetadata (ctx , & banktypes.QueryDenomsMetadataRequest {})
120
69
return res .Metadatas , err
121
70
}
122
71
123
72
func (c * CosmosChain ) BankQueryParams (ctx context.Context ) (* banktypes.Params , error ) {
124
- grpcConn , err := grpc .Dial (
125
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
126
- )
127
- if err != nil {
128
- return nil , err
129
- }
130
- defer grpcConn .Close ()
131
-
132
- res , err := banktypes .NewQueryClient (grpcConn ).Params (ctx , & banktypes.QueryParamsRequest {})
73
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).Params (ctx , & banktypes.QueryParamsRequest {})
133
74
return & res .Params , err
134
75
}
135
76
136
77
func (c * CosmosChain ) BankQuerySendEnabled (ctx context.Context , denoms []string ) ([]* banktypes.SendEnabled , error ) {
137
- grpcConn , err := grpc .Dial (
138
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
139
- )
140
- if err != nil {
141
- return nil , err
142
- }
143
- defer grpcConn .Close ()
144
-
145
- res , err := banktypes .NewQueryClient (grpcConn ).SendEnabled (ctx , & banktypes.QuerySendEnabledRequest {
78
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).SendEnabled (ctx , & banktypes.QuerySendEnabledRequest {
146
79
Denoms : denoms ,
147
80
})
148
81
return res .SendEnabled , err
149
82
}
150
83
151
84
func (c * CosmosChain ) BankQuerySpendableBalance (ctx context.Context , address , denom string ) (* types.Coin , error ) {
152
- grpcConn , err := grpc .Dial (
153
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
154
- )
155
- if err != nil {
156
- return nil , err
157
- }
158
- defer grpcConn .Close ()
159
-
160
- res , err := banktypes .NewQueryClient (grpcConn ).SpendableBalanceByDenom (ctx , & banktypes.QuerySpendableBalanceByDenomRequest {
85
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).SpendableBalanceByDenom (ctx , & banktypes.QuerySpendableBalanceByDenomRequest {
161
86
Address : address ,
162
87
Denom : denom ,
163
88
})
164
89
return res .Balance , err
165
90
}
166
91
167
92
func (c * CosmosChain ) BankQuerySpendableBalances (ctx context.Context , address string ) (* types.Coins , error ) {
168
- grpcConn , err := grpc .Dial (
169
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
170
- )
171
- if err != nil {
172
- return nil , err
173
- }
174
- defer grpcConn .Close ()
175
-
176
- res , err := banktypes .NewQueryClient (grpcConn ).SpendableBalances (ctx , & banktypes.QuerySpendableBalancesRequest {Address : address })
93
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).SpendableBalances (ctx , & banktypes.QuerySpendableBalancesRequest {Address : address })
177
94
return & res .Balances , err
178
95
}
179
96
180
97
func (c * CosmosChain ) BankQueryTotalSupply (ctx context.Context ) (* types.Coins , error ) {
181
- grpcConn , err := grpc .Dial (
182
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
183
- )
184
- if err != nil {
185
- return nil , err
186
- }
187
- defer grpcConn .Close ()
188
-
189
- res , err := banktypes .NewQueryClient (grpcConn ).TotalSupply (ctx , & banktypes.QueryTotalSupplyRequest {})
98
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).TotalSupply (ctx , & banktypes.QueryTotalSupplyRequest {})
190
99
return & res .Supply , err
191
100
}
192
101
193
102
func (c * CosmosChain ) BankQueryTotalSupplyOf (ctx context.Context , address string ) (* types.Coin , error ) {
194
- grpcConn , err := grpc .Dial (
195
- c .GetNode ().hostGRPCPort , grpc .WithTransportCredentials (insecure .NewCredentials ()),
196
- )
197
- if err != nil {
198
- return nil , err
199
- }
200
- defer grpcConn .Close ()
201
-
202
- res , err := banktypes .NewQueryClient (grpcConn ).SupplyOf (ctx , & banktypes.QuerySupplyOfRequest {Denom : address })
103
+ res , err := banktypes .NewQueryClient (c .GetNode ().GrpcConn ).SupplyOf (ctx , & banktypes.QuerySupplyOfRequest {Denom : address })
203
104
204
105
return & res .Amount , err
205
106
}
0 commit comments