@@ -16,15 +16,23 @@ import (
1616 host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
1717)
1818
19+ const (
20+ flagVersionIdentifier = "version-identifier"
21+ flagVersionFeatures = "version-features"
22+ flagProvedID = "proved-id"
23+ )
24+
1925// NewConnectionOpenInitCmd defines the command to initialize a connection on
2026// chain A with a given counterparty chain B
2127func NewConnectionOpenInitCmd () * cobra.Command {
2228 cmd := & cobra.Command {
2329 Use : "open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]" ,
2430 Short : "Initialize connection on chain A" ,
25- Long : "Initialize a connection on chain A with a given counterparty chain B" ,
31+ Long : `Initialize a connection on chain A with a given counterparty chain B.
32+ - 'version-identifier' flag can be a single pre-selected version identifier to be used in the handshake.
33+ - 'version-features' flag can be a list of features separated by commas to accompany the version identifier.` ,
2634 Example : fmt .Sprintf (
27- "%s tx %s %s open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]" ,
35+ "%s tx %s %s open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json] --version-identifier= \" 1.0 \" --version-features= \" ORDER_UNORDERED \" " ,
2836 version .AppName , host .ModuleName , types .SubModuleName ,
2937 ),
3038 Args : cobra .ExactArgs (5 ),
@@ -45,9 +53,27 @@ func NewConnectionOpenInitCmd() *cobra.Command {
4553 return err
4654 }
4755
56+ var encodedVersion string
57+ versionIdentifier , _ := cmd .Flags ().GetString (flagVersionIdentifier )
58+
59+ if versionIdentifier != "" {
60+ var features []string
61+
62+ versionFeatures , _ := cmd .Flags ().GetString (flagVersionFeatures )
63+ if versionFeatures != "" {
64+ features = strings .Split (versionFeatures , "," )
65+ }
66+
67+ version := types .NewVersion (versionIdentifier , features )
68+ encodedVersion , err = version .Encode ()
69+ if err != nil {
70+ return err
71+ }
72+ }
73+
4874 msg := types .NewMsgConnectionOpenInit (
4975 connectionID , clientID , counterpartyConnectionID , counterpartyClientID ,
50- counterpartyPrefix , clientCtx .GetFromAddress (),
76+ counterpartyPrefix , encodedVersion , clientCtx .GetFromAddress (),
5177 )
5278
5379 if err := msg .ValidateBasic (); err != nil {
@@ -58,6 +84,10 @@ func NewConnectionOpenInitCmd() *cobra.Command {
5884 },
5985 }
6086
87+ // NOTE: we should use empty default values since the user may not want to select a version
88+ // at this step in the handshake.
89+ cmd .Flags ().String (flagVersionIdentifier , "" , "version identifier to be used in the connection handshake version negotiation" )
90+ cmd .Flags ().String (flagVersionFeatures , "" , "version features list separated by commas without spaces. The features must function with the version identifier." )
6191 flags .AddTxFlagsToCmd (cmd )
6292
6393 return cmd
@@ -87,6 +117,7 @@ func NewConnectionOpenTryCmd() *cobra.Command {
87117 }
88118
89119 connectionID := args [0 ]
120+ provedID , _ := cmd .Flags ().GetString (flagProvedID )
90121 clientID := args [1 ]
91122 counterpartyConnectionID := args [2 ]
92123 counterpartyClientID := args [3 ]
@@ -129,7 +160,7 @@ func NewConnectionOpenTryCmd() *cobra.Command {
129160 }
130161
131162 msg := types .NewMsgConnectionOpenTry (
132- connectionID , clientID , counterpartyConnectionID , counterpartyClientID ,
163+ connectionID , provedID , clientID , counterpartyConnectionID , counterpartyClientID ,
133164 counterpartyClient , counterpartyPrefix , []string {counterpartyVersions },
134165 proofInit , proofClient , proofConsensus , proofHeight ,
135166 consensusHeight , clientCtx .GetFromAddress (),
@@ -143,6 +174,7 @@ func NewConnectionOpenTryCmd() *cobra.Command {
143174 },
144175 }
145176
177+ cmd .Flags ().String (flagProvedID , "" , "identifier set by the counterparty chain" )
146178 flags .AddTxFlagsToCmd (cmd )
147179
148180 return cmd
@@ -152,16 +184,16 @@ func NewConnectionOpenTryCmd() *cobra.Command {
152184// connection open attempt from chain B to chain A
153185func NewConnectionOpenAckCmd () * cobra.Command {
154186 cmd := & cobra.Command {
155- Use : `open-ack [connection-id] [path/to/client_state.json] [consensus-height] [proof-height]
187+ Use : `open-ack [connection-id] [counterparty-connection-id] [ path/to/client_state.json] [consensus-height] [proof-height]
156188 [path/to/proof_try.json] [path/to/proof_client.json] [path/to/proof_consensus.json] [version]` ,
157189 Short : "relay the acceptance of a connection open attempt" ,
158190 Long : "Relay the acceptance of a connection open attempt from chain B to chain A" ,
159191 Example : fmt .Sprintf (
160- `%s tx %s %s open-ack [connection-id] [path/to/client_state.json] [consensus-height] [proof-height]
192+ `%s tx %s %s open-ack [connection-id] [counterparty-connection-id] [ path/to/client_state.json] [consensus-height] [proof-height]
161193 [path/to/proof_try.json] [path/to/proof_client.json] [path/to/proof_consensus.json] [version]` ,
162194 version .AppName , host .ModuleName , types .SubModuleName ,
163195 ),
164- Args : cobra .ExactArgs (8 ),
196+ Args : cobra .ExactArgs (9 ),
165197 RunE : func (cmd * cobra.Command , args []string ) error {
166198 clientCtx := client .GetClientContextFromCmd (cmd )
167199 clientCtx , err := client .ReadTxCommandFlags (clientCtx , cmd .Flags ())
@@ -170,40 +202,41 @@ func NewConnectionOpenAckCmd() *cobra.Command {
170202 }
171203
172204 connectionID := args [0 ]
205+ counterpartyConnectionID := args [1 ]
173206
174- counterpartyClient , err := utils .ParseClientState (clientCtx .LegacyAmino , args [1 ])
207+ counterpartyClient , err := utils .ParseClientState (clientCtx .LegacyAmino , args [2 ])
175208 if err != nil {
176209 return err
177210 }
178211
179- consensusHeight , err := clienttypes .ParseHeight (args [2 ])
212+ consensusHeight , err := clienttypes .ParseHeight (args [3 ])
180213 if err != nil {
181214 return err
182215 }
183- proofHeight , err := clienttypes .ParseHeight (args [3 ])
216+ proofHeight , err := clienttypes .ParseHeight (args [4 ])
184217 if err != nil {
185218 return err
186219 }
187220
188- proofTry , err := utils .ParseProof (clientCtx .LegacyAmino , args [4 ])
221+ proofTry , err := utils .ParseProof (clientCtx .LegacyAmino , args [5 ])
189222 if err != nil {
190223 return err
191224 }
192225
193- proofClient , err := utils .ParseProof (clientCtx .LegacyAmino , args [5 ])
226+ proofClient , err := utils .ParseProof (clientCtx .LegacyAmino , args [6 ])
194227 if err != nil {
195228 return err
196229 }
197230
198- proofConsensus , err := utils .ParseProof (clientCtx .LegacyAmino , args [6 ])
231+ proofConsensus , err := utils .ParseProof (clientCtx .LegacyAmino , args [7 ])
199232 if err != nil {
200233 return err
201234 }
202235
203- version := args [7 ]
236+ version := args [8 ]
204237
205238 msg := types .NewMsgConnectionOpenAck (
206- connectionID , counterpartyClient , proofTry , proofClient , proofConsensus , proofHeight ,
239+ connectionID , counterpartyConnectionID , counterpartyClient , proofTry , proofClient , proofConsensus , proofHeight ,
207240 consensusHeight , version , clientCtx .GetFromAddress (),
208241 )
209242
0 commit comments