Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eureka): add CLI to submit MsgProvideCounterparty #7118

Merged
merged 9 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/core/02-client/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func NewTxCmd() *cobra.Command {
newUpgradeClientCmd(),
newSubmitRecoverClientProposalCmd(),
newScheduleIBCUpgradeProposalCmd(),
newProvideCounterpartyCmd(),
)

return txCmd
Expand Down
54 changes: 54 additions & 0 deletions modules/core/02-client/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cli

import (
"encoding/hex"
"fmt"
"os"
"strconv"
"strings"

"github.com/spf13/cobra"

Expand All @@ -20,6 +22,7 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
)

Expand Down Expand Up @@ -450,3 +453,54 @@ func newScheduleIBCUpgradeProposalCmd() *cobra.Command {

return cmd
}

// newProvideCounterpartyCmd defines the command to provide the counterparty to an IBC client.
func newProvideCounterpartyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "provide-counterparty [client-identifier] [counterparty-client-identifier] [counterparty-merkle-path-prefix]",
Args: cobra.ExactArgs(3),
Short: "provide the counterparty to an IBC client",
Long: `Provide the counterparty to an IBC client specified by its client ID.
The [counterparty-merkle-path-prefix] is a comma-separated list of hex-encoded strings.`,
Example: fmt.Sprintf("%s tx %s %s provide-counterparty 07-tendermint-0 07-tendermint-1 696263,657572656b61", version.AppName, exported.ModuleName, types.SubModuleName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

clientIdentifier := args[0]
counterpartyClientIdentifier := args[1]
counterpartyMerklePathPrefix, err := parseMerklePathPrefix(args[2])
if err != nil {
return err
}

counterparty := types.NewCounterparty(counterpartyClientIdentifier, counterpartyMerklePathPrefix)
msg := types.MsgProvideCounterparty{
ClientId: clientIdentifier,
Counterparty: counterparty,
Signer: clientCtx.GetFromAddress().String(),
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

// parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath.
func parseMerklePathPrefix(merklePathPrefixString string) (commitmenttypesv2.MerklePath, error) {
var keyPath [][]byte
hexPrefixes := strings.Split(merklePathPrefixString, ",")
for _, hexPrefix := range hexPrefixes {
prefix, err := hex.DecodeString(hexPrefix)
if err != nil {
return commitmenttypesv2.MerklePath{}, fmt.Errorf("invalid hex merkle path prefix: %w", err)
}
keyPath = append(keyPath, prefix)
}

return commitmenttypesv2.MerklePath{KeyPath: keyPath}, nil
}
Loading