From 8c9b7b73d0a1e148ba4e86f409320a04a9e5749d Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Wed, 17 May 2023 12:21:33 +0800 Subject: [PATCH] feat(cli): merge crosschain cmd from v4 --- app/modules.go | 2 + cmd/root.go | 21 +- x/avalanche/client/cli/query.go | 21 + x/avalanche/client/cli/tx.go | 21 + x/avalanche/module.go | 5 +- x/bsc/client/cli/query.go | 21 + x/bsc/client/cli/tx.go | 21 + x/bsc/module.go | 5 +- x/crosschain/client/cli/query.go | 532 ++++++++++-------------- x/crosschain/client/cli/tx.go | 287 +++++-------- x/crosschain/client/cli/tx_proposal.go | 76 ++++ x/crosschain/client/proposal_handler.go | 25 ++ x/eth/client/cli/query.go | 21 + x/eth/client/cli/tx.go | 21 + x/eth/module.go | 5 +- x/polygon/client/cli/query.go | 21 + x/polygon/client/cli/tx.go | 21 + x/polygon/module.go | 5 +- x/tron/client/cli/query.go | 21 + x/tron/client/cli/tx.go | 21 + x/tron/module.go | 5 +- 21 files changed, 686 insertions(+), 492 deletions(-) create mode 100644 x/avalanche/client/cli/query.go create mode 100644 x/avalanche/client/cli/tx.go create mode 100644 x/bsc/client/cli/query.go create mode 100644 x/bsc/client/cli/tx.go create mode 100644 x/crosschain/client/cli/tx_proposal.go create mode 100644 x/crosschain/client/proposal_handler.go create mode 100644 x/eth/client/cli/query.go create mode 100644 x/eth/client/cli/tx.go create mode 100644 x/polygon/client/cli/query.go create mode 100644 x/polygon/client/cli/tx.go create mode 100644 x/tron/client/cli/query.go create mode 100644 x/tron/client/cli/tx.go diff --git a/app/modules.go b/app/modules.go index 808a32468..eb8af9137 100644 --- a/app/modules.go +++ b/app/modules.go @@ -50,6 +50,7 @@ import ( avalanchetypes "github.com/functionx/fx-core/v3/x/avalanche/types" "github.com/functionx/fx-core/v3/x/bsc" bsctypes "github.com/functionx/fx-core/v3/x/bsc/types" + crosschainclient "github.com/functionx/fx-core/v3/x/crosschain/client" crosschaintypes "github.com/functionx/fx-core/v3/x/crosschain/types" "github.com/functionx/fx-core/v3/x/erc20" erc20client "github.com/functionx/fx-core/v3/x/erc20/client" @@ -118,6 +119,7 @@ var ModuleBasics = module.NewBasicManager( erc20client.RegisterERC20ProposalHandler, erc20client.ToggleTokenConversionProposalHandler, erc20client.UpdateDenomAliasProposalHandler, + crosschainclient.UpdateChainOraclesProposalHandler, }...), params.AppModuleBasic{}, crisis.AppModuleBasic{}, diff --git a/cmd/root.go b/cmd/root.go index 204babab7..2c77a2880 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -37,7 +37,12 @@ import ( fxcfg "github.com/functionx/fx-core/v3/server/config" "github.com/functionx/fx-core/v3/server/grpc/base/gasprice" fxtypes "github.com/functionx/fx-core/v3/types" + avalanchecli "github.com/functionx/fx-core/v3/x/avalanche/client/cli" + bsccli "github.com/functionx/fx-core/v3/x/bsc/client/cli" crosschaincli "github.com/functionx/fx-core/v3/x/crosschain/client/cli" + ethcli "github.com/functionx/fx-core/v3/x/eth/client/cli" + polygoncli "github.com/functionx/fx-core/v3/x/polygon/client/cli" + troncli "github.com/functionx/fx-core/v3/x/tron/client/cli" ) // NewRootCmd creates a new root command for simd. It is called once in the @@ -157,7 +162,13 @@ func queryCommand() *cobra.Command { cli.QueryValidatorByConsAddr(), cli.QueryBlockResultsCmd(), gasprice.QueryCmd(), - crosschaincli.GetQueryCmd(), + crosschaincli.GetQueryCmd( + avalanchecli.GetQueryCmd(), + bsccli.GetQueryCmd(), + ethcli.GetQueryCmd(), + polygoncli.GetQueryCmd(), + troncli.GetQueryCmd(), + ), ) app.ModuleBasics.AddQueryCommands(cmd) @@ -184,7 +195,13 @@ func txCommand() *cobra.Command { authcmd.GetBroadcastCommand(), authcmd.GetEncodeCommand(), authcmd.GetDecodeCommand(), - crosschaincli.GetTxCmd(), + crosschaincli.GetTxCmd( + avalanchecli.GetTxCmd(), + bsccli.GetTxCmd(), + ethcli.GetTxCmd(), + polygoncli.GetTxCmd(), + troncli.GetTxCmd(), + ), ) app.ModuleBasics.AddTxCommands(cmd) diff --git a/x/avalanche/client/cli/query.go b/x/avalanche/client/cli/query.go new file mode 100644 index 000000000..b74c828de --- /dev/null +++ b/x/avalanche/client/cli/query.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/avalanche/types" + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" +) + +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the avalanche module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetQuerySubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/avalanche/client/cli/tx.go b/x/avalanche/client/cli/tx.go new file mode 100644 index 000000000..401344173 --- /dev/null +++ b/x/avalanche/client/cli/tx.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/avalanche/types" + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" +) + +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Avalanche transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetTxSubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/avalanche/module.go b/x/avalanche/module.go index 5a14e3cef..6bea61104 100644 --- a/x/avalanche/module.go +++ b/x/avalanche/module.go @@ -14,6 +14,7 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "github.com/functionx/fx-core/v3/x/avalanche/client/cli" "github.com/functionx/fx-core/v3/x/avalanche/types" crosschainkeeper "github.com/functionx/fx-core/v3/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v3/x/crosschain/types" @@ -61,12 +62,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.Ser // GetQueryCmd implements app module basic func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil + return cli.GetQueryCmd() } // GetTxCmd implements app module basic func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil + return cli.GetTxCmd() } // RegisterInterfaces implements app bmodule basic diff --git a/x/bsc/client/cli/query.go b/x/bsc/client/cli/query.go new file mode 100644 index 000000000..afbaf54c9 --- /dev/null +++ b/x/bsc/client/cli/query.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/bsc/types" + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" +) + +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the bsc module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetQuerySubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/bsc/client/cli/tx.go b/x/bsc/client/cli/tx.go new file mode 100644 index 000000000..702385d6e --- /dev/null +++ b/x/bsc/client/cli/tx.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/bsc/types" + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" +) + +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "BSC transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetTxSubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/bsc/module.go b/x/bsc/module.go index 913900b25..5fba36ae3 100644 --- a/x/bsc/module.go +++ b/x/bsc/module.go @@ -14,6 +14,7 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + "github.com/functionx/fx-core/v3/x/bsc/client/cli" "github.com/functionx/fx-core/v3/x/bsc/types" crosschainkeeper "github.com/functionx/fx-core/v3/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v3/x/crosschain/types" @@ -61,12 +62,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.Ser // GetQueryCmd implements app module basic func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil + return cli.GetQueryCmd() } // GetTxCmd implements app module basic func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil + return cli.GetTxCmd() } // RegisterInterfaces implements app bmodule basic diff --git a/x/crosschain/client/cli/query.go b/x/crosschain/client/cli/query.go index 246e7cf0c..97f85b432 100644 --- a/x/crosschain/client/cli/query.go +++ b/x/crosschain/client/cli/query.go @@ -4,123 +4,122 @@ import ( "encoding/json" "fmt" "strconv" - "strings" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" tranfsertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" - gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/spf13/cobra" abcitype "github.com/tendermint/tendermint/abci/types" - fxtypes "github.com/functionx/fx-core/v3/types" "github.com/functionx/fx-core/v3/x/crosschain/types" ) -const ( - flagChannelIBC = "channelIBC" -) - -func GetQueryCmd() *cobra.Command { +func GetQueryCmd(subCmd ...*cobra.Command) *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, - Short: "Querying commands from cross chain", + Short: "Querying commands for the crosschain module", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, } + cmd.AddCommand(subCmd...) + return cmd +} - cmd.AddCommand([]*cobra.Command{ +func GetQuerySubCmds(chainName string) []*cobra.Command { + cmds := []*cobra.Command{ // query module params - CmdGetParams(), + CmdGetParams(chainName), // query Oracle - CmdGetOracles(), - CmdGetOracleReward(), - CmdGetOracleDelegateAddr(), - CmdGetProposalOracles(), - CmdGetOracleByAddr(), - CmdGetOracleByBridgerAddr(), - CmdGetOracleByExternalAddr(), + CmdGetOracles(chainName), + CmdGetOracleReward(chainName), + CmdGetOracleDelegateAddr(chainName), + CmdGetProposalOracles(chainName), + CmdGetOracleByAddr(chainName), + CmdGetOracleByBridgerAddr(chainName), + CmdGetOracleByExternalAddr(chainName), // query oracle set - CmdGetCurrentOracleSet(), - CmdGetOracleSetRequest(), + CmdGetCurrentOracleSet(chainName), + CmdGetOracleSetRequest(chainName), // need oracle consensus sign // 1. oracle set change confirm - CmdGetLastOracleSetRequests(), - CmdGetPendingOracleSetRequest(), - CmdGetOracleSetConfirm(), - CmdGetOracleSetConfirms(), + CmdGetLastOracleSetRequests(chainName), + CmdGetPendingOracleSetRequest(chainName), + CmdGetOracleSetConfirm(chainName), + CmdGetOracleSetConfirms(chainName), // 2. request batch confirm - CmdGetPendingOutgoingTXBatchRequest(), - CmdBatchConfirm(), - CmdBatchConfirms(), + CmdGetPendingOutgoingTXBatchRequest(chainName), + CmdBatchConfirm(chainName), + CmdBatchConfirms(chainName), // send to external - CmdBatchRequestByNonce(), - CmdGetPendingSendToExternal(), - CmdOutgoingTxBatches(), - CmdGetBatchFees(), + CmdBatchRequestByNonce(chainName), + CmdGetPendingSendToExternal(chainName), + CmdOutgoingTxBatches(chainName), + CmdGetBatchFees(chainName), - CmdGetLastObservedBlockHeight(), - CmdProjectedBatchTimeoutHeight(), + CmdGetLastObservedBlockHeight(chainName), + CmdProjectedBatchTimeoutHeight(chainName), // denom <-> external token - CmdGetDenomToExternalToken(), - CmdGetExternalTokenToDenom(), - CmdGetBridgeTokens(), + CmdGetDenomToExternalToken(chainName), + CmdGetExternalTokenToDenom(chainName), + CmdGetBridgeTokens(chainName), // 1. oracle event nonce - CmdGetOracleEventNonce(), + CmdGetOracleEventNonce(chainName), // 2. event nonce block height - CmdGetOracleEventBlockHeight(), + CmdGetOracleEventBlockHeight(chainName), // help cmd. - CmdCovertBridgeToken(), - }...) + CmdCovertBridgeToken(chainName), + } - for _, command := range cmd.Commands() { + for _, command := range cmds { flags.AddQueryFlagsToCmd(command) } - return cmd + return cmds } -func CmdGetParams() *cobra.Command { +func CmdGetParams(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "params [chain-name]", + Use: "params", Short: "Query the current parameters information", - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - chainName := args[0] - res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{ChainName: chainName}) + + res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{ + ChainName: chainName, + }) if err != nil { return err } return clientCtx.PrintProto(&res.Params) }, } - return cmd } -func CmdGetOracles() *cobra.Command { +func CmdGetOracles(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracles [chain-name]", - Short: "Query oracles", - Args: cobra.ExactArgs(1), + Use: "oracles", + Short: "Query current oracles", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.Oracles(cmd.Context(), &types.QueryOraclesRequest{ - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err @@ -128,26 +127,24 @@ func CmdGetOracles() *cobra.Command { return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetProposalOracles() *cobra.Command { +func CmdGetProposalOracles(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "proposal-oracles [chain-name]", - Short: "Query active oracles address", - Args: cobra.ExactArgs(1), + Use: "proposal-oracles", + Short: "Query proposal oracles address", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - req := abcitype.RequestQuery{ + + abciResp, err := clientCtx.QueryABCI(abcitype.RequestQuery{ Data: types.ProposalOracleKey, - Path: fmt.Sprintf("/store/%s/key", args[0]), - } - abciResp, err := clientCtx.QueryABCI(req) + Path: fmt.Sprintf("/store/%s/key", chainName), + }) if err != nil { return err } - var proposalOracle types.ProposalOracle if err := clientCtx.LegacyAmino.Unmarshal(abciResp.Value, &proposalOracle); err != nil { return err @@ -155,141 +152,124 @@ func CmdGetProposalOracles() *cobra.Command { return clientCtx.PrintProto(&proposalOracle) }, } - return cmd } -func CmdGetOracleReward() *cobra.Command { +func CmdGetOracleReward(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "reward [chain-name] [oracle-address]", + Use: "reward [oracle-address]", Short: "Query oracle reward", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) + queryClient := distrtypes.NewQueryClient(clientCtx) - oracleAddr, err := sdk.AccAddressFromBech32(args[1]) + oracleAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - - data := append(oracleAddr.Bytes(), []byte(args[0])...) - queryClient := distrtypes.NewQueryClient(clientCtx) + data := append(oracleAddr.Bytes(), []byte(chainName)...) rewards, err := queryClient.DelegationTotalRewards(cmd.Context(), &distrtypes.QueryDelegationTotalRewardsRequest{ DelegatorAddress: sdk.AccAddress(crypto.Keccak256(data)[12:]).String(), }) if err != nil { return err } - if err != nil { - return err - } return clientCtx.PrintProto(rewards) }, } - return cmd } -func CmdGetOracleDelegateAddr() *cobra.Command { +func CmdGetOracleDelegateAddr(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracle-delegate [chain-name] [oracle-address]", + Use: "oracle-delegate [oracle-address]", Short: "Query oracle delegate address", Hidden: true, - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - oracleAddr, err := sdk.AccAddressFromBech32(args[1]) + oracleAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - data := append(oracleAddr.Bytes(), []byte(args[0])...) + data := append(oracleAddr.Bytes(), []byte(chainName)...) cmd.Println(sdk.AccAddress(crypto.Keccak256(data)[12:]).String()) return nil }, } - return cmd } -func CmdGetOracleByAddr() *cobra.Command { +func CmdGetOracleByAddr(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracle-by-addr [chain-name] [oracle-address]", - Short: "Query Oracle for a given oracle address", - Args: cobra.ExactArgs(2), + Use: "oracle-by-addr [oracle-address]", + Short: "Query oracle for a given oracle address", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - oracleAddress, err := sdk.AccAddressFromBech32(args[1]) + oracleAddress, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - req := &types.QueryOracleByAddrRequest{ + res, err := queryClient.GetOracleByAddr(cmd.Context(), &types.QueryOracleByAddrRequest{ OracleAddress: oracleAddress.String(), - ChainName: args[0], - } - res, err := queryClient.GetOracleByAddr(cmd.Context(), req) + ChainName: chainName, + }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetOracleByBridgerAddr() *cobra.Command { +func CmdGetOracleByBridgerAddr(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracle-by-bridger [chain-name] [bridger-address]", - Short: "Query Oracle for a given bridger address", - Args: cobra.ExactArgs(2), + Use: "oracle-by-bridger [bridger-address]", + Short: "Query oracle for a given bridger address", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - bridgerAddr, err := sdk.AccAddressFromBech32(args[1]) + bridgerAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - req := &types.QueryOracleByBridgerAddrRequest{ + res, err := queryClient.GetOracleByBridgerAddr(cmd.Context(), &types.QueryOracleByBridgerAddrRequest{ BridgerAddress: bridgerAddr.String(), - ChainName: args[0], - } - res, err := queryClient.GetOracleByBridgerAddr(cmd.Context(), req) + ChainName: chainName, + }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetOracleByExternalAddr() *cobra.Command { +func CmdGetOracleByExternalAddr(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracle-key-by-external-addr [chain-name] [external-address]", - Short: "Query Oracle by external address", - Args: cobra.ExactArgs(2), + Use: "oracle-key-by-external-addr [external-address]", + Short: "Query oracle by external address", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - externalAddress := args[1] - if strings.HasPrefix(externalAddress, "0x") { - if !gethcommon.IsHexAddress(externalAddress) { - return fmt.Errorf("target address is invalid!address: [%s]", externalAddress) - } - externalAddress = gethcommon.HexToAddress(externalAddress).Hex() + externalAddress, err := getContractAddr(args[0]) + if err != nil { + return err } - res, err := queryClient.GetOracleByExternalAddr(cmd.Context(), &types.QueryOracleByExternalAddrRequest{ ExternalAddress: externalAddress, - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err @@ -300,206 +280,186 @@ func CmdGetOracleByExternalAddr() *cobra.Command { return cmd } -func CmdGetCurrentOracleSet() *cobra.Command { +func CmdGetCurrentOracleSet(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "current-oracle-set [chain-name]", + Use: "current-oracle-set", Short: "Query current oracle-set", - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) res, err := queryClient.CurrentOracleSet(cmd.Context(), &types.QueryCurrentOracleSetRequest{ - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetOracleSetRequest() *cobra.Command { +func CmdGetOracleSetRequest(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracle-set-request [chain-name] [nonce]", + Use: "oracle-set-request [nonce]", Short: "Query requested oracle-set with a particular nonce", - Args: cobra.RangeArgs(1, 2), + Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) var nonce uint64 - if len(args) == 1 { + if len(args) == 0 { queryAbciResp, err := clientCtx.QueryABCI(abcitype.RequestQuery{ - Path: fmt.Sprintf("store/%s/key", args[0]), + Path: fmt.Sprintf("store/%s/key", chainName), Data: types.LatestOracleSetNonce, }) if err != nil { return err } nonce = sdk.BigEndianToUint64(queryAbciResp.Value) - if err = clientCtx.PrintString(fmt.Sprintf("latest oracle-set nonce:[%d]\n", nonce)); err != nil { - return err - } } else { var err error - nonce, err = strconv.ParseUint(args[1], 10, 64) + nonce, err = strconv.ParseUint(args[0], 10, 64) if err != nil { return err } } res, err := queryClient.OracleSetRequest(cmd.Context(), &types.QueryOracleSetRequestRequest{ - ChainName: args[0], + ChainName: chainName, Nonce: nonce, }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } return cmd } -func CmdGetLastOracleSetRequests() *cobra.Command { +func CmdGetLastOracleSetRequests(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "last-oracle-set-requests [chain-name]", + Use: "last-oracle-set-requests", Short: "Query last oracle set requests", - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - req := &types.QueryLastOracleSetRequestsRequest{ - ChainName: args[0], - } - - res, err := queryClient.LastOracleSetRequests(cmd.Context(), req) + res, err := queryClient.LastOracleSetRequests(cmd.Context(), &types.QueryLastOracleSetRequestsRequest{ + ChainName: chainName, + }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetPendingOracleSetRequest() *cobra.Command { +func CmdGetPendingOracleSetRequest(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "pending-oracle-set-request [chain-name] [bridger]", + Use: "pending-oracle-set-request [bridger]", Short: "Query the latest oracle-set request which has not been signed by a particular oracle bridger", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - bridgerAddr, err := sdk.AccAddressFromBech32(args[1]) + bridgerAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - - req := &types.QueryLastPendingOracleSetRequestByAddrRequest{ + res, err := queryClient.LastPendingOracleSetRequestByAddr(cmd.Context(), &types.QueryLastPendingOracleSetRequestByAddrRequest{ BridgerAddress: bridgerAddr.String(), - ChainName: args[0], - } - - res, err := queryClient.LastPendingOracleSetRequestByAddr(cmd.Context(), req) + ChainName: chainName, + }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetOracleSetConfirm() *cobra.Command { +func CmdGetOracleSetConfirm(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracle-set-confirm [chain-name] [nonce] [bridger-address]", + Use: "oracle-set-confirm [nonce] [bridger-address]", Short: "Query oracle-set confirmation with a particular nonce from a particular oracle bridger", - Args: cobra.ExactArgs(3), + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - nonce, err := strconv.ParseUint(args[1], 10, 64) + nonce, err := strconv.ParseUint(args[0], 10, 64) if err != nil { return err } - bridgerAddr, err := sdk.AccAddressFromBech32(args[2]) + bridgerAddr, err := sdk.AccAddressFromBech32(args[1]) if err != nil { return err } res, err := queryClient.OracleSetConfirm(cmd.Context(), &types.QueryOracleSetConfirmRequest{ Nonce: nonce, BridgerAddress: bridgerAddr.String(), - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } return cmd } -func CmdGetOracleSetConfirms() *cobra.Command { +func CmdGetOracleSetConfirms(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracle-set-confirms [chain-name] [nonce]", + Use: "oracle-set-confirms [nonce]", Short: "Query oracle-set confirmations with a particular nonce", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - nonce, err := strconv.ParseUint(args[1], 10, 64) + nonce, err := strconv.ParseUint(args[0], 10, 64) if err != nil { return err } res, err := queryClient.OracleSetConfirmsByNonce(cmd.Context(), &types.QueryOracleSetConfirmsByNonceRequest{ Nonce: nonce, - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } - if err = clientCtx.PrintString(fmt.Sprintf("confirm size:[%d]\n", len(res.Confirms))); err != nil { - return err - } return clientCtx.PrintProto(res) }, } return cmd } -func CmdGetPendingOutgoingTXBatchRequest() *cobra.Command { +func CmdGetPendingOutgoingTXBatchRequest(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "pending-batch-request [chain-name] [bridger-address]", + Use: "pending-batch-request [bridger-address]", Short: "Query the latest outgoing TX batch request which has not been signed by a particular oracle bridger address", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - bridgerAddr, err := sdk.AccAddressFromBech32(args[1]) + bridgerAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - res, err := queryClient.LastPendingBatchRequestByAddr(cmd.Context(), &types.QueryLastPendingBatchRequestByAddrRequest{ BridgerAddress: bridgerAddr.String(), - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err @@ -510,33 +470,29 @@ func CmdGetPendingOutgoingTXBatchRequest() *cobra.Command { return cmd } -func CmdBatchConfirm() *cobra.Command { +func CmdBatchConfirm(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "batch-confirm [chain-name] [token-contract] [nonce] [bridger-address]", + Use: "batch-confirm [token-contract] [nonce] [bridger-address]", Short: "Query outgoing tx batches confirm by oracle bridger address", - Args: cobra.ExactArgs(4), + Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - tokenContract := args[1] - if strings.HasPrefix(tokenContract, "0x") { - if !gethcommon.IsHexAddress(tokenContract) { - return fmt.Errorf("contract address is invalid!address:[%s]", tokenContract) - } - tokenContract = gethcommon.HexToAddress(tokenContract).Hex() + tokenContract, err := getContractAddr(args[0]) + if err != nil { + return err } - - nonce, err := strconv.ParseUint(args[2], 10, 64) + nonce, err := strconv.ParseUint(args[1], 10, 64) if err != nil { return err } - bridgerAddr, err := sdk.AccAddressFromBech32(args[3]) + bridgerAddr, err := sdk.AccAddressFromBech32(args[2]) if err != nil { return err } res, err := queryClient.BatchConfirm(cmd.Context(), &types.QueryBatchConfirmRequest{ - ChainName: args[0], + ChainName: chainName, TokenContract: tokenContract, Nonce: nonce, BridgerAddress: bridgerAddr.String(), @@ -550,91 +506,84 @@ func CmdBatchConfirm() *cobra.Command { return cmd } -func CmdBatchConfirms() *cobra.Command { +func CmdBatchConfirms(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "batch-confirms [chain-name] [token-contract] [nonce]", + Use: "batch-confirms [token-contract] [nonce]", Short: "Query outgoing tx batches confirms", - Args: cobra.ExactArgs(3), + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - tokenContract := args[1] - if strings.HasPrefix(tokenContract, "0x") { - if !gethcommon.IsHexAddress(tokenContract) { - return fmt.Errorf("contract address is invalid!address:[%s]", tokenContract) - } - tokenContract = gethcommon.HexToAddress(tokenContract).Hex() + tokenContract, err := getContractAddr(args[0]) + if err != nil { + return err } - nonce, err := strconv.Atoi(args[2]) + nonce, err := strconv.Atoi(args[1]) if err != nil { return err } res, err := queryClient.BatchConfirms(cmd.Context(), &types.QueryBatchConfirmsRequest{ TokenContract: tokenContract, Nonce: uint64(nonce), - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } - if err = clientCtx.PrintString(fmt.Sprintf("confirm size:[%d]\n", len(res.Confirms))); err != nil { - return err - } return clientCtx.PrintProto(res) }, } return cmd } -func CmdBatchRequestByNonce() *cobra.Command { +func CmdBatchRequestByNonce(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "batch-request [chain-name] [token-contract] [nonce]", + Use: "batch-request [token-contract] [nonce]", Short: "Query outgoing tx batches", - Args: cobra.ExactArgs(3), + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - nonce, err := strconv.ParseUint(args[2], 10, 64) + tokenContract, err := getContractAddr(args[0]) + if err != nil { + return err + } + nonce, err := strconv.ParseUint(args[1], 10, 64) if err != nil { return err } - res, err := queryClient.BatchRequestByNonce(cmd.Context(), &types.QueryBatchRequestByNonceRequest{ - ChainName: args[0], - TokenContract: args[1], + ChainName: chainName, + TokenContract: tokenContract, Nonce: nonce, }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } return cmd } -func CmdGetPendingSendToExternal() *cobra.Command { +func CmdGetPendingSendToExternal(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "pending-send-to-external [chain-name] [address]", + Use: "pending-send-to-external [address]", Short: "Query pending send to external txs", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - chainName := args[0] - if err := types.ValidateModuleName(chainName); err != nil { - return err - } - fxAddr := args[1] - if _, err := sdk.AccAddressFromBech32(fxAddr); err != nil { + + addr, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { return nil } res, err := queryClient.GetPendingSendToExternal(cmd.Context(), &types.QueryPendingSendToExternalRequest{ ChainName: chainName, - SenderAddress: fxAddr, + SenderAddress: addr.String(), }) if err != nil { return err @@ -645,39 +594,38 @@ func CmdGetPendingSendToExternal() *cobra.Command { return cmd } -func CmdOutgoingTxBatches() *cobra.Command { +func CmdOutgoingTxBatches(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "outgoing-tx-batches [chain-name]", + Use: "outgoing-tx-batches", Short: "Query outgoing tx batches", - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) res, err := queryClient.OutgoingTxBatches(cmd.Context(), &types.QueryOutgoingTxBatchesRequest{ - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } return cmd } -func CmdGetBatchFees() *cobra.Command { +func CmdGetBatchFees(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "batch-fees [chain-name]", + Use: "batch-fees", Short: "Query a list of send to external transaction fees to be processed", - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) res, err := queryClient.BatchFees(cmd.Context(), &types.QueryBatchFeeRequest{ - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err @@ -685,21 +633,20 @@ func CmdGetBatchFees() *cobra.Command { return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetLastObservedBlockHeight() *cobra.Command { +func CmdGetLastObservedBlockHeight(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "last-observed-block-height [chain-name]", + Use: "last-observed-block-height", Short: "Query last observed block height", - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) res, err := queryClient.LastObservedBlockHeight(cmd.Context(), &types.QueryLastObservedBlockHeightRequest{ - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err @@ -710,17 +657,17 @@ func CmdGetLastObservedBlockHeight() *cobra.Command { return cmd } -func CmdProjectedBatchTimeoutHeight() *cobra.Command { +func CmdProjectedBatchTimeoutHeight(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "projected-batch-timeout-height [chain-name]", + Use: "projected-batch-timeout-height", Short: "Query projected batch timeout height", - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) res, err := queryClient.ProjectedBatchTimeoutHeight(cmd.Context(), &types.QueryProjectedBatchTimeoutHeightRequest{ - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err @@ -731,18 +678,22 @@ func CmdProjectedBatchTimeoutHeight() *cobra.Command { return cmd } -func CmdGetDenomToExternalToken() *cobra.Command { +func CmdGetDenomToExternalToken(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "token [chain-name] [denom]", + Use: "token [denom]", Short: "Query contract address from denom", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) + denom := args[0] + if err := sdk.ValidateDenom(denom); err != nil { + return err + } res, err := queryClient.DenomToToken(cmd.Context(), &types.QueryDenomToTokenRequest{ - ChainName: args[0], - Denom: args[1], + ChainName: chainName, + Denom: denom, }) if err != nil { return err @@ -750,141 +701,121 @@ func CmdGetDenomToExternalToken() *cobra.Command { return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetExternalTokenToDenom() *cobra.Command { +func CmdGetExternalTokenToDenom(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "denom [chain-name] [token-contract]", + Use: "denom [token-contract]", Short: "Query denom from contract address", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - tokenAddress := args[1] - if strings.HasPrefix(tokenAddress, "0x") { - if !gethcommon.IsHexAddress(tokenAddress) { - return fmt.Errorf("invalid contract address:%s", tokenAddress) - } - tokenAddress = gethcommon.HexToAddress(tokenAddress).Hex() + tokenAddress, err := getContractAddr(args[0]) + if err != nil { + return err } - res, err := queryClient.TokenToDenom(cmd.Context(), &types.QueryTokenToDenomRequest{ - ChainName: args[0], + ChainName: chainName, Token: tokenAddress, }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetBridgeTokens() *cobra.Command { +func CmdGetBridgeTokens(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "bridge-tokens [chain-name]", + Use: "bridge-tokens", Short: "Query bridge token list", - Args: cobra.ExactArgs(1), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) res, err := queryClient.BridgeTokens(cmd.Context(), &types.QueryBridgeTokensRequest{ - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetOracleEventNonce() *cobra.Command { +func CmdGetOracleEventNonce(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "event-nonce [chain-name] [bridger-address]", - Short: "Query last event nonce by oracle bridger address", - Args: cobra.ExactArgs(2), + Use: "event-nonce [bridger-address]", + Short: "Query last event nonce by bridger address", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - bridgerAddr, err := sdk.AccAddressFromBech32(args[1]) + bridgerAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } res, err := queryClient.LastEventNonceByAddr(cmd.Context(), &types.QueryLastEventNonceByAddrRequest{ - ChainName: args[0], + ChainName: chainName, BridgerAddress: bridgerAddr.String(), }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } - return cmd } -func CmdGetOracleEventBlockHeight() *cobra.Command { +func CmdGetOracleEventBlockHeight(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "event-block-height [chain-name] [bridger-address]", - Short: "Query last event block height by oracle bridger address", - Args: cobra.ExactArgs(2), + Use: "event-block-height [bridger-address]", + Short: "Query last event block height by bridger address", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) queryClient := types.NewQueryClient(clientCtx) - bridgerAddr, err := sdk.AccAddressFromBech32(args[1]) + bridgerAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } res, err := queryClient.LastEventBlockHeightByAddr(cmd.Context(), &types.QueryLastEventBlockHeightByAddrRequest{ BridgerAddress: bridgerAddr.String(), - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } - return clientCtx.PrintProto(res) }, } return cmd } -func CmdCovertBridgeToken() *cobra.Command { +func CmdCovertBridgeToken(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "covert-bridge-token [chain-name] [token-contract]", - Short: "Covert bridge claim token name", - Example: "fxcored q crosschain covert-bridge-token bsc 0x3f6795b8ABE0775a88973469909adE1405f7ac09 --channelIBC=transfer/channel-0", - Args: cobra.ExactArgs(2), + Use: "covert-bridge-token [token-contract] [channel ibc]", + Short: "Covert bridge claim token name", + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - chainName := args[0] - if err := types.ValidateModuleName(chainName); err != nil { - return err - } - tokenContract := args[1] - if err := fxtypes.ValidateEthereumAddress(tokenContract); err != nil { - return err - } - channelIbc, err := cmd.Flags().GetString(flagChannelIBC) + tokenContract, err := getContractAddr(args[0]) if err != nil { return err } + channelIbc := args[1] coinName := fmt.Sprintf("%s%s", chainName, tokenContract) if len(channelIbc) > 0 { coinName = tranfsertypes.DenomTrace{ @@ -892,17 +823,11 @@ func CmdCovertBridgeToken() *cobra.Command { BaseDenom: coinName, }.IBCDenom() } - type output struct { - ChainName string - TokenContract string - ChannelIbc string - CoinName string - } - indent, err := json.MarshalIndent(output{ - ChainName: chainName, - TokenContract: tokenContract, - ChannelIbc: channelIbc, - CoinName: coinName, + indent, err := json.MarshalIndent(map[string]interface{}{ + "chain_name": chainName, + "token_contract": tokenContract, + "channel_ibc": channelIbc, + "coin_name": coinName, }, "", " ") if err != nil { return err @@ -910,6 +835,5 @@ func CmdCovertBridgeToken() *cobra.Command { return clientCtx.PrintBytes(indent) }, } - cmd.Flags().String(flagChannelIBC, "", "bridge bind channel: transfer/channel-0") return cmd } diff --git a/x/crosschain/client/cli/tx.go b/x/crosschain/client/cli/tx.go index 111b7b668..84b0e1b09 100644 --- a/x/crosschain/client/cli/tx.go +++ b/x/crosschain/client/cli/tx.go @@ -14,127 +14,73 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/ethereum/go-ethereum/accounts/keystore" gethcommon "github.com/ethereum/go-ethereum/common" ethcrypto "github.com/ethereum/go-ethereum/crypto" + troncommon "github.com/fbsobreira/gotron-sdk/pkg/common" "github.com/spf13/cobra" "github.com/functionx/fx-core/v3/x/crosschain/types" ) -const ( - flagProposalTitle = "title" - flagProposalDescription = "desc" - flagInitParamsOracles = "oracles" -) - -func GetTxCmd() *cobra.Command { +func GetTxCmd(subCmd ...*cobra.Command) *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, - Short: "Cross chain transaction subcommands", + Short: "Crosschain transaction subcommands", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, } + cmd.AddCommand(subCmd...) + return cmd +} - cmd.AddCommand([]*cobra.Command{ - CmdUpdateChainOraclesProposal(), +func GetTxSubCmds(chainName string) []*cobra.Command { + cmds := []*cobra.Command{ + CmdUpdateChainOraclesProposal(chainName), // set bridger address - CmdCreateOracleBridger(), + CmdCreateOracleBridger(chainName), // add oracle stake - CmdAddOracleDelegate(), + CmdAddOracleDelegate(chainName), // send to external chain - CmdSendToExternal(), - CmdCancelSendToExternal(), - CmdRequestBatch(), + CmdSendToExternal(chainName), + CmdCancelSendToExternal(chainName), + CmdRequestBatch(chainName), // oracle consensus confirm - CmdOracleSetConfirm(), - CmdRequestBatchConfirm(), - }...) - - return cmd + CmdOracleSetConfirm(chainName), + CmdRequestBatchConfirm(chainName), + } + for _, command := range cmds { + flags.AddTxFlagsToCmd(command) + } + return cmds } -func CmdUpdateChainOraclesProposal() *cobra.Command { +func CmdCreateOracleBridger(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "update-crosschain-oracles [chain-name] [initial proposal stake]", - Short: "update cross chain oracles", - Example: "fxcored tx crosschain update-crosschain-oracles bsc 100000000000000000000FX --title=\"Update Bsc chain oracles\", --desc=\"oracles description\" --oracles ", - Args: cobra.ExactArgs(2), + Use: "create-oracle-bridger [validator-address] [bridger-address] [external-address] [delegate-amount]", + Short: "Allows oracle to delegate their voting responsibilities to a given key.", + Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { cliCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - chainName := args[0] - initProposalAmount, err := sdk.ParseCoinsNormalized(args[1]) + valAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { return err } - title, err := cmd.Flags().GetString(flagProposalTitle) + bridgerAddr, err := sdk.AccAddressFromBech32(args[1]) if err != nil { return err } - description, err := cmd.Flags().GetString(flagProposalDescription) + externalAddress, err := getContractAddr(args[2]) if err != nil { return err } - - oracles, err := cmd.Flags().GetStringSlice(flagInitParamsOracles) - if err != nil { - return err - } - for i, oracle := range oracles { - oracleAddr, err := sdk.AccAddressFromBech32(oracle) - if err != nil { - return err - } - oracles[i] = oracleAddr.String() - } - proposal := &types.UpdateChainOraclesProposal{ - Title: title, - Description: description, - Oracles: oracles, - ChainName: chainName, - } - fromAddress := cliCtx.GetFromAddress() - msg, err := govtypes.NewMsgSubmitProposal(proposal, initProposalAmount, fromAddress) - if err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg) - }, - } - flags.AddTxFlagsToCmd(cmd) - cmd.Flags().String(flagProposalTitle, "", "proposal title") - cmd.Flags().String(flagProposalDescription, "", "proposal desc") - cmd.Flags().StringSlice(flagInitParamsOracles, nil, "list of Oracles that have permission to participate in consensus, using comma split") - return cmd -} - -func CmdCreateOracleBridger() *cobra.Command { - cmd := &cobra.Command{ - Use: "create-oracle-bridger [chain-name] [validator-address] [bridger-address] [external-address] [delegate-amount]", - Short: "Allows oracle to delegate their voting responsibilities to a given key.", - Args: cobra.ExactArgs(5), - RunE: func(cmd *cobra.Command, args []string) error { - cliCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - valAddr, err := sdk.ValAddressFromBech32(args[1]) - if err != nil { - return err - } - bridgerAddr, err := sdk.AccAddressFromBech32(args[2]) - if err != nil { - return err - } - externalAddress := args[3] - amount, err := sdk.ParseCoinNormalized(args[4]) + amount, err := sdk.ParseCoinNormalized(args[3]) if err != nil { return err } @@ -144,65 +90,60 @@ func CmdCreateOracleBridger() *cobra.Command { ExternalAddress: externalAddress, ValidatorAddress: valAddr.String(), DelegateAmount: amount, - ChainName: args[0], + ChainName: chainName, } return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg) }, } - flags.AddTxFlagsToCmd(cmd) return cmd } -func CmdAddOracleDelegate() *cobra.Command { +func CmdAddOracleDelegate(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "add-oracle-delegate [chain-name] [delegate-amount]", + Use: "add-oracle-delegate [delegate-amount]", Short: "Allows oracle add delegate.", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - amount, err := sdk.ParseCoinNormalized(args[1]) + amount, err := sdk.ParseCoinNormalized(args[0]) if err != nil { return err } msg := types.MsgAddDelegate{ OracleAddress: cliCtx.GetFromAddress().String(), Amount: amount, - ChainName: args[0], + ChainName: chainName, } return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg) }, } - flags.AddTxFlagsToCmd(cmd) return cmd } -func CmdSendToExternal() *cobra.Command { +func CmdSendToExternal(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "send-to-external [chain-name] [external-dest] [amount] [bridge-fee]", - Short: "Adds a new entry to the transaction pool to withdraw an amount from the Ethereum bridge contract", - Args: cobra.ExactArgs(4), + Use: "send-to-external [external-dest] [amount] [bridge-fee]", + Short: "Adds a new entry to the transaction pool to withdraw an amount from the bridge contract", + Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { cliCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - externalDestAddr := args[1] - if strings.HasPrefix(externalDestAddr, "0x") { - if !gethcommon.IsHexAddress(externalDestAddr) { - return fmt.Errorf("target address is invalid!address: [%s]", externalDestAddr) - } - externalDestAddr = gethcommon.HexToAddress(externalDestAddr).Hex() - } - amount, err := sdk.ParseCoinNormalized(args[2]) + externalDestAddr, err := getContractAddr(args[0]) + if err != nil { + return err + } + amount, err := sdk.ParseCoinNormalized(args[1]) if err != nil { return sdkerrors.Wrap(err, "amount") } - bridgeFee, err := sdk.ParseCoinNormalized(args[3]) + bridgeFee, err := sdk.ParseCoinNormalized(args[2]) if err != nil { return sdkerrors.Wrap(err, "bridge fee") } @@ -212,46 +153,43 @@ func CmdSendToExternal() *cobra.Command { Dest: externalDestAddr, Amount: amount, BridgeFee: bridgeFee, - ChainName: args[0], + ChainName: chainName, } return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg) }, } - flags.AddTxFlagsToCmd(cmd) return cmd } -func CmdCancelSendToExternal() *cobra.Command { +func CmdCancelSendToExternal(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "cancel-send-to-external [chain-name] [tx-ID]", + Use: "cancel-send-to-external [tx-ID]", Short: "Cancel transaction send to external", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } - txId, err := strconv.ParseUint(args[1], 10, 64) + txId, err := strconv.ParseUint(args[0], 10, 64) if err != nil { return err } - msg := &types.MsgCancelSendToExternal{ TransactionId: txId, Sender: cliCtx.GetFromAddress().String(), - ChainName: args[0], + ChainName: chainName, } return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg) }, } - flags.AddTxFlagsToCmd(cmd) return cmd } -func CmdRequestBatch() *cobra.Command { +func CmdRequestBatch(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "build-batch [chain-name] [token-denom] [minimum-fee] [external-fee-receive]", + Use: "build-batch [token-denom] [minimum-fee] [base-fee] [external-fee-receive]", Short: "Build a new batch on the fx side for pooled withdrawal transactions", Args: cobra.ExactArgs(4), RunE: func(cmd *cobra.Command, args []string) error { @@ -259,10 +197,18 @@ func CmdRequestBatch() *cobra.Command { if err != nil { return err } + denom := args[0] - minimumFee, ok := sdk.NewIntFromString(args[2]) + minimumFee, ok := sdk.NewIntFromString(args[1]) if !ok || minimumFee.IsNegative() { - return fmt.Errorf("miniumu fee is valid, %v\n", args[2]) + return fmt.Errorf("miniumu fee is valid, %v", args[1]) + } + baseFee := sdk.ZeroInt() + if len(args[2]) > 0 { + baseFee, ok = sdk.NewIntFromString(args[2]) + if !ok { + return fmt.Errorf("invalid base fee: %v", args[2]) + } } feeReceive := args[3] if strings.HasPrefix(feeReceive, "0x") { @@ -271,58 +217,41 @@ func CmdRequestBatch() *cobra.Command { } feeReceive = gethcommon.HexToAddress(feeReceive).Hex() } - baseFee := sdk.ZeroInt() - baseFeeStr, err := cmd.Flags().GetString("base-fee") - if err == nil { - baseFeeStr = strings.TrimSpace(baseFeeStr) - if len(baseFeeStr) > 0 { - baseFee, ok = sdk.NewIntFromString(baseFeeStr) - if !ok { - return fmt.Errorf("invalid baseFee:%v", baseFeeStr) - } - } - } msg := &types.MsgRequestBatch{ Sender: clientCtx.GetFromAddress().String(), - Denom: args[1], + Denom: denom, MinimumFee: minimumFee, FeeReceive: feeReceive, - ChainName: args[0], + ChainName: chainName, BaseFee: baseFee, } return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } - cmd.Flags().String("base-fee", "", "requestBatch baseFee, is empty is sdk.ZeroInt") - flags.AddTxFlagsToCmd(cmd) return cmd } -func CmdRequestBatchConfirm() *cobra.Command { +func CmdRequestBatchConfirm(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "request-batch-confirm [chain-name] [contract-address] [nonce] [private-key]", + Use: "request-batch-confirm [contract-address] [nonce] [private-key]", Short: "Send batch confirm msg", - Args: cobra.ExactArgs(4), + Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } fromAddress := clientCtx.GetFromAddress() - tokenContract := args[1] - if strings.HasPrefix(tokenContract, "0x") { - if !gethcommon.IsHexAddress(tokenContract) { - return fmt.Errorf("invalid contract address:%v", tokenContract) - } - tokenContract = gethcommon.HexToAddress(tokenContract).Hex() - } - nonce, err := strconv.ParseUint(args[2], 10, 64) + tokenContract, err := getContractAddr(args[0]) if err != nil { return err } - - privateKey, err := recoveryPrivateKeyByKeystore(args[3]) + nonce, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + privateKey, err := recoveryPrivateKeyByKeystore(args[2]) if err != nil { return err } @@ -332,36 +261,31 @@ func CmdRequestBatchConfirm() *cobra.Command { batchRequestByNonceResp, err := queryClient.BatchRequestByNonce(cmd.Context(), &types.QueryBatchRequestByNonceRequest{ Nonce: nonce, TokenContract: tokenContract, - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } if batchRequestByNonceResp.Batch == nil { - return fmt.Errorf("not found batch request by nonce!!!tokenContract:[%v], nonce:[%v]", tokenContract, nonce) + return fmt.Errorf("not found batch request by nonce, tokenContract: %v, nonce: %v", tokenContract, nonce) } // Determine whether it has been confirmed batchConfirmResp, err := queryClient.BatchConfirm(cmd.Context(), &types.QueryBatchConfirmRequest{ Nonce: nonce, TokenContract: tokenContract, BridgerAddress: fromAddress.String(), - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } if batchConfirmResp.GetConfirm() != nil { confirm := batchConfirmResp.GetConfirm() - return clientCtx.PrintString(fmt.Sprintf(`already confirm requestBatch: - nonce:[%v] - tokenContract:[%v] - bridgerAddress:[%v] - externalAddress:[%v] - signature:[%v] -`, - confirm.Nonce, confirm.TokenContract, confirm.BridgerAddress, confirm.ExternalAddress, confirm.Signature)) - } - paramsResp, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{ChainName: args[0]}) + return clientCtx.PrintProto(confirm) + } + paramsResp, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{ + ChainName: chainName, + }) if err != nil { return err } @@ -379,20 +303,19 @@ func CmdRequestBatchConfirm() *cobra.Command { ExternalAddress: externalAddress.String(), BridgerAddress: fromAddress.String(), Signature: hex.EncodeToString(signature), - ChainName: args[0], + ChainName: chainName, } return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } - flags.AddTxFlagsToCmd(cmd) return cmd } -func CmdOracleSetConfirm() *cobra.Command { +func CmdOracleSetConfirm(chainName string) *cobra.Command { cmd := &cobra.Command{ - Use: "oracle-set-confirm [chain-name] [nonce] [private-key]", + Use: "oracle-set-confirm [nonce] [private-key]", Short: "Send oracle-set confirm msg", - Args: cobra.ExactArgs(3), + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { @@ -400,18 +323,20 @@ func CmdOracleSetConfirm() *cobra.Command { } fromAddress := clientCtx.GetFromAddress() - nonce, err := strconv.ParseUint(args[1], 10, 64) + nonce, err := strconv.ParseUint(args[0], 10, 64) if err != nil { return err } - privateKey, err := recoveryPrivateKeyByKeystore(args[2]) + privateKey, err := recoveryPrivateKeyByKeystore(args[1]) if err != nil { return err } externalAddress := ethcrypto.PubkeyToAddress(privateKey.PublicKey) queryClient := types.NewQueryClient(clientCtx) - oracleSetRequestResp, err := queryClient.OracleSetRequest(cmd.Context(), &types.QueryOracleSetRequestRequest{Nonce: nonce, ChainName: args[0]}) + oracleSetRequestResp, err := queryClient.OracleSetRequest(cmd.Context(), &types.QueryOracleSetRequestRequest{ + Nonce: nonce, ChainName: chainName, + }) if err != nil { return err } @@ -419,22 +344,17 @@ func CmdOracleSetConfirm() *cobra.Command { oracleSetConfirmResp, err := queryClient.OracleSetConfirm(cmd.Context(), &types.QueryOracleSetConfirmRequest{ Nonce: nonce, BridgerAddress: fromAddress.String(), - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err } if oracleSetConfirmResp.GetConfirm() != nil { confirm := oracleSetConfirmResp.GetConfirm() - return fmt.Errorf(`already confirm oracleSet: - nonce:[%v] - bridgerAddress:[%v] - externalAddress:[%v] - signature:[%v] -`, confirm.Nonce, confirm.BridgerAddress, confirm.ExternalAddress, confirm.Signature) + return clientCtx.PrintProto(confirm) } paramsResp, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{ - ChainName: args[0], + ChainName: chainName, }) if err != nil { return err @@ -452,12 +372,11 @@ func CmdOracleSetConfirm() *cobra.Command { BridgerAddress: fromAddress.String(), ExternalAddress: externalAddress.String(), Signature: hex.EncodeToString(signature), - ChainName: args[0], + ChainName: chainName, } return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } - flags.AddTxFlagsToCmd(cmd) return cmd } @@ -487,3 +406,19 @@ func recoveryPrivateKeyByKeystore(privateKey string) (*ecdsa.PrivateKey, error) } return ethPrivateKey, nil } + +func getContractAddr(addr string) (string, error) { + if strings.HasPrefix(addr, "0x") { + if !gethcommon.IsHexAddress(addr) { + return "", fmt.Errorf("invalid address: %s", addr) + } + addr = gethcommon.HexToAddress(addr).Hex() + } else { + tronAddr, err := troncommon.DecodeCheck(addr) + if err != nil { + return "", fmt.Errorf("doesn't pass format validation: %s", addr) + } + addr = troncommon.EncodeCheck(tronAddr) + } + return addr, nil +} diff --git a/x/crosschain/client/cli/tx_proposal.go b/x/crosschain/client/cli/tx_proposal.go new file mode 100644 index 000000000..753b0b525 --- /dev/null +++ b/x/crosschain/client/cli/tx_proposal.go @@ -0,0 +1,76 @@ +// nolint:staticcheck +package cli + +import ( + "strings" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/crosschain/types" +) + +func CmdUpdateChainOraclesProposal(chainName string) *cobra.Command { + cmd := &cobra.Command{ + Use: "update-crosschain-oracles [oracles]", + Short: "Submit a update cross chain oracles proposal", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + title, err := cmd.Flags().GetString(cli.FlagTitle) + if err != nil { + return err + } + + description, err := cmd.Flags().GetString(cli.FlagDescription) + if err != nil { + return err + } + + depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) + if err != nil { + return err + } + deposit, err := sdk.ParseCoinsNormalized(depositStr) + if err != nil { + return err + } + + oracles := strings.Split(args[0], ",") + for i, oracle := range oracles { + oracleAddr, err := sdk.AccAddressFromBech32(oracle) + if err != nil { + return err + } + oracles[i] = oracleAddr.String() + } + proposal := &types.UpdateChainOraclesProposal{ + Title: title, + Description: description, + Oracles: oracles, + ChainName: chainName, + } + fromAddress := cliCtx.GetFromAddress() + msg, err := govtypes.NewMsgSubmitProposal(proposal, deposit, fromAddress) + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), msg) + }, + } + cmd.Flags().String(cli.FlagTitle, "", "title of proposal") + cmd.Flags().String(cli.FlagDescription, "", "description of proposal") + cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") + _ = cmd.MarkFlagRequired(cli.FlagTitle) + _ = cmd.MarkFlagRequired(cli.FlagDescription) + _ = cmd.MarkFlagRequired(cli.FlagDeposit) + return cmd +} diff --git a/x/crosschain/client/proposal_handler.go b/x/crosschain/client/proposal_handler.go new file mode 100644 index 000000000..c7e837996 --- /dev/null +++ b/x/crosschain/client/proposal_handler.go @@ -0,0 +1,25 @@ +package client + +import ( + "github.com/cosmos/cosmos-sdk/client" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" +) + +var UpdateChainOraclesProposalHandler = govclient.NewProposalHandler(NewLegacyUpdateChainOraclesProposalCmd, func(context client.Context) govrest.ProposalRESTHandler { + return govrest.ProposalRESTHandler{ + SubRoute: "update_chain_oracles", + Handler: nil, + } +}) + +func NewLegacyUpdateChainOraclesProposalCmd() *cobra.Command { + var chainName string + cmd := cli.CmdUpdateChainOraclesProposal(chainName) + cmd.Flags().StringVarP(&chainName, "chain-name", "", "", "cross chain name") + _ = cmd.MarkFlagRequired("chain-name") + return cmd +} diff --git a/x/eth/client/cli/query.go b/x/eth/client/cli/query.go new file mode 100644 index 000000000..912085535 --- /dev/null +++ b/x/eth/client/cli/query.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" + "github.com/functionx/fx-core/v3/x/eth/types" +) + +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the eth module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetQuerySubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/eth/client/cli/tx.go b/x/eth/client/cli/tx.go new file mode 100644 index 000000000..e60975959 --- /dev/null +++ b/x/eth/client/cli/tx.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" + "github.com/functionx/fx-core/v3/x/eth/types" +) + +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "ETH transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetTxSubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/eth/module.go b/x/eth/module.go index 88cc9901a..e70e3d705 100644 --- a/x/eth/module.go +++ b/x/eth/module.go @@ -16,6 +16,7 @@ import ( crosschainkeeper "github.com/functionx/fx-core/v3/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v3/x/crosschain/types" + "github.com/functionx/fx-core/v3/x/eth/client/cli" "github.com/functionx/fx-core/v3/x/eth/types" ) @@ -61,12 +62,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.Ser // GetQueryCmd implements app module basic func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil + return cli.GetQueryCmd() } // GetTxCmd implements app module basic func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil + return cli.GetTxCmd() } // RegisterInterfaces implements app bmodule basic diff --git a/x/polygon/client/cli/query.go b/x/polygon/client/cli/query.go new file mode 100644 index 000000000..40d015f08 --- /dev/null +++ b/x/polygon/client/cli/query.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" + "github.com/functionx/fx-core/v3/x/polygon/types" +) + +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the polygon module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetQuerySubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/polygon/client/cli/tx.go b/x/polygon/client/cli/tx.go new file mode 100644 index 000000000..18e71d166 --- /dev/null +++ b/x/polygon/client/cli/tx.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" + "github.com/functionx/fx-core/v3/x/polygon/types" +) + +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Polygon transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetTxSubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/polygon/module.go b/x/polygon/module.go index 74954a3b8..e20291409 100644 --- a/x/polygon/module.go +++ b/x/polygon/module.go @@ -16,6 +16,7 @@ import ( crosschainkeeper "github.com/functionx/fx-core/v3/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v3/x/crosschain/types" + "github.com/functionx/fx-core/v3/x/polygon/client/cli" "github.com/functionx/fx-core/v3/x/polygon/types" ) @@ -54,12 +55,12 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} // GetQueryCmd implements app module basic func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil + return cli.GetQueryCmd() } // GetTxCmd implements app module basic func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil + return cli.GetTxCmd() } // RegisterGRPCGatewayRoutes registers the gRPC Gateway diff --git a/x/tron/client/cli/query.go b/x/tron/client/cli/query.go new file mode 100644 index 000000000..223091b61 --- /dev/null +++ b/x/tron/client/cli/query.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" + "github.com/functionx/fx-core/v3/x/tron/types" +) + +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the tron module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetQuerySubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/tron/client/cli/tx.go b/x/tron/client/cli/tx.go new file mode 100644 index 000000000..34e15bac6 --- /dev/null +++ b/x/tron/client/cli/tx.go @@ -0,0 +1,21 @@ +package cli + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v3/x/crosschain/client/cli" + "github.com/functionx/fx-core/v3/x/tron/types" +) + +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Tron transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + cmd.AddCommand(cli.GetTxSubCmds(types.ModuleName)...) + return cmd +} diff --git a/x/tron/module.go b/x/tron/module.go index f3dc5bd45..060fe8aa2 100644 --- a/x/tron/module.go +++ b/x/tron/module.go @@ -16,6 +16,7 @@ import ( crosschainkeeper "github.com/functionx/fx-core/v3/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v3/x/crosschain/types" + "github.com/functionx/fx-core/v3/x/tron/client/cli" "github.com/functionx/fx-core/v3/x/tron/keeper" "github.com/functionx/fx-core/v3/x/tron/types" ) @@ -55,12 +56,12 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} // GetQueryCmd implements app module basic func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil + return cli.GetQueryCmd() } // GetTxCmd implements app module basic func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil + return cli.GetTxCmd() } // RegisterGRPCGatewayRoutes registers the gRPC Gateway