1
1
package cli
2
2
3
3
import (
4
+ "encoding/hex"
4
5
"fmt"
6
+ "strings"
5
7
6
8
"github.com/spf13/cobra"
7
9
@@ -11,11 +13,42 @@ import (
11
13
"github.com/cosmos/cosmos-sdk/version"
12
14
13
15
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
16
+ commitmenttypesv2 "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
14
17
"github.com/cosmos/ibc-go/v9/modules/core/exported"
15
18
)
16
19
20
+ // newCreateChannelTxCmd defines the command to create an IBC channel/v2.
21
+ func newCreateChannelTxCmd () * cobra.Command {
22
+ cmd := & cobra.Command {
23
+ Use : "create-channel [client-identifier] [merkle-path-prefix]" ,
24
+ Args : cobra .ExactArgs (2 ),
25
+ Short : "create an IBC channel/v2" ,
26
+ 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.` ,
27
+ Example : fmt .Sprintf ("%s tx %s %s create-channel 07-tendermint-0 696263,657572656b61" , version .AppName , exported .ModuleName , types .SubModuleName ),
28
+ RunE : func (cmd * cobra.Command , args []string ) error {
29
+ clientCtx , err := client .GetClientTxContext (cmd )
30
+ if err != nil {
31
+ return err
32
+ }
33
+
34
+ clientID := args [0 ]
35
+ merklePathPrefix , err := parseMerklePathPrefix (args [2 ])
36
+ if err != nil {
37
+ return err
38
+ }
39
+
40
+ msg := types .NewMsgCreateChannel (clientID , merklePathPrefix , clientCtx .GetFromAddress ().String ())
41
+
42
+ return tx .GenerateOrBroadcastTxCLI (clientCtx , cmd .Flags (), msg )
43
+ },
44
+ }
45
+
46
+ flags .AddTxFlagsToCmd (cmd )
47
+ return cmd
48
+ }
49
+
17
50
// newProvideCounterpartyCmd defines the command to provide the counterparty channel identifier to an IBC channel.
18
- func newProvideCounterpartyCmd () * cobra.Command {
51
+ func newProvideCounterpartyTxCmd () * cobra.Command {
19
52
cmd := & cobra.Command {
20
53
Use : "provide-counterparty [channel-identifier] [counterparty-channel-identifier]" ,
21
54
Args : cobra .ExactArgs (2 ),
@@ -43,3 +76,18 @@ func newProvideCounterpartyCmd() *cobra.Command {
43
76
flags .AddTxFlagsToCmd (cmd )
44
77
return cmd
45
78
}
79
+
80
+ // parseMerklePathPrefix parses a comma-separated list of hex-encoded strings into a MerklePath.
81
+ func parseMerklePathPrefix (merklePathPrefixString string ) (commitmenttypesv2.MerklePath , error ) {
82
+ var keyPath [][]byte
83
+ hexPrefixes := strings .Split (merklePathPrefixString , "," )
84
+ for _ , hexPrefix := range hexPrefixes {
85
+ prefix , err := hex .DecodeString (hexPrefix )
86
+ if err != nil {
87
+ return commitmenttypesv2.MerklePath {}, fmt .Errorf ("invalid hex merkle path prefix: %w" , err )
88
+ }
89
+ keyPath = append (keyPath , prefix )
90
+ }
91
+
92
+ return commitmenttypesv2.MerklePath {KeyPath : keyPath }, nil
93
+ }
0 commit comments