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

x/ibc: CLI Remove Viper #6608

Merged
merged 1 commit into from
Jul 6, 2020
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
4 changes: 2 additions & 2 deletions x/ibc-transfer/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -32,7 +31,7 @@ $ %s query ibc-transfer next-recv [port-id] [channel-id]

portID := args[0]
channelID := args[1]
prove := viper.GetBool(flags.FlagProve)
prove, _ := cmd.Flags().GetBool(flags.FlagProve)

sequenceRes, err := utils.QueryNextSequenceRecv(clientCtx, portID, channelID, prove)
if err != nil {
Expand All @@ -43,6 +42,7 @@ $ %s query ibc-transfer next-recv [port-id] [channel-id]
return clientCtx.PrintOutput(sequenceRes)
},
}

cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")

return cmd
Expand Down
7 changes: 4 additions & 3 deletions x/ibc-transfer/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down Expand Up @@ -38,8 +37,8 @@ func NewTransferTxCmd(clientCtx client.Context) *cobra.Command {
return err
}

timeoutHeight := viper.GetUint64(flagTimeoutHeight)
timeoutTimestamp := viper.GetUint64(flagTimeoutHeight)
timeoutHeight, _ := cmd.Flags().GetUint64(flagTimeoutHeight)
timeoutTimestamp, _ := cmd.Flags().GetUint64(flagTimeoutHeight)

msg := types.NewMsgTransfer(
srcPort, srcChannel, coins, sender, receiver, timeoutHeight, timeoutTimestamp,
Expand All @@ -51,7 +50,9 @@ func NewTransferTxCmd(clientCtx client.Context) *cobra.Command {
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}

cmd.Flags().Uint64(flagTimeoutHeight, types.DefaultAbsolutePacketTimeoutHeight, "Absolute timeout block height. The timeout is disabled when set to 0.")
cmd.Flags().Uint64(flagTimeoutTimestamp, types.DefaultAbsolutePacketTimeoutTimestamp, "Absolute timeout timestamp in nanoseconds. The timeout is disabled when set to 0.")

return cmd
}
13 changes: 8 additions & 5 deletions x/ibc/02-client/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -33,8 +32,8 @@ $ %s query ibc client states
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx = clientCtx.Init()

page := viper.GetInt(flags.FlagPage)
limit := viper.GetInt(flags.FlagLimit)
page, _ := cmd.Flags().GetInt(flags.FlagPage)
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)

clientStates, height, err := utils.QueryAllClientStates(clientCtx, page, limit)
if err != nil {
Expand All @@ -45,8 +44,10 @@ $ %s query ibc client states
return clientCtx.PrintOutput(clientStates)
},
}

cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for")
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for")

return cmd
}

Expand All @@ -72,7 +73,7 @@ $ %s query ibc client state [client-id]
return errors.New("client ID can't be blank")
}

prove := viper.GetBool(flags.FlagProve)
prove, _ := cmd.Flags().GetBool(flags.FlagProve)

clientStateRes, err := utils.QueryClientState(clientCtx, clientID, prove)
if err != nil {
Expand All @@ -83,6 +84,7 @@ $ %s query ibc client state [client-id]
return clientCtx.PrintOutput(clientStateRes)
},
}

cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
return cmd
}
Expand All @@ -109,7 +111,7 @@ func GetCmdQueryConsensusState(clientCtx client.Context) *cobra.Command {
return fmt.Errorf("expected integer height, got: %s", args[1])
}

prove := viper.GetBool(flags.FlagProve)
prove, _ := cmd.Flags().GetBool(flags.FlagProve)

csRes, err := utils.QueryConsensusState(clientCtx, clientID, height, prove)
if err != nil {
Expand All @@ -120,6 +122,7 @@ func GetCmdQueryConsensusState(clientCtx client.Context) *cobra.Command {
return clientCtx.PrintOutput(csRes)
},
}

cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")
return cmd
}
Expand Down
16 changes: 9 additions & 7 deletions x/ibc/03-connection/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -31,8 +30,8 @@ $ %s query ibc connection connections
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx = clientCtx.Init()

page := viper.GetInt(flags.FlagPage)
limit := viper.GetInt(flags.FlagLimit)
page, _ := cmd.Flags().GetInt(flags.FlagPage)
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)

connections, height, err := utils.QueryAllConnections(clientCtx, page, limit)
if err != nil {
Expand All @@ -43,6 +42,7 @@ $ %s query ibc connection connections
return clientCtx.PrintOutput(connections)
},
}

cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for")
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for")

Expand All @@ -66,7 +66,7 @@ $ %s query ibc connection end [connection-id]
clientCtx = clientCtx.Init()

connectionID := args[0]
prove := viper.GetBool(flags.FlagProve)
prove, _ := cmd.Flags().GetBool(flags.FlagProve)

connRes, err := utils.QueryConnection(clientCtx, connectionID, prove)
if err != nil {
Expand All @@ -77,6 +77,7 @@ $ %s query ibc connection end [connection-id]
return clientCtx.PrintOutput(connRes)
},
}

cmd.Flags().Bool(flags.FlagProve, true, "show proofs for the query results")

return cmd
Expand All @@ -98,8 +99,8 @@ $ %s query ibc connection paths
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx = clientCtx.Init()

page := viper.GetInt(flags.FlagPage)
limit := viper.GetInt(flags.FlagLimit)
page, _ := cmd.Flags().GetInt(flags.FlagPage)
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)

connectionPaths, height, err := utils.QueryAllClientConnectionPaths(clientCtx, page, limit)
if err != nil {
Expand All @@ -110,6 +111,7 @@ $ %s query ibc connection paths
return clientCtx.PrintOutput(connectionPaths)
},
}

cmd.Flags().Int(flags.FlagPage, 1, "pagination page of light clients to to query for")
cmd.Flags().Int(flags.FlagLimit, 100, "pagination limit of light clients to query for")

Expand All @@ -133,7 +135,7 @@ $ %s query ibc connection path [client-id]
clientCtx = clientCtx.Init()

clientID := args[0]
prove := viper.GetBool(flags.FlagProve)
prove, _ := cmd.Flags().GetBool(flags.FlagProve)

connPathsRes, err := utils.QueryClientConnections(clientCtx, clientID, prove)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions x/ibc/04-channel/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -29,7 +28,7 @@ func GetCmdQueryChannel(clientCtx client.Context) *cobra.Command {

portID := args[0]
channelID := args[1]
prove := viper.GetBool(flags.FlagProve)
prove, _ := cmd.Flags().GetBool(flags.FlagProve)

channelRes, err := utils.QueryChannel(clientCtx, portID, channelID, prove)
if err != nil {
Expand Down
24 changes: 16 additions & 8 deletions x/ibc/04-channel/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/spf13/pflag"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand Down Expand Up @@ -33,8 +33,8 @@ func NewChannelOpenInitCmd(clientCtx client.Context) *cobra.Command {
counterpartyPortID := args[2]
counterpartyChannelID := args[3]
hops := strings.Split(args[4], "/")
order := channelOrder()
version := viper.GetString(FlagIBCVersion)
order := channelOrder(cmd.Flags())
version, _ := cmd.Flags().GetString(FlagIBCVersion)

msg := types.NewMsgChannelOpenInit(
portID, channelID, version, order, hops,
Expand Down Expand Up @@ -68,8 +68,10 @@ func NewChannelOpenTryCmd(clientCtx client.Context) *cobra.Command {
counterpartyPortID := args[2]
counterpartyChannelID := args[3]
hops := strings.Split(args[4], "/")
order := channelOrder()
version := viper.GetString(FlagIBCVersion) // TODO: diferenciate between channel and counterparty versions
order := channelOrder(cmd.Flags())

// TODO: Differentiate between channel and counterparty versions.
version, _ := cmd.Flags().GetString(FlagIBCVersion)

proofInit, err := connectionutils.ParseProof(clientCtx.Codec, args[5])
if err != nil {
Expand All @@ -93,6 +95,7 @@ func NewChannelOpenTryCmd(clientCtx client.Context) *cobra.Command {
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}

cmd.Flags().Bool(FlagOrdered, true, "Pass flag for opening ordered channels")
cmd.Flags().String(FlagIBCVersion, "1.0.0", "supported IBC version")

Expand All @@ -110,7 +113,9 @@ func NewChannelOpenAckCmd(clientCtx client.Context) *cobra.Command {

portID := args[0]
channelID := args[1]
version := viper.GetString(FlagIBCVersion) // TODO: diferenciate between channel and counterparty versions

// TODO: Differentiate between channel and counterparty versions.
version, _ := cmd.Flags().GetString(FlagIBCVersion)

proofTry, err := connectionutils.ParseProof(clientCtx.Codec, args[5])
if err != nil {
Expand All @@ -132,7 +137,9 @@ func NewChannelOpenAckCmd(clientCtx client.Context) *cobra.Command {
return tx.GenerateOrBroadcastTx(clientCtx, msg)
},
}

cmd.Flags().String(FlagIBCVersion, "1.0.0", "supported IBC version")

return cmd
}

Expand Down Expand Up @@ -226,9 +233,10 @@ func NewChannelCloseConfirmCmd(clientCtx client.Context) *cobra.Command {
}
}

func channelOrder() types.Order {
if viper.GetBool(FlagOrdered) {
func channelOrder(fs *pflag.FlagSet) types.Order {
if ordered, _ := fs.GetBool(FlagOrdered); ordered {
return types.ORDERED
}

return types.UNORDERED
}
7 changes: 4 additions & 3 deletions x/ibc/07-tendermint/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/pkg/errors"

"github.com/spf13/cobra"
"github.com/spf13/viper"

tmmath "github.com/tendermint/tendermint/libs/math"
lite "github.com/tendermint/tendermint/lite2"
Expand Down Expand Up @@ -70,7 +69,7 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
err error
)

lvl := viper.GetString(flagTrustLevel)
lvl, _ := cmd.Flags().GetString(flagTrustLevel)

if lvl == "default" {
trustLevel = lite.DefaultTrustLevel
Expand All @@ -96,7 +95,7 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
return err
}

spc := viper.GetString(flagProofSpecs)
spc, _ := cmd.Flags().GetString(flagProofSpecs)
if spc == "default" {
specs = commitmenttypes.GetSDKSpecs()
} else if err := cdc.UnmarshalJSON([]byte(spc), &specs); err != nil {
Expand All @@ -121,8 +120,10 @@ func GetCmdCreateClient(cdc *codec.Codec) *cobra.Command {
return authclient.GenerateOrBroadcastMsgs(clientCtx, txBldr, []sdk.Msg{msg})
},
}

cmd.Flags().String(flagTrustLevel, "default", "light client trust level fraction for header updates")
cmd.Flags().String(flagProofSpecs, "default", "proof specs format to be used for verification")

return cmd
}

Expand Down