Skip to content

Commit

Permalink
x/tokenfactory: cli (CosmWasm#1376)
Browse files Browse the repository at this point in the history
* add proto files

* Update proto/osmosis/tokenfactory/v1beta1/authorityMetadata.proto

Co-authored-by: Dev Ojha <[email protected]>

* update comments on proto

* add other types files

* Apply suggestions from code review

Co-authored-by: Aleksandr Bezobchuk <[email protected]>

* update errors to not start from 1

* add more comments

* add logic

* update app setup

* add back query

* Apply suggestions from code review

Co-authored-by: Aleksandr Bezobchuk <[email protected]>

* add migration

* Apply suggestions from code review

Co-authored-by: Aleksandr Bezobchuk <[email protected]>

* address comment

* Apply suggestions from code review

Co-authored-by: Roman <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>

* Apply suggestions from code review

Co-authored-by: Roman <[email protected]>

* address comments

* removed mintTo and burnFrom

* fixed typo

* fix comments

* metadata Validate() function

* fix stuff

* add mint restriction

* remove unused argument from NewMsgBurn()

* x/tokenfactory: cli

* fix extra arguments

* address comments

* Apply suggestions from code review

Co-authored-by: Roman <[email protected]>

* ?

* params

* tests

* add params command

Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Roman <[email protected]>
  • Loading branch information
4 people authored May 6, 2022
1 parent de17217 commit 6c866c8
Show file tree
Hide file tree
Showing 3 changed files with 316 additions and 6 deletions.
122 changes: 122 additions & 0 deletions client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package cli

import (
"fmt"

// "strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

// "github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v7/x/tokenfactory/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd() *cobra.Command {
// Group tokenfactory queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(
GetParams(),
GetCmdDenomAuthorityMetadata(),
GetCmdDenomsFromCreator(),
)

return cmd
}

// GetParams returns the params for the module
func GetParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params [flags]",
Short: "Get the params for the x/tokenfactory module",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdDenomAuthorityMetadata returns the authority metadata for a queried denom
func GetCmdDenomAuthorityMetadata() *cobra.Command {
cmd := &cobra.Command{
Use: "denom-authority-metadata [denom] [flags]",
Short: "Get the authority metadata for a specific denom",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.DenomAuthorityMetadata(cmd.Context(), &types.QueryDenomAuthorityMetadataRequest{
Denom: args[0],
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdDenomsFromCreator a command to get a list of all tokens created by a specific creator address
func GetCmdDenomsFromCreator() *cobra.Command {
cmd := &cobra.Command{
Use: "denoms-from-creator [creator address] [flags]",
Short: "Returns a list of all tokens created by a specific creator address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.DenomsFromCreator(cmd.Context(), &types.QueryDenomsFromCreatorRequest{
Creator: args[0],
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
189 changes: 189 additions & 0 deletions client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"

// "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/osmosis-labs/osmosis/v7/x/tokenfactory/types"
)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(
NewCreateDenomCmd(),
NewMintCmd(),
NewBurnCmd(),
// NewForceTransferCmd(),
NewChangeAdminCmd(),
)

return cmd
}

// NewCreateDenomCmd broadcast MsgCreateDenom
func NewCreateDenomCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-denom [nonce] [flags]",
Short: "create a new denom from an account",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)

msg := types.NewMsgCreateDenom(
clientCtx.GetFromAddress().String(),
args[0],
)

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

// NewMintCmd broadcast MsgMint
func NewMintCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "mint [amount] [flags]",
Short: "Mint a denom to an address. Must have admin authority to do so.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)

amount, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return err
}

msg := types.NewMsgMint(
clientCtx.GetFromAddress().String(),
amount,
)

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

// NewBurnCmd broadcast MsgBurn
func NewBurnCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "burn [amount] [flags]",
Short: "Burn tokens from an address. Must have admin authority to do so.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)

amount, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return err
}

msg := types.NewMsgBurn(
clientCtx.GetFromAddress().String(),
amount,
)

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

// // NewForceTransferCmd broadcast MsgForceTransfer
// func NewForceTransferCmd() *cobra.Command {
// cmd := &cobra.Command{
// Use: "force-transfer [amount] [transfer-from-address] [transfer-to-address] [flags]",
// Short: "Force transfer tokens from one address to another address. Must have admin authority to do so.",
// Args: cobra.ExactArgs(3),
// RunE: func(cmd *cobra.Command, args []string) error {
// clientCtx, err := client.GetClientTxContext(cmd)
// if err != nil {
// return err
// }

// txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)

// amount, err := sdk.ParseCoinNormalized(args[0])
// if err != nil {
// return err
// }

// msg := types.NewMsgForceTransfer(
// clientCtx.GetFromAddress().String(),
// amount,
// args[1],
// args[2],
// )

// return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
// },
// }

// flags.AddTxFlagsToCmd(cmd)
// return cmd
// }

// NewChangeAdminCmd broadcast MsgChangeAdmin
func NewChangeAdminCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "change-admin [denom] [new-admin-address] [flags]",
Short: "Changes the admin address for a factory-created denom. Must have admin authority to do so.",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

txf := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)

msg := types.NewMsgChangeAdmin(
clientCtx.GetFromAddress().String(),
args[0],
args[1],
)

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}
11 changes: 5 additions & 6 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

"github.com/osmosis-labs/osmosis/v7/x/tokenfactory/client/cli"
"github.com/osmosis-labs/osmosis/v7/x/tokenfactory/keeper"
"github.com/osmosis-labs/osmosis/v7/x/tokenfactory/types"
)
Expand Down Expand Up @@ -78,16 +79,14 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck
}

// GetTxCmd returns the capability module's root tx command.
// GetTxCmd returns the tokenfactory module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
// return cli.GetTxCmd()
return nil
return cli.GetTxCmd()
}

// GetQueryCmd returns the capability module's root query command.
// GetQueryCmd returns the tokenfactory module's root query command.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
// return cli.GetQueryCmd(types.StoreKey)
return nil
return cli.GetQueryCmd()
}

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit 6c866c8

Please sign in to comment.