diff --git a/x/arbitrum/module.go b/x/arbitrum/module.go index 8225bb17..796b4467 100644 --- a/x/arbitrum/module.go +++ b/x/arbitrum/module.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/cobra" "github.com/functionx/fx-core/v8/x/arbitrum/types" + "github.com/functionx/fx-core/v8/x/crosschain" crosschaincli "github.com/functionx/fx-core/v8/x/crosschain/client/cli" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types" @@ -81,6 +82,7 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} // AppModule object for module implementation type AppModule struct { + crosschain.AutoCLIAppModule AppModuleBasic keeper crosschainkeeper.Keeper } @@ -88,8 +90,9 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, + AutoCLIAppModule: crosschain.AutoCLIAppModule{ModuleName: types.ModuleName}, + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, } } diff --git a/x/avalanche/module.go b/x/avalanche/module.go index c5d7c38f..a26da9d6 100644 --- a/x/avalanche/module.go +++ b/x/avalanche/module.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/cobra" "github.com/functionx/fx-core/v8/x/avalanche/types" + "github.com/functionx/fx-core/v8/x/crosschain" crosschaincli "github.com/functionx/fx-core/v8/x/crosschain/client/cli" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types" @@ -81,6 +82,7 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} // AppModule object for module implementation type AppModule struct { + crosschain.AutoCLIAppModule AppModuleBasic keeper crosschainkeeper.Keeper } @@ -88,8 +90,9 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, + AutoCLIAppModule: crosschain.AutoCLIAppModule{ModuleName: types.ModuleName}, + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, } } diff --git a/x/bsc/module.go b/x/bsc/module.go index 391aa06e..850d8e5f 100644 --- a/x/bsc/module.go +++ b/x/bsc/module.go @@ -16,6 +16,7 @@ import ( "github.com/spf13/cobra" "github.com/functionx/fx-core/v8/x/bsc/types" + "github.com/functionx/fx-core/v8/x/crosschain" crosschaincli "github.com/functionx/fx-core/v8/x/crosschain/client/cli" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types" @@ -81,6 +82,7 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} // AppModule object for module implementation type AppModule struct { + crosschain.AutoCLIAppModule AppModuleBasic keeper crosschainkeeper.Keeper } @@ -88,8 +90,9 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, + AutoCLIAppModule: crosschain.AutoCLIAppModule{ModuleName: types.ModuleName}, + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, } } diff --git a/x/crosschain/autocli.go b/x/crosschain/autocli.go new file mode 100644 index 00000000..5b754dff --- /dev/null +++ b/x/crosschain/autocli.go @@ -0,0 +1,69 @@ +package crosschain + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + + crosschainv1 "github.com/functionx/fx-core/v8/api/fx/gravity/crosschain/v1" +) + +type AutoCLIAppModule struct { + ModuleName string +} + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AutoCLIAppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + // add chain_name flag to all rpc commands + rpcCommandOptions := make([]*autocliv1.RpcCommandOptions, 0, len(crosschainv1.Query_ServiceDesc.Methods)) + for _, method := range crosschainv1.Query_ServiceDesc.Methods { + // exclude QueryBridgeChainListRequest, because it does not have chain_name flag + if method.MethodName == "BridgeChainList" { + continue + } + + rpcCommandOptions = append(rpcCommandOptions, &autocliv1.RpcCommandOptions{ + RpcMethod: method.MethodName, + FlagOptions: map[string]*autocliv1.FlagOptions{ + "chain_name": { + DefaultValue: am.ModuleName, + }, + }, + }) + } + + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: crosschainv1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: rpcCommandOptions, + EnhanceCustomCommand: true, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: crosschainv1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + // skipped because deprecated + { + RpcMethod: "OracleSetConfirm", + Skip: true, + }, + { + RpcMethod: "ConfirmBatch", + Skip: true, + }, + { + RpcMethod: "BridgeCallConfirm", + Skip: true, + }, + + // skipped because authority gated + { + RpcMethod: "UpdateParams", + Skip: true, + }, + { + RpcMethod: "UpdateChainOracles", + Skip: true, + }, + }, + EnhanceCustomCommand: true, + }, + } +} diff --git a/x/crosschain/client/cli/query.go b/x/crosschain/client/cli/query.go index 5ff2bf81..26a6a5bb 100644 --- a/x/crosschain/client/cli/query.go +++ b/x/crosschain/client/cli/query.go @@ -36,58 +36,20 @@ func GetQueryCmd(moduleName string, subNames ...string) *cobra.Command { func getQuerySubCmds(chainName string) []*cobra.Command { cmds := []*cobra.Command{ - // query module params - CmdGetParams(chainName), - // query Oracle CmdGetOracle(chainName), - CmdGetOracles(chainName), CmdGetOracleReward(chainName), CmdGetOracleDelegateAddr(chainName), CmdGetProposalOracles(chainName), // query oracle set - CmdGetCurrentOracleSet(chainName), CmdGetOracleSetRequest(chainName), - // need oracle consensus sign - // oracle set change confirm - CmdGetLastOracleSetRequests(chainName), - CmdGetPendingOracleSetRequest(chainName), - CmdGetOracleSetConfirm(chainName), - CmdGetOracleSetConfirms(chainName), - // request batch confirm - CmdGetPendingOutgoingTXBatchRequest(chainName), - CmdBatchConfirm(chainName), - CmdBatchConfirms(chainName), - - // send to external - CmdOutgoingTxBatch(chainName), - CmdOutgoingTxBatches(chainName), - - CmdGetLastObservedBlockHeight(chainName), - CmdProjectedBatchTimeoutHeight(chainName), - // denom <-> external token - CmdGetDenomToExternalToken(chainName), - CmdGetExternalTokenToDenom(chainName), - CmdGetBridgeTokens(chainName), - CmdGetBridgeCoinByDenom(chainName), CmdCovertBridgeToken(chainName), - + // // event nonce - CmdGetOracleEventNonce(chainName), - CmdGetOracleEventBlockHeight(chainName), CmdGetLastObservedEventNonce(chainName), - - // bridge call - CmdGetBridgeCalls(chainName), - CmdGetBridgeCall(chainName), - CmdBridgeCallByAddr(chainName), - CmdBridgeCallConfirm(chainName), - CmdLastPendingBridgeCall(chainName), - - CmdGetPendingExecuteClaim(chainName), } for _, command := range cmds { @@ -96,48 +58,6 @@ func getQuerySubCmds(chainName string) []*cobra.Command { return cmds } -func CmdGetParams(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "params", - Short: "Query the current parameters information", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{ - ChainName: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(&res.Params) - }, - } - return cmd -} - -func CmdGetOracles(chainName string) *cobra.Command { - cmd := &cobra.Command{ - 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: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - func CmdGetProposalOracles(chainName string) *cobra.Command { cmd := &cobra.Command{ Use: "proposal-oracles", @@ -251,27 +171,6 @@ func CmdGetOracle(chainName string) *cobra.Command { return cmd } -func CmdGetCurrentOracleSet(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "current-oracle-set", - Short: "Query current oracle-set", - 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: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res.OracleSet) - }, - } - return cmd -} - func CmdGetOracleSetRequest(chainName string) *cobra.Command { cmd := &cobra.Command{ Use: "oracle-set-request [nonce]", @@ -283,14 +182,14 @@ func CmdGetOracleSetRequest(chainName string) *cobra.Command { var nonce uint64 if len(args) == 0 { - queryAbciResp, err := clientCtx.QueryABCI(abcitype.RequestQuery{ + queryABCIResp, err := clientCtx.QueryABCI(abcitype.RequestQuery{ Path: fmt.Sprintf("store/%s/key", chainName), Data: types.LatestOracleSetNonce, }) if err != nil { return err } - nonce = sdk.BigEndianToUint64(queryAbciResp.Value) + nonce = sdk.BigEndianToUint64(queryABCIResp.Value) } else { var err error nonce, err = strconv.ParseUint(args[0], 10, 64) @@ -311,396 +210,6 @@ func CmdGetOracleSetRequest(chainName string) *cobra.Command { return cmd } -func CmdGetLastOracleSetRequests(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "last-oracle-set-requests", - Short: "Query last oracle set requests", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.LastOracleSetRequests(cmd.Context(), &types.QueryLastOracleSetRequestsRequest{ - ChainName: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetPendingOracleSetRequest(chainName string) *cobra.Command { - cmd := &cobra.Command{ - 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(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - bridgerAddr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - res, err := queryClient.LastPendingOracleSetRequestByAddr(cmd.Context(), &types.QueryLastPendingOracleSetRequestByAddrRequest{ - BridgerAddress: bridgerAddr.String(), - ChainName: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetOracleSetConfirm(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "oracle-set-confirm [nonce] [bridger-address]", - Short: "Query oracle-set confirmation with a particular nonce from a particular oracle bridger", - 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[0], 10, 64) - if err != nil { - return err - } - 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: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res.Confirm) - }, - } - return cmd -} - -func CmdGetOracleSetConfirms(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "oracle-set-confirms [nonce]", - Short: "Query oracle-set confirmations with a particular nonce", - 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[0], 10, 64) - if err != nil { - return err - } - res, err := queryClient.OracleSetConfirmsByNonce(cmd.Context(), &types.QueryOracleSetConfirmsByNonceRequest{ - Nonce: nonce, - ChainName: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetPendingOutgoingTXBatchRequest(chainName string) *cobra.Command { - cmd := &cobra.Command{ - 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(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - bridgerAddr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - res, err := queryClient.LastPendingBatchRequestByAddr(cmd.Context(), &types.QueryLastPendingBatchRequestByAddrRequest{ - BridgerAddress: bridgerAddr.String(), - ChainName: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res.Batch) - }, - } - return cmd -} - -func CmdBatchConfirm(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "batch-confirm [token-contract] [nonce] [bridger-address]", - Short: "Query outgoing tx batches confirm by oracle bridger address", - Args: cobra.ExactArgs(3), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - tokenContract := args[0] - if err := types.ValidateExternalAddr(chainName, tokenContract); err != nil { - return err - } - nonce, err := strconv.ParseUint(args[1], 10, 64) - if err != nil { - return err - } - bridgerAddr, err := sdk.AccAddressFromBech32(args[2]) - if err != nil { - return err - } - res, err := queryClient.BatchConfirm(cmd.Context(), &types.QueryBatchConfirmRequest{ - ChainName: chainName, - TokenContract: tokenContract, - Nonce: nonce, - BridgerAddress: bridgerAddr.String(), - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res.Confirm) - }, - } - return cmd -} - -func CmdBatchConfirms(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "batch-confirms [token-contract] [nonce]", - Short: "Query outgoing tx batches confirms", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - tokenContract := args[0] - if err := types.ValidateExternalAddr(chainName, tokenContract); err != nil { - return err - } - 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: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdOutgoingTxBatch(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "outgoing-tx-batch [token-contract] [nonce]", - Short: "Query outgoing tx batches", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - tokenContract := args[0] - if err := types.ValidateExternalAddr(chainName, tokenContract); err != nil { - return err - } - nonce, err := strconv.ParseUint(args[1], 10, 64) - if err != nil { - return err - } - res, err := queryClient.OutgoingTxBatch(cmd.Context(), &types.QueryOutgoingTxBatchRequest{ - ChainName: chainName, - TokenContract: tokenContract, - Nonce: nonce, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res.Batch) - }, - } - return cmd -} - -func CmdOutgoingTxBatches(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "outgoing-tx-batches", - Short: "Query outgoing tx batches", - 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: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetLastObservedBlockHeight(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "last-observed-block-height", - Short: "Query last observed block height", - 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: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdProjectedBatchTimeoutHeight(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "projected-batch-timeout-height", - Short: "Query projected batch timeout height", - 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: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetDenomToExternalToken(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "token [denom]", - Short: "Query contract address from denom", - 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: chainName, - Denom: denom, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetExternalTokenToDenom(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "denom [token-contract]", - Short: "Query denom from contract address", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - tokenContract := args[0] - if err := types.ValidateExternalAddr(chainName, tokenContract); err != nil { - return err - } - res, err := queryClient.TokenToDenom(cmd.Context(), &types.QueryTokenToDenomRequest{ - ChainName: chainName, - Token: tokenContract, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetBridgeTokens(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "bridge-tokens", - Short: "Query bridge token list", - 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: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetOracleEventNonce(chainName string) *cobra.Command { - cmd := &cobra.Command{ - 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[0]) - if err != nil { - return err - } - res, err := queryClient.LastEventNonceByAddr(cmd.Context(), &types.QueryLastEventNonceByAddrRequest{ - ChainName: chainName, - BridgerAddress: bridgerAddr.String(), - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - func CmdGetLastObservedEventNonce(chainName string) *cobra.Command { cmd := &cobra.Command{ Use: "last-observed-nonce", @@ -709,40 +218,14 @@ func CmdGetLastObservedEventNonce(chainName string) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - queryAbciResp, err := clientCtx.QueryABCI(abcitype.RequestQuery{ + queryABCIResp, err := clientCtx.QueryABCI(abcitype.RequestQuery{ Path: fmt.Sprintf("store/%s/key", chainName), Data: types.LastObservedEventNonceKey, }) if err != nil { return err } - return clientCtx.PrintString(fmt.Sprintf("%d\n", sdk.BigEndianToUint64(queryAbciResp.Value))) - }, - } - return cmd -} - -func CmdGetOracleEventBlockHeight(chainName string) *cobra.Command { - cmd := &cobra.Command{ - 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[0]) - if err != nil { - return err - } - res, err := queryClient.LastEventBlockHeightByAddr(cmd.Context(), &types.QueryLastEventBlockHeightByAddrRequest{ - BridgerAddress: bridgerAddr.String(), - ChainName: chainName, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) + return clientCtx.PrintString(fmt.Sprintf("%d\n", sdk.BigEndianToUint64(queryABCIResp.Value))) }, } return cmd @@ -782,189 +265,3 @@ func CmdCovertBridgeToken(chainName string) *cobra.Command { } return cmd } - -func CmdGetBridgeCoinByDenom(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "bridge-coin [denom]", - Short: "Query bridge coin from contract address", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - denom := args[0] - res, err := queryClient.BridgeCoinByDenom(cmd.Context(), &types.QueryBridgeCoinByDenomRequest{ - ChainName: chainName, - Denom: denom, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetBridgeCalls(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "bridge-calls", - Short: "Query bridge calls", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - res, err := queryClient.BridgeCalls(cmd.Context(), &types.QueryBridgeCallsRequest{ - ChainName: chainName, - Pagination: pageReq, - }) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - flags.AddPaginationFlagsToCmd(cmd, "bridge calls") - return cmd -} - -func CmdGetBridgeCall(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "bridge-call [nonce]", - Short: "Query bridge call by event nonce", - 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[0], 10, 64) - if err != nil { - return err - } - - res, err := queryClient.BridgeCallByNonce(cmd.Context(), &types.QueryBridgeCallByNonceRequest{ - ChainName: chainName, - Nonce: nonce, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdBridgeCallByAddr(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "bridge-call-by-sender [address]", - Short: "Query bridge call by sender", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - senderAddr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - res, err := queryClient.BridgeCallBySender(cmd.Context(), &types.QueryBridgeCallBySenderRequest{ - ChainName: chainName, - SenderAddress: senderAddr.String(), - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdBridgeCallConfirm(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "bridge-call-confirm [nonce]", - Short: "Query bridge call confirm by event nonce", - 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[0], 10, 64) - if err != nil { - return err - } - - res, err := queryClient.BridgeCallConfirmByNonce(cmd.Context(), &types.QueryBridgeCallConfirmByNonceRequest{ - ChainName: chainName, - EventNonce: nonce, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdLastPendingBridgeCall(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "last-pending-bridge-call [bridger-address]", - Short: "Query last pending bridge call for 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[0]) - if err != nil { - return err - } - res, err := queryClient.LastPendingBridgeCallByAddr(cmd.Context(), &types.QueryLastPendingBridgeCallByAddrRequest{ - ChainName: chainName, - BridgerAddress: bridgerAddr.String(), - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - return cmd -} - -func CmdGetPendingExecuteClaim(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "pending-execute-claim", - Short: "Query pending execute claim", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) - - pageReq, err := client.ReadPageRequest(cmd.Flags()) - if err != nil { - return err - } - - res, err := queryClient.PendingExecuteClaim(cmd.Context(), &types.QueryPendingExecuteClaimRequest{ - ChainName: chainName, - Pagination: pageReq, - }) - if err != nil { - return err - } - return clientCtx.PrintProto(res) - }, - } - flags.AddPaginationFlagsToCmd(cmd, "pending execute claim") - return cmd -} diff --git a/x/crosschain/client/cli/tx.go b/x/crosschain/client/cli/tx.go index 22ae4972..74122cb4 100644 --- a/x/crosschain/client/cli/tx.go +++ b/x/crosschain/client/cli/tx.go @@ -12,7 +12,6 @@ import ( "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/ethereum/go-ethereum/accounts/keystore" ethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/spf13/cobra" @@ -39,14 +38,6 @@ func GetTxCmd(moduleName string, subNames ...string) *cobra.Command { func getTxSubCmds(chainName string) []*cobra.Command { cmds := []*cobra.Command{ - CmdBoundedOracle(chainName), - CmdUnboundedOracle(chainName), - CmdReDelegate(chainName), - CmdAddDelegate(chainName), - - // send to external chain - CmdSendToExternal(chainName), - // oracle consensus confirm CmdOracleSetConfirm(chainName), CmdRequestBatchConfirm(chainName), @@ -57,135 +48,6 @@ func getTxSubCmds(chainName string) []*cobra.Command { return cmds } -func CmdBoundedOracle(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "bounded-oracle [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 - } - amount, err := sdk.ParseCoinNormalized(args[3]) - if err != nil { - return err - } - msg := types.MsgBondedOracle{ - OracleAddress: cliCtx.GetFromAddress().String(), - ValidatorAddress: args[0], - BridgerAddress: args[1], - ExternalAddress: args[2], - DelegateAmount: amount, - ChainName: chainName, - } - return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg) - }, - } - return cmd -} - -func CmdUnboundedOracle(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "unbounded-oracle", - Short: "Quit the oracle", - Args: cobra.ExactArgs(4), - RunE: func(cmd *cobra.Command, args []string) error { - cliCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - msg := types.MsgUnbondedOracle{ - OracleAddress: cliCtx.GetFromAddress().String(), - ChainName: chainName, - } - return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg) - }, - } - return cmd -} - -func CmdAddDelegate(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "add-delegate [delegate-amount]", - Short: "Allows oracle add delegate.", - 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[0]) - if err != nil { - return err - } - msg := types.MsgAddDelegate{ - OracleAddress: cliCtx.GetFromAddress().String(), - Amount: amount, - ChainName: chainName, - } - return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg) - }, - } - return cmd -} - -func CmdReDelegate(chainName string) *cobra.Command { - cmd := &cobra.Command{ - Use: "re-delegate [validator-address]", - Short: "Allows oracle re delegate.", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - cliCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.MsgReDelegate{ - OracleAddress: cliCtx.GetFromAddress().String(), - ValidatorAddress: args[0], - ChainName: chainName, - } - return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg) - }, - } - return cmd -} - -func CmdSendToExternal(chainName string) *cobra.Command { - cmd := &cobra.Command{ - 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 - } - - amount, err := sdk.ParseCoinNormalized(args[1]) - if err != nil { - return fmt.Errorf("amount: %w", err) - } - bridgeFee, err := sdk.ParseCoinNormalized(args[2]) - if err != nil { - return fmt.Errorf("bridge fee: %w", err) - } - - msg := types.MsgSendToExternal{ - Sender: cliCtx.GetFromAddress().String(), - Dest: args[0], - Amount: amount, - BridgeFee: bridgeFee, - ChainName: chainName, - } - return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg) - }, - } - return cmd -} - func CmdRequestBatchConfirm(chainName string) *cobra.Command { cmd := &cobra.Command{ Use: "request-batch-confirm [contract-address] [nonce] [private-key]", diff --git a/x/eth/module.go b/x/eth/module.go index dd524aec..93d79507 100644 --- a/x/eth/module.go +++ b/x/eth/module.go @@ -15,6 +15,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" + "github.com/functionx/fx-core/v8/x/crosschain" crosschaincli "github.com/functionx/fx-core/v8/x/crosschain/client/cli" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types" @@ -81,6 +82,7 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} // AppModule object for module implementation type AppModule struct { + crosschain.AutoCLIAppModule AppModuleBasic keeper crosschainkeeper.Keeper } @@ -88,8 +90,9 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, + AutoCLIAppModule: crosschain.AutoCLIAppModule{ModuleName: types.ModuleName}, + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, } } diff --git a/x/layer2/module.go b/x/layer2/module.go index dfda6082..4cc98e09 100644 --- a/x/layer2/module.go +++ b/x/layer2/module.go @@ -15,6 +15,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" + "github.com/functionx/fx-core/v8/x/crosschain" crosschaincli "github.com/functionx/fx-core/v8/x/crosschain/client/cli" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types" @@ -81,6 +82,7 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} // AppModule object for module implementation type AppModule struct { + crosschain.AutoCLIAppModule AppModuleBasic keeper crosschainkeeper.Keeper } @@ -88,8 +90,9 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, + AutoCLIAppModule: crosschain.AutoCLIAppModule{ModuleName: types.ModuleName}, + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, } } diff --git a/x/optimism/module.go b/x/optimism/module.go index d5032d6b..624bc495 100644 --- a/x/optimism/module.go +++ b/x/optimism/module.go @@ -15,6 +15,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" + "github.com/functionx/fx-core/v8/x/crosschain" crosschaincli "github.com/functionx/fx-core/v8/x/crosschain/client/cli" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types" @@ -81,6 +82,7 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} // AppModule object for module implementation type AppModule struct { + crosschain.AutoCLIAppModule AppModuleBasic keeper crosschainkeeper.Keeper } @@ -88,8 +90,9 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, + AutoCLIAppModule: crosschain.AutoCLIAppModule{ModuleName: types.ModuleName}, + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, } } diff --git a/x/polygon/module.go b/x/polygon/module.go index f7f66e31..4bfa4ee3 100644 --- a/x/polygon/module.go +++ b/x/polygon/module.go @@ -15,6 +15,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" + "github.com/functionx/fx-core/v8/x/crosschain" crosschaincli "github.com/functionx/fx-core/v8/x/crosschain/client/cli" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types" @@ -77,6 +78,7 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} // AppModule object for module implementation type AppModule struct { + crosschain.AutoCLIAppModule AppModuleBasic keeper crosschainkeeper.Keeper } @@ -84,8 +86,9 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, + AutoCLIAppModule: crosschain.AutoCLIAppModule{ModuleName: types.ModuleName}, + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, } } diff --git a/x/tron/module.go b/x/tron/module.go index 7faba106..a95fbbbf 100644 --- a/x/tron/module.go +++ b/x/tron/module.go @@ -15,6 +15,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" + "github.com/functionx/fx-core/v8/x/crosschain" crosschaincli "github.com/functionx/fx-core/v8/x/crosschain/client/cli" crosschainkeeper "github.com/functionx/fx-core/v8/x/crosschain/keeper" crosschaintypes "github.com/functionx/fx-core/v8/x/crosschain/types" @@ -77,6 +78,7 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} // AppModule object for module implementation type AppModule struct { + crosschain.AutoCLIAppModule AppModuleBasic keeper crosschainkeeper.Keeper } @@ -84,8 +86,9 @@ type AppModule struct { // NewAppModule creates a new AppModule Object func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, + AutoCLIAppModule: crosschain.AutoCLIAppModule{ModuleName: types.ModuleName}, + AppModuleBasic: AppModuleBasic{}, + keeper: keeper, } }