-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(x/callback): Adding module skeleton (#495)
* adding callback module skeleton * lint fix
- Loading branch information
Showing
16 changed files
with
359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GetQueryCmd builds query command group for the module. | ||
func GetQueryCmd() *cobra.Command { | ||
panic("unimplemented 👻") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GetTxCmd builds tx command group for the module. | ||
func GetTxCmd() *cobra.Command { | ||
panic("unimplemented 👻") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package callback | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/archway-network/archway/x/callback/keeper" | ||
"github.com/archway-network/archway/x/callback/types" | ||
) | ||
|
||
// InitGenesis initializes the module genesis state. | ||
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// ExportGenesis exports the module genesis for the current block. | ||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { | ||
panic("unimplemented 👻") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package keeper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/archway-network/archway/x/callback/types" | ||
) | ||
|
||
var _ types.QueryServer = &QueryServer{} | ||
|
||
// QueryServer implements the module gRPC query service. | ||
type QueryServer struct { | ||
keeper Keeper | ||
} | ||
|
||
// NewQueryServer creates a new gRPC query server. | ||
func NewQueryServer(keeper Keeper) *QueryServer { | ||
return &QueryServer{ | ||
keeper: keeper, | ||
} | ||
} | ||
|
||
// Callbacks implements types.QueryServer. | ||
func (*QueryServer) Callbacks(context.Context, *types.QueryCallbacksRequest) (*types.QueryCallbacksResponse, error) { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// EstimateCallbackFees implements types.QueryServer. | ||
func (*QueryServer) EstimateCallbackFees(context.Context, *types.QueryEstimateCallbackFeesRequest) (*types.QueryEstimateCallbackFeesResponse, error) { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// Params implements types.QueryServer. | ||
func (*QueryServer) Params(context.Context, *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { | ||
panic("unimplemented 👻") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/cometbft/cometbft/libs/log" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
paramTypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
|
||
"github.com/archway-network/archway/x/callback/types" | ||
) | ||
|
||
// Keeper provides module state operations. | ||
type Keeper struct { | ||
cdc codec.Codec | ||
paramStore paramTypes.Subspace | ||
} | ||
|
||
// NewKeeper creates a new Keeper instance. | ||
func NewKeeper(cdc codec.Codec, ps paramTypes.Subspace) Keeper { | ||
return Keeper{ | ||
cdc: cdc, | ||
paramStore: ps, | ||
} | ||
} | ||
|
||
// Logger returns a module-specific logger. | ||
func (k Keeper) Logger(ctx sdk.Context) log.Logger { | ||
return ctx.Logger().With("module", "x/"+types.ModuleName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/archway-network/archway/x/callback/types" | ||
) | ||
|
||
var _ types.MsgServer = (*MsgServer)(nil) | ||
|
||
// MsgServer implements the module gRPC messaging service. | ||
type MsgServer struct { | ||
keeper Keeper | ||
} | ||
|
||
// NewMsgServer creates a new gRPC messaging server. | ||
func NewMsgServer(keeper Keeper) *MsgServer { | ||
return &MsgServer{ | ||
keeper: keeper, | ||
} | ||
} | ||
|
||
// CancelCallback implements types.MsgServer. | ||
func (*MsgServer) CancelCallback(context.Context, *types.MsgCancelCallback) (*types.MsgCancelCallbackResponse, error) { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// RequestCallback implements types.MsgServer. | ||
func (*MsgServer) RequestCallback(context.Context, *types.MsgRequestCallback) (*types.MsgRequestCallbackResponse, error) { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// UpdateParams implements types.MsgServer. | ||
func (*MsgServer) UpdateParams(context.Context, *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { | ||
panic("unimplemented 👻") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package keeper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package callback | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codecTypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/archway-network/archway/x/callback/client/cli" | ||
"github.com/archway-network/archway/x/callback/keeper" | ||
"github.com/archway-network/archway/x/callback/types" | ||
) | ||
|
||
var ( | ||
_ module.AppModuleBasic = AppModuleBasic{} | ||
_ module.AppModule = AppModule{} | ||
) | ||
|
||
// AppModuleBasic defines the basic application module for this module. | ||
type AppModuleBasic struct { | ||
cdc codec.Codec | ||
} | ||
|
||
// Name returns the module's name. | ||
func (a AppModuleBasic) Name() string { | ||
return types.ModuleName | ||
} | ||
|
||
// RegisterLegacyAminoCodec registers the module's types on the given LegacyAmino codec. | ||
func (a AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { | ||
types.RegisterLegacyAminoCodec(amino) | ||
} | ||
|
||
// RegisterInterfaces registers the module's interface types. | ||
func (a AppModuleBasic) RegisterInterfaces(registry codecTypes.InterfaceRegistry) { | ||
types.RegisterInterfaces(registry) | ||
} | ||
|
||
// DefaultGenesis returns default genesis state as raw bytes for the module. | ||
func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { | ||
return cdc.MustMarshalJSON(types.DefaultGenesis()) | ||
} | ||
|
||
// ValidateGenesis performs genesis state validation for the module. | ||
func (a AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { | ||
var state types.GenesisState | ||
if err := cdc.UnmarshalJSON(bz, &state); err != nil { | ||
return fmt.Errorf("failed to unmarshal x/%s genesis state: %w", types.ModuleName, err) | ||
} | ||
|
||
return state.Validate() | ||
} | ||
|
||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. | ||
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, serveMux *runtime.ServeMux) { | ||
if err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(clientCtx)); err != nil { | ||
panic(fmt.Errorf("registering query handler for x/%s: %w", types.ModuleName, err)) | ||
} | ||
} | ||
|
||
// GetTxCmd returns the root tx command for the module. | ||
func (a AppModuleBasic) GetTxCmd() *cobra.Command { | ||
return cli.GetTxCmd() | ||
} | ||
|
||
// GetQueryCmd returns no root query command for the module. | ||
func (a AppModuleBasic) GetQueryCmd() *cobra.Command { | ||
return cli.GetQueryCmd() | ||
} | ||
|
||
// AppModule implements an application module for this module. | ||
type AppModule struct { | ||
AppModuleBasic | ||
|
||
keeper keeper.Keeper | ||
} | ||
|
||
// NewAppModule creates a new AppModule object. | ||
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule { | ||
return AppModule{ | ||
AppModuleBasic: AppModuleBasic{cdc: cdc}, | ||
keeper: keeper, | ||
} | ||
} | ||
|
||
// RegisterInvariants registers the module invariants. | ||
func (a AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { | ||
} | ||
|
||
// RegisterServices registers the module services. | ||
func (a AppModule) RegisterServices(cfg module.Configurator) { | ||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(a.keeper)) | ||
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServer(a.keeper)) | ||
} | ||
|
||
// InitGenesis performs genesis initialization for the module. It returns no validator updates. | ||
func (a AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { | ||
var genesisState types.GenesisState | ||
cdc.MustUnmarshalJSON(bz, &genesisState) | ||
|
||
InitGenesis(ctx, a.keeper, genesisState) | ||
|
||
return []abci.ValidatorUpdate{} | ||
} | ||
|
||
// ExportGenesis returns the exported genesis state as raw bytes for the module. | ||
func (a AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { | ||
state := ExportGenesis(ctx, a.keeper) | ||
return cdc.MustMarshalJSON(state) | ||
} | ||
|
||
// ConsensusVersion implements AppModule/ConsensusVersion. | ||
func (a AppModule) ConsensusVersion() uint64 { | ||
return 1 | ||
} | ||
|
||
// BeginBlock returns the begin blocker for the module. | ||
func (a AppModule) BeginBlock(ctx sdk.Context, block abci.RequestBeginBlock) {} | ||
|
||
// EndBlock returns the end blocker for the module. It returns no validator updates. | ||
func (a AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { | ||
return []abci.ValidatorUpdate{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/codec/types" | ||
cryptoCodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// RegisterLegacyAminoCodec registers the necessary interfaces and concrete types on the provided LegacyAmino codec. | ||
// These types are used for Amino JSON serialization. | ||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { | ||
} | ||
|
||
// RegisterInterfaces registers interfaces types with the interface registry. | ||
func RegisterInterfaces(registry types.InterfaceRegistry) { | ||
} | ||
|
||
var ( | ||
ModuleCdc = codec.NewAminoCodec(amino) | ||
amino = codec.NewLegacyAmino() | ||
) | ||
|
||
func init() { | ||
RegisterLegacyAminoCodec(amino) | ||
cryptoCodec.RegisterCrypto(amino) | ||
sdk.RegisterLegacyAminoCodec(amino) | ||
amino.Seal() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package types | ||
|
||
import errorsmod "cosmossdk.io/errors" | ||
|
||
var ( | ||
DefaultCodespace = ModuleName | ||
ErrInternal = errorsmod.Register(DefaultCodespace, 0, "internal error") // smth went wrong | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package types | ||
|
||
// NewGenesisState creates a new GenesisState object. | ||
func NewGenesisState( | ||
params Params, | ||
) *GenesisState { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// DefaultGenesisState returns a default genesis state. | ||
func DefaultGenesis() *GenesisState { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// Validate perform object fields validation. | ||
func (m GenesisState) Validate() error { | ||
panic("unimplemented 👻") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package types | ||
|
||
const ( | ||
// ModuleName is the module name. | ||
ModuleName = "callback" | ||
// StoreKey is the module KV storage prefix key. | ||
StoreKey = ModuleName | ||
// QuerierRoute is the querier route for the module. | ||
QuerierRoute = ModuleName | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// NewParams creates a new Params instance. | ||
func NewParams(inflationRewardsRatio, txFeeRebateRatio sdk.Dec, maxwithdrawRecords uint64) Params { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// DefaultParams returns a default set of parameters. | ||
func DefaultParams() Params { | ||
panic("unimplemented 👻") | ||
} | ||
|
||
// Validate perform object fields validation. | ||
func (m Params) Validate() error { | ||
panic("unimplemented 👻") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package types |