go-cyber/x/bandwidth/module.go

package bandwidth

import (
	"context"
	"encoding/json"
	"fmt"

	"github.com/cosmos/cosmos-sdk/client"
	"github.com/cosmos/cosmos-sdk/codec"
	codectypes "github.com/cosmos/cosmos-sdk/codec/types"
	"github.com/cosmos/cosmos-sdk/types/module"
	authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
	"github.com/grpc-ecosystem/grpc-gateway/runtime"
	"github.com/spf13/cobra"

	"github.com/cybercongress/go-cyber/v7/x/bandwidth/client/cli"
	"github.com/cybercongress/go-cyber/v7/x/bandwidth/exported"
	"github.com/cybercongress/go-cyber/v7/x/bandwidth/keeper"
	"github.com/cybercongress/go-cyber/v7/x/bandwidth/types"

	abci "github.com/cometbft/cometbft/abci/types"
	sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
	_ module.AppModule      = AppModule{}
	_ module.AppModuleBasic = AppModuleBasic{}
)

type AppModuleBasic struct {
	cdc codec.Codec
}

// Name returns the wasm module's name.
func (AppModuleBasic) Name() string { return types.ModuleName }

func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
	types.RegisterLegacyAminoCodec(cdc)
}

func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
	return cdc.MustMarshalJSON(&types.GenesisState{
		Params: types.DefaultParams(),
	})
}

func (b AppModuleBasic) ValidateGenesis(marshaler codec.JSONCodec, _ client.TxEncodingConfig, message json.RawMessage) error {
	var data types.GenesisState
	err := marshaler.UnmarshalJSON(message, &data)
	if err != nil {
		return err
	}
	return types.ValidateGenesis(data)
}

func (b AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, serveMux *runtime.ServeMux) {
	err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(clientCtx))
	if err != nil {
		panic(err)
	}
}

func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil }

func (AppModuleBasic) GetQueryCmd() *cobra.Command {
	return cli.GetQueryCmd()
}

func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
	types.RegisterInterfaces(registry)
}

type AppModule struct {
	AppModuleBasic
	cdc            codec.Codec
	ak             authkeeper.AccountKeeper
	bm             *keeper.BandwidthMeter
	legacySubspace exported.Subspace
}

func NewAppModule(
	cdc codec.Codec,
	ak authkeeper.AccountKeeper,
	bm *keeper.BandwidthMeter,
	ss exported.Subspace,
) AppModule {
	return AppModule{
		AppModuleBasic: AppModuleBasic{cdc: cdc},
		cdc:            cdc,
		ak:             ak,
		bm:             bm,
		legacySubspace: ss,
	}
}

func (AppModule) Name() string { return types.ModuleName }

func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

func (am AppModule) RegisterServices(cfg module.Configurator) {
	types.RegisterQueryServer(cfg.QueryServer(), am.bm)
	types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(*am.bm))

	m := keeper.NewMigrator(*am.bm, am.legacySubspace)
	if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil {
		panic(fmt.Sprintf("failed to migrate x/%s from version 1 to 2: %v", types.ModuleName, err))
	}
}

func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
	var genesisState types.GenesisState
	cdc.MustUnmarshalJSON(data, &genesisState)
	keeper.InitGenesis(ctx, am.bm, am.ak, genesisState)
	return []abci.ValidatorUpdate{}
}

func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
	gs := keeper.ExportGenesis(ctx, am.bm)
	return cdc.MustMarshalJSON(gs)
}

func (am AppModule) ConsensusVersion() uint64 {
	return 2
}

func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}

func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
	EndBlocker(ctx, am.bm)
	return []abci.ValidatorUpdate{}
}

Synonyms

go-cyber/x/liquidity/module.go
cyberindex/modules/graph/module.go
cyberindex/modules/grid/module.go
space-pussy/x/grid/module.go
cyberindex/modules/liquidity/module.go
go-cyber/x/rank/module.go
space-pussy/x/resources/module.go
go-cyber/x/dmn/module.go
space-pussy/x/graph/module.go
go-cyber/x/graph/module.go
go-cyber/x/tokenfactory/module.go
cyberindex/modules/resources/module.go
go-cyber/x/clock/module.go
space-pussy/x/rank/module.go
cyberindex/modules/bank/module.go
space-pussy/x/bandwidth/module.go
go-cyber/x/cyberbank/module.go
space-pussy/x/cyberbank/module.go
go-cyber/x/resources/module.go
space-pussy/x/dmn/module.go
go-cyber/x/staking/module.go
cyberindex/modules/wasm/module.go
space-pussy/x/staking/module.go
go-cyber/x/grid/module.go

Neighbours