Skip to content

Commit d8fae4f

Browse files
committed
basic cli and first draft command for ct module
1 parent b6ed1a7 commit d8fae4f

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package cli
2+
3+
import (
4+
"github.com/cosmos/cosmos-sdk/client"
5+
"github.com/cosmos/cosmos-sdk/client/flags"
6+
"github.com/cosmos/cosmos-sdk/client/tx"
7+
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
const (
12+
FlagPrivateKey = "private-key"
13+
)
14+
15+
// NewTxCmd returns a root CLI command handler for all x/confidentialtransfers transaction commands.
16+
func NewTxCmd() *cobra.Command {
17+
txCmd := &cobra.Command{
18+
Use: types.ShortModuleName,
19+
Short: "Confidential transfers transaction subcommands",
20+
DisableFlagParsing: true,
21+
SuggestionsMinimumDistance: 2,
22+
RunE: client.ValidateCmd,
23+
}
24+
25+
txCmd.AddCommand(NewInitializeAccountTxCmd())
26+
27+
return txCmd
28+
}
29+
30+
// NewInitializeAccountTxCmd returns a CLI command handler for creating a MsgInitializeAccount transaction.
31+
func NewInitializeAccountTxCmd() *cobra.Command {
32+
cmd := &cobra.Command{
33+
Use: "init-account [denom] [flags]",
34+
Short: "Initialize confidential transfers account",
35+
Long: `Initialize confidential transfers account for the specified denomination.`,
36+
Args: cobra.ExactArgs(1),
37+
RunE: makeInitializeAccountCmd,
38+
}
39+
40+
cmd.Flags().String(FlagPrivateKey, "", "Private key of the account")
41+
flags.AddTxFlagsToCmd(cmd)
42+
43+
return cmd
44+
}
45+
46+
func makeInitializeAccountCmd(cmd *cobra.Command, args []string) error {
47+
clientCtx, err := client.GetClientTxContext(cmd)
48+
if err != nil {
49+
return err
50+
}
51+
52+
_, err = cmd.Flags().GetString(FlagPrivateKey)
53+
if err != nil {
54+
return err
55+
}
56+
// TODO: Get below values from NewInitializeAccount function once merged
57+
msg := &types.MsgInitializeAccount{
58+
FromAddress: clientCtx.GetFromAddress().String(),
59+
Denom: args[1],
60+
PublicKey: nil,
61+
DecryptableBalance: "",
62+
Proofs: nil,
63+
}
64+
if err = msg.ValidateBasic(); err != nil {
65+
return err
66+
}
67+
68+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
69+
}

x/confidentialtransfers/module.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,19 @@ import (
1515
"fmt"
1616
"math/rand"
1717

18-
"github.com/grpc-ecosystem/grpc-gateway/runtime"
19-
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/keeper"
20-
"github.com/spf13/cobra"
21-
2218
"github.com/cosmos/cosmos-sdk/client"
2319
"github.com/cosmos/cosmos-sdk/codec"
2420
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
2521
sdk "github.com/cosmos/cosmos-sdk/types"
2622
"github.com/cosmos/cosmos-sdk/types/module"
23+
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
2724
"github.com/gorilla/mux"
28-
abci "github.com/tendermint/tendermint/abci/types"
29-
30-
//"github.com/sei-protocol/sei-chain/x/tokenfactory/client/cli"
31-
//"github.com/sei-protocol/sei-chain/x/tokenfactory/keeper"
25+
"github.com/grpc-ecosystem/grpc-gateway/runtime"
26+
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/client/cli"
27+
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/keeper"
3228
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
33-
34-
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
29+
"github.com/spf13/cobra"
30+
abci "github.com/tendermint/tendermint/abci/types"
3531
)
3632

3733
var (
@@ -103,8 +99,7 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
10399
// TODO: Implement this when we add the CLI methods
104100
// GetTxCmd returns the x/confidentialtransfers module's root tx command.
105101
func (am AppModuleBasic) GetTxCmd() *cobra.Command {
106-
//return cli.GetTxCmd()
107-
return nil
102+
return cli.NewTxCmd()
108103
}
109104

110105
// TODO: Implement this when we add the CLI methods

x/confidentialtransfers/types/keys.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const (
1010
// ModuleName defines the module name
1111
ModuleName = "confidentialtransfers"
1212

13+
ShortModuleName = "ct"
14+
1315
// StoreKey defines the primary module store key
1416
StoreKey = ModuleName
1517

0 commit comments

Comments
 (0)