x/ibc: tx client protobuf migration (#6461)

* ibc/03-connection: tx client migration

* update commands

* update ibc-transfer

* remove unused queryRoute

* initialize clientCtx
This commit is contained in:
Federico Kunze 2020-06-17 21:56:48 +02:00 committed by GitHub
parent 32278d9a2b
commit 1c8249e26d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 223 additions and 272 deletions

View File

@ -5,11 +5,10 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
)
// GetQueryCmd returns the query commands for IBC fungible token transfer
func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command {
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
ics20TransferQueryCmd := &cobra.Command{
Use: "ibc-transfer",
Short: "IBC fungible token transfer query subcommands",
@ -19,14 +18,14 @@ func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command {
}
ics20TransferQueryCmd.AddCommand(flags.GetCommands(
GetCmdQueryNextSequence(cdc, queryRoute),
GetCmdQueryNextSequence(clientCtx),
)...)
return ics20TransferQueryCmd
}
// GetTxCmd returns the transaction commands for IBC fungible token transfer
func GetTxCmd(cdc *codec.Codec) *cobra.Command {
// NewTxCmd returns the transaction commands for IBC fungible token transfer
func NewTxCmd(clientCtx client.Context) *cobra.Command {
ics20TransferTxCmd := &cobra.Command{
Use: "ibc-transfer",
Short: "IBC fungible token transfer transaction subcommands",
@ -36,7 +35,7 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
}
ics20TransferTxCmd.AddCommand(flags.PostCommands(
GetTransferTxCmd(cdc),
NewTransferTxCmd(clientCtx),
)...)
return ics20TransferTxCmd

View File

@ -9,13 +9,13 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/client/utils"
)
// GetCmdQueryNextSequence defines the command to query a next receive sequence
func GetCmdQueryNextSequence(cdc *codec.Codec, queryRoute string) *cobra.Command {
// TODO: move to channel
func GetCmdQueryNextSequence(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "next-recv [port-id] [channel-id]",
Short: "Query a next receive sequence",
@ -28,7 +28,8 @@ $ %s query ibc-transfer next-recv [port-id] [channel-id]
Example: fmt.Sprintf("%s query ibc-transfer next-recv [port-id] [channel-id]", version.ClientName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
portID := args[0]
channelID := args[1]
prove := viper.GetBool(flags.FlagProve)

View File

@ -1,19 +1,15 @@
package cli
import (
"bufio"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
)
@ -22,17 +18,15 @@ const (
flagTimeoutTimestamp = "timeout-timestamp"
)
// GetTransferTxCmd returns the command to create a NewMsgTransfer transaction
func GetTransferTxCmd(cdc *codec.Codec) *cobra.Command {
// NewTransferTxCmd returns the command to create a NewMsgTransfer transaction
func NewTransferTxCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "transfer [src-port] [src-channel] [receiver] [amount]",
Short: "Transfer a fungible token through IBC",
Example: fmt.Sprintf("%s tx ibc-transfer transfer [src-port] [src-channel] [receiver] [amount]", version.ClientName),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc).WithBroadcastMode(flags.BroadcastBlock)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
sender := clientCtx.GetFromAddress()
srcPort := args[0]
@ -54,7 +48,7 @@ func GetTransferTxCmd(cdc *codec.Codec) *cobra.Command {
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
cmd.Flags().Uint64(flagTimeoutHeight, types.DefaultAbsolutePacketTimeoutHeight, "Absolute timeout block height. The timeout is disabled when set to 0.")

View File

@ -74,12 +74,12 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
// GetTxCmd implements AppModuleBasic interface
func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.GetTxCmd(clientCtx.Codec)
return cli.NewTxCmd(clientCtx)
}
// GetQueryCmd implements AppModuleBasic interface
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx.Codec, types.QuerierRoute)
return cli.GetQueryCmd(clientCtx)
}
// RegisterInterfaceTypes registers module concrete types into protobuf Any.

View File

@ -5,13 +5,13 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
)
// GetQueryCmd returns the query commands for IBC clients
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
ics02ClientQueryCmd := &cobra.Command{
Use: "client",
Use: types.SubModuleName,
Short: "IBC client query subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
@ -19,12 +19,12 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
}
ics02ClientQueryCmd.AddCommand(flags.GetCommands(
GetCmdQueryClientStates(queryRoute, cdc),
GetCmdQueryClientState(queryRoute, cdc),
GetCmdQueryConsensusState(queryRoute, cdc),
GetCmdQueryHeader(cdc),
GetCmdNodeConsensusState(queryRoute, cdc),
GetCmdQueryPath(queryRoute, cdc),
GetCmdQueryClientStates(clientCtx),
GetCmdQueryClientState(clientCtx),
GetCmdQueryConsensusState(clientCtx),
GetCmdQueryHeader(clientCtx),
GetCmdNodeConsensusState(clientCtx),
GetCmdQueryPath(clientCtx),
)...)
return ics02ClientQueryCmd
}

View File

@ -11,7 +11,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/utils"
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
@ -19,7 +18,7 @@ import (
// GetCmdQueryClientStates defines the command to query all the light clients
// that this chain mantains.
func GetCmdQueryClientStates(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryClientStates(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "states",
Short: "Query all available light clients",
@ -32,7 +31,8 @@ $ %s query ibc client states
),
Example: fmt.Sprintf("%s query ibc client states", version.ClientName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
page := viper.GetInt(flags.FlagPage)
limit := viper.GetInt(flags.FlagLimit)
@ -52,7 +52,7 @@ $ %s query ibc client states
// GetCmdQueryClientState defines the command to query the state of a client with
// a given id as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#query
func GetCmdQueryClientState(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryClientState(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "state [client-id]",
Short: "Query a client state",
@ -65,7 +65,8 @@ $ %s query ibc client state [client-id]
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
clientID := args[0]
if strings.TrimSpace(clientID) == "" {
return errors.New("client ID can't be blank")
@ -88,7 +89,7 @@ $ %s query ibc client state [client-id]
// GetCmdQueryConsensusState defines the command to query the consensus state of
// the chain as defined in https://github.com/cosmos/ics/tree/master/spec/ics-002-client-semantics#query
func GetCmdQueryConsensusState(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryConsensusState(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "consensus-state [client-id] [height]",
Short: "Query the consensus state of a client at a given height",
@ -96,7 +97,8 @@ func GetCmdQueryConsensusState(queryRoute string, cdc *codec.Codec) *cobra.Comma
Example: fmt.Sprintf("%s query ibc client consensus-state [client-id] [height]", version.ClientName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
clientID := args[0]
if strings.TrimSpace(clientID) == "" {
return errors.New("client ID can't be blank")
@ -123,14 +125,14 @@ func GetCmdQueryConsensusState(queryRoute string, cdc *codec.Codec) *cobra.Comma
}
// GetCmdQueryHeader defines the command to query the latest header on the chain
func GetCmdQueryHeader(cdc *codec.Codec) *cobra.Command {
func GetCmdQueryHeader(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "header",
Short: "Query the latest header of the running chain",
Long: "Query the latest Tendermint header of the running chain",
Example: fmt.Sprintf("%s query ibc client header", version.ClientName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
header, height, err := utils.QueryTendermintHeader(clientCtx)
if err != nil {
@ -145,7 +147,7 @@ func GetCmdQueryHeader(cdc *codec.Codec) *cobra.Command {
// GetCmdNodeConsensusState defines the command to query the latest consensus state of a node
// The result is feed to client creation
func GetCmdNodeConsensusState(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdNodeConsensusState(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "node-state",
Short: "Query a node consensus state",
@ -158,7 +160,7 @@ $ %s query ibc client node-state
),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
state, height, err := utils.QueryNodeConsensusState(clientCtx)
if err != nil {
@ -172,14 +174,15 @@ $ %s query ibc client node-state
}
// GetCmdQueryPath defines the command to query the commitment path.
func GetCmdQueryPath(storeName string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryPath(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "path",
Short: "Query the commitment path of the running chain",
RunE: func(cmd *cobra.Command, args []string) error {
clienCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
path := commitmenttypes.NewMerklePrefix([]byte("ibc"))
return clienCtx.PrintOutput(path)
return clientCtx.PrintOutput(path)
},
}
}

View File

@ -13,6 +13,6 @@ const (
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(clientCtx client.Context, r *mux.Router, queryRoute string) {
func RegisterRoutes(clientCtx client.Context, r *mux.Router) {
registerQueryRoutes(clientCtx, r)
}

View File

@ -1,13 +1,10 @@
package client
import (
"fmt"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/cli"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/rest"
)
@ -18,11 +15,11 @@ func Name() string {
}
// RegisterRESTRoutes registers the REST routes for the IBC client
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router, queryRoute string) {
rest.RegisterRoutes(clientCtx, rtr, fmt.Sprintf("%s/%s", queryRoute, SubModuleName))
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
rest.RegisterRoutes(clientCtx, rtr)
}
// GetQueryCmd returns no root query command for the IBC client
func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command {
return cli.GetQueryCmd(fmt.Sprintf("%s/%s", queryRoute, SubModuleName), cdc)
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx)
}

View File

@ -3,39 +3,43 @@ package cli
import (
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
)
// GetQueryCmd returns the query commands for IBC connections
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
ics03ConnectionQueryCmd := &cobra.Command{
Use: "connection",
Use: types.SubModuleName,
Short: "IBC connection query subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}
ics03ConnectionQueryCmd.AddCommand(flags.GetCommands(
GetCmdQueryConnections(queryRoute, cdc),
GetCmdQueryConnection(queryRoute, cdc),
GetCmdQueryConnections(clientCtx),
GetCmdQueryConnection(clientCtx),
)...)
return ics03ConnectionQueryCmd
}
// GetTxCmd returns the transaction commands for IBC connections
func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// NewTxCmd returns a CLI command handler for all x/ibc connection transaction commands.
func NewTxCmd(clientCtx client.Context) *cobra.Command {
ics03ConnectionTxCmd := &cobra.Command{
Use: "connection",
Short: "IBC connection transaction subcommands",
Use: types.SubModuleName,
Short: "IBC connection transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
ics03ConnectionTxCmd.AddCommand(flags.PostCommands(
GetCmdConnectionOpenInit(storeKey, cdc),
GetCmdConnectionOpenTry(storeKey, cdc),
GetCmdConnectionOpenAck(storeKey, cdc),
GetCmdConnectionOpenConfirm(storeKey, cdc),
NewConnectionOpenInitCmd(clientCtx),
NewConnectionOpenTryCmd(clientCtx),
NewConnectionOpenAckCmd(clientCtx),
NewConnectionOpenConfirmCmd(clientCtx),
)...)
return ics03ConnectionTxCmd

View File

@ -9,14 +9,13 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils"
)
// GetCmdQueryConnections defines the command to query all the connection ends
// that this chain mantains.
func GetCmdQueryConnections(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryConnections(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "connections",
Short: "Query all available light clients",
@ -30,7 +29,8 @@ $ %s query ibc connection connections
Example: fmt.Sprintf("%s query ibc connection connections", version.ClientName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
page := viper.GetInt(flags.FlagPage)
limit := viper.GetInt(flags.FlagLimit)
@ -50,7 +50,7 @@ $ %s query ibc connection connections
}
// GetCmdQueryConnection defines the command to query a connection end
func GetCmdQueryConnection(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryConnection(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "end [connection-id]",
Short: "Query stored connection end",
@ -63,7 +63,8 @@ $ %s query ibc connection end [connection-id]
Example: fmt.Sprintf("%s query ibc connection end [connection-id]", version.ClientName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
connectionID := args[0]
prove := viper.GetBool(flags.FlagProve)
@ -82,7 +83,7 @@ $ %s query ibc connection end [connection-id]
}
// GetCmdQueryAllClientConnections defines the command to query a all the client connection paths.
func GetCmdQueryAllClientConnections(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryAllClientConnections(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "paths",
Short: "Query all stored client connection paths",
@ -95,7 +96,8 @@ $ %s query ibc connection paths
Example: fmt.Sprintf("%s query ibc connection paths", version.ClientName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
page := viper.GetInt(flags.FlagPage)
limit := viper.GetInt(flags.FlagLimit)
@ -115,7 +117,7 @@ $ %s query ibc connection paths
}
// GetCmdQueryClientConnections defines the command to query a client connections
func GetCmdQueryClientConnections(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryClientConnections(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "path [client-id]",
Short: "Query stored client connection paths",
@ -128,7 +130,8 @@ $ %s query ibc connection path [client-id]
Example: fmt.Sprintf("%s query ibc connection path [client-id]", version.ClientName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
clientID := args[0]
prove := viper.GetBool(flags.FlagProve)

View File

@ -1,53 +1,33 @@
package cli
import (
"bufio"
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/version"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// Connection Handshake flags
const (
FlagNode1 = "node1"
FlagNode2 = "node2"
FlagFrom1 = "from1"
FlagFrom2 = "from2"
FlagChainID2 = "chain-id2"
)
// GetCmdConnectionOpenInit defines the command to initialize a connection on
// NewConnectionOpenInitCmd defines the command to initialize a connection on
// chain A with a given counterparty chain B
func GetCmdConnectionOpenInit(storeKey string, cdc *codec.Codec) *cobra.Command {
func NewConnectionOpenInitCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: strings.TrimSpace(`open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]`),
Short: "initialize connection on chain A",
Long: strings.TrimSpace(
fmt.Sprintf(`initialize a connection on chain A with a given counterparty chain B:
Example:
$ %s tx ibc connection open-init [connection-id] [client-id] \
[counterparty-connection-id] [counterparty-client-id] \
[path/to/counterparty_prefix.json]
`, version.ClientName),
Use: "open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]",
Short: "Initialize connection on chain A",
Long: "Initialize a connection on chain A with a given counterparty chain B",
Example: fmt.Sprintf(
"%s tx %s %s open-init [connection-id] [client-id] [counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]",
version.ClientName, host.ModuleName, types.SubModuleName,
),
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
connectionID := args[0]
clientID := args[1]
@ -68,37 +48,31 @@ $ %s tx ibc connection open-init [connection-id] [client-id] \
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
return cmd
}
// GetCmdConnectionOpenTry defines the command to relay a try open a connection on
// NewConnectionOpenTryCmd defines the command to relay a try open a connection on
// chain B
func GetCmdConnectionOpenTry(storeKey string, cdc *codec.Codec) *cobra.Command {
func NewConnectionOpenTryCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: strings.TrimSpace(`open-try [connection-id] [client-id]
[counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json]
[counterparty-versions] [path/to/proof_init.json] [path/to/proof_consensus.json]`),
Short: "initiate connection handshake between two chains",
Long: strings.TrimSpace(
fmt.Sprintf(`initialize a connection on chain A with a given counterparty chain B:
Example:
$ %s tx ibc connection open-try connection-id] [client-id] \
Long: "Initialize a connection on chain A with a given counterparty chain B",
Example: fmt.Sprintf(
`%s tx %s %s open-try connection-id] [client-id] \
[counterparty-connection-id] [counterparty-client-id] [path/to/counterparty_prefix.json] \
[counterparty-versions] [path/to/proof_init.json] [path/tp/proof_consensus.json]
`, version.ClientName),
[counterparty-versions] [path/to/proof_init.json] [path/tp/proof_consensus.json]`,
version.ClientName, host.ModuleName, types.SubModuleName,
),
Args: cobra.ExactArgs(8),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).
WithCodec(cdc).
WithHeight(viper.GetInt64(flags.FlagHeight))
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
connectionID := args[0]
clientID := args[1]
@ -139,31 +113,27 @@ $ %s tx ibc connection open-try connection-id] [client-id] \
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
return cmd
}
// GetCmdConnectionOpenAck defines the command to relay the acceptance of a
// NewConnectionOpenAckCmd defines the command to relay the acceptance of a
// connection open attempt from chain B to chain A
func GetCmdConnectionOpenAck(storeKey string, cdc *codec.Codec) *cobra.Command {
func NewConnectionOpenAckCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "open-ack [connection-id] [path/to/proof_try.json] [path/to/proof_consensus.json] [version]",
Short: "relay the acceptance of a connection open attempt from chain B to chain A",
Long: strings.TrimSpace(
fmt.Sprintf(`relay the acceptance of a connection open attempt from chain B to chain A:
Example:
$ %s tx ibc connection open-ack [connection-id] [path/to/proof_try.json] [path/to/proof_consensus.json] [version]
`, version.ClientName),
Short: "relay the acceptance of a connection open attempt",
Long: "Relay the acceptance of a connection open attempt from chain B to chain A",
Example: fmt.Sprintf(
"%s tx %s %s open-ack [connection-id] [path/to/proof_try.json] [path/to/proof_consensus.json] [version]",
version.ClientName, host.ModuleName, types.SubModuleName,
),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
connectionID := args[0]
@ -194,33 +164,27 @@ $ %s tx ibc connection open-ack [connection-id] [path/to/proof_try.json] [path/t
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
return cmd
}
// GetCmdConnectionOpenConfirm defines the command to initialize a connection on
// NewConnectionOpenConfirmCmd defines the command to initialize a connection on
// chain A with a given counterparty chain B
func GetCmdConnectionOpenConfirm(storeKey string, cdc *codec.Codec) *cobra.Command {
func NewConnectionOpenConfirmCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "open-confirm [connection-id] [path/to/proof_ack.json]",
Short: "confirm to chain B that connection is open on chain A",
Long: strings.TrimSpace(
fmt.Sprintf(`confirm to chain B that connection is open on chain A:
Example:
$ %s tx ibc connection open-confirm [connection-id] [path/to/proof_ack.json]
`, version.ClientName),
Long: "Confirm to chain B that connection is open on chain A",
Example: fmt.Sprintf(
"%s tx %s %s open-confirm [connection-id] [path/to/proof_ack.json]",
version.ClientName, host.ModuleName, types.SubModuleName,
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).
WithCodec(cdc).
WithHeight(viper.GetInt64(flags.FlagHeight))
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
connectionID := args[0]
@ -242,7 +206,7 @@ $ %s tx ibc connection open-confirm [connection-id] [path/to/proof_ack.json]
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}

View File

@ -12,11 +12,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils"
)
func registerQueryRoutes(clientCtx client.Context, r *mux.Router, queryRoute string) {
func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {
r.HandleFunc("/ibc/connections", queryConnectionsHandlerFn(clientCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/ibc/connections/{%s}", RestConnectionID), queryConnectionHandlerFn(clientCtx, queryRoute)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/ibc/connections/{%s}", RestConnectionID), queryConnectionHandlerFn(clientCtx)).Methods("GET")
r.HandleFunc("/ibc/clients/connections", queryClientsConnectionsHandlerFn(clientCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/ibc/clients/{%s}/connections", RestClientID), queryClientConnectionsHandlerFn(clientCtx, queryRoute)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/ibc/clients/{%s}/connections", RestClientID), queryClientConnectionsHandlerFn(clientCtx)).Methods("GET")
}
// queryConnectionsHandlerFn implements connections querying route
@ -64,7 +64,7 @@ func queryClientsConnectionsHandlerFn(clientCtx client.Context) http.HandlerFunc
// @Failure 400 {object} rest.ErrorResponse "Invalid connection id"
// @Failure 500 {object} rest.ErrorResponse "Internal Server Error"
// @Router /ibc/connections/{connection-id} [get]
func queryConnectionHandlerFn(clientCtx client.Context, _ string) http.HandlerFunc {
func queryConnectionHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
connectionID := vars[RestConnectionID]
@ -131,7 +131,7 @@ func queryConnectionsHandlerFn(clientCtx client.Context) http.HandlerFunc {
// @Failure 400 {object} rest.ErrorResponse "Invalid client id"
// @Failure 500 {object} rest.ErrorResponse "Internal Server Error"
// @Router /ibc/clients/{client-id}/connections [get]
func queryClientConnectionsHandlerFn(clientCtx client.Context, _ string) http.HandlerFunc {
func queryClientConnectionsHandlerFn(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
clientID := vars[RestClientID]

View File

@ -14,8 +14,8 @@ const (
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(clientCtx client.Context, r *mux.Router, queryRoute string) {
registerQueryRoutes(clientCtx, r, queryRoute)
func RegisterRoutes(clientCtx client.Context, r *mux.Router) {
registerQueryRoutes(clientCtx, r)
registerTxRoutes(clientCtx, r)
}

View File

@ -1,13 +1,10 @@
package connection
import (
"fmt"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/cli"
"github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/rest"
)
@ -18,16 +15,16 @@ func Name() string {
}
// GetTxCmd returns the root tx command for the IBC connections.
func GetTxCmd(cdc *codec.Codec, storeKey string) *cobra.Command {
return cli.GetTxCmd(fmt.Sprintf("%s/%s", storeKey, SubModuleName), cdc)
func GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.NewTxCmd(clientCtx)
}
// GetQueryCmd returns no root query command for the IBC connections.
func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command {
return cli.GetQueryCmd(fmt.Sprintf("%s/%s", queryRoute, SubModuleName), cdc)
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx)
}
// RegisterRESTRoutes registers the REST routes for the IBC connections.
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router, queryRoute string) {
rest.RegisterRoutes(clientCtx, rtr, fmt.Sprintf("%s/%s", queryRoute, SubModuleName))
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
rest.RegisterRoutes(clientCtx, rtr)
}

View File

@ -3,41 +3,51 @@ package cli
import (
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
)
// GetQueryCmd returns the query commands for IBC channels
func GetQueryCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
ics04ChannelQueryCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC channel query subcommands",
DisableFlagParsing: true,
Use: types.SubModuleName,
Short: "IBC channel query subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
ics04ChannelQueryCmd.AddCommand(flags.GetCommands(
GetCmdQueryChannel(storeKey, cdc),
GetCmdQueryChannelClientState(cdc),
// TODO: Query all channels
GetCmdQueryChannel(clientCtx),
// TODO: Query channels from a connection
GetCmdQueryChannelClientState(clientCtx),
// TODO: Query all packet commitments
// TODO: Query unrelayed packet ACKS
// TODO: Query unrelayed packet sends
)...)
return ics04ChannelQueryCmd
}
// GetTxCmd returns the transaction commands for IBC channels
func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// NewTxCmd returns a CLI command handler for all x/ibc channel transaction commands.
func NewTxCmd(clientCtx client.Context) *cobra.Command {
ics04ChannelTxCmd := &cobra.Command{
Use: types.SubModuleName,
Short: "IBC channel transaction subcommands",
Use: types.SubModuleName,
Short: "IBC channel transaction subcommands",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
ics04ChannelTxCmd.AddCommand(flags.PostCommands(
GetMsgChannelOpenInitCmd(storeKey, cdc),
GetMsgChannelOpenTryCmd(storeKey, cdc),
GetMsgChannelOpenAckCmd(storeKey, cdc),
GetMsgChannelOpenConfirmCmd(storeKey, cdc),
GetMsgChannelCloseInitCmd(storeKey, cdc),
GetMsgChannelCloseConfirmCmd(storeKey, cdc),
NewChannelOpenInitCmd(clientCtx),
NewChannelOpenTryCmd(clientCtx),
NewChannelOpenAckCmd(clientCtx),
NewChannelOpenConfirmCmd(clientCtx),
NewChannelCloseInitCmd(clientCtx),
NewChannelCloseConfirmCmd(clientCtx),
)...)
return ics04ChannelTxCmd

View File

@ -2,33 +2,31 @@ package cli
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/client/utils"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
// GetCmdQueryChannel defines the command to query a channel end
func GetCmdQueryChannel(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQueryChannel(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "end [port-id] [channel-id]",
Short: "Query a channel end",
Long: strings.TrimSpace(fmt.Sprintf(`Query an IBC channel end
Example:
$ %s query ibc channel end [port-id] [channel-id]
`, version.ClientName),
Long: "Query an IBC channel end from a port and channel identifiers",
Example: fmt.Sprintf(
"%s query %s %s end [port-id] [channel-id]", version.ClientName, host.ModuleName, types.SubModuleName,
),
Example: fmt.Sprintf("%s query ibc channel end [port-id] [channel-id]", version.ClientName),
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
portID := args[0]
channelID := args[1]
prove := viper.GetBool(flags.FlagProve)
@ -48,7 +46,7 @@ $ %s query ibc channel end [port-id] [channel-id]
}
// GetCmdQueryChannelClientState defines the command to query a client state from a channel
func GetCmdQueryChannelClientState(cdc *codec.Codec) *cobra.Command {
func GetCmdQueryChannelClientState(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "client-state [port-id] [channel-id]",
Short: "Query the client state associated with a channel",
@ -56,7 +54,8 @@ func GetCmdQueryChannelClientState(cdc *codec.Codec) *cobra.Command {
Example: fmt.Sprintf("%s query ibc channel client-state [port-id] [channel-id]", version.ClientName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.NewContext().WithCodec(cdc)
clientCtx = clientCtx.Init()
portID := args[0]
channelID := args[1]

View File

@ -1,7 +1,6 @@
package cli
import (
"bufio"
"strconv"
"strings"
@ -9,10 +8,7 @@ import (
"github.com/spf13/viper"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/client/tx"
connectionutils "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/client/utils"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
)
@ -23,16 +19,14 @@ const (
FlagIBCVersion = "ibc-version"
)
// GetMsgChannelOpenInitCmd returns the command to create a MsgChannelOpenInit transaction
func GetMsgChannelOpenInitCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// NewChannelOpenInitCmd returns the command to create a MsgChannelOpenInit transaction
func NewChannelOpenInitCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "open-init [port-id] [channel-id] [counterparty-port-id] [counterparty-channel-id] [connection-hops]",
Short: "Creates and sends a ChannelOpenInit message",
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
portID := args[0]
channelID := args[1]
@ -50,7 +44,7 @@ func GetMsgChannelOpenInitCmd(storeKey string, cdc *codec.Codec) *cobra.Command
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
@ -60,16 +54,14 @@ func GetMsgChannelOpenInitCmd(storeKey string, cdc *codec.Codec) *cobra.Command
return cmd
}
// GetMsgChannelOpenTryCmd returns the command to create a MsgChannelOpenTry transaction
func GetMsgChannelOpenTryCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// NewChannelOpenTryCmd returns the command to create a MsgChannelOpenTry transaction
func NewChannelOpenTryCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "open-try [port-id] [channel-id] [counterparty-port-id] [counterparty-channel-id] [connection-hops] [/path/to/proof_init.json] [proof-height]",
Short: "Creates and sends a ChannelOpenTry message",
Args: cobra.ExactArgs(7),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
portID := args[0]
channelID := args[1]
@ -98,7 +90,7 @@ func GetMsgChannelOpenTryCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
cmd.Flags().Bool(FlagOrdered, true, "Pass flag for opening ordered channels")
@ -107,16 +99,14 @@ func GetMsgChannelOpenTryCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
return cmd
}
// GetMsgChannelOpenAckCmd returns the command to create a MsgChannelOpenAck transaction
func GetMsgChannelOpenAckCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// NewChannelOpenAckCmd returns the command to create a MsgChannelOpenAck transaction
func NewChannelOpenAckCmd(clientCtx client.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "open-ack [port-id] [channel-id] [/path/to/proof_try.json] [proof-height]",
Short: "Creates and sends a ChannelOpenAck message",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
portID := args[0]
channelID := args[1]
@ -139,23 +129,21 @@ func GetMsgChannelOpenAckCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
cmd.Flags().String(FlagIBCVersion, "1.0.0", "supported IBC version")
return cmd
}
// GetMsgChannelOpenConfirmCmd returns the command to create a MsgChannelOpenConfirm transaction
func GetMsgChannelOpenConfirmCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// NewChannelOpenConfirmCmd returns the command to create a MsgChannelOpenConfirm transaction
func NewChannelOpenConfirmCmd(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "open-confirm [port-id] [channel-id] [/path/to/proof_ack.json] [proof-height]",
Short: "Creates and sends a ChannelOpenConfirm message",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
portID := args[0]
channelID := args[1]
@ -177,21 +165,19 @@ func GetMsgChannelOpenConfirmCmd(storeKey string, cdc *codec.Codec) *cobra.Comma
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
}
// GetMsgChannelCloseInitCmd returns the command to create a MsgChannelCloseInit transaction
func GetMsgChannelCloseInitCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// NewChannelCloseInitCmd returns the command to create a MsgChannelCloseInit transaction
func NewChannelCloseInitCmd(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "close-init [port-id] [channel-id]",
Short: "Creates and sends a ChannelCloseInit message",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
portID := args[0]
channelID := args[1]
@ -201,21 +187,19 @@ func GetMsgChannelCloseInitCmd(storeKey string, cdc *codec.Codec) *cobra.Command
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
}
// GetMsgChannelCloseConfirmCmd returns the command to create a MsgChannelCloseConfirm transaction
func GetMsgChannelCloseConfirmCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
// NewChannelCloseConfirmCmd returns the command to create a MsgChannelCloseConfirm transaction
func NewChannelCloseConfirmCmd(clientCtx client.Context) *cobra.Command {
return &cobra.Command{
Use: "close-confirm [port-id] [channel-id] [/path/to/proof_init.json] [proof-height]",
Short: "Creates and sends a ChannelCloseConfirm message",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := authtypes.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc))
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
clientCtx = clientCtx.InitWithInput(cmd.InOrStdin())
portID := args[0]
channelID := args[1]
@ -237,7 +221,7 @@ func GetMsgChannelCloseConfirmCmd(storeKey string, cdc *codec.Codec) *cobra.Comm
return err
}
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}
}

View File

@ -1,13 +1,10 @@
package channel
import (
"fmt"
"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/client/cli"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/client/rest"
)
@ -17,17 +14,17 @@ func Name() string {
return SubModuleName
}
// RegisterRESTRoutes registers the REST routes for the IBC channel
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router, queryRoute string) {
rest.RegisterRoutes(clientCtx, rtr)
}
// GetTxCmd returns the root tx command for the IBC connections.
func GetTxCmd(cdc *codec.Codec, storeKey string) *cobra.Command {
return cli.GetTxCmd(fmt.Sprintf("%s/%s", storeKey, SubModuleName), cdc)
func GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.NewTxCmd(clientCtx)
}
// GetQueryCmd returns no root query command for the IBC connections.
func GetQueryCmd(cdc *codec.Codec, queryRoute string) *cobra.Command {
return cli.GetQueryCmd(fmt.Sprintf("%s/%s", queryRoute, SubModuleName), cdc)
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(clientCtx)
}
// RegisterRESTRoutes registers the REST routes for the IBC channel
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
rest.RegisterRoutes(clientCtx, rtr)
}

View File

@ -21,7 +21,7 @@ const (
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(clientCtx client.Context, r *mux.Router, queryRoute string) {
func RegisterRoutes(clientCtx client.Context, r *mux.Router) {
registerTxRoutes(clientCtx, r)
}

View File

@ -19,8 +19,8 @@ func Name() string {
}
// RegisterRESTRoutes registers the REST routes for the IBC client
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router, queryRoute string) {
rest.RegisterRoutes(clientCtx, rtr, fmt.Sprintf("%s/%s", queryRoute, types.SubModuleName))
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
rest.RegisterRoutes(clientCtx, rtr)
}
// GetTxCmd returns the root tx command for the IBC client

View File

@ -8,7 +8,7 @@ import (
)
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(clientCtx client.Context, r *mux.Router, queryRoute string) {
func RegisterRoutes(clientCtx client.Context, r *mux.Router) {
registerTxRoutes(clientCtx, r)
}

View File

@ -19,8 +19,8 @@ func Name() string {
}
// RegisterRESTRoutes registers the REST routes for the IBC localhost client
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router, queryRoute string) {
rest.RegisterRoutes(clientCtx, rtr, fmt.Sprintf("%s/%s", queryRoute, types.SubModuleName))
func RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
rest.RegisterRoutes(clientCtx, rtr)
}
// GetTxCmd returns the root tx command for the IBC localhost client

View File

@ -5,7 +5,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
@ -15,7 +14,7 @@ import (
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
func GetTxCmd(clientCtx client.Context) *cobra.Command {
ibcTxCmd := &cobra.Command{
Use: host.ModuleName,
Short: "IBC transaction subcommands",
@ -25,16 +24,16 @@ func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
}
ibcTxCmd.AddCommand(flags.PostCommands(
tmclient.GetTxCmd(cdc, storeKey),
localhost.GetTxCmd(cdc, storeKey),
connection.GetTxCmd(cdc, storeKey),
channel.GetTxCmd(cdc, storeKey),
tmclient.GetTxCmd(clientCtx.Codec, host.StoreKey),
localhost.GetTxCmd(clientCtx.Codec, host.StoreKey),
connection.GetTxCmd(clientCtx),
channel.GetTxCmd(clientCtx),
)...)
return ibcTxCmd
}
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetQueryCmd(clientCtx client.Context) *cobra.Command {
// Group ibc queries under a subcommand
ibcQueryCmd := &cobra.Command{
Use: host.ModuleName,
@ -45,9 +44,9 @@ func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
}
ibcQueryCmd.AddCommand(flags.GetCommands(
ibcclient.GetQueryCmd(cdc, queryRoute),
connection.GetQueryCmd(cdc, queryRoute),
channel.GetQueryCmd(cdc, queryRoute),
ibcclient.GetQueryCmd(clientCtx),
connection.GetQueryCmd(clientCtx),
channel.GetQueryCmd(clientCtx),
)...)
return ibcQueryCmd
}

View File

@ -4,7 +4,7 @@ import (
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client"
client2 "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
connection "github.com/cosmos/cosmos-sdk/x/ibc/03-connection"
channel "github.com/cosmos/cosmos-sdk/x/ibc/04-channel"
tendermint "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint"
@ -13,9 +13,9 @@ import (
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(clientCtx client.Context, r *mux.Router, queryRoute string) {
client2.RegisterRESTRoutes(clientCtx, r, queryRoute)
tendermint.RegisterRESTRoutes(clientCtx, r, queryRoute)
localhost.RegisterRESTRoutes(clientCtx, r, queryRoute)
connection.RegisterRESTRoutes(clientCtx, r, queryRoute)
channel.RegisterRESTRoutes(clientCtx, r, queryRoute)
ibcclient.RegisterRESTRoutes(clientCtx, r)
tendermint.RegisterRESTRoutes(clientCtx, r)
localhost.RegisterRESTRoutes(clientCtx, r)
connection.RegisterRESTRoutes(clientCtx, r)
channel.RegisterRESTRoutes(clientCtx, r)
}

View File

@ -70,12 +70,12 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
// GetTxCmd returns the root tx command for the ibc module.
func (AppModuleBasic) GetTxCmd(clientCtx client.Context) *cobra.Command {
return cli.GetTxCmd(host.StoreKey, clientCtx.Codec)
return cli.GetTxCmd(clientCtx)
}
// GetQueryCmd returns no root query command for the ibc module.
func (AppModuleBasic) GetQueryCmd(clientCtx client.Context) *cobra.Command {
return cli.GetQueryCmd(host.QuerierRoute, clientCtx.Codec)
return cli.GetQueryCmd(clientCtx)
}
// RegisterInterfaceTypes registers module concrete types into protobuf Any.