Skip to content

Commit

Permalink
feat(x/crosschain): use autocli instead of cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
fx0x55 authored and zakir-code committed Oct 16, 2024
1 parent 93edf6f commit cbdc02c
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 862 deletions.
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

0 comments on commit cbdc02c

Please sign in to comment.