@@ -18,7 +18,6 @@ import (
18
18
sdk "github.com/cosmos/cosmos-sdk/types"
19
19
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
20
20
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
21
- "github.com/cosmos/cosmos-sdk/types/query"
22
21
querytypes "github.com/cosmos/cosmos-sdk/types/query"
23
22
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
24
23
"github.com/cosmos/cosmos-sdk/x/feegrant"
@@ -189,7 +188,7 @@ func parseEventsFromResponseDeliverTx(resp abci.ResponseDeliverTx) []provider.Re
189
188
190
189
// QueryFeegrantsByGrantee returns all requested grants for the given grantee.
191
190
// Default behavior will return all grants.
192
- func (cc * CosmosProvider ) QueryFeegrantsByGrantee (address string , paginator * query .PageRequest ) ([]* feegrant.Grant , error ) {
191
+ func (cc * CosmosProvider ) QueryFeegrantsByGrantee (address string , paginator * querytypes .PageRequest ) ([]* feegrant.Grant , error ) {
193
192
grants := []* feegrant.Grant {}
194
193
allPages := paginator == nil
195
194
@@ -228,7 +227,7 @@ func (cc *CosmosProvider) QueryFeegrantsByGrantee(address string, paginator *que
228
227
229
228
// Feegrant_GrantsByGranterRPC returns all requested grants for the given Granter.
230
229
// Default behavior will return all grants.
231
- func (cc * CosmosProvider ) QueryFeegrantsByGranter (address string , paginator * query .PageRequest ) ([]* feegrant.Grant , error ) {
230
+ func (cc * CosmosProvider ) QueryFeegrantsByGranter (address string , paginator * querytypes .PageRequest ) ([]* feegrant.Grant , error ) {
232
231
grants := []* feegrant.Grant {}
233
232
allPages := paginator == nil
234
233
@@ -311,47 +310,55 @@ func (cc *CosmosProvider) QueryBalanceWithAddress(ctx context.Context, address s
311
310
return coins , nil
312
311
}
313
312
314
- func (cc * CosmosProvider ) queryConsumerUnbondingPeriod (ctx context.Context ) (time.Duration , error ) {
313
+ func (cc * CosmosProvider ) queryParamsSubspaceTime (ctx context.Context , subspace string , key string ) (time.Duration , error ) {
315
314
queryClient := proposal .NewQueryClient (cc )
316
315
317
- params := proposal.QueryParamsRequest {Subspace : "ccvconsumer" , Key : "UnbondingPeriod" }
316
+ params := proposal.QueryParamsRequest {Subspace : subspace , Key : key }
318
317
319
- resICS , err := queryClient .Params (ctx , & params )
318
+ res , err := queryClient .Params (ctx , & params )
320
319
321
320
if err != nil {
322
- return 0 , fmt .Errorf ("failed to make ccvconsumer params request: %w" , err )
321
+ return 0 , fmt .Errorf ("failed to make %s params request: %w" , subspace , err )
323
322
}
324
323
325
- if resICS .Param .Value == "" {
326
- return 0 , fmt .Errorf ("ccvconsumer unbonding period is empty" )
324
+ if res .Param .Value == "" {
325
+ return 0 , fmt .Errorf ("%s %s is empty" , subspace , key )
327
326
}
328
327
329
- unbondingPeriod , err := strconv .ParseUint (strings .ReplaceAll (resICS .Param .Value , `"` , "" ), 10 , 64 )
328
+ unbondingValue , err := strconv .ParseUint (strings .ReplaceAll (res .Param .Value , `"` , "" ), 10 , 64 )
330
329
if err != nil {
331
- return 0 , fmt .Errorf ("failed to parse unbonding period from ccvconsumer param: %w" , err )
330
+ return 0 , fmt .Errorf ("failed to parse %s from %s param: %w" , key , subspace , err )
332
331
}
333
332
334
- return time .Duration (unbondingPeriod ), nil
333
+ return time .Duration (unbondingValue ), nil
335
334
}
336
335
337
336
// QueryUnbondingPeriod returns the unbonding period of the chain
338
337
func (cc * CosmosProvider ) QueryUnbondingPeriod (ctx context.Context ) (time.Duration , error ) {
338
+
339
+ // Attempt ICS query
340
+ consumerUnbondingPeriod , consumerErr := cc .queryParamsSubspaceTime (ctx , "ccvconsumer" , "UnbondingPeriod" )
341
+ if consumerErr == nil {
342
+ return consumerUnbondingPeriod , nil
343
+ }
344
+
345
+ //Attempt Staking query.
346
+ unbondingPeriod , stakingParamsErr := cc .queryParamsSubspaceTime (ctx , "staking" , "UnbondingTime" )
347
+ if stakingParamsErr == nil {
348
+ return unbondingPeriod , nil
349
+ }
350
+
351
+ // Fallback
339
352
req := stakingtypes.QueryParamsRequest {}
340
353
queryClient := stakingtypes .NewQueryClient (cc )
341
-
342
354
res , err := queryClient .Params (ctx , & req )
343
- if err != nil {
344
- // Attempt ICS query
345
- consumerUnbondingPeriod , consumerErr := cc .queryConsumerUnbondingPeriod (ctx )
346
- if consumerErr != nil {
347
- return 0 ,
348
- fmt .Errorf ("failed to query unbonding period as both standard and consumer chain: %s: %w" , err .Error (), consumerErr )
349
- }
355
+ if err == nil {
356
+ return res .Params .UnbondingTime , nil
350
357
351
- return consumerUnbondingPeriod , nil
352
358
}
353
359
354
- return res .Params .UnbondingTime , nil
360
+ return 0 ,
361
+ fmt .Errorf ("failed to query unbonding period from ccvconsumer, staking & fallback : %w: %s : %s" , consumerErr , stakingParamsErr .Error (), err .Error ())
355
362
}
356
363
357
364
// QueryTendermintProof performs an ABCI query with the given key and returns
0 commit comments