Skip to content

Commit e4a27ff

Browse files
committed
add tx commands
1 parent 23b4580 commit e4a27ff

File tree

4 files changed

+275
-77
lines changed

4 files changed

+275
-77
lines changed

x/tokenfactory/autocli.go

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -41,80 +41,81 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
4141
Short: "Returns the tokenfactory module's parameters",
4242
},
4343
},
44+
EnhanceCustomCommand: true, // We still have manual commands in gov that we want to keep
4445
},
45-
Tx: &autocliv1.ServiceCommandDescriptor{
46-
Service: tokenfactoryv1beta1.Msg_ServiceDesc.ServiceName,
47-
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
48-
{
49-
RpcMethod: "CreateDenom",
50-
Use: "create-denom [sender] [sub-denom]",
51-
Short: "create a new denom from an account.",
52-
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
53-
{ProtoField: "sender"},
54-
{ProtoField: "subdenom"},
55-
},
56-
},
57-
{
58-
RpcMethod: "Mint",
59-
Use: "mint [sender] [amount] [mint-to-address]",
60-
Short: "Mint a denom to an address. Must have admin authority to do so.",
61-
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
62-
{ProtoField: "sender"},
63-
{ProtoField: "amount"},
64-
{ProtoField: "mintToAddress"},
65-
},
66-
},
67-
{
68-
RpcMethod: "Burn",
69-
Use: "burn [sender] [amount] [burn-from-address]",
70-
Short: "Burn tokens from an address. Must have admin authority to do so.",
71-
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
72-
{ProtoField: "sender"},
73-
{ProtoField: "amount"},
74-
{ProtoField: "burnFromAddress"},
75-
},
76-
},
77-
{
78-
RpcMethod: "ChangeAdmin",
79-
Use: "change-admin [sender] [denom] [new-admin]",
80-
Short: "Changes the admin address for a factory-created denom. Must have admin authority to do so.",
81-
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
82-
{ProtoField: "sender"},
83-
{ProtoField: "denom"},
84-
{ProtoField: "new_admin"},
85-
},
86-
},
87-
{
88-
RpcMethod: "SetDenomMetadata",
89-
Use: "set-denom-metadata [sender] [denom] [cosmwasm-address]",
90-
Short: "Set a denom metadata",
91-
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
92-
{ProtoField: "sender"},
93-
{ProtoField: "denom"},
94-
{ProtoField: "cosmwasm_address"},
95-
},
96-
},
97-
{
98-
RpcMethod: "SetBeforeSendHook",
99-
Use: "set-beforesend-hook [denom] [cosmwasm-address]",
100-
Short: "Set a cosmwasm contract to be the beforesend hook for a factory-created denom. Must have admin authority to do so.",
101-
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
102-
{ProtoField: "sender"},
103-
{ProtoField: "subdenom"},
104-
},
105-
},
106-
{
107-
RpcMethod: "ForceTransfer",
108-
Use: "force-transfer [sender] [amount] [transfer-from-address] [transfer-to-address]",
109-
Short: "Transfer a factory-crated denom",
110-
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
111-
{ProtoField: "sender"},
112-
{ProtoField: "amount"},
113-
{ProtoField: "transferFromAddress"},
114-
{ProtoField: "transferToAddress"},
115-
},
116-
},
117-
},
118-
},
46+
// Tx: &autocliv1.ServiceCommandDescriptor{
47+
// Service: tokenfactoryv1beta1.Msg_ServiceDesc.ServiceName,
48+
// RpcCommandOptions: []*autocliv1.RpcCommandOptions{
49+
// {
50+
// RpcMethod: "CreateDenom",
51+
// Use: "create-denom [sender] [sub-denom]",
52+
// Short: "create a new denom from an account.",
53+
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{
54+
// {ProtoField: "sender"},
55+
// {ProtoField: "subdenom"},
56+
// },
57+
// },
58+
// {
59+
// RpcMethod: "Mint",
60+
// Use: "mint [sender] [amount] [mint-to-address]",
61+
// Short: "Mint a denom to an address. Must have admin authority to do so.",
62+
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{
63+
// {ProtoField: "sender"},
64+
// {ProtoField: "amount"},
65+
// {ProtoField: "mintToAddress"},
66+
// },
67+
// },
68+
// {
69+
// RpcMethod: "Burn",
70+
// Use: "burn [sender] [amount] [burn-from-address]",
71+
// Short: "Burn tokens from an address. Must have admin authority to do so.",
72+
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{
73+
// {ProtoField: "sender"},
74+
// {ProtoField: "amount"},
75+
// {ProtoField: "burnFromAddress"},
76+
// },
77+
// },
78+
// {
79+
// RpcMethod: "ChangeAdmin",
80+
// Use: "change-admin [sender] [denom] [new-admin]",
81+
// Short: "Changes the admin address for a factory-created denom. Must have admin authority to do so.",
82+
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{
83+
// {ProtoField: "sender"},
84+
// {ProtoField: "denom"},
85+
// {ProtoField: "new_admin"},
86+
// },
87+
// },
88+
// {
89+
// RpcMethod: "SetDenomMetadata",
90+
// Use: "set-denom-metadata [sender] [denom] [cosmwasm-address]",
91+
// Short: "Set a denom metadata",
92+
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{
93+
// {ProtoField: "sender"},
94+
// {ProtoField: "denom"},
95+
// {ProtoField: "cosmwasm_address"},
96+
// },
97+
// },
98+
// {
99+
// RpcMethod: "SetBeforeSendHook",
100+
// Use: "set-beforesend-hook [denom] [cosmwasm-address]",
101+
// Short: "Set a cosmwasm contract to be the beforesend hook for a factory-created denom. Must have admin authority to do so.",
102+
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{
103+
// {ProtoField: "denom"},
104+
// {ProtoField: "cosmwasm-address"},
105+
// },
106+
// },
107+
// {
108+
// RpcMethod: "ForceTransfer",
109+
// Use: "force-transfer [sender] [amount] [transfer-from-address] [transfer-to-address]",
110+
// Short: "Transfer a factory-crated denom",
111+
// PositionalArgs: []*autocliv1.PositionalArgDescriptor{
112+
// {ProtoField: "sender"},
113+
// {ProtoField: "amount"},
114+
// {ProtoField: "transferFromAddress"},
115+
// {ProtoField: "transferToAddress"},
116+
// },
117+
// },
118+
// },
119+
// },
119120
}
120121
}

x/tokenfactory/client/cli/flags.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

x/tokenfactory/client/cli/tx.go

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,198 @@
11
package cli
2+
3+
import (
4+
"cosmossdk.io/core/address"
5+
"github.com/cosmos/cosmos-sdk/client"
6+
"github.com/cosmos/cosmos-sdk/client/flags"
7+
"github.com/cosmos/cosmos-sdk/client/tx"
8+
sdk "github.com/cosmos/cosmos-sdk/types"
9+
"github.com/spf13/cobra"
10+
11+
"github.com/initia-labs/miniwasm/x/tokenfactory/types"
12+
)
13+
14+
// GetTxCmd returns the transaction commands for this module
15+
func GetTxCmd(ac address.Codec) *cobra.Command {
16+
txCmd := &cobra.Command{
17+
Use: types.ModuleName,
18+
Short: "Tokenfactory transaction subcommands",
19+
DisableFlagParsing: true,
20+
SuggestionsMinimumDistance: 2,
21+
RunE: client.ValidateCmd,
22+
}
23+
txCmd.AddCommand(
24+
NewCreateDenomCmd(ac),
25+
NewMintCmd(ac),
26+
NewBurnCmd(ac),
27+
// NewForceTransferCmd(),
28+
NewChangeAdminCmd(ac),
29+
NewSetBeforeSendHookCmd(ac),
30+
)
31+
return txCmd
32+
}
33+
34+
func NewCreateDenomCmd(ac address.Codec) *cobra.Command {
35+
cmd := &cobra.Command{
36+
Use: "create-denom [sub-denom] [flags]",
37+
Short: "create a new denom from an account.",
38+
Args: cobra.ExactArgs(1),
39+
RunE: func(cmd *cobra.Command, args []string) error {
40+
clientCtx, err := client.GetClientTxContext(cmd)
41+
if err != nil {
42+
return err
43+
}
44+
45+
msg := types.NewMsgCreateDenom(
46+
clientCtx.GetFromAddress().String(),
47+
args[0],
48+
)
49+
50+
if err = msg.Validate(ac); err != nil {
51+
return err
52+
}
53+
54+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
55+
},
56+
}
57+
flags.AddTxFlagsToCmd(cmd)
58+
return cmd
59+
}
60+
61+
func NewMintCmd(ac address.Codec) *cobra.Command {
62+
cmd := &cobra.Command{
63+
Use: "mint [amount] [mint-to-address] [flags]",
64+
Short: "Mint a denom to an address. Must have admin authority to do so.",
65+
Args: cobra.RangeArgs(1, 2),
66+
RunE: func(cmd *cobra.Command, args []string) error {
67+
clientCtx, err := client.GetClientTxContext(cmd)
68+
if err != nil {
69+
return err
70+
}
71+
72+
amount, err := sdk.ParseCoinNormalized(args[0])
73+
if err != nil {
74+
return err
75+
}
76+
77+
mintToAddress := ""
78+
if len(args) == 2 {
79+
mintToAddress = args[1]
80+
}
81+
82+
msg := types.NewMsgMintTo(
83+
clientCtx.GetFromAddress().String(),
84+
amount,
85+
mintToAddress,
86+
)
87+
88+
if err = msg.Validate(ac); err != nil {
89+
return err
90+
}
91+
92+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
93+
},
94+
}
95+
flags.AddTxFlagsToCmd(cmd)
96+
return cmd
97+
}
98+
99+
func NewBurnCmd(ac address.Codec) *cobra.Command {
100+
cmd := &cobra.Command{
101+
Use: "burn [amount] [burn-from-address] [flags]",
102+
Short: "Burn tokens from an address. Must have admin authority to do so.",
103+
Args: cobra.RangeArgs(1, 2),
104+
RunE: func(cmd *cobra.Command, args []string) error {
105+
clientCtx, err := client.GetClientTxContext(cmd)
106+
if err != nil {
107+
return err
108+
}
109+
110+
amount, err := sdk.ParseCoinNormalized(args[0])
111+
if err != nil {
112+
return err
113+
}
114+
115+
burnFromAddress := ""
116+
if len(args) == 2 {
117+
burnFromAddress = args[1]
118+
}
119+
120+
msg := types.NewMsgBurnFrom(
121+
clientCtx.GetFromAddress().String(),
122+
amount,
123+
burnFromAddress,
124+
)
125+
126+
if err = msg.Validate(ac); err != nil {
127+
return err
128+
}
129+
130+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
131+
},
132+
}
133+
flags.AddTxFlagsToCmd(cmd)
134+
return cmd
135+
}
136+
137+
func NewChangeAdminCmd(ac address.Codec) *cobra.Command {
138+
cmd := &cobra.Command{
139+
Use: "change-admin [denom] [new-admin] [flags]",
140+
Short: "Changes the admin address for a factory-created denom. Must have admin authority to do so.",
141+
Args: cobra.ExactArgs(2),
142+
RunE: func(cmd *cobra.Command, args []string) error {
143+
clientCtx, err := client.GetClientTxContext(cmd)
144+
if err != nil {
145+
return err
146+
}
147+
148+
msg := types.NewMsgChangeAdmin(
149+
clientCtx.GetFromAddress().String(),
150+
args[0],
151+
args[1],
152+
)
153+
154+
if err = msg.Validate(ac); err != nil {
155+
return err
156+
}
157+
158+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
159+
},
160+
}
161+
flags.AddTxFlagsToCmd(cmd)
162+
return cmd
163+
}
164+
165+
// NewChangeAdminCmd broadcast MsgChangeAdmin
166+
func NewSetBeforeSendHookCmd(ac address.Codec) *cobra.Command {
167+
cmd := &cobra.Command{
168+
Use: "set-beforesend-hook [denom] [cosmwasm-address] [flags]",
169+
Short: "Set a cosmwasm contract to be the beforesend hook for a factory-created denom. Must have admin authority to do so.",
170+
Args: cobra.ExactArgs(2),
171+
RunE: func(cmd *cobra.Command, args []string) error {
172+
clientCtx, err := client.GetClientTxContext(cmd)
173+
if err != nil {
174+
return err
175+
}
176+
177+
txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags())
178+
if err != nil {
179+
return err
180+
}
181+
txf = txf.WithTxConfig(clientCtx.TxConfig).WithAccountRetriever(clientCtx.AccountRetriever)
182+
183+
msg := types.NewMsgSetBeforeSendHook(
184+
clientCtx.GetFromAddress().String(),
185+
args[0],
186+
args[1],
187+
)
188+
189+
if err = msg.Validate(ac); err != nil {
190+
return err
191+
}
192+
193+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
194+
},
195+
}
196+
flags.AddTxFlagsToCmd(cmd)
197+
return cmd
198+
}

x/tokenfactory/module.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/grpc-ecosystem/grpc-gateway/runtime"
2525
"github.com/spf13/cobra"
2626

27+
"github.com/initia-labs/miniwasm/x/tokenfactory/client/cli"
2728
"github.com/initia-labs/miniwasm/x/tokenfactory/keeper"
2829
"github.com/initia-labs/miniwasm/x/tokenfactory/types"
2930
)
@@ -87,8 +88,8 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
8788
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) //nolint:errcheck
8889
}
8990

90-
func (AppModuleBasic) GetTxCmd() *cobra.Command {
91-
return &cobra.Command{}
91+
func (am AppModuleBasic) GetTxCmd() *cobra.Command {
92+
return cli.GetTxCmd(am.cdc.InterfaceRegistry().SigningContext().AddressCodec())
9293
}
9394

9495
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)