Skip to content

Commit

Permalink
added ics v6 types and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric authored and Reecepbcups committed Nov 29, 2024
1 parent 0c2078b commit a1629f2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chain/cosmos/ics.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,11 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi
return err
}

ccvStateMarshaled, _, err := c.Provider.GetNode().ExecQuery(ctx, "provider", "consumer-genesis", consumerID)
consumerId, err := c.Provider.GetNode().GetConsumerChainByChainId(ctx, c.cfg.ChainID)
if err != nil {
return err
}
ccvStateMarshaled, _, err := c.Provider.GetNode().ExecQuery(ctx, "provider", "consumer-genesis", consumerId)
if err != nil {
return fmt.Errorf("failed to query provider for ccv state: %w", err)
}
Expand Down
70 changes: 70 additions & 0 deletions chain/cosmos/ics_v6_query_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cosmos

import (
"context"
"encoding/json"
"fmt"
)

func (node *ChainNode) GetConsumerChainByChainId(ctx context.Context, chainId string) (string, error) {
chains, err := node.ListConsumerChains(ctx)
if err != nil {
return "", err
}
for _, chain := range chains.Chains {
if chain.ChainID == chainId {
return chain.ConsumerID, nil
}
}
return "", fmt.Errorf("chain not found")
}

func (node *ChainNode) ListConsumerChains(ctx context.Context) (ListConsumerChainsResponse, error) {
queryRes, _, err := node.ExecQuery(
ctx,
"provider", "list-consumer-chains",
)
if err != nil {
return ListConsumerChainsResponse{}, err
}

var queryResponse ListConsumerChainsResponse
err = json.Unmarshal([]byte(queryRes), &queryResponse)
if err != nil {
return ListConsumerChainsResponse{}, err
}

return queryResponse, nil
}

type ListConsumerChainsResponse struct {
Chains []ConsumerChain `json:"chains"`
Pagination Pagination `json:"pagination"`
}

type ConsumerChain struct {
ChainID string `json:"chain_id"`
ClientID string `json:"client_id"`
TopN int `json:"top_N"`
MinPowerInTopN string `json:"min_power_in_top_N"`
ValidatorsPowerCap int `json:"validators_power_cap"`
ValidatorSetCap int `json:"validator_set_cap"`
Allowlist []string `json:"allowlist"`
Denylist []string `json:"denylist"`
Phase string `json:"phase"`
Metadata Metadata `json:"metadata"`
MinStake string `json:"min_stake"`
AllowInactiveVals bool `json:"allow_inactive_vals"`
ConsumerID string `json:"consumer_id"`
}

type Pagination struct {
NextKey interface{} `json:"next_key"`
Total string `json:"total"`
}

type Metadata struct {
Name string `json:"name"`
Description string `json:"description"`
Metadata string `json:"metadata"`
}

0 comments on commit a1629f2

Please sign in to comment.