Skip to content

Commit

Permalink
[Session] Just scaffold the Session module without any params (#36)
Browse files Browse the repository at this point in the history
Ran the following command:

```
ignite scaffold module session --dep bank
```
  • Loading branch information
Olshansk authored Oct 10, 2023
1 parent f16f93a commit 6d2840a
Show file tree
Hide file tree
Showing 31 changed files with 906 additions and 4 deletions.
29 changes: 25 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ import (
pocketmodulekeeper "pocket/x/pocket/keeper"
pocketmoduletypes "pocket/x/pocket/types"

sessionmodule "pocket/x/session"
sessionmodulekeeper "pocket/x/session/keeper"
sessionmoduletypes "pocket/x/session/types"

applicationmodule "pocket/x/application"
applicationmodulekeeper "pocket/x/application/keeper"
applicationmoduletypes "pocket/x/application/types"

suppliermodule "pocket/x/supplier"
suppliermodulekeeper "pocket/x/supplier/keeper"
suppliermoduletypes "pocket/x/supplier/types"

// this line is used by starport scaffolding # stargate/app/moduleImport

appparams "pocket/app/params"
Expand Down Expand Up @@ -183,6 +189,7 @@ var (
consensus.AppModuleBasic{},
pocketmodule.AppModuleBasic{},
suppliermodule.AppModuleBasic{},
sessionmodule.AppModuleBasic{},
applicationmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)
Expand Down Expand Up @@ -261,11 +268,11 @@ type App struct {
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper

PocketKeeper pocketmodulekeeper.Keeper

SupplierKeeper suppliermodulekeeper.Keeper

PocketKeeper pocketmodulekeeper.Keeper
SupplierKeeper suppliermodulekeeper.Keeper
SessionKeeper sessionmodulekeeper.Keeper
ApplicationKeeper applicationmodulekeeper.Keeper

// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
Expand Down Expand Up @@ -314,6 +321,7 @@ func New(
capabilitytypes.StoreKey, group.StoreKey, icacontrollertypes.StoreKey, consensusparamtypes.StoreKey,
pocketmoduletypes.StoreKey,
suppliermoduletypes.StoreKey,
sessionmoduletypes.StoreKey,
applicationmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
Expand Down Expand Up @@ -555,6 +563,14 @@ func New(
)
supplierModule := suppliermodule.NewAppModule(appCodec, app.SupplierKeeper, app.AccountKeeper, app.BankKeeper)

app.SessionKeeper = *sessionmodulekeeper.NewKeeper(
appCodec,
keys[sessionmoduletypes.StoreKey],
keys[sessionmoduletypes.MemStoreKey],
app.GetSubspace(sessionmoduletypes.ModuleName),
)
sessionModule := sessionmodule.NewAppModule(appCodec, app.SessionKeeper, app.AccountKeeper, app.BankKeeper)

app.ApplicationKeeper = *applicationmodulekeeper.NewKeeper(
appCodec,
keys[applicationmoduletypes.StoreKey],
Expand Down Expand Up @@ -628,6 +644,7 @@ func New(
icaModule,
pocketModule,
supplierModule,
sessionModule,
applicationModule,
// this line is used by starport scaffolding # stargate/app/appModule

Expand Down Expand Up @@ -663,6 +680,7 @@ func New(
consensusparamtypes.ModuleName,
pocketmoduletypes.ModuleName,
suppliermoduletypes.ModuleName,
sessionmoduletypes.ModuleName,
applicationmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)
Expand Down Expand Up @@ -691,6 +709,7 @@ func New(
consensusparamtypes.ModuleName,
pocketmoduletypes.ModuleName,
suppliermoduletypes.ModuleName,
sessionmoduletypes.ModuleName,
applicationmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)
Expand Down Expand Up @@ -724,6 +743,7 @@ func New(
consensusparamtypes.ModuleName,
pocketmoduletypes.ModuleName,
suppliermoduletypes.ModuleName,
sessionmoduletypes.ModuleName,
applicationmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
}
Expand Down Expand Up @@ -951,6 +971,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(pocketmoduletypes.ModuleName)
paramsKeeper.Subspace(suppliermoduletypes.ModuleName)
paramsKeeper.Subspace(sessionmoduletypes.ModuleName)
paramsKeeper.Subspace(applicationmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

Expand Down
46 changes: 46 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46509,6 +46509,42 @@ paths:
additionalProperties: {}
tags:
- Query
/pocket/session/params:
get:
summary: Parameters queries the parameters of the module.
operationId: PocketSessionParams
responses:
'200':
description: A successful response.
schema:
type: object
properties:
params:
description: params holds all the parameters of this module.
type: object
description: >-
QueryParamsResponse is response type for the Query/Params RPC
method.
default:
description: An unexpected error response.
schema:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
'@type':
type: string
additionalProperties: {}
tags:
- Query
/pocket/supplier/params:
get:
summary: Parameters queries the parameters of the module.
Expand Down Expand Up @@ -75304,6 +75340,16 @@ definitions:
description: params holds all the parameters of this module.
type: object
description: QueryParamsResponse is response type for the Query/Params RPC method.
pocket.session.Params:
type: object
description: Params defines the parameters for the module.
pocket.session.QueryParamsResponse:
type: object
properties:
params:
description: params holds all the parameters of this module.
type: object
description: QueryParamsResponse is response type for the Query/Params RPC method.
pocket.supplier.Params:
type: object
description: Params defines the parameters for the module.
Expand Down
12 changes: 12 additions & 0 deletions proto/pocket/session/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package pocket.session;

import "gogoproto/gogo.proto";
import "pocket/session/params.proto";

option go_package = "pocket/x/session/types";

// GenesisState defines the session module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
}
12 changes: 12 additions & 0 deletions proto/pocket/session/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package pocket.session;

import "gogoproto/gogo.proto";

option go_package = "pocket/x/session/types";

// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;

}
26 changes: 26 additions & 0 deletions proto/pocket/session/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package pocket.session;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "pocket/session/params.proto";

option go_package = "pocket/x/session/types";

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/pocket/session/params";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}
7 changes: 7 additions & 0 deletions proto/pocket/session/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package pocket.session;

option go_package = "pocket/x/session/types";

// Msg defines the Msg service.
service Msg {}
52 changes: 52 additions & 0 deletions testutil/keeper/session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package keeper

import (
"testing"

tmdb "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/require"
"pocket/x/session/keeper"
"pocket/x/session/types"
)

func SessionKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
require.NoError(t, stateStore.LoadLatestVersion())

registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)

paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
memStoreKey,
"SessionParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())

// Initialize params
k.SetParams(ctx, types.DefaultParams())

return k, ctx
}
31 changes: 31 additions & 0 deletions x/session/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cli

import (
"fmt"
// "strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"

"pocket/x/session/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group session queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())
// this line is used by starport scaffolding # 1

return cmd
}
36 changes: 36 additions & 0 deletions x/session/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"

"pocket/x/session/types"
)

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
36 changes: 36 additions & 0 deletions x/session/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"fmt"
"time"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
"pocket/x/session/types"
)

var (
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
)

const (
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

// this line is used by starport scaffolding # 1

return cmd
}
Loading

0 comments on commit 6d2840a

Please sign in to comment.