generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: scaffold logic module using ignite
with the following command: > ignite scaffold module --params foo logic
- Loading branch information
Showing
35 changed files
with
3,013 additions
and
691 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something 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,14 @@ | ||
syntax = "proto3"; | ||
package okp4.okp4d.logic; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "logic/params.proto"; | ||
// this line is used by starport scaffolding # genesis/proto/import | ||
|
||
option go_package = "github.com/okp4/okp4d/x/logic/types"; | ||
|
||
// GenesisState defines the logic module's genesis state. | ||
message GenesisState { | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
// this line is used by starport scaffolding # genesis/proto/state | ||
} |
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,13 @@ | ||
syntax = "proto3"; | ||
package okp4.okp4d.logic; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/okp4/okp4d/x/logic/types"; | ||
|
||
// Params defines the parameters for the module. | ||
message Params { | ||
option (gogoproto.goproto_stringer) = false; | ||
|
||
string foo = 1 [(gogoproto.moretags) = "yaml:\"foo\""]; | ||
} |
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,30 @@ | ||
syntax = "proto3"; | ||
package okp4.okp4d.logic; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "logic/params.proto"; | ||
// this line is used by starport scaffolding # 1 | ||
|
||
option go_package = "github.com/okp4/okp4d/x/logic/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 = "/okp4/okp4d/logic/params"; | ||
} | ||
// this line is used by starport scaffolding # 2 | ||
} | ||
|
||
// 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]; | ||
} | ||
|
||
// this line is used by starport scaffolding # 3 |
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,13 @@ | ||
syntax = "proto3"; | ||
package okp4.okp4d.logic; | ||
|
||
// this line is used by starport scaffolding # proto/tx/import | ||
|
||
option go_package = "github.com/okp4/okp4d/x/logic/types"; | ||
|
||
// Msg defines the Msg service. | ||
service Msg { | ||
// this line is used by starport scaffolding # proto/tx/rpc | ||
} | ||
|
||
// this line is used by starport scaffolding # proto/tx/message |
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,52 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
"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/okp4/okp4d/x/logic/keeper" | ||
"github.com/okp4/okp4d/x/logic/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
tmdb "github.com/tendermint/tm-db" | ||
) | ||
|
||
func LogicKeeper(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, | ||
"LogicParams", | ||
) | ||
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 | ||
} |
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,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" | ||
|
||
"github.com/okp4/okp4d/x/logic/types" | ||
) | ||
|
||
// GetQueryCmd returns the cli query commands for this module | ||
func GetQueryCmd(queryRoute string) *cobra.Command { | ||
// Group logic 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 | ||
} |
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,34 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/okp4/okp4d/x/logic/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
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 := client.GetClientContextFromCmd(cmd) | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
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 cli | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
// "github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/okp4/okp4d/x/logic/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 | ||
} |
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,23 @@ | ||
package logic | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/okp4/okp4d/x/logic/keeper" | ||
"github.com/okp4/okp4d/x/logic/types" | ||
) | ||
|
||
// InitGenesis initializes the module's state from a provided genesis state. | ||
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { | ||
// this line is used by starport scaffolding # genesis/module/init | ||
k.SetParams(ctx, genState.Params) | ||
} | ||
|
||
// ExportGenesis returns the module's exported genesis | ||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { | ||
genesis := types.DefaultGenesis() | ||
genesis.Params = k.GetParams(ctx) | ||
|
||
// this line is used by starport scaffolding # genesis/module/export | ||
|
||
return genesis | ||
} |
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 logic_test | ||
|
||
import ( | ||
"testing" | ||
|
||
keepertest "github.com/okp4/okp4d/testutil/keeper" | ||
"github.com/okp4/okp4d/testutil/nullify" | ||
"github.com/okp4/okp4d/x/logic" | ||
"github.com/okp4/okp4d/x/logic/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGenesis(t *testing.T) { | ||
genesisState := types.GenesisState{ | ||
Params: types.DefaultParams(), | ||
|
||
// this line is used by starport scaffolding # genesis/test/state | ||
} | ||
|
||
k, ctx := keepertest.LogicKeeper(t) | ||
logic.InitGenesis(ctx, *k, genesisState) | ||
got := logic.ExportGenesis(ctx, *k) | ||
require.NotNil(t, got) | ||
|
||
nullify.Fill(&genesisState) | ||
nullify.Fill(got) | ||
|
||
// this line is used by starport scaffolding # genesis/test/assert | ||
} |
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,7 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/okp4/okp4d/x/logic/types" | ||
) | ||
|
||
var _ types.QueryServer = 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,19 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/okp4/okp4d/x/logic/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
ctx := sdk.UnwrapSDKContext(c) | ||
|
||
return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil | ||
} |
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,21 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
testkeeper "github.com/okp4/okp4d/testutil/keeper" | ||
"github.com/okp4/okp4d/x/logic/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParamsQuery(t *testing.T) { | ||
keeper, ctx := testkeeper.LogicKeeper(t) | ||
wctx := sdk.WrapSDKContext(ctx) | ||
params := types.DefaultParams() | ||
keeper.SetParams(ctx, params) | ||
|
||
response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) | ||
require.NoError(t, err) | ||
require.Equal(t, &types.QueryParamsResponse{Params: params}, response) | ||
} |
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,46 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
"github.com/okp4/okp4d/x/logic/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
) | ||
|
||
type ( | ||
Keeper struct { | ||
cdc codec.BinaryCodec | ||
storeKey storetypes.StoreKey | ||
memKey storetypes.StoreKey | ||
paramstore paramtypes.Subspace | ||
} | ||
) | ||
|
||
func NewKeeper( | ||
cdc codec.BinaryCodec, | ||
storeKey, | ||
memKey storetypes.StoreKey, | ||
ps paramtypes.Subspace, | ||
|
||
) *Keeper { | ||
// set KeyTable if it has not already been set | ||
if !ps.HasKeyTable() { | ||
ps = ps.WithKeyTable(types.ParamKeyTable()) | ||
} | ||
|
||
return &Keeper{ | ||
|
||
cdc: cdc, | ||
storeKey: storeKey, | ||
memKey: memKey, | ||
paramstore: ps, | ||
} | ||
} | ||
|
||
func (k Keeper) Logger(ctx sdk.Context) log.Logger { | ||
return ctx.Logger().With("module", fmt.Sprintf("x/%s", 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,17 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/okp4/okp4d/x/logic/types" | ||
) | ||
|
||
type msgServer struct { | ||
Keeper | ||
} | ||
|
||
// NewMsgServerImpl returns an implementation of the MsgServer interface | ||
// for the provided Keeper. | ||
func NewMsgServerImpl(keeper Keeper) types.MsgServer { | ||
return &msgServer{Keeper: keeper} | ||
} | ||
|
||
var _ types.MsgServer = msgServer{} |
Oops, something went wrong.