|
| 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 | +} |
0 commit comments