Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/crosschain): use autocli instead of cmd #743

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions x/arbitrum/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -81,15 +82,17 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {}

// AppModule object for module implementation
type AppModule struct {
crosschain.AutoCLIAppModule
AppModuleBasic
keeper crosschainkeeper.Keeper
}

// 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,
}
}

Expand Down
7 changes: 5 additions & 2 deletions x/avalanche/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -81,15 +82,17 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {}

// AppModule object for module implementation
type AppModule struct {
crosschain.AutoCLIAppModule
AppModuleBasic
keeper crosschainkeeper.Keeper
}

// 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,
}
}

Expand Down
7 changes: 5 additions & 2 deletions x/bsc/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -81,15 +82,17 @@ func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {}

// AppModule object for module implementation
type AppModule struct {
crosschain.AutoCLIAppModule
AppModuleBasic
keeper crosschainkeeper.Keeper
}

// 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,
}
}

Expand Down
69 changes: 69 additions & 0 deletions x/crosschain/autocli.go
Original file line number Diff line number Diff line change
@@ -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,
},
}
}
Loading