Standardize CLI Exports from Modules (#2840)
* Move query and tx commands to modules * Move GetAccountDecoder to prevent import cycle and replace calls to it with one call in WithAccountDecoder * Add moduleClients interface and implement in all applicable modules * Use module clients in cli initialization
This commit is contained in:
parent
fd968f7d8f
commit
f525717054
|
@ -31,6 +31,7 @@ FEATURES
|
|||
* [gov][cli] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added governance
|
||||
parameter query commands.
|
||||
* [stake][cli] [\#2027] Add CLI query command for getting all delegations to a specific validator.
|
||||
* [\#2840](https://github.com/cosmos/cosmos-sdk/pull/2840) Standardize CLI exports from modules
|
||||
|
||||
* Gaia
|
||||
* [app] \#2791 Support export at a specific height, with `gaiad export --height=HEIGHT`.
|
||||
|
|
|
@ -175,10 +175,22 @@ func (ctx CLIContext) WithCodec(cdc *codec.Codec) CLIContext {
|
|||
return ctx
|
||||
}
|
||||
|
||||
// GetAccountDecoder gets the account decoder for auth.DefaultAccount.
|
||||
func GetAccountDecoder(cdc *codec.Codec) auth.AccountDecoder {
|
||||
return func(accBytes []byte) (acct auth.Account, err error) {
|
||||
err = cdc.UnmarshalBinaryBare(accBytes, &acct)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return acct, err
|
||||
}
|
||||
}
|
||||
|
||||
// WithAccountDecoder returns a copy of the context with an updated account
|
||||
// decoder.
|
||||
func (ctx CLIContext) WithAccountDecoder(decoder auth.AccountDecoder) CLIContext {
|
||||
ctx.AccDecoder = decoder
|
||||
func (ctx CLIContext) WithAccountDecoder(cdc *codec.Codec) CLIContext {
|
||||
ctx.AccDecoder = GetAccountDecoder(cdc)
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmserver "github.com/tendermint/tendermint/rpc/lib/server"
|
||||
|
||||
// Import statik for light client stuff
|
||||
_ "github.com/cosmos/cosmos-sdk/client/lcd/statik"
|
||||
)
|
||||
|
||||
// RestServer represents the Light Client Rest server
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -9,6 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
amino "github.com/tendermint/go-amino"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
|
@ -19,29 +21,29 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
|
||||
gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
|
||||
slashing "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
|
||||
stake "github.com/cosmos/cosmos-sdk/x/stake/client/rest"
|
||||
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
distClient "github.com/cosmos/cosmos-sdk/x/distribution/client"
|
||||
govClient "github.com/cosmos/cosmos-sdk/x/gov/client"
|
||||
slashingClient "github.com/cosmos/cosmos-sdk/x/slashing/client"
|
||||
stakeClient "github.com/cosmos/cosmos-sdk/x/stake/client"
|
||||
|
||||
_ "github.com/cosmos/cosmos-sdk/client/lcd/statik"
|
||||
)
|
||||
|
||||
const (
|
||||
storeAcc = "acc"
|
||||
storeGov = "gov"
|
||||
storeSlashing = "slashing"
|
||||
storeStake = "stake"
|
||||
queryRouteStake = "stake"
|
||||
)
|
||||
|
||||
// rootCmd is the entry point for this binary
|
||||
var (
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "gaiacli",
|
||||
Short: "Command line interface for interacting with gaiad",
|
||||
}
|
||||
storeAcc = "acc"
|
||||
storeGov = "gov"
|
||||
storeSlashing = "slashing"
|
||||
storeStake = "stake"
|
||||
storeDist = "distr"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -68,13 +70,27 @@ func main() {
|
|||
// the below functions and eliminate global vars, like we do
|
||||
// with the cdc
|
||||
|
||||
// Module clients hold cli commnads (tx,query) and lcd routes
|
||||
// TODO: Make the lcd command take a list of ModuleClient
|
||||
mc := []sdk.ModuleClients{
|
||||
govClient.NewModuleClient(storeGov, cdc),
|
||||
distClient.NewModuleClient(storeDist, cdc),
|
||||
stakeClient.NewModuleClient(storeStake, cdc),
|
||||
slashingClient.NewModuleClient(storeSlashing, cdc),
|
||||
}
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "gaiacli",
|
||||
Short: "Command line interface for interacting with gaiad",
|
||||
}
|
||||
|
||||
// Construct Root Command
|
||||
rootCmd.AddCommand(
|
||||
rpc.InitClientCommand(),
|
||||
rpc.StatusCommand(),
|
||||
client.ConfigCmd(),
|
||||
queryCmd(cdc),
|
||||
txCmd(cdc),
|
||||
queryCmd(cdc, mc),
|
||||
txCmd(cdc, mc),
|
||||
client.LineBreak,
|
||||
rs.ServeCommand(),
|
||||
client.LineBreak,
|
||||
|
@ -92,11 +108,55 @@ func main() {
|
|||
|
||||
err = executor.Execute()
|
||||
if err != nil {
|
||||
// handle with #870
|
||||
panic(err)
|
||||
fmt.Printf("Failed executing CLI command: %s, exiting...\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func queryCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
|
||||
queryCmd := &cobra.Command{
|
||||
Use: "query",
|
||||
Aliases: []string{"q"},
|
||||
Short: "Querying subcommands",
|
||||
}
|
||||
|
||||
queryCmd.AddCommand(
|
||||
rpc.ValidatorCommand(),
|
||||
rpc.BlockCommand(),
|
||||
tx.SearchTxCmd(cdc),
|
||||
tx.QueryTxCmd(cdc),
|
||||
client.LineBreak,
|
||||
authcmd.GetAccountCmd(storeAcc, cdc),
|
||||
)
|
||||
|
||||
for _, m := range mc {
|
||||
queryCmd.AddCommand(m.GetQueryCmd())
|
||||
}
|
||||
|
||||
return queryCmd
|
||||
}
|
||||
|
||||
func txCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: "tx",
|
||||
Short: "Transactions subcommands",
|
||||
}
|
||||
|
||||
txCmd.AddCommand(
|
||||
bankcmd.SendTxCmd(cdc),
|
||||
client.LineBreak,
|
||||
authcmd.GetSignCommand(cdc),
|
||||
bankcmd.GetBroadcastCommand(cdc),
|
||||
client.LineBreak,
|
||||
)
|
||||
|
||||
for _, m := range mc {
|
||||
txCmd.AddCommand(m.GetTxCmd())
|
||||
}
|
||||
|
||||
return txCmd
|
||||
}
|
||||
|
||||
// registerRoutes registers the routes from the different modules for the LCD.
|
||||
// NOTE: details on the routes added for each module are in the module documentation
|
||||
// NOTE: If making updates here you also need to update the test helper in client/lcd/test_helper.go
|
||||
|
@ -105,7 +165,7 @@ func registerRoutes(rs *lcd.RestServer) {
|
|||
keys.RegisterRoutes(rs.Mux, rs.CliCtx.Indent)
|
||||
rpc.RegisterRoutes(rs.CliCtx, rs.Mux)
|
||||
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
|
||||
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, "acc")
|
||||
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, storeAcc)
|
||||
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
|
||||
stake.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
|
||||
slashing.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
||||
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
|
||||
func queryCmd(cdc *amino.Codec) *cobra.Command {
|
||||
//Add query commands
|
||||
queryCmd := &cobra.Command{
|
||||
Use: "query",
|
||||
Aliases: []string{"q"},
|
||||
Short: "Querying subcommands",
|
||||
}
|
||||
|
||||
// Group staking queries under a subcommand
|
||||
stakeQueryCmd := &cobra.Command{
|
||||
Use: "stake",
|
||||
Short: "Querying commands for the staking module",
|
||||
}
|
||||
|
||||
stakeQueryCmd.AddCommand(client.GetCommands(
|
||||
stakecmd.GetCmdQueryDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidator(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidators(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorUnbondingDelegations(queryRouteStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorRedelegations(queryRouteStake, cdc),
|
||||
stakecmd.GetCmdQueryParams(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryPool(storeStake, cdc))...)
|
||||
|
||||
// Group gov queries under a subcommand
|
||||
govQueryCmd := &cobra.Command{
|
||||
Use: "gov",
|
||||
Short: "Querying commands for the governance module",
|
||||
}
|
||||
|
||||
govQueryCmd.AddCommand(client.GetCommands(
|
||||
govcmd.GetCmdQueryProposal(storeGov, cdc),
|
||||
govcmd.GetCmdQueryProposals(storeGov, cdc),
|
||||
govcmd.GetCmdQueryVote(storeGov, cdc),
|
||||
govcmd.GetCmdQueryVotes(storeGov, cdc),
|
||||
govcmd.GetCmdQueryParams(storeGov, cdc),
|
||||
govcmd.GetCmdQueryDeposit(storeGov, cdc),
|
||||
govcmd.GetCmdQueryDeposits(storeGov, cdc))...)
|
||||
|
||||
// Group slashing queries under a subcommand
|
||||
slashingQueryCmd := &cobra.Command{
|
||||
Use: "slashing",
|
||||
Short: "Querying commands for the slashing module",
|
||||
}
|
||||
|
||||
slashingQueryCmd.AddCommand(client.GetCommands(
|
||||
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc))...)
|
||||
|
||||
// Query commcmmand structure
|
||||
queryCmd.AddCommand(
|
||||
rpc.BlockCommand(),
|
||||
rpc.ValidatorCommand(),
|
||||
tx.SearchTxCmd(cdc),
|
||||
tx.QueryTxCmd(cdc),
|
||||
client.LineBreak,
|
||||
client.GetCommands(authcmd.GetAccountCmd(storeAcc, cdc, authcmd.GetAccountDecoder(cdc)))[0],
|
||||
stakeQueryCmd,
|
||||
govQueryCmd,
|
||||
slashingQueryCmd,
|
||||
)
|
||||
|
||||
return queryCmd
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
distrcmd "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
|
||||
govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
||||
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
|
||||
func txCmd(cdc *amino.Codec) *cobra.Command {
|
||||
//Add transaction generation commands
|
||||
txCmd := &cobra.Command{
|
||||
Use: "tx",
|
||||
Short: "Transactions subcommands",
|
||||
}
|
||||
|
||||
stakeTxCmd := &cobra.Command{
|
||||
Use: "stake",
|
||||
Short: "Staking transaction subcommands",
|
||||
}
|
||||
|
||||
stakeTxCmd.AddCommand(client.PostCommands(
|
||||
stakecmd.GetCmdCreateValidator(cdc),
|
||||
stakecmd.GetCmdEditValidator(cdc),
|
||||
stakecmd.GetCmdDelegate(cdc),
|
||||
stakecmd.GetCmdRedelegate(storeStake, cdc),
|
||||
stakecmd.GetCmdUnbond(storeStake, cdc),
|
||||
)...)
|
||||
|
||||
distTxCmd := &cobra.Command{
|
||||
Use: "dist",
|
||||
Short: "Distribution transactions subcommands",
|
||||
}
|
||||
|
||||
distTxCmd.AddCommand(client.PostCommands(
|
||||
distrcmd.GetCmdWithdrawRewards(cdc),
|
||||
distrcmd.GetCmdSetWithdrawAddr(cdc),
|
||||
)...)
|
||||
|
||||
govTxCmd := &cobra.Command{
|
||||
Use: "gov",
|
||||
Short: "Governance transactions subcommands",
|
||||
}
|
||||
|
||||
govTxCmd.AddCommand(client.PostCommands(
|
||||
govcmd.GetCmdDeposit(cdc),
|
||||
govcmd.GetCmdVote(cdc),
|
||||
govcmd.GetCmdSubmitProposal(cdc),
|
||||
)...)
|
||||
|
||||
slashingTxCmd := &cobra.Command{
|
||||
Use: "slashing",
|
||||
Short: "Slashing transactions subcommands",
|
||||
}
|
||||
|
||||
slashingTxCmd.AddCommand(client.PostCommands(
|
||||
slashingcmd.GetCmdUnjail(cdc),
|
||||
)...)
|
||||
|
||||
txCmd.AddCommand(
|
||||
//Add auth and bank commands
|
||||
client.PostCommands(
|
||||
bankcmd.SendTxCmd(cdc),
|
||||
bankcmd.GetBroadcastCommand(cdc),
|
||||
authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)),
|
||||
)...)
|
||||
|
||||
txCmd.AddCommand(
|
||||
client.LineBreak,
|
||||
stakeTxCmd,
|
||||
distTxCmd,
|
||||
govTxCmd,
|
||||
slashingTxCmd,
|
||||
)
|
||||
|
||||
return txCmd
|
||||
}
|
|
@ -2,6 +2,10 @@ package init
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
||||
|
@ -17,9 +21,6 @@ import (
|
|||
"github.com/tendermint/tendermint/crypto"
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
"github.com/tendermint/tendermint/libs/common"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -94,7 +95,7 @@ following delegation and commission default parameters:
|
|||
w.Close()
|
||||
|
||||
prepareFlagsForTxSign()
|
||||
signCmd := authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc))
|
||||
signCmd := authcmd.GetSignCommand(cdc)
|
||||
if w, err = prepareOutputFile(config.RootDir, nodeID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/basecoin/app"
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/basecoin/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
|
@ -24,6 +24,12 @@ import (
|
|||
"github.com/tendermint/tendermint/libs/cli"
|
||||
)
|
||||
|
||||
const (
|
||||
storeAcc = "acc"
|
||||
storeSlashing = "slashing"
|
||||
storeStake = "stake"
|
||||
)
|
||||
|
||||
// rootCmd is the entry point for this binary
|
||||
var (
|
||||
rootCmd = &cobra.Command{
|
||||
|
@ -67,20 +73,20 @@ func main() {
|
|||
// add query/post commands (custom to binary)
|
||||
rootCmd.AddCommand(
|
||||
client.GetCommands(
|
||||
stakecmd.GetCmdQueryValidator("stake", cdc),
|
||||
stakecmd.GetCmdQueryValidators("stake", cdc),
|
||||
stakecmd.GetCmdQueryValidatorUnbondingDelegations("stake", cdc),
|
||||
stakecmd.GetCmdQueryValidatorRedelegations("stake", cdc),
|
||||
stakecmd.GetCmdQueryDelegation("stake", cdc),
|
||||
stakecmd.GetCmdQueryDelegations("stake", cdc),
|
||||
stakecmd.GetCmdQueryPool("stake", cdc),
|
||||
stakecmd.GetCmdQueryParams("stake", cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegation("stake", cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegations("stake", cdc),
|
||||
stakecmd.GetCmdQueryRedelegation("stake", cdc),
|
||||
stakecmd.GetCmdQueryRedelegations("stake", cdc),
|
||||
slashingcmd.GetCmdQuerySigningInfo("slashing", cdc),
|
||||
authcmd.GetAccountCmd("acc", cdc, types.GetAccountDecoder(cdc)),
|
||||
stakecmd.GetCmdQueryValidator(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidators(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorUnbondingDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryValidatorRedelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryPool(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryParams(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryUnbondingDelegations(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegation(storeStake, cdc),
|
||||
stakecmd.GetCmdQueryRedelegations(storeStake, cdc),
|
||||
slashingcmd.GetCmdQuerySigningInfo(storeSlashing, cdc),
|
||||
authcmd.GetAccountCmd(storeAcc, cdc),
|
||||
)...)
|
||||
|
||||
rootCmd.AddCommand(
|
||||
|
@ -91,8 +97,8 @@ func main() {
|
|||
stakecmd.GetCmdCreateValidator(cdc),
|
||||
stakecmd.GetCmdEditValidator(cdc),
|
||||
stakecmd.GetCmdDelegate(cdc),
|
||||
stakecmd.GetCmdUnbond("stake", cdc),
|
||||
stakecmd.GetCmdRedelegate("stake", cdc),
|
||||
stakecmd.GetCmdUnbond(storeStake, cdc),
|
||||
stakecmd.GetCmdRedelegate(storeStake, cdc),
|
||||
slashingcmd.GetCmdUnjail(cdc),
|
||||
)...)
|
||||
|
||||
|
@ -118,7 +124,7 @@ func registerRoutes(rs *lcd.RestServer) {
|
|||
keys.RegisterRoutes(rs.Mux, rs.CliCtx.Indent)
|
||||
rpc.RegisterRoutes(rs.CliCtx, rs.Mux)
|
||||
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
|
||||
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, "acc")
|
||||
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, storeAcc)
|
||||
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
|
||||
stake.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
|
||||
slashing.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/democoin/app"
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/democoin/types"
|
||||
coolcmd "github.com/cosmos/cosmos-sdk/docs/examples/democoin/x/cool/client/cli"
|
||||
powcmd "github.com/cosmos/cosmos-sdk/docs/examples/democoin/x/pow/client/cli"
|
||||
simplestakingcmd "github.com/cosmos/cosmos-sdk/docs/examples/democoin/x/simplestake/client/cli"
|
||||
|
@ -32,6 +31,7 @@ var (
|
|||
Use: "democli",
|
||||
Short: "Democoin light-client",
|
||||
}
|
||||
storeAcc = "acc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -71,7 +71,7 @@ func main() {
|
|||
// start with commands common to basecoin
|
||||
rootCmd.AddCommand(
|
||||
client.GetCommands(
|
||||
authcmd.GetAccountCmd("acc", cdc, types.GetAccountDecoder(cdc)),
|
||||
authcmd.GetAccountCmd(storeAcc, cdc),
|
||||
)...)
|
||||
rootCmd.AddCommand(
|
||||
client.PostCommands(
|
||||
|
@ -115,6 +115,6 @@ func registerRoutes(rs *lcd.RestServer) {
|
|||
keys.RegisterRoutes(rs.Mux, rs.CliCtx.Indent)
|
||||
rpc.RegisterRoutes(rs.CliCtx, rs.Mux)
|
||||
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
|
||||
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, "acc")
|
||||
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, storeAcc)
|
||||
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/democoin/x/cool"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
)
|
||||
|
||||
|
@ -22,7 +21,7 @@ func QuizTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
from, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
@ -46,7 +45,7 @@ func SetTrendTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
from, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/democoin/x/pow"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -24,7 +23,7 @@ func MineCmd(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
from, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/docs/examples/democoin/x/simplestake"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -32,7 +31,7 @@ func BondTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
from, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// ModuleClients helps modules provide a standard interface for exporting client functionality
|
||||
type ModuleClients interface {
|
||||
GetQueryCmd() *cobra.Command
|
||||
GetTxCmd() *cobra.Command
|
||||
}
|
|
@ -5,34 +5,17 @@ import (
|
|||
|
||||
"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/x/auth"
|
||||
)
|
||||
|
||||
// GetAccountCmdDefault invokes the GetAccountCmd for the auth.BaseAccount type.
|
||||
func GetAccountCmdDefault(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
return GetAccountCmd(storeName, cdc, GetAccountDecoder(cdc))
|
||||
}
|
||||
|
||||
// GetAccountDecoder gets the account decoder for auth.DefaultAccount.
|
||||
func GetAccountDecoder(cdc *codec.Codec) auth.AccountDecoder {
|
||||
return func(accBytes []byte) (acct auth.Account, err error) {
|
||||
err = cdc.UnmarshalBinaryBare(accBytes, &acct)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return acct, err
|
||||
}
|
||||
}
|
||||
|
||||
// GetAccountCmd returns a query account that will display the state of the
|
||||
// account at a given address.
|
||||
// nolint: unparam
|
||||
func GetAccountCmd(storeName string, cdc *codec.Codec, decoder auth.AccountDecoder) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
func GetAccountCmd(storeName string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "account [address]",
|
||||
Short: "Query account balance",
|
||||
Args: cobra.ExactArgs(1),
|
||||
|
@ -47,9 +30,9 @@ func GetAccountCmd(storeName string, cdc *codec.Codec, decoder auth.AccountDecod
|
|||
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(decoder)
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
if err := cliCtx.EnsureAccountExistsFromAddr(key); err != nil {
|
||||
if err = cliCtx.EnsureAccountExistsFromAddr(key); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -72,4 +55,7 @@ func GetAccountCmd(storeName string, cdc *codec.Codec, decoder auth.AccountDecod
|
|||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
// Add the flags here and return the command
|
||||
return client.GetCommands(cmd)[0]
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@ package cli
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
|
@ -24,7 +25,7 @@ const (
|
|||
)
|
||||
|
||||
// GetSignCommand returns the sign command
|
||||
func GetSignCommand(codec *amino.Codec, decoder auth.AccountDecoder) *cobra.Command {
|
||||
func GetSignCommand(codec *amino.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "sign <file>",
|
||||
Short: "Sign transactions generated offline",
|
||||
|
@ -41,7 +42,7 @@ order.
|
|||
The --offline flag makes sure that the client will not reach out to the local cache.
|
||||
Thus account number or sequence number lookups will not be performed and it is
|
||||
recommended to set such parameters manually.`,
|
||||
RunE: makeSignCmd(codec, decoder),
|
||||
RunE: makeSignCmd(codec),
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
cmd.Flags().String(client.FlagName, "", "Name of private key with which to sign")
|
||||
|
@ -51,10 +52,12 @@ recommended to set such parameters manually.`,
|
|||
cmd.Flags().Bool(flagValidateSigs, false, "Print the addresses that must sign the transaction, "+
|
||||
"those who have already signed it, and make sure that signatures are in the correct order.")
|
||||
cmd.Flags().Bool(flagOffline, false, "Offline mode. Do not query local cache.")
|
||||
return cmd
|
||||
|
||||
// Add the flags here and return the command
|
||||
return client.PostCommands(cmd)[0]
|
||||
}
|
||||
|
||||
func makeSignCmd(cdc *amino.Codec, decoder auth.AccountDecoder) func(cmd *cobra.Command, args []string) error {
|
||||
func makeSignCmd(cdc *amino.Codec) func(cmd *cobra.Command, args []string) error {
|
||||
return func(cmd *cobra.Command, args []string) (err error) {
|
||||
stdTx, err := readAndUnmarshalStdTx(cdc, args[0])
|
||||
if err != nil {
|
||||
|
@ -72,7 +75,7 @@ func makeSignCmd(cdc *amino.Codec, decoder auth.AccountDecoder) func(cmd *cobra.
|
|||
if name == "" {
|
||||
return errors.New("required flag \"name\" has not been set")
|
||||
}
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(decoder)
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
|
||||
txBldr := authtxb.NewTxBuilderFromCLI()
|
||||
|
||||
// if --signature-only is on, then override --append
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
@ -17,11 +16,11 @@ import (
|
|||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, storeName string) {
|
||||
r.HandleFunc(
|
||||
"/auth/accounts/{address}",
|
||||
QueryAccountRequestHandlerFn(storeName, cdc, authcmd.GetAccountDecoder(cdc), cliCtx),
|
||||
QueryAccountRequestHandlerFn(storeName, cdc, context.GetAccountDecoder(cdc), cliCtx),
|
||||
).Methods("GET")
|
||||
r.HandleFunc(
|
||||
"/bank/balances/{address}",
|
||||
QueryBalancesRequestHandlerFn(storeName, cdc, authcmd.GetAccountDecoder(cdc), cliCtx),
|
||||
QueryBalancesRequestHandlerFn(storeName, cdc, context.GetAccountDecoder(cdc), cliCtx),
|
||||
).Methods("GET")
|
||||
r.HandleFunc(
|
||||
"/tx/sign",
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -36,7 +37,7 @@ in place of an input filename, the command reads from standard input.`,
|
|||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
return client.PostCommands(cmd)[0]
|
||||
}
|
||||
|
||||
func readAndUnmarshalStdTx(cdc *amino.Codec, filename string) (stdTx auth.StdTx, err error) {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/client"
|
||||
bankClient "github.com/cosmos/cosmos-sdk/x/bank/client"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -28,7 +28,7 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
if err := cliCtx.EnsureAccountExists(); err != nil {
|
||||
return err
|
||||
|
@ -64,7 +64,7 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
}
|
||||
|
||||
// build and sign the transaction, then broadcast to Tendermint
|
||||
msg := client.CreateMsg(from, to, coins)
|
||||
msg := bankClient.CreateMsg(from, to, coins)
|
||||
if cliCtx.GenerateOnly {
|
||||
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg}, false)
|
||||
}
|
||||
|
@ -78,5 +78,5 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||
cmd.MarkFlagRequired(flagTo)
|
||||
cmd.MarkFlagRequired(flagAmount)
|
||||
|
||||
return cmd
|
||||
return client.PostCommands(cmd)[0]
|
||||
}
|
||||
|
|
|
@ -6,12 +6,13 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||
|
@ -22,6 +23,21 @@ var (
|
|||
flagIsValidator = "is-validator"
|
||||
)
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func GetTxCmd(storeKey string, cdc *amino.Codec) *cobra.Command {
|
||||
distTxCmd := &cobra.Command{
|
||||
Use: "dist",
|
||||
Short: "Distribution transactions subcommands",
|
||||
}
|
||||
|
||||
distTxCmd.AddCommand(client.PostCommands(
|
||||
GetCmdWithdrawRewards(cdc),
|
||||
GetCmdSetWithdrawAddr(cdc),
|
||||
)...)
|
||||
|
||||
return distTxCmd
|
||||
}
|
||||
|
||||
// command to withdraw rewards
|
||||
func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
|
@ -41,7 +57,7 @@ func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
var msg sdk.Msg
|
||||
switch {
|
||||
|
@ -92,7 +108,7 @@ func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
delAddr, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
distCmds "github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
|
||||
// ModuleClient exports all client functionality from this module
|
||||
type ModuleClient struct {
|
||||
storeKey string
|
||||
cdc *amino.Codec
|
||||
}
|
||||
|
||||
func NewModuleClient(storeKey string, cdc *amino.Codec) ModuleClient {
|
||||
return ModuleClient{storeKey, cdc}
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func (mc ModuleClient) GetQueryCmd() *cobra.Command {
|
||||
return &cobra.Command{Hidden: true}
|
||||
}
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func (mc ModuleClient) GetTxCmd() *cobra.Command {
|
||||
distTxCmd := &cobra.Command{
|
||||
Use: "dist",
|
||||
Short: "Distribution transactions subcommands",
|
||||
}
|
||||
|
||||
distTxCmd.AddCommand(client.PostCommands(
|
||||
distCmds.GetCmdWithdrawRewards(mc.cdc),
|
||||
distCmds.GetCmdSetWithdrawAddr(mc.cdc),
|
||||
)...)
|
||||
|
||||
return distTxCmd
|
||||
}
|
|
@ -0,0 +1,324 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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/x/gov"
|
||||
govClientUtils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// GetCmdQueryProposal implements the query proposal command.
|
||||
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "proposal",
|
||||
Short: "Query details of a single proposal",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
params := gov.QueryProposalParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposal", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of proposal being queried")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryProposals implements a query proposals command.
|
||||
func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "proposals",
|
||||
Short: "Query proposals with optional filters",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
bechDepositerAddr := viper.GetString(flagDepositer)
|
||||
bechVoterAddr := viper.GetString(flagVoter)
|
||||
strProposalStatus := viper.GetString(flagStatus)
|
||||
numLimit := uint64(viper.GetInt64(flagNumLimit))
|
||||
|
||||
params := gov.QueryProposalsParams{
|
||||
Limit: numLimit,
|
||||
}
|
||||
|
||||
if len(bechDepositerAddr) != 0 {
|
||||
depositerAddr, err := sdk.AccAddressFromBech32(bechDepositerAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.Depositer = depositerAddr
|
||||
}
|
||||
|
||||
if len(bechVoterAddr) != 0 {
|
||||
voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.Voter = voterAddr
|
||||
}
|
||||
|
||||
if len(strProposalStatus) != 0 {
|
||||
proposalStatus, err := gov.ProposalStatusFromString(govClientUtils.NormalizeProposalStatus(strProposalStatus))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.ProposalStatus = proposalStatus
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposals", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var matchingProposals []gov.Proposal
|
||||
err = cdc.UnmarshalJSON(res, &matchingProposals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(matchingProposals) == 0 {
|
||||
fmt.Println("No matching proposals found")
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, proposal := range matchingProposals {
|
||||
fmt.Printf(" %d - %s\n", proposal.GetProposalID(), proposal.GetTitle())
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagNumLimit, "", "(optional) limit to latest [number] proposals. Defaults to all proposals")
|
||||
cmd.Flags().String(flagDepositer, "", "(optional) filter by proposals deposited on by depositer")
|
||||
cmd.Flags().String(flagVoter, "", "(optional) filter by proposals voted on by voted")
|
||||
cmd.Flags().String(flagStatus, "", "(optional) filter proposals by proposal status, status: deposit_period/voting_period/passed/rejected")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Command to Get a Proposal Information
|
||||
// GetCmdQueryVote implements the query proposal vote command.
|
||||
func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "vote",
|
||||
Short: "Query details of a single vote",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
voterAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagVoter))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params := gov.QueryVoteParams{
|
||||
Voter: voterAddr,
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/vote", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of proposal voting on")
|
||||
cmd.Flags().String(flagVoter, "", "bech32 voter address")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryVotes implements the command to query for proposal votes.
|
||||
func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "votes",
|
||||
Short: "Query votes on a proposal",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
params := gov.QueryVotesParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/votes", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of which proposal's votes are being queried")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Command to Get a specific Deposit Information
|
||||
// GetCmdQueryDeposit implements the query proposal deposit command.
|
||||
func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "deposit",
|
||||
Short: "Query details of a deposit",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
depositerAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagDepositer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params := gov.QueryDepositParams{
|
||||
Depositer: depositerAddr,
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposit", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of proposal deposited on")
|
||||
cmd.Flags().String(flagDepositer, "", "bech32 depositer address")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryDeposits implements the command to query for proposal deposits.
|
||||
func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "deposits",
|
||||
Short: "Query deposits on a proposal",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
params := gov.QueryDepositsParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposits", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of which proposal's deposits are being queried")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryTally implements the command to query for proposal tally result.
|
||||
func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "tally",
|
||||
Short: "Get the tally of a proposal vote",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
params := gov.QueryTallyParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/tally", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of which proposal is being tallied")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryProposal implements the query proposal command.
|
||||
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "param [param-type]",
|
||||
Short: "Query the parameters (voting|tallying|deposit) of the governance process",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
paramType := args[0]
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, paramType), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
|
||||
|
@ -15,7 +14,7 @@ import (
|
|||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/client"
|
||||
govClientUtils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -80,7 +79,7 @@ $ gaiacli gov submit-proposal --title="Test Proposal" --description="My awesome
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
fromAddr, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
@ -130,7 +129,7 @@ func parseSubmitProposalFlags() (*proposal, error) {
|
|||
if proposalFile == "" {
|
||||
proposal.Title = viper.GetString(flagTitle)
|
||||
proposal.Description = viper.GetString(flagDescription)
|
||||
proposal.Type = client.NormalizeProposalType(viper.GetString(flagProposalType))
|
||||
proposal.Type = govClientUtils.NormalizeProposalType(viper.GetString(flagProposalType))
|
||||
proposal.Deposit = viper.GetString(flagDeposit)
|
||||
return proposal, nil
|
||||
}
|
||||
|
@ -163,7 +162,7 @@ func GetCmdDeposit(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
depositerAddr, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
@ -208,7 +207,7 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
voterAddr, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
@ -218,7 +217,7 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command {
|
|||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
option := viper.GetString(flagOption)
|
||||
|
||||
byteVoteOption, err := gov.VoteOptionFromString(client.NormalizeVoteOption(option))
|
||||
byteVoteOption, err := gov.VoteOptionFromString(govClientUtils.NormalizeVoteOption(option))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -248,314 +247,3 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command {
|
|||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryProposal implements the query proposal command.
|
||||
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "param [param-type]",
|
||||
Short: "Query the parameters (voting|tallying|deposit) of the governance process",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
paramType := args[0]
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/params/%s", queryRoute, paramType), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryProposal implements the query proposal command.
|
||||
func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "proposal",
|
||||
Short: "Query details of a single proposal",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
params := gov.QueryProposalParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposal", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of proposal being queried")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryProposals implements a query proposals command.
|
||||
func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "proposals",
|
||||
Short: "Query proposals with optional filters",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
bechDepositerAddr := viper.GetString(flagDepositer)
|
||||
bechVoterAddr := viper.GetString(flagVoter)
|
||||
strProposalStatus := viper.GetString(flagStatus)
|
||||
numLimit := uint64(viper.GetInt64(flagNumLimit))
|
||||
|
||||
params := gov.QueryProposalsParams{
|
||||
Limit: numLimit,
|
||||
}
|
||||
|
||||
if len(bechDepositerAddr) != 0 {
|
||||
depositerAddr, err := sdk.AccAddressFromBech32(bechDepositerAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.Depositer = depositerAddr
|
||||
}
|
||||
|
||||
if len(bechVoterAddr) != 0 {
|
||||
voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.Voter = voterAddr
|
||||
}
|
||||
|
||||
if len(strProposalStatus) != 0 {
|
||||
proposalStatus, err := gov.ProposalStatusFromString(client.NormalizeProposalStatus(strProposalStatus))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params.ProposalStatus = proposalStatus
|
||||
}
|
||||
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/proposals", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var matchingProposals []gov.Proposal
|
||||
err = cdc.UnmarshalJSON(res, &matchingProposals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(matchingProposals) == 0 {
|
||||
fmt.Println("No matching proposals found")
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, proposal := range matchingProposals {
|
||||
fmt.Printf(" %d - %s\n", proposal.GetProposalID(), proposal.GetTitle())
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagNumLimit, "", "(optional) limit to latest [number] proposals. Defaults to all proposals")
|
||||
cmd.Flags().String(flagDepositer, "", "(optional) filter by proposals deposited on by depositer")
|
||||
cmd.Flags().String(flagVoter, "", "(optional) filter by proposals voted on by voted")
|
||||
cmd.Flags().String(flagStatus, "", "(optional) filter proposals by proposal status, status: deposit_period/voting_period/passed/rejected")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Command to Get a Proposal Information
|
||||
// GetCmdQueryVote implements the query proposal vote command.
|
||||
func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "vote",
|
||||
Short: "Query details of a single vote",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
voterAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagVoter))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params := gov.QueryVoteParams{
|
||||
Voter: voterAddr,
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/vote", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of proposal voting on")
|
||||
cmd.Flags().String(flagVoter, "", "bech32 voter address")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryVotes implements the command to query for proposal votes.
|
||||
func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "votes",
|
||||
Short: "Query votes on a proposal",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
params := gov.QueryVotesParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/votes", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of which proposal's votes are being queried")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Command to Get a specific Deposit Information
|
||||
// GetCmdQueryDeposit implements the query proposal deposit command.
|
||||
func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "deposit",
|
||||
Short: "Query details of a deposit",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
depositerAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagDepositer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params := gov.QueryDepositParams{
|
||||
Depositer: depositerAddr,
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposit", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of proposal deposited on")
|
||||
cmd.Flags().String(flagDepositer, "", "bech32 depositer address")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryDeposits implements the command to query for proposal deposits.
|
||||
func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "deposits",
|
||||
Short: "Query deposits on a proposal",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
params := gov.QueryDepositsParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/deposits", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of which proposal's deposits are being queried")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// GetCmdQueryTally implements the command to query for proposal tally result.
|
||||
func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "tally",
|
||||
Short: "Get the tally of a proposal vote",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
proposalID := uint64(viper.GetInt64(flagProposalID))
|
||||
|
||||
params := gov.QueryTallyParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
bz, err := cdc.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/tally", queryRoute), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(res))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String(flagProposalID, "", "proposalID of which proposal is being tallied")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
govCli "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
|
||||
// ModuleClient exports all client functionality from this module
|
||||
type ModuleClient struct {
|
||||
storeKey string
|
||||
cdc *amino.Codec
|
||||
}
|
||||
|
||||
func NewModuleClient(storeKey string, cdc *amino.Codec) ModuleClient {
|
||||
return ModuleClient{storeKey, cdc}
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func (mc ModuleClient) GetQueryCmd() *cobra.Command {
|
||||
// Group gov queries under a subcommand
|
||||
govQueryCmd := &cobra.Command{
|
||||
Use: "gov",
|
||||
Short: "Querying commands for the governance module",
|
||||
}
|
||||
|
||||
govQueryCmd.AddCommand(client.GetCommands(
|
||||
govCli.GetCmdQueryProposal(mc.storeKey, mc.cdc),
|
||||
govCli.GetCmdQueryProposals(mc.storeKey, mc.cdc),
|
||||
govCli.GetCmdQueryVote(mc.storeKey, mc.cdc),
|
||||
govCli.GetCmdQueryVotes(mc.storeKey, mc.cdc),
|
||||
govCli.GetCmdQueryParams(mc.storeKey, mc.cdc),
|
||||
govCli.GetCmdQueryDeposit(mc.storeKey, mc.cdc),
|
||||
govCli.GetCmdQueryDeposits(mc.storeKey, mc.cdc),
|
||||
govCli.GetCmdQueryTally(mc.storeKey, mc.cdc))...)
|
||||
|
||||
return govQueryCmd
|
||||
}
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func (mc ModuleClient) GetTxCmd() *cobra.Command {
|
||||
govTxCmd := &cobra.Command{
|
||||
Use: "gov",
|
||||
Short: "Governance transactions subcommands",
|
||||
}
|
||||
|
||||
govTxCmd.AddCommand(client.PostCommands(
|
||||
govCli.GetCmdDeposit(mc.cdc),
|
||||
govCli.GetCmdVote(mc.cdc),
|
||||
govCli.GetCmdSubmitProposal(mc.cdc),
|
||||
)...)
|
||||
|
||||
return govTxCmd
|
||||
}
|
|
@ -10,7 +10,7 @@ import (
|
|||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/client"
|
||||
govClientUtils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -81,7 +81,7 @@ func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
|
|||
return
|
||||
}
|
||||
|
||||
proposalType, err := gov.ProposalTypeFromString(client.NormalizeProposalType(req.ProposalType))
|
||||
proposalType, err := gov.ProposalTypeFromString(govClientUtils.NormalizeProposalType(req.ProposalType))
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
|
@ -165,7 +165,7 @@ func voteHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc
|
|||
return
|
||||
}
|
||||
|
||||
voteOption, err := gov.VoteOptionFromString(client.NormalizeVoteOption(req.Option))
|
||||
voteOption, err := gov.VoteOptionFromString(govClientUtils.NormalizeVoteOption(req.Option))
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
|
@ -460,7 +460,7 @@ func queryProposalsWithParameterFn(cdc *codec.Codec, cliCtx context.CLIContext)
|
|||
}
|
||||
|
||||
if len(strProposalStatus) != 0 {
|
||||
proposalStatus, err := gov.ProposalStatusFromString(client.NormalizeProposalStatus(strProposalStatus))
|
||||
proposalStatus, err := gov.ProposalStatusFromString(govClientUtils.NormalizeProposalStatus(strProposalStatus))
|
||||
if err != nil {
|
||||
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package client
|
||||
package utils
|
||||
|
||||
// NormalizeVoteOption - normalize user specified vote option
|
||||
func NormalizeVoteOption(option string) string {
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc"
|
||||
|
||||
|
@ -30,7 +29,7 @@ func IBCTransferCmd(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
from, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
codec "github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc"
|
||||
|
||||
|
@ -42,7 +41,7 @@ type relayCommander struct {
|
|||
func IBCRelayCmd(cdc *codec.Codec) *cobra.Command {
|
||||
cmdr := relayCommander{
|
||||
cdc: cdc,
|
||||
decoder: authcmd.GetAccountDecoder(cdc),
|
||||
decoder: context.GetAccountDecoder(cdc),
|
||||
ibcStore: "ibc",
|
||||
mainStore: "main",
|
||||
accStore: "acc",
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
|
||||
|
@ -22,7 +21,7 @@ func GetCmdUnjail(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
valAddr, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
|
||||
// ModuleClient exports all client functionality from this module
|
||||
type ModuleClient struct {
|
||||
storeKey string
|
||||
cdc *amino.Codec
|
||||
}
|
||||
|
||||
func NewModuleClient(storeKey string, cdc *amino.Codec) ModuleClient {
|
||||
return ModuleClient{storeKey, cdc}
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func (mc ModuleClient) GetQueryCmd() *cobra.Command {
|
||||
// Group slashing queries under a subcommand
|
||||
slashingQueryCmd := &cobra.Command{
|
||||
Use: "slashing",
|
||||
Short: "Querying commands for the slashing module",
|
||||
}
|
||||
|
||||
slashingQueryCmd.AddCommand(client.GetCommands(
|
||||
cli.GetCmdQuerySigningInfo(mc.storeKey, mc.cdc))...)
|
||||
|
||||
return slashingQueryCmd
|
||||
|
||||
}
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func (mc ModuleClient) GetTxCmd() *cobra.Command {
|
||||
slashingTxCmd := &cobra.Command{
|
||||
Use: "slashing",
|
||||
Short: "Slashing transactions subcommands",
|
||||
}
|
||||
|
||||
slashingTxCmd.AddCommand(client.PostCommands(
|
||||
cli.GetCmdUnjail(mc.cdc),
|
||||
)...)
|
||||
|
||||
return slashingTxCmd
|
||||
}
|
|
@ -115,7 +115,7 @@ func GetCmdQueryValidators(storeName string, cdc *codec.Codec) *cobra.Command {
|
|||
}
|
||||
|
||||
// GetCmdQueryValidatorUnbondingDelegations implements the query all unbonding delegatations from a validator command.
|
||||
func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
func GetCmdQueryValidatorUnbondingDelegations(storeKey string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "unbonding-delegations-from [operator-addr]",
|
||||
Short: "Query all unbonding delegatations from a validator",
|
||||
|
@ -135,7 +135,7 @@ func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Code
|
|||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(
|
||||
fmt.Sprintf("custom/%s/validatorUnbondingDelegations", queryRoute),
|
||||
fmt.Sprintf("custom/%s/validatorUnbondingDelegations", storeKey),
|
||||
bz)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -150,7 +150,7 @@ func GetCmdQueryValidatorUnbondingDelegations(queryRoute string, cdc *codec.Code
|
|||
}
|
||||
|
||||
// GetCmdQueryValidatorRedelegations implements the query all redelegatations from a validator command.
|
||||
func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
func GetCmdQueryValidatorRedelegations(storeKey string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "redelegations-from [operator-addr]",
|
||||
Short: "Query all outgoing redelegatations from a validator",
|
||||
|
@ -170,7 +170,7 @@ func GetCmdQueryValidatorRedelegations(queryRoute string, cdc *codec.Codec) *cob
|
|||
}
|
||||
|
||||
res, err := cliCtx.QueryWithData(
|
||||
fmt.Sprintf("custom/%s/validatorRedelegations", queryRoute),
|
||||
fmt.Sprintf("custom/%s/validatorRedelegations", storeKey),
|
||||
bz)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -288,7 +288,7 @@ func GetCmdQueryDelegations(storeName string, cdc *codec.Codec) *cobra.Command {
|
|||
|
||||
// GetCmdQueryValidatorDelegations implements the command to query all the
|
||||
// delegations to a specific validator.
|
||||
func GetCmdQueryValidatorDelegations(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
func GetCmdQueryValidatorDelegations(storeKey string, cdc *codec.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "delegations-to [validator-addr]",
|
||||
Short: "Query all delegations made to one validator",
|
||||
|
@ -308,7 +308,7 @@ func GetCmdQueryValidatorDelegations(queryRoute string, cdc *codec.Codec) *cobra
|
|||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validatorDelegations", queryRoute), bz)
|
||||
res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/validatorDelegations", storeKey), bz)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
|
||||
|
@ -25,7 +24,7 @@ func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
amounstStr := viper.GetString(FlagAmount)
|
||||
if amounstStr == "" {
|
||||
|
@ -126,7 +125,7 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
valAddr, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
@ -178,7 +177,7 @@ func GetCmdDelegate(cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
amount, err := sdk.ParseCoin(viper.GetString(FlagAmount))
|
||||
if err != nil {
|
||||
|
@ -220,7 +219,7 @@ func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
var err error
|
||||
|
||||
|
@ -275,7 +274,7 @@ func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command {
|
|||
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
delAddr, err := cliCtx.GetFromAddress()
|
||||
if err != nil {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -45,7 +44,7 @@ func getShares(
|
|||
key := stake.GetDelegationKey(delAddr, valAddr)
|
||||
cliCtx := context.NewCLIContext().
|
||||
WithCodec(cdc).
|
||||
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
|
||||
WithAccountDecoder(cdc)
|
||||
|
||||
resQuery, err := cliCtx.QueryStore(key, storeName)
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake/client/cli"
|
||||
"github.com/spf13/cobra"
|
||||
amino "github.com/tendermint/go-amino"
|
||||
)
|
||||
|
||||
// ModuleClient exports all client functionality from this module
|
||||
type ModuleClient struct {
|
||||
storeKey string
|
||||
cdc *amino.Codec
|
||||
}
|
||||
|
||||
func NewModuleClient(storeKey string, cdc *amino.Codec) ModuleClient {
|
||||
return ModuleClient{storeKey, cdc}
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for this module
|
||||
func (mc ModuleClient) GetQueryCmd() *cobra.Command {
|
||||
stakeQueryCmd := &cobra.Command{
|
||||
Use: "stake",
|
||||
Short: "Querying commands for the staking module",
|
||||
}
|
||||
stakeQueryCmd.AddCommand(client.GetCommands(
|
||||
cli.GetCmdQueryDelegation(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryDelegations(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryUnbondingDelegation(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryUnbondingDelegations(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryRedelegation(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryRedelegations(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryValidator(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryValidators(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryValidatorDelegations(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryValidatorUnbondingDelegations(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryValidatorRedelegations(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryParams(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdQueryPool(mc.storeKey, mc.cdc))...)
|
||||
|
||||
return stakeQueryCmd
|
||||
|
||||
}
|
||||
|
||||
// GetTxCmd returns the transaction commands for this module
|
||||
func (mc ModuleClient) GetTxCmd() *cobra.Command {
|
||||
stakeTxCmd := &cobra.Command{
|
||||
Use: "stake",
|
||||
Short: "Staking transaction subcommands",
|
||||
}
|
||||
|
||||
stakeTxCmd.AddCommand(client.PostCommands(
|
||||
cli.GetCmdCreateValidator(mc.cdc),
|
||||
cli.GetCmdEditValidator(mc.cdc),
|
||||
cli.GetCmdDelegate(mc.cdc),
|
||||
cli.GetCmdRedelegate(mc.storeKey, mc.cdc),
|
||||
cli.GetCmdUnbond(mc.storeKey, mc.cdc),
|
||||
)...)
|
||||
|
||||
return stakeTxCmd
|
||||
}
|
Loading…
Reference in New Issue