Skip to content

Commit

Permalink
[Gateway] Scaffold Gateway module and nothing else
Browse files Browse the repository at this point in the history
Simply ran
```
ignite scaffold module gateway --dep bank,account
```
  • Loading branch information
h5law authored Oct 12, 2023
1 parent 326e9c8 commit 8be5d05
Show file tree
Hide file tree
Showing 31 changed files with 914 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ import (
suppliermodulekeeper "pocket/x/supplier/keeper"
suppliermoduletypes "pocket/x/supplier/types"

gatewaymodule "pocket/x/gateway"
gatewaymodulekeeper "pocket/x/gateway/keeper"
gatewaymoduletypes "pocket/x/gateway/types"
// this line is used by starport scaffolding # stargate/app/moduleImport

appparams "pocket/app/params"
Expand Down Expand Up @@ -196,6 +199,7 @@ var (
sessionmodule.AppModuleBasic{},
applicationmodule.AppModuleBasic{},
suppliermodule.AppModuleBasic{},
gatewaymodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand All @@ -212,6 +216,7 @@ var (
suppliermoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
servicemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
applicationmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
gatewaymoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -280,6 +285,7 @@ type App struct {
ApplicationKeeper applicationmodulekeeper.Keeper
SupplierKeeper suppliermodulekeeper.Keeper

GatewayKeeper gatewaymodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
Expand Down Expand Up @@ -331,6 +337,7 @@ func New(
sessionmoduletypes.StoreKey,
applicationmoduletypes.StoreKey,
suppliermoduletypes.StoreKey,
gatewaymoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -599,6 +606,17 @@ func New(
)
supplierModule := suppliermodule.NewAppModule(appCodec, app.SupplierKeeper, app.AccountKeeper, app.BankKeeper)

app.GatewayKeeper = *gatewaymodulekeeper.NewKeeper(
appCodec,
keys[gatewaymoduletypes.StoreKey],
keys[gatewaymoduletypes.MemStoreKey],
app.GetSubspace(gatewaymoduletypes.ModuleName),

app.BankKeeper,
app.AccountKeeper,
)
gatewayModule := gatewaymodule.NewAppModule(appCodec, app.GatewayKeeper, app.AccountKeeper, app.BankKeeper)

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

/**** IBC Routing ****/
Expand Down Expand Up @@ -665,6 +683,7 @@ func New(
sessionModule,
applicationModule,
supplierModule,
gatewayModule,
// this line is used by starport scaffolding # stargate/app/appModule

crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
Expand Down Expand Up @@ -702,6 +721,7 @@ func New(
sessionmoduletypes.ModuleName,
applicationmoduletypes.ModuleName,
suppliermoduletypes.ModuleName,
gatewaymoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand Down Expand Up @@ -732,6 +752,7 @@ func New(
sessionmoduletypes.ModuleName,
applicationmoduletypes.ModuleName,
suppliermoduletypes.ModuleName,
gatewaymoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

Expand Down Expand Up @@ -767,6 +788,7 @@ func New(
sessionmoduletypes.ModuleName,
applicationmoduletypes.ModuleName,
suppliermoduletypes.ModuleName,
gatewaymoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
}
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -996,6 +1018,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(sessionmoduletypes.ModuleName)
paramsKeeper.Subspace(applicationmoduletypes.ModuleName)
paramsKeeper.Subspace(suppliermoduletypes.ModuleName)
paramsKeeper.Subspace(gatewaymoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
46 changes: 46 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46634,6 +46634,42 @@ paths:
additionalProperties: {}
tags:
- Query
/pocket/gateway/params:
get:
summary: Parameters queries the parameters of the module.
operationId: PocketGatewayParams
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/pocket/params:
get:
summary: Parameters queries the parameters of the module.
Expand Down Expand Up @@ -75741,6 +75777,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.gateway.Params:
type: object
description: Params defines the parameters for the module.
pocket.gateway.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.pocket.Params:
type: object
description: Params defines the parameters for the module.
Expand Down
12 changes: 12 additions & 0 deletions proto/pocket/gateway/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package pocket.gateway;

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

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

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

import "gogoproto/gogo.proto";

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

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

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

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

option go_package = "pocket/x/gateway/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/gateway/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/gateway/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package pocket.gateway;

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

// Msg defines the Msg service.
service Msg {}
54 changes: 54 additions & 0 deletions testutil/keeper/gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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/gateway/keeper"
"pocket/x/gateway/types"
)

func GatewayKeeper(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,
"GatewayParams",
)
k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
paramsSubspace,
nil,
nil,
)

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/gateway/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/gateway/types"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group gateway 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/gateway/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/gateway/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/gateway/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/gateway/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 8be5d05

Please sign in to comment.