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

Add cli commands for the coinswap module. #4719

Merged
merged 19 commits into from
Sep 9, 2019
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a42b045
Added query.go that includes the cli commands for querying.
aayushijain23 Jul 12, 2019
6af249b
Added transaction subcommands such as add and remove liquidity.
aayushijain23 Jul 18, 2019
7aa6998
Added tx command for swap order message type.
aayushijain23 Jul 22, 2019
f9b248e
Added REST API commands for transaction sub commands specific to the …
aayushijain23 Jul 22, 2019
39306cb
Added REST API commands for the query sub commands. Also added a stru…
aayushijain23 Jul 23, 2019
7445656
Removed some lines of code that were commented.
aayushijain23 Jul 30, 2019
920166e
Update x/coinswap/client/cli/tx.go
aayushijain23 Jul 31, 2019
405f7d8
Update x/coinswap/client/cli/tx.go
aayushijain23 Jul 31, 2019
31038a7
Update x/coinswap/internal/types/querier.go
aayushijain23 Aug 1, 2019
0c9fef3
Incorporating Colin's and Fede's review comments.
aayushijain23 Aug 1, 2019
438d219
Update x/coinswap/client/rest/query.go
aayushijain23 Aug 2, 2019
f9f3b0b
Update x/coinswap/client/rest/query.go
aayushijain23 Aug 2, 2019
03d4687
Incorporating Fede and Colin's review comments.
aayushijain23 Aug 2, 2019
de2a089
Address Colin's comments.
aayushijain23 Aug 8, 2019
81856e8
Addressing comments on handling time.parse errors.
aayushijain23 Aug 8, 2019
5f2af25
Addressed review comments about flags and splitting swap order into b…
aayushijain23 Aug 8, 2019
f8532d0
Addressed Colin's comments.
aayushijain23 Aug 9, 2019
8f1ccfb
Merge branch 'colin/4443-coinswap' of github.com:cosmos/cosmos-sdk in…
aayushijain23 Aug 9, 2019
fb30336
Addressing comment of removing req.Sender.
aayushijain23 Aug 9, 2019
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
93 changes: 93 additions & 0 deletions x/coinswap/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package cli

import (
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/coinswap/internal/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
coinswapQueryCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Querying commands for the coinswap module",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
coinswapQueryCmd.AddCommand(client.GetCommands(
GetCmdQueryLiquidity(queryRoute, cdc),
GetCmdQueryParams(queryRoute, cdc))...)

return coinswapQueryCmd
}

// GetCmdQueryLiquidity implements the liquidity query command
func GetCmdQueryLiquidity(queryRoute string, cdc *codec.Codec) *cobra.Command {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
return &cobra.Command{
Use: "liquidity",
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
Short: "Query the current liquidity values",
Long: strings.TrimSpace(
fmt.Sprintf(`Query values for the liquidity stored in the reserve pool.
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

Example:
$ %s query coinswap liquidity
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
`,
version.ClientName,
),
),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryLiquidity)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}

var liquidity sdk.Coin
cdc.MustUnmarshalJSON(bz, &liquidity)
return cliCtx.PrintOutput(liquidity)
},
}
}

// GetCmdQueryParams implements the params query command
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
return &cobra.Command{
Use: "params",
Short: "Query the parameters involved in the coinswap process",
Long: strings.TrimSpace(
fmt.Sprintf(`Query all the parameters for the coinswap process.

Example:
$ %s query coinswap params
`,
version.ClientName,
),
),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryParameters)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}

var params types.Params
cdc.MustUnmarshalJSON(bz, &params)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
return cliCtx.PrintOutput(params)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
},
}
}