-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/ibc-eureka' into damian/7414-timeouts
- Loading branch information
Showing
57 changed files
with
2,641 additions
and
2,109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/cosmos/cosmos-sdk/version" | ||
|
||
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types" | ||
commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2" | ||
"github.com/cosmos/ibc-go/v9/modules/core/exported" | ||
) | ||
|
||
// newCreateChannelTxCmd defines the command to create an IBC channel/v2. | ||
func newCreateChannelTxCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "create-channel [client-identifier] [merkle-path-prefix]", | ||
Args: cobra.ExactArgs(2), | ||
Short: "create an IBC channel/v2", | ||
Long: `Creates an IBC channel/v2 using the client identifier representing the counterparty chain and the hex-encoded merkle path prefix under which the counterparty stores packet flow information.`, | ||
Example: fmt.Sprintf("%s tx %s %s create-channel 07-tendermint-0 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 | ||
} | ||
|
||
clientID := args[0] | ||
merklePathPrefix, err := parseMerklePathPrefix(args[2]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgCreateChannel(clientID, merklePathPrefix, clientCtx.GetFromAddress().String()) | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
return cmd | ||
} | ||
|
||
// newProvideCounterpartyCmd defines the command to provide the counterparty channel identifier to an IBC channel. | ||
func newProvideCounterpartyTxCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "provide-counterparty [channel-identifier] [counterparty-channel-identifier]", | ||
Args: cobra.ExactArgs(2), | ||
Short: "provide the counterparty channel id to an IBC channel", | ||
Long: `Provide the counterparty channel id to an IBC channel specified by its channel ID.`, | ||
Example: fmt.Sprintf("%s tx %s %s provide-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
channelID := args[0] | ||
counterpartyChannelID := args[1] | ||
|
||
msg := types.MsgProvideCounterparty{ | ||
ChannelId: channelID, | ||
CounterpartyChannelId: counterpartyChannelID, | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.