Skip to content

Commit

Permalink
Merge branch 'main' into feat/auto-migdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored Mar 20, 2024
2 parents c663fa9 + 5382150 commit b44ebe5
Show file tree
Hide file tree
Showing 35 changed files with 333 additions and 455 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- [#3707](https://github.com/ignite/cli/pull/3707) Add collections support.
- [#4019](https://github.com/ignite/cli/pull/4019) Add `skip-proto` flag to `s chain` command
- [#3977](https://github.com/ignite/cli/pull/3977) Add `chain lint` command to lint the chain's codebase using `golangci-lint`
- [#3770](https://github.com/ignite/cli/pull/3770) Add `scaffold configs` and `scaffold params` commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import (
)


func (k msgServer) <%= MsgName.UpperCamel %>(goCtx context.Context, msg *types.Msg<%= MsgName.UpperCamel %>) (*types.Msg<%= MsgName.UpperCamel %>Response, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx
func (k msgServer) <%= MsgName.UpperCamel %>(ctx context.Context, msg *types.Msg<%= MsgName.UpperCamel %>) (*types.Msg<%= MsgName.UpperCamel %>Response, error) {
// TODO: Handle the message

return &types.Msg<%= MsgName.UpperCamel %>Response{}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func <%= title(moduleName) %>Keeper(t testing.TB) (keeper.Keeper, sdk.Context) {
ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger())

// Initialize params
if err := k.SetParams(ctx, types.DefaultParams()); err != nil {
if err := k.Params.Set(ctx, types.DefaultParams()); err != nil {
panic(err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"fmt"

"cosmossdk.io/collections"
"cosmossdk.io/core/store"
"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -26,9 +27,14 @@ type (
storeService store.KVStoreService
logger log.Logger

// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
// the address capable of executing a MsgUpdateParams message.
// Typically, this should be the x/gov module account.
authority string

Schema collections.Schema
Params collections.Item[types.Params]
// this line is used by starport scaffolding # collection/type

<%= if (isIBC) { %>
ibcKeeperFn func() *ibckeeper.Keeper
capabilityScopedFn func(string) capabilitykeeper.ScopedKeeper
Expand All @@ -52,7 +58,9 @@ func NewKeeper(
panic(fmt.Sprintf("invalid authority address: %s", authority))
}

return Keeper{
sb := collections.NewSchemaBuilder(storeService)

k := Keeper{
cdc: cdc,
storeService: storeService,
authority: authority,
Expand All @@ -61,7 +69,17 @@ func NewKeeper(
capabilityScopedFn: capabilityScopedFn,<% } %>
<%= for (dependency) in dependencies { %>
<%= toVariableName(dependency.KeeperName()) %>: <%= toVariableName(dependency.KeeperName()) %>,<% } %>
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
// this line is used by starport scaffolding # collection/instantiate
}

schema, err := sb.Build()
if err != nil {
panic(err)
}
k.Schema = schema

return k
}

// GetAuthority returns the module's authority.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import (
"context"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

"<%= modulePath %>/x/<%= moduleName %>/types"
)

func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
func (k msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != req.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.SetParams(ctx, req.Params); err != nil {
if err := k.Params.Set(ctx, req.Params); err != nil {
return nil, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
func TestMsgUpdateParams(t *testing.T) {
k, ms, ctx := setupMsgServer(t)
params := types.DefaultParams()
require.NoError(t, k.SetParams(ctx, params))
wctx := sdk.UnwrapSDKContext(ctx)
require.NoError(t, k.Params.Set(ctx, params))

// default params
testCases := []struct {
Expand Down Expand Up @@ -51,7 +50,7 @@ func TestMsgUpdateParams(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
_, err := ms.UpdateParams(wctx, tc.input)
_, err := ms.UpdateParams(ctx, tc.input)

if tc.expErr {
require.Error(t, err)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (

var _ types.QueryServer = queryServer{}

type queryServer struct {
k Keeper
}

// NewQueryServerImpl returns an implementation of the QueryServer interface.
// NewQueryServerImpl returns an implementation of the QueryServer interface
// for the provided Keeper.
func NewQueryServerImpl(k Keeper) types.QueryServer {
return queryServer{k}
}

type queryServer struct {
k Keeper
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@ package keeper

import (
"context"
"errors"

"cosmossdk.io/collections"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"<%= modulePath %>/x/<%= moduleName %>/types"
)

func (s queryServer) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
func (q queryServer) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

return &types.QueryParamsResponse{Params: s.k.GetParams(ctx)}, nil
params, err := q.k.Params.Get(ctx)
if err != nil {
if errors.Is(err, collections.ErrNotFound) {
return nil, status.Error(codes.NotFound, "not found")
}

return nil, status.Error(codes.Internal, "internal error")
}

return &types.QueryParamsResponse{Params: params}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import (

"github.com/stretchr/testify/require"

keepertest "<%= modulePath %>/testutil/keeper"
keepertest "<%= modulePath %>/testutil/keeper"
"<%= modulePath %>/x/<%= moduleName %>/keeper"
"<%= modulePath %>/x/<%= moduleName %>/types"
"<%= modulePath %>/x/<%= moduleName %>/keeper"
"<%= modulePath %>/x/<%= moduleName %>/types"
)

func TestParamsQuery(t *testing.T) {
k, ctx := keepertest.<%= title(moduleName) %>Keeper(t)

qs := keeper.NewQueryServerImpl(k)
params := types.DefaultParams()
require.NoError(t, k.SetParams(ctx, params))
require.NoError(t, k.Params.Set(ctx, params))

response, err := qs.Params(ctx, &types.QueryParamsRequest{})
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ import (
// 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
if err := k.SetParams(ctx, genState.Params); err != nil {
if err := k.Params.Set(ctx, genState.Params); err != nil {
panic(err)
}
}

// ExportGenesis returns the module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
var err error

genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.Params, err = k.Params.Get(ctx)
if err != nil {
panic(err)
}

// this line is used by starport scaffolding # genesis/module/export

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "cosmossdk.io/collections"

const (
// ModuleName defines the module name
ModuleName = "<%= moduleName %>"
Expand All @@ -14,11 +16,11 @@ const (
)

var (
ParamsKey = []byte("p_<%= moduleName %>")
ParamsKey = collections.NewPrefix("p_<%= moduleName %>")
)

<%= if (isIBC) { %>// this line is used by starport scaffolding # ibc/keys/port<% } %>

func KeyPrefix(p string) []byte {
return []byte(p)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func <%= title(moduleName) %>Keeper(t testing.TB) (keeper.Keeper, sdk.Context) {
ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger())

// Initialize params
if err := k.SetParams(ctx, types.DefaultParams()); err != nil {
if err := k.Params.Set(ctx, types.DefaultParams()); err != nil {
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/templates/module/create/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ PortID = "%[1]v"`
// PlaceholderIBCKeysPort
templatePort := `var (
// PortKey defines the key to store the port ID in store
PortKey = KeyPrefix("%[1]v-port-")
PortKey = collections.NewPrefix("%[1]v-port-")
)`
replacementPort := fmt.Sprintf(templatePort, opts.ModuleName)
content = replacer.Replace(content, module.PlaceholderIBCKeysPort, replacementPort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import (
"context"

"<%= ModulePath %>/x/<%= ModuleName %>/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (s queryServer) <%= QueryName.UpperCamel %>(goCtx context.Context, req *types.Query<%= QueryName.UpperCamel %>Request) (*types.Query<%= QueryName.UpperCamel %>Response, error) {
func (q queryServer) <%= QueryName.UpperCamel %>(ctx context.Context, req *types.Query<%= QueryName.UpperCamel %>Request) (*types.Query<%= QueryName.UpperCamel %>Response, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Process the query
_ = ctx

return &types.Query<%= QueryName.UpperCamel %>Response{}, nil
}
Loading

0 comments on commit b44ebe5

Please sign in to comment.