diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4ce6d55..0f9ac4d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -116,7 +116,7 @@ jobs: if: env.GIT_DIFF || github.ref == 'refs/heads/main' - run: make test-coverage if: env.GIT_DIFF || github.ref == 'refs/heads/main' - - uses: codecov/codecov-action@v4 + - uses: codecov/codecov-action@v3 with: file: coverage.txt if: env.GIT_DIFF || github.ref == 'refs/heads/main' diff --git a/content/server/config.go b/content/keeper/config.go similarity index 90% rename from content/server/config.go rename to content/keeper/config.go index dcf49ef..d126fbd 100644 --- a/content/server/config.go +++ b/content/keeper/config.go @@ -1,4 +1,4 @@ -package server +package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/content/server/features/msg_create.feature b/content/keeper/features/msg_create.feature similarity index 100% rename from content/server/features/msg_create.feature rename to content/keeper/features/msg_create.feature diff --git a/content/server/features/msg_delete.feature b/content/keeper/features/msg_delete.feature similarity index 100% rename from content/server/features/msg_delete.feature rename to content/keeper/features/msg_delete.feature diff --git a/content/server/features/msg_update_curator.feature b/content/keeper/features/msg_update_curator.feature similarity index 100% rename from content/server/features/msg_update_curator.feature rename to content/keeper/features/msg_update_curator.feature diff --git a/content/server/features/msg_update_metadata.feature b/content/keeper/features/msg_update_metadata.feature similarity index 100% rename from content/server/features/msg_update_metadata.feature rename to content/keeper/features/msg_update_metadata.feature diff --git a/content/server/features/query_content.feature b/content/keeper/features/query_content.feature similarity index 100% rename from content/server/features/query_content.feature rename to content/keeper/features/query_content.feature diff --git a/content/server/features/query_contents.feature b/content/keeper/features/query_contents.feature similarity index 100% rename from content/server/features/query_contents.feature rename to content/keeper/features/query_contents.feature diff --git a/content/server/features/query_contents_by_curator.feature b/content/keeper/features/query_contents_by_curator.feature similarity index 100% rename from content/server/features/query_contents_by_curator.feature rename to content/keeper/features/query_contents_by_curator.feature diff --git a/content/server/server.go b/content/keeper/keeper.go similarity index 63% rename from content/server/server.go rename to content/keeper/keeper.go index ce169ce..4512a0c 100644 --- a/content/server/server.go +++ b/content/keeper/keeper.go @@ -1,10 +1,9 @@ -package server +package keeper import ( "encoding/json" "cosmossdk.io/orm/model/ormdb" - storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,36 +13,36 @@ import ( ) var ( - _ v1.MsgServer = &Server{} - _ v1.QueryServer = &Server{} + _ v1.MsgServer = &Keeper{} + _ v1.QueryServer = &Keeper{} ) -// Server is the server. -type Server struct { - db ormdb.ModuleDB - ss contentv1.StateStore +// Keeper is the keeper. +type Keeper struct { + db ormdb.ModuleDB // module database + ss contentv1.StateStore // module state store } -// NewServer creates a new server. -func NewServer(key storetypes.StoreKey) Server { - s := Server{} +// NewKeeper creates a new keeper. +func NewKeeper() Keeper { + k := Keeper{} var err error - s.db, err = ormdb.NewModuleDB(&content.ModuleSchema, ormdb.ModuleDBOptions{}) + k.db, err = ormdb.NewModuleDB(&content.ModuleSchema, ormdb.ModuleDBOptions{}) if err != nil { panic(err) } - s.ss, err = contentv1.NewStateStore(s.db) + k.ss, err = contentv1.NewStateStore(k.db) if err != nil { panic(err) } - return s + return k } // InitGenesis initializes genesis state. -func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error { +func (k Keeper) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error { //source, err := ormjson.NewRawMessageSource(data) //if err != nil { // return err @@ -58,7 +57,7 @@ func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMes } // ExportGenesis exports genesis state. -func (s Server) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) { +func (k Keeper) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) { //target := ormjson.NewRawMessageTarget() // //err := s.db.ExportJSON(sdk.WrapSDKContext(ctx), target) diff --git a/content/server/server_test.go b/content/keeper/keeper_test.go similarity index 94% rename from content/server/server_test.go rename to content/keeper/keeper_test.go index 6da07e7..50db6bc 100644 --- a/content/server/server_test.go +++ b/content/keeper/keeper_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "cosmossdk.io/log" @@ -19,7 +19,7 @@ import ( type baseSuite struct { t gocuke.TestingT sdkCtx sdk.Context - srv Server + k Keeper } func setupBase(t gocuke.TestingT) *baseSuite { @@ -46,8 +46,8 @@ func setupBase(t gocuke.TestingT) *baseSuite { // create and set sdk context from commit multi-store with orm context s.sdkCtx = sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()).WithContext(ormCtx) - // create and set server - s.srv = NewServer(key) + // create and set keeper + s.k = NewKeeper() return s } diff --git a/content/server/msg_create.go b/content/keeper/msg_create.go similarity index 84% rename from content/server/msg_create.go rename to content/keeper/msg_create.go index a26c52d..2868d24 100644 --- a/content/server/msg_create.go +++ b/content/keeper/msg_create.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -10,7 +10,7 @@ import ( ) // Create implements Msg/Create. -func (s Server) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateResponse, error) { +func (k Keeper) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from curator address @@ -20,7 +20,7 @@ func (s Server) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateRes } // insert content into content table - id, err := s.ss.ContentTable().InsertReturningId(ctx, &contentv1.Content{ + id, err := k.ss.ContentTable().InsertReturningId(ctx, &contentv1.Content{ Curator: curator, Metadata: req.Metadata, }) diff --git a/content/server/msg_create_test.go b/content/keeper/msg_create_test.go similarity index 93% rename from content/server/msg_create_test.go rename to content/keeper/msg_create_test.go index b71e10d..1ec7bf6 100644 --- a/content/server/msg_create_test.go +++ b/content/keeper/msg_create_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgCreate) MsgCreate(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.Create(s.sdkCtx, &msg) + s.res, s.err = s.k.Create(s.sdkCtx, &msg) } func (s *msgCreate) ExpectNoError() { @@ -53,7 +53,7 @@ func (s *msgCreate) ExpectStateContent(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.ContentTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.ContentTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/content/server/msg_delete.go b/content/keeper/msg_delete.go similarity index 87% rename from content/server/msg_delete.go rename to content/keeper/msg_delete.go index 7270b0c..20bdb02 100644 --- a/content/server/msg_delete.go +++ b/content/keeper/msg_delete.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,7 +11,7 @@ import ( ) // Delete implements Msg/Delete. -func (s Server) Delete(ctx context.Context, req *v1.MsgDelete) (*v1.MsgDeleteResponse, error) { +func (k Keeper) Delete(ctx context.Context, req *v1.MsgDelete) (*v1.MsgDeleteResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from curator address @@ -21,7 +21,7 @@ func (s Server) Delete(ctx context.Context, req *v1.MsgDelete) (*v1.MsgDeleteRes } // get content from content table - content, err := s.ss.ContentTable().Get(ctx, req.Id) + content, err := k.ss.ContentTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf( @@ -42,7 +42,7 @@ func (s Server) Delete(ctx context.Context, req *v1.MsgDelete) (*v1.MsgDeleteRes } // delete content from content table - err = s.ss.ContentTable().Delete(ctx, content) + err = k.ss.ContentTable().Delete(ctx, content) if err != nil { return nil, err // internal error } diff --git a/content/server/msg_delete_test.go b/content/keeper/msg_delete_test.go similarity index 90% rename from content/server/msg_delete_test.go rename to content/keeper/msg_delete_test.go index e65cd08..8b112e1 100644 --- a/content/server/msg_delete_test.go +++ b/content/keeper/msg_delete_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "strconv" @@ -34,7 +34,7 @@ func (s *msgDelete) Content(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &content) require.NoError(s.t, err) - id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ + id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ Curator: content.Curator, Metadata: content.Metadata, }) @@ -47,7 +47,7 @@ func (s *msgDelete) MsgDelete(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.Delete(s.sdkCtx, &msg) + s.res, s.err = s.k.Delete(s.sdkCtx, &msg) } func (s *msgDelete) ExpectNoError() { @@ -70,7 +70,7 @@ func (s *msgDelete) ExpectNoStateContentWithId(a string) { id, err := strconv.ParseUint(a, 10, 32) require.NoError(s.t, err) - found, err := s.srv.ss.ContentTable().Has(s.sdkCtx, id) + found, err := s.k.ss.ContentTable().Has(s.sdkCtx, id) require.NoError(s.t, err) require.False(s.t, found) } diff --git a/content/server/msg_update_curator.go b/content/keeper/msg_update_curator.go similarity index 89% rename from content/server/msg_update_curator.go rename to content/keeper/msg_update_curator.go index e2e8e1e..7714743 100644 --- a/content/server/msg_update_curator.go +++ b/content/keeper/msg_update_curator.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,7 +11,7 @@ import ( ) // UpdateCurator implements the Msg/UpdateCurator method. -func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v1.MsgUpdateCuratorResponse, error) { +func (k Keeper) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v1.MsgUpdateCuratorResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from curator address @@ -21,7 +21,7 @@ func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v } // get content from content table - content, err := s.ss.ContentTable().Get(ctx, req.Id) + content, err := k.ss.ContentTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("content with id %d: %s", req.Id, err) @@ -49,7 +49,7 @@ func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v content.Curator = newCurator // update content in content table - err = s.ss.ContentTable().Update(ctx, content) + err = k.ss.ContentTable().Update(ctx, content) if err != nil { return nil, err // internal error } diff --git a/content/server/msg_update_curator_test.go b/content/keeper/msg_update_curator_test.go similarity index 91% rename from content/server/msg_update_curator_test.go rename to content/keeper/msg_update_curator_test.go index 6eedba3..a1b166e 100644 --- a/content/server/msg_update_curator_test.go +++ b/content/keeper/msg_update_curator_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgUpdateCurator) Content(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &content) require.NoError(s.t, err) - id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ + id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ Curator: content.Curator, Metadata: content.Metadata, }) @@ -46,7 +46,7 @@ func (s *msgUpdateCurator) MsgUpdateCurator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.UpdateCurator(s.sdkCtx, &msg) + s.res, s.err = s.k.UpdateCurator(s.sdkCtx, &msg) } func (s *msgUpdateCurator) ExpectNoError() { @@ -70,7 +70,7 @@ func (s *msgUpdateCurator) ExpectStateContent(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.ContentTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.ContentTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/content/server/msg_update_metadata.go b/content/keeper/msg_update_metadata.go similarity index 88% rename from content/server/msg_update_metadata.go rename to content/keeper/msg_update_metadata.go index 1348699..c6a7eee 100644 --- a/content/server/msg_update_metadata.go +++ b/content/keeper/msg_update_metadata.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,7 +11,7 @@ import ( ) // UpdateMetadata implements the Msg/UpdateMetadata method. -func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (*v1.MsgUpdateMetadataResponse, error) { +func (k Keeper) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (*v1.MsgUpdateMetadataResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from curator address @@ -21,7 +21,7 @@ func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) ( } // get content from content table - content, err := s.ss.ContentTable().Get(ctx, req.Id) + content, err := k.ss.ContentTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("content with id %d: %s", req.Id, err) @@ -43,7 +43,7 @@ func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) ( content.Metadata = req.NewMetadata // update content in content table - err = s.ss.ContentTable().Update(ctx, content) + err = k.ss.ContentTable().Update(ctx, content) if err != nil { return nil, err // internal error } diff --git a/content/server/msg_update_metadata_test.go b/content/keeper/msg_update_metadata_test.go similarity index 91% rename from content/server/msg_update_metadata_test.go rename to content/keeper/msg_update_metadata_test.go index 2596c14..f408a44 100644 --- a/content/server/msg_update_metadata_test.go +++ b/content/keeper/msg_update_metadata_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgUpdateMetadata) Content(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &content) require.NoError(s.t, err) - id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ + id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ Curator: content.Curator, Metadata: content.Metadata, }) @@ -46,7 +46,7 @@ func (s *msgUpdateMetadata) MsgUpdateMetadata(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.UpdateMetadata(s.sdkCtx, &msg) + s.res, s.err = s.k.UpdateMetadata(s.sdkCtx, &msg) } func (s *msgUpdateMetadata) ExpectNoError() { @@ -70,7 +70,7 @@ func (s *msgUpdateMetadata) ExpectStateContent(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.ContentTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.ContentTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/content/server/query_content.go b/content/keeper/query_content.go similarity index 84% rename from content/server/query_content.go rename to content/keeper/query_content.go index e0fc7a0..b519ac0 100644 --- a/content/server/query_content.go +++ b/content/keeper/query_content.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,10 +11,10 @@ import ( ) // Content implements the Query/Content method. -func (s Server) Content(ctx context.Context, req *v1.QueryContentRequest) (*v1.QueryContentResponse, error) { +func (k Keeper) Content(ctx context.Context, req *v1.QueryContentRequest) (*v1.QueryContentResponse, error) { // get content from content table - content, err := s.ss.ContentTable().Get(ctx, req.Id) + content, err := k.ss.ContentTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("content with id %d", req.Id) diff --git a/content/server/query_content_test.go b/content/keeper/query_content_test.go similarity index 90% rename from content/server/query_content_test.go rename to content/keeper/query_content_test.go index 75a8046..5d744ea 100644 --- a/content/server/query_content_test.go +++ b/content/keeper/query_content_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryContent) Content(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &content) require.NoError(s.t, err) - id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ + id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ Curator: content.Curator, Metadata: content.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryContent) QueryContent(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Content(s.sdkCtx, &req) + s.res, s.err = s.k.Content(s.sdkCtx, &req) } func (s *queryContent) ExpectNoError() { diff --git a/content/server/query_contents.go b/content/keeper/query_contents.go similarity index 90% rename from content/server/query_contents.go rename to content/keeper/query_contents.go index d320071..64e159e 100644 --- a/content/server/query_contents.go +++ b/content/keeper/query_contents.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -12,7 +12,7 @@ import ( ) // Contents implements the Query/Contents method. -func (s Server) Contents(ctx context.Context, req *v1.QueryContentsRequest) (*v1.QueryContentsResponse, error) { +func (k Keeper) Contents(ctx context.Context, req *v1.QueryContentsRequest) (*v1.QueryContentsResponse, error) { // set the index for table lookup index := contentv1.ContentIdIndexKey{} @@ -24,7 +24,7 @@ func (s Server) Contents(ctx context.Context, req *v1.QueryContentsRequest) (*v1 } // get contents from content table - it, err := s.ss.ContentTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.ContentTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/content/server/query_contents_by_curator.go b/content/keeper/query_contents_by_curator.go similarity index 92% rename from content/server/query_contents_by_curator.go rename to content/keeper/query_contents_by_curator.go index 7face3f..31a3033 100644 --- a/content/server/query_contents_by_curator.go +++ b/content/keeper/query_contents_by_curator.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -13,7 +13,7 @@ import ( ) // ContentsByCurator implements the Query/ContentsByCurator method. -func (s Server) ContentsByCurator(ctx context.Context, req *v1.QueryContentsByCuratorRequest) (*v1.QueryContentsByCuratorResponse, error) { +func (k Keeper) ContentsByCurator(ctx context.Context, req *v1.QueryContentsByCuratorRequest) (*v1.QueryContentsByCuratorResponse, error) { // get account from curator address curator, err := sdk.AccAddressFromBech32(req.Curator) @@ -31,7 +31,7 @@ func (s Server) ContentsByCurator(ctx context.Context, req *v1.QueryContentsByCu } // get contents by curator from content table - it, err := s.ss.ContentTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.ContentTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/content/server/query_contents_by_curator_test.go b/content/keeper/query_contents_by_curator_test.go similarity index 90% rename from content/server/query_contents_by_curator_test.go rename to content/keeper/query_contents_by_curator_test.go index 0f07763..1aa9712 100644 --- a/content/server/query_contents_by_curator_test.go +++ b/content/keeper/query_contents_by_curator_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryContentsByCurator) Content(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &content) require.NoError(s.t, err) - id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ + id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ Curator: content.Curator, Metadata: content.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryContentsByCurator) QueryContentsByCurator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.ContentsByCurator(s.sdkCtx, &req) + s.res, s.err = s.k.ContentsByCurator(s.sdkCtx, &req) } func (s *queryContentsByCurator) ExpectNoError() { diff --git a/content/server/query_contents_test.go b/content/keeper/query_contents_test.go similarity index 90% rename from content/server/query_contents_test.go rename to content/keeper/query_contents_test.go index ad41395..28911c2 100644 --- a/content/server/query_contents_test.go +++ b/content/keeper/query_contents_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryContents) Content(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &content) require.NoError(s.t, err) - id, err := s.srv.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ + id, err := s.k.ss.ContentTable().InsertReturningId(s.sdkCtx, &contentv1.Content{ Curator: content.Curator, Metadata: content.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryContents) QueryContents(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Contents(s.sdkCtx, &req) + s.res, s.err = s.k.Contents(s.sdkCtx, &req) } func (s *queryContents) ExpectNoError() { diff --git a/content/module/module.go b/content/module/module.go index 0f6ff72..955cc83 100644 --- a/content/module/module.go +++ b/content/module/module.go @@ -7,8 +7,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "cosmossdk.io/core/appmodule" - storetypes "cosmossdk.io/store/types" - sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -17,7 +15,7 @@ import ( "github.com/choraio/mods/content" "github.com/choraio/mods/content/genesis" - "github.com/choraio/mods/content/server" + "github.com/choraio/mods/content/keeper" v1 "github.com/choraio/mods/content/types/v1" ) @@ -25,32 +23,29 @@ import ( const ConsensusVersion = 1 var ( - _ appmodule.AppModule = AppModule{} - _ module.AppModuleBasic = AppModule{} - _ module.HasGenesis = AppModule{} - _ module.HasServices = AppModule{} + _ appmodule.AppModule = AppModule{} + + _ module.AppModuleBasic = AppModule{} + _ module.HasConsensusVersion = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasInvariants = AppModule{} + _ module.HasServices = AppModule{} ) // AppModule implements the AppModule interface. type AppModule struct { - key storetypes.StoreKey - srv server.Server + cdc codec.BinaryCodec + k keeper.Keeper } -// NewAppModule returns a new module. -func NewAppModule(key storetypes.StoreKey) AppModule { - srv := server.NewServer(key) +// NewAppModule returns a new AppModule instance. +func NewAppModule(cdc codec.BinaryCodec, k keeper.Keeper) AppModule { return AppModule{ - key: key, - srv: srv, + cdc: cdc, + k: k, } } -// ConsensusVersion returns ConsensusVersion. -func (am AppModule) ConsensusVersion() uint64 { - return ConsensusVersion -} - // IsAppModule implements the appmodule.AppModule/IsAppModule. func (am AppModule) IsAppModule() {} @@ -62,11 +57,6 @@ func (am AppModule) Name() string { return content.ModuleName } -// RegisterInterfaces implements module.AppModuleBasic/RegisterInterfaces. -func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { - v1.RegisterInterfaces(registry) -} - // RegisterGRPCGatewayRoutes implements module.AppModuleBasic/RegisterGRPCGatewayRoutes. func (am AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { err := v1.RegisterQueryHandlerClient(context.Background(), mux, v1.NewQueryClient(clientCtx)) @@ -75,14 +65,24 @@ func (am AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux * } } +// RegisterInterfaces implements module.AppModuleBasic/RegisterInterfaces. +func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + v1.RegisterInterfaces(registry) +} + // RegisterLegacyAminoCodec implements module.AppModuleBasic/RegisterLegacyAminoCodec. func (am AppModule) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { v1.RegisterLegacyAminoCodec(amino) } +// ConsensusVersion implements module.HasConsensusVersion/ConsensusVersion. +func (am AppModule) ConsensusVersion() uint64 { + return ConsensusVersion +} + // InitGenesis implements module.HasGenesis/InitGenesis. func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, message json.RawMessage) { - err := am.srv.InitGenesis(ctx, jsonCodec, message) + err := am.k.InitGenesis(ctx, jsonCodec, message) if err != nil { panic(err) } @@ -90,7 +90,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, mess // ExportGenesis implements module.HasGenesis/ExportGenesis. func (am AppModule) ExportGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec) json.RawMessage { - export, err := am.srv.ExportGenesis(ctx, jsonCodec) + export, err := am.k.ExportGenesis(ctx, jsonCodec) if err != nil { panic(err) } @@ -107,8 +107,11 @@ func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ sdkclient.TxEncodingCon return genesis.ValidateGenesis(bz) } +// RegisterInvariants implements module.HasInvariants/RegisterInvariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + // RegisterServices implements module.HasServices/RegisterServices. func (am AppModule) RegisterServices(cfg module.Configurator) { - v1.RegisterMsgServer(cfg.MsgServer(), am.srv) - v1.RegisterQueryServer(cfg.QueryServer(), am.srv) + v1.RegisterMsgServer(cfg.MsgServer(), am.k) + v1.RegisterQueryServer(cfg.QueryServer(), am.k) } diff --git a/geonode/server/config.go b/geonode/keeper/config.go similarity index 90% rename from geonode/server/config.go rename to geonode/keeper/config.go index dcf49ef..d126fbd 100644 --- a/geonode/server/config.go +++ b/geonode/keeper/config.go @@ -1,4 +1,4 @@ -package server +package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/geonode/server/features/msg_create.feature b/geonode/keeper/features/msg_create.feature similarity index 100% rename from geonode/server/features/msg_create.feature rename to geonode/keeper/features/msg_create.feature diff --git a/geonode/server/features/msg_update_curator.feature b/geonode/keeper/features/msg_update_curator.feature similarity index 100% rename from geonode/server/features/msg_update_curator.feature rename to geonode/keeper/features/msg_update_curator.feature diff --git a/geonode/server/features/msg_update_metadata.feature b/geonode/keeper/features/msg_update_metadata.feature similarity index 100% rename from geonode/server/features/msg_update_metadata.feature rename to geonode/keeper/features/msg_update_metadata.feature diff --git a/geonode/server/features/query_node.feature b/geonode/keeper/features/query_node.feature similarity index 100% rename from geonode/server/features/query_node.feature rename to geonode/keeper/features/query_node.feature diff --git a/geonode/server/features/query_nodes.feature b/geonode/keeper/features/query_nodes.feature similarity index 100% rename from geonode/server/features/query_nodes.feature rename to geonode/keeper/features/query_nodes.feature diff --git a/geonode/server/features/query_nodes_by_curator.feature b/geonode/keeper/features/query_nodes_by_curator.feature similarity index 100% rename from geonode/server/features/query_nodes_by_curator.feature rename to geonode/keeper/features/query_nodes_by_curator.feature diff --git a/geonode/server/server.go b/geonode/keeper/keeper.go similarity index 63% rename from geonode/server/server.go rename to geonode/keeper/keeper.go index d7075e3..7c8e7d9 100644 --- a/geonode/server/server.go +++ b/geonode/keeper/keeper.go @@ -1,10 +1,9 @@ -package server +package keeper import ( "encoding/json" "cosmossdk.io/orm/model/ormdb" - storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,36 +13,36 @@ import ( ) var ( - _ v1.MsgServer = &Server{} - _ v1.QueryServer = &Server{} + _ v1.MsgServer = &Keeper{} + _ v1.QueryServer = &Keeper{} ) -// Server is the server. -type Server struct { - db ormdb.ModuleDB - ss geonodev1.StateStore +// Keeper is the keeper. +type Keeper struct { + db ormdb.ModuleDB // module database + ss geonodev1.StateStore // module state store } -// NewServer creates a new server. -func NewServer(key storetypes.StoreKey) Server { - s := Server{} +// NewKeeper creates a new keeper. +func NewKeeper() Keeper { + k := Keeper{} var err error - s.db, err = ormdb.NewModuleDB(&geonode.ModuleSchema, ormdb.ModuleDBOptions{}) + k.db, err = ormdb.NewModuleDB(&geonode.ModuleSchema, ormdb.ModuleDBOptions{}) if err != nil { panic(err) } - s.ss, err = geonodev1.NewStateStore(s.db) + k.ss, err = geonodev1.NewStateStore(k.db) if err != nil { panic(err) } - return s + return k } // InitGenesis initializes genesis state. -func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error { +func (k Keeper) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error { //source, err := ormjson.NewRawMessageSource(data) //if err != nil { // return err @@ -58,7 +57,7 @@ func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMes } // ExportGenesis exports genesis state. -func (s Server) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) { +func (k Keeper) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) { //target := ormjson.NewRawMessageTarget() // //err := s.db.ExportJSON(sdk.WrapSDKContext(ctx), target) diff --git a/geonode/server/server_test.go b/geonode/keeper/keeper_test.go similarity index 94% rename from geonode/server/server_test.go rename to geonode/keeper/keeper_test.go index 42f3b26..278efac 100644 --- a/geonode/server/server_test.go +++ b/geonode/keeper/keeper_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "cosmossdk.io/log" @@ -19,7 +19,7 @@ import ( type baseSuite struct { t gocuke.TestingT sdkCtx sdk.Context - srv Server + k Keeper } func setupBase(t gocuke.TestingT) *baseSuite { @@ -46,8 +46,8 @@ func setupBase(t gocuke.TestingT) *baseSuite { // create and set sdk context from commit multi-store with orm context s.sdkCtx = sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()).WithContext(ormCtx) - // create and set server - s.srv = NewServer(key) + // create and set keeper + s.k = NewKeeper() return s } diff --git a/geonode/server/msg_create.go b/geonode/keeper/msg_create.go similarity index 84% rename from geonode/server/msg_create.go rename to geonode/keeper/msg_create.go index a48d901..d62dfc2 100644 --- a/geonode/server/msg_create.go +++ b/geonode/keeper/msg_create.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -10,7 +10,7 @@ import ( ) // Create implements Msg/Create. -func (s Server) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateResponse, error) { +func (k Keeper) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from curator address @@ -20,7 +20,7 @@ func (s Server) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateRes } // insert node into node table - id, err := s.ss.NodeTable().InsertReturningId(ctx, &geonodev1.Node{ + id, err := k.ss.NodeTable().InsertReturningId(ctx, &geonodev1.Node{ Curator: curator, Metadata: req.Metadata, }) diff --git a/geonode/server/msg_create_test.go b/geonode/keeper/msg_create_test.go similarity index 93% rename from geonode/server/msg_create_test.go rename to geonode/keeper/msg_create_test.go index f7625ba..8bb8041 100644 --- a/geonode/server/msg_create_test.go +++ b/geonode/keeper/msg_create_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgCreate) MsgCreate(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.Create(s.sdkCtx, &msg) + s.res, s.err = s.k.Create(s.sdkCtx, &msg) } func (s *msgCreate) ExpectNoError() { @@ -53,7 +53,7 @@ func (s *msgCreate) ExpectStateNode(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.NodeTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.NodeTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/geonode/server/msg_update_curator.go b/geonode/keeper/msg_update_curator.go similarity index 89% rename from geonode/server/msg_update_curator.go rename to geonode/keeper/msg_update_curator.go index 01ef6a2..8a51d75 100644 --- a/geonode/server/msg_update_curator.go +++ b/geonode/keeper/msg_update_curator.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,7 +11,7 @@ import ( ) // UpdateCurator implements the Msg/UpdateCurator method. -func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v1.MsgUpdateCuratorResponse, error) { +func (k Keeper) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v1.MsgUpdateCuratorResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from curator address @@ -21,7 +21,7 @@ func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v } // get node from node table - node, err := s.ss.NodeTable().Get(ctx, req.Id) + node, err := k.ss.NodeTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("node with id %d: %s", req.Id, err) @@ -49,7 +49,7 @@ func (s Server) UpdateCurator(ctx context.Context, req *v1.MsgUpdateCurator) (*v node.Curator = newCurator // update node in node table - err = s.ss.NodeTable().Update(ctx, node) + err = k.ss.NodeTable().Update(ctx, node) if err != nil { return nil, err // internal error } diff --git a/geonode/server/msg_update_curator_test.go b/geonode/keeper/msg_update_curator_test.go similarity index 91% rename from geonode/server/msg_update_curator_test.go rename to geonode/keeper/msg_update_curator_test.go index ea2d5bf..0579d33 100644 --- a/geonode/server/msg_update_curator_test.go +++ b/geonode/keeper/msg_update_curator_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgUpdateCurator) Node(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &node) require.NoError(s.t, err) - id, err := s.srv.ss.NodeTable().InsertReturningId(s.sdkCtx, &contentv1.Node{ + id, err := s.k.ss.NodeTable().InsertReturningId(s.sdkCtx, &contentv1.Node{ Curator: node.Curator, Metadata: node.Metadata, }) @@ -46,7 +46,7 @@ func (s *msgUpdateCurator) MsgUpdateCurator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.UpdateCurator(s.sdkCtx, &msg) + s.res, s.err = s.k.UpdateCurator(s.sdkCtx, &msg) } func (s *msgUpdateCurator) ExpectNoError() { @@ -70,7 +70,7 @@ func (s *msgUpdateCurator) ExpectStateNode(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.NodeTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.NodeTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/geonode/server/msg_update_metadata.go b/geonode/keeper/msg_update_metadata.go similarity index 89% rename from geonode/server/msg_update_metadata.go rename to geonode/keeper/msg_update_metadata.go index 60ccd19..a3a14cd 100644 --- a/geonode/server/msg_update_metadata.go +++ b/geonode/keeper/msg_update_metadata.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,7 +11,7 @@ import ( ) // UpdateMetadata implements the Msg/UpdateMetadata method. -func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (*v1.MsgUpdateMetadataResponse, error) { +func (k Keeper) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (*v1.MsgUpdateMetadataResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from curator address @@ -21,7 +21,7 @@ func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) ( } // get node from node table - node, err := s.ss.NodeTable().Get(ctx, req.Id) + node, err := k.ss.NodeTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("node with id %d: %s", req.Id, err) @@ -43,7 +43,7 @@ func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) ( node.Metadata = req.NewMetadata // update node in node table - err = s.ss.NodeTable().Update(ctx, node) + err = k.ss.NodeTable().Update(ctx, node) if err != nil { return nil, err // internal error } diff --git a/geonode/server/msg_update_metadata_test.go b/geonode/keeper/msg_update_metadata_test.go similarity index 91% rename from geonode/server/msg_update_metadata_test.go rename to geonode/keeper/msg_update_metadata_test.go index 27c31fa..ac3d335 100644 --- a/geonode/server/msg_update_metadata_test.go +++ b/geonode/keeper/msg_update_metadata_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgUpdateMetadata) Node(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &node) require.NoError(s.t, err) - id, err := s.srv.ss.NodeTable().InsertReturningId(s.sdkCtx, &contentv1.Node{ + id, err := s.k.ss.NodeTable().InsertReturningId(s.sdkCtx, &contentv1.Node{ Curator: node.Curator, Metadata: node.Metadata, }) @@ -46,7 +46,7 @@ func (s *msgUpdateMetadata) MsgUpdateMetadata(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.UpdateMetadata(s.sdkCtx, &msg) + s.res, s.err = s.k.UpdateMetadata(s.sdkCtx, &msg) } func (s *msgUpdateMetadata) ExpectNoError() { @@ -70,7 +70,7 @@ func (s *msgUpdateMetadata) ExpectStateNode(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.NodeTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.NodeTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/geonode/server/query_node.go b/geonode/keeper/query_node.go similarity index 84% rename from geonode/server/query_node.go rename to geonode/keeper/query_node.go index 3894584..884625a 100644 --- a/geonode/server/query_node.go +++ b/geonode/keeper/query_node.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,10 +11,10 @@ import ( ) // Node implements the Query/Node method. -func (s Server) Node(ctx context.Context, req *v1.QueryNodeRequest) (*v1.QueryNodeResponse, error) { +func (k Keeper) Node(ctx context.Context, req *v1.QueryNodeRequest) (*v1.QueryNodeResponse, error) { // get node from node table - node, err := s.ss.NodeTable().Get(ctx, req.Id) + node, err := k.ss.NodeTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("node with id %d", req.Id) diff --git a/geonode/server/query_node_test.go b/geonode/keeper/query_node_test.go similarity index 90% rename from geonode/server/query_node_test.go rename to geonode/keeper/query_node_test.go index 45cf266..4832dcc 100644 --- a/geonode/server/query_node_test.go +++ b/geonode/keeper/query_node_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryNode) Node(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &node) require.NoError(s.t, err) - id, err := s.srv.ss.NodeTable().InsertReturningId(s.sdkCtx, &geonodev1.Node{ + id, err := s.k.ss.NodeTable().InsertReturningId(s.sdkCtx, &geonodev1.Node{ Curator: node.Curator, Metadata: node.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryNode) QueryNode(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Node(s.sdkCtx, &req) + s.res, s.err = s.k.Node(s.sdkCtx, &req) } func (s *queryNode) ExpectNoError() { diff --git a/geonode/server/query_nodes.go b/geonode/keeper/query_nodes.go similarity index 90% rename from geonode/server/query_nodes.go rename to geonode/keeper/query_nodes.go index 907d766..1d434f0 100644 --- a/geonode/server/query_nodes.go +++ b/geonode/keeper/query_nodes.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -12,7 +12,7 @@ import ( ) // Nodes implements the Query/Nodes method. -func (s Server) Nodes(ctx context.Context, req *v1.QueryNodesRequest) (*v1.QueryNodesResponse, error) { +func (k Keeper) Nodes(ctx context.Context, req *v1.QueryNodesRequest) (*v1.QueryNodesResponse, error) { // set index for table lookup index := geonodev1.NodeIdIndexKey{} @@ -24,7 +24,7 @@ func (s Server) Nodes(ctx context.Context, req *v1.QueryNodesRequest) (*v1.Query } // get nodes from node table - it, err := s.ss.NodeTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.NodeTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/geonode/server/query_nodes_by_curator.go b/geonode/keeper/query_nodes_by_curator.go similarity index 91% rename from geonode/server/query_nodes_by_curator.go rename to geonode/keeper/query_nodes_by_curator.go index 8ce22df..1f91428 100644 --- a/geonode/server/query_nodes_by_curator.go +++ b/geonode/keeper/query_nodes_by_curator.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -13,7 +13,7 @@ import ( ) // NodesByCurator implements the Query/NodesByCurator method. -func (s Server) NodesByCurator(ctx context.Context, req *v1.QueryNodesByCuratorRequest) (*v1.QueryNodesByCuratorResponse, error) { +func (k Keeper) NodesByCurator(ctx context.Context, req *v1.QueryNodesByCuratorRequest) (*v1.QueryNodesByCuratorResponse, error) { // get account from curator address curator, err := sdk.AccAddressFromBech32(req.Curator) @@ -31,7 +31,7 @@ func (s Server) NodesByCurator(ctx context.Context, req *v1.QueryNodesByCuratorR } // get nodes by curator from node table - it, err := s.ss.NodeTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.NodeTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/geonode/server/query_nodes_by_curator_test.go b/geonode/keeper/query_nodes_by_curator_test.go similarity index 90% rename from geonode/server/query_nodes_by_curator_test.go rename to geonode/keeper/query_nodes_by_curator_test.go index c79175f..95066f7 100644 --- a/geonode/server/query_nodes_by_curator_test.go +++ b/geonode/keeper/query_nodes_by_curator_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryNodesByCurator) Node(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &node) require.NoError(s.t, err) - id, err := s.srv.ss.NodeTable().InsertReturningId(s.sdkCtx, &geonodev1.Node{ + id, err := s.k.ss.NodeTable().InsertReturningId(s.sdkCtx, &geonodev1.Node{ Curator: node.Curator, Metadata: node.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryNodesByCurator) QueryNodesByCurator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.NodesByCurator(s.sdkCtx, &req) + s.res, s.err = s.k.NodesByCurator(s.sdkCtx, &req) } func (s *queryNodesByCurator) ExpectNoError() { diff --git a/geonode/server/query_nodes_test.go b/geonode/keeper/query_nodes_test.go similarity index 90% rename from geonode/server/query_nodes_test.go rename to geonode/keeper/query_nodes_test.go index f2f3495..ba5dc9b 100644 --- a/geonode/server/query_nodes_test.go +++ b/geonode/keeper/query_nodes_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryNodes) Node(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &node) require.NoError(s.t, err) - id, err := s.srv.ss.NodeTable().InsertReturningId(s.sdkCtx, &geonodev1.Node{ + id, err := s.k.ss.NodeTable().InsertReturningId(s.sdkCtx, &geonodev1.Node{ Curator: node.Curator, Metadata: node.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryNodes) QueryNodes(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Nodes(s.sdkCtx, &req) + s.res, s.err = s.k.Nodes(s.sdkCtx, &req) } func (s *queryNodes) ExpectNoError() { diff --git a/geonode/module/module.go b/geonode/module/module.go index 0e6efb3..4282bb9 100644 --- a/geonode/module/module.go +++ b/geonode/module/module.go @@ -7,8 +7,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "cosmossdk.io/core/appmodule" - storetypes "cosmossdk.io/store/types" - sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -17,7 +15,7 @@ import ( "github.com/choraio/mods/geonode" "github.com/choraio/mods/geonode/genesis" - "github.com/choraio/mods/geonode/server" + "github.com/choraio/mods/geonode/keeper" v1 "github.com/choraio/mods/geonode/types/v1" ) @@ -25,32 +23,29 @@ import ( const ConsensusVersion = 1 var ( - _ appmodule.AppModule = AppModule{} - _ module.AppModuleBasic = AppModule{} - _ module.HasGenesis = AppModule{} - _ module.HasServices = AppModule{} + _ appmodule.AppModule = AppModule{} + + _ module.AppModuleBasic = AppModule{} + _ module.HasConsensusVersion = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasInvariants = AppModule{} + _ module.HasServices = AppModule{} ) // AppModule implements the AppModule interface. type AppModule struct { - key storetypes.StoreKey - srv server.Server + cdc codec.BinaryCodec + k keeper.Keeper } -// NewAppModule returns a new module. -func NewAppModule(key storetypes.StoreKey) AppModule { - srv := server.NewServer(key) +// NewAppModule returns a new AppModule instance. +func NewAppModule(cdc codec.BinaryCodec, k keeper.Keeper) AppModule { return AppModule{ - key: key, - srv: srv, + cdc: cdc, + k: k, } } -// ConsensusVersion returns ConsensusVersion. -func (am AppModule) ConsensusVersion() uint64 { - return ConsensusVersion -} - // IsAppModule implements the appmodule.AppModule/IsAppModule. func (am AppModule) IsAppModule() {} @@ -62,11 +57,6 @@ func (am AppModule) Name() string { return geonode.ModuleName } -// RegisterInterfaces implements module.AppModuleBasic/RegisterInterfaces. -func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { - v1.RegisterInterfaces(registry) -} - // RegisterGRPCGatewayRoutes implements module.AppModuleBasic/RegisterGRPCGatewayRoutes. func (am AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { err := v1.RegisterQueryHandlerClient(context.Background(), mux, v1.NewQueryClient(clientCtx)) @@ -75,14 +65,24 @@ func (am AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux * } } +// RegisterInterfaces implements module.AppModuleBasic/RegisterInterfaces. +func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + v1.RegisterInterfaces(registry) +} + // RegisterLegacyAminoCodec implements module.AppModuleBasic/RegisterLegacyAminoCodec. func (am AppModule) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { v1.RegisterLegacyAminoCodec(amino) } +// ConsensusVersion implements module.HasConsensusVersion/ConsensusVersion. +func (am AppModule) ConsensusVersion() uint64 { + return ConsensusVersion +} + // InitGenesis implements module.HasGenesis/InitGenesis. func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, message json.RawMessage) { - err := am.srv.InitGenesis(ctx, jsonCodec, message) + err := am.k.InitGenesis(ctx, jsonCodec, message) if err != nil { panic(err) } @@ -90,7 +90,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, mess // ExportGenesis implements module.HasGenesis/ExportGenesis. func (am AppModule) ExportGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec) json.RawMessage { - export, err := am.srv.ExportGenesis(ctx, jsonCodec) + export, err := am.k.ExportGenesis(ctx, jsonCodec) if err != nil { panic(err) } @@ -107,8 +107,11 @@ func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ sdkclient.TxEncodingCon return genesis.ValidateGenesis(bz) } +// RegisterInvariants implements module.HasInvariants/RegisterInvariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + // RegisterServices implements module.HasServices/RegisterServices. func (am AppModule) RegisterServices(cfg module.Configurator) { - v1.RegisterMsgServer(cfg.MsgServer(), am.srv) - v1.RegisterQueryServer(cfg.QueryServer(), am.srv) + v1.RegisterMsgServer(cfg.MsgServer(), am.k) + v1.RegisterQueryServer(cfg.QueryServer(), am.k) } diff --git a/validator/server/config.go b/validator/keeper/config.go similarity index 90% rename from validator/server/config.go rename to validator/keeper/config.go index dcf49ef..d126fbd 100644 --- a/validator/server/config.go +++ b/validator/keeper/config.go @@ -1,4 +1,4 @@ -package server +package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/validator/server/features/msg_add_validator.feature b/validator/keeper/features/msg_add_validator.feature similarity index 100% rename from validator/server/features/msg_add_validator.feature rename to validator/keeper/features/msg_add_validator.feature diff --git a/validator/server/features/msg_remove_validator.feature b/validator/keeper/features/msg_remove_validator.feature similarity index 100% rename from validator/server/features/msg_remove_validator.feature rename to validator/keeper/features/msg_remove_validator.feature diff --git a/validator/server/features/msg_update_policy.feature b/validator/keeper/features/msg_update_policy.feature similarity index 100% rename from validator/server/features/msg_update_policy.feature rename to validator/keeper/features/msg_update_policy.feature diff --git a/validator/server/features/msg_update_validator.feature b/validator/keeper/features/msg_update_validator.feature similarity index 100% rename from validator/server/features/msg_update_validator.feature rename to validator/keeper/features/msg_update_validator.feature diff --git a/validator/server/features/query_policy.feature b/validator/keeper/features/query_policy.feature similarity index 100% rename from validator/server/features/query_policy.feature rename to validator/keeper/features/query_policy.feature diff --git a/validator/server/features/query_validator.feature b/validator/keeper/features/query_validator.feature similarity index 100% rename from validator/server/features/query_validator.feature rename to validator/keeper/features/query_validator.feature diff --git a/validator/server/features/query_validators.feature b/validator/keeper/features/query_validators.feature similarity index 100% rename from validator/server/features/query_validators.feature rename to validator/keeper/features/query_validators.feature diff --git a/validator/server/server.go b/validator/keeper/keeper.go similarity index 72% rename from validator/server/server.go rename to validator/keeper/keeper.go index ce205a2..596a1b0 100644 --- a/validator/server/server.go +++ b/validator/keeper/keeper.go @@ -1,10 +1,9 @@ -package server +package keeper import ( "encoding/json" "cosmossdk.io/orm/model/ormdb" - storetypes "cosmossdk.io/store/types" abci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,45 +14,45 @@ import ( ) var ( - _ v1.MsgServer = &Server{} - _ v1.QueryServer = &Server{} + _ v1.MsgServer = &Keeper{} + _ v1.QueryServer = &Keeper{} ) -// Server is the server. -type Server struct { - db ormdb.ModuleDB - ss validatorv1.StateStore - authority sdk.AccAddress +// Keeper is the keeper. +type Keeper struct { + authority sdk.AccAddress // authority account address + + db ormdb.ModuleDB // module database + ss validatorv1.StateStore // module state store } -// NewServer creates a new server. -func NewServer(key storetypes.StoreKey, authority sdk.AccAddress) Server { - s := Server{} +// NewKeeper creates a new keeper. +func NewKeeper(authority sdk.AccAddress) Keeper { + k := Keeper{authority: authority} var err error - s.db, err = ormdb.NewModuleDB(&validator.ModuleSchema, ormdb.ModuleDBOptions{}) + + k.db, err = ormdb.NewModuleDB(&validator.ModuleSchema, ormdb.ModuleDBOptions{}) if err != nil { panic(err) } - s.ss, err = validatorv1.NewStateStore(s.db) + k.ss, err = validatorv1.NewStateStore(k.db) if err != nil { panic(err) } - s.authority = authority - - return s + return k } // InitGenesis initializes genesis state. -func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error { +func (k Keeper) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error { //source, err := ormjson.NewRawMessageSource(data) //if err != nil { // return err //} // - //err = s.db.ImportJSON(sdk.WrapSDKContext(ctx), source) + //err = k.db.ImportJSON(sdk.WrapSDKContext(ctx), source) //if err != nil { // return err //} @@ -62,10 +61,10 @@ func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMes } // ExportGenesis exports genesis state. -func (s Server) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) { +func (k Keeper) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) { //target := ormjson.NewRawMessageTarget() // - //err := s.db.ExportJSON(sdk.WrapSDKContext(ctx), target) + //err := k.db.ExportJSON(sdk.WrapSDKContext(ctx), target) //if err != nil { // return nil, err //} @@ -76,8 +75,8 @@ func (s Server) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessa } // GetPolicy gets the validator signing policy. -func (s Server) GetPolicy(ctx sdk.Context) (*validatorv1.Policy, error) { - policy, err := s.ss.PolicyTable().Get(ctx) +func (k Keeper) GetPolicy(ctx sdk.Context) (*validatorv1.Policy, error) { + policy, err := k.ss.PolicyTable().Get(ctx) if err != nil { return nil, err } @@ -85,14 +84,14 @@ func (s Server) GetPolicy(ctx sdk.Context) (*validatorv1.Policy, error) { } // HandleSigningInfo tracks validator signing info and enforces the policy. -func (s Server) HandleSigningInfo(ctx sdk.Context, voteInfo abci.VoteInfo, policy *validatorv1.Policy) error { +func (k Keeper) HandleSigningInfo(ctx sdk.Context, voteInfo abci.VoteInfo, policy *validatorv1.Policy) error { height := ctx.BlockHeight() // set validator address address := sdk.ConsAddress(voteInfo.Validator.Address) // get validator signing info - signingInfo, err := s.ss.ValidatorSigningInfoTable().Get(ctx, address.String()) + signingInfo, err := k.ss.ValidatorSigningInfoTable().Get(ctx, address.String()) if err != nil { return err // internal error } @@ -138,19 +137,19 @@ func (s Server) HandleSigningInfo(ctx sdk.Context, voteInfo abci.VoteInfo, polic // remove validator if validator missed blocks exceeds max missed blocks if height > minHeight && signingInfo.MissedBlocksCount > maxMissed { // get validator - validator, err := s.ss.ValidatorTable().Get(ctx, address.String()) + validator, err := k.ss.ValidatorTable().Get(ctx, address.String()) if err != nil { return err // internal error } // delete validator - err = s.ss.ValidatorTable().Delete(ctx, validator) + err = k.ss.ValidatorTable().Delete(ctx, validator) if err != nil { return err // internal error } // delete validator signing info - err = s.ss.ValidatorSigningInfoTable().Delete(ctx, signingInfo) + err = k.ss.ValidatorSigningInfoTable().Delete(ctx, signingInfo) if err != nil { return err // internal error } @@ -163,7 +162,7 @@ func (s Server) HandleSigningInfo(ctx sdk.Context, voteInfo abci.VoteInfo, polic } } else { // update validator signing info - err = s.ss.ValidatorSigningInfoTable().Update(ctx, signingInfo) + err = k.ss.ValidatorSigningInfoTable().Update(ctx, signingInfo) if err != nil { return err // internal error } diff --git a/validator/server/server_test.go b/validator/keeper/keeper_test.go similarity index 94% rename from validator/server/server_test.go rename to validator/keeper/keeper_test.go index f6dec31..b487c6a 100644 --- a/validator/server/server_test.go +++ b/validator/keeper/keeper_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "cosmossdk.io/log" @@ -19,8 +19,8 @@ import ( type baseSuite struct { t gocuke.TestingT sdkCtx sdk.Context + k Keeper authority sdk.AccAddress - srv Server } func setupBase(t gocuke.TestingT) *baseSuite { @@ -53,8 +53,8 @@ func setupBase(t gocuke.TestingT) *baseSuite { s.authority, err = sdk.AccAddressFromBech32("chora1q5m97jdcksj24g9enlkjqq75ygt5q6ak54jk38") require.NoError(t, err) - // create and set server - s.srv = NewServer(key, s.authority) + // create and set keeper + s.k = NewKeeper(s.authority) return s } diff --git a/validator/server/msg_add_validator.go b/validator/keeper/msg_add_validator.go similarity index 81% rename from validator/server/msg_add_validator.go rename to validator/keeper/msg_add_validator.go index 776abc3..6e75e62 100644 --- a/validator/server/msg_add_validator.go +++ b/validator/keeper/msg_add_validator.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,10 +11,10 @@ import ( ) // AddValidator implements Msg/AddValidator. -func (s Server) AddValidator(ctx context.Context, req *v1.MsgAddValidator) (*v1.MsgAddValidatorResponse, error) { +func (k Keeper) AddValidator(ctx context.Context, req *v1.MsgAddValidator) (*v1.MsgAddValidatorResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - authorityAddress := s.authority.String() + authorityAddress := k.authority.String() if authorityAddress != req.Authority { return nil, sdkerrors.ErrUnauthorized.Wrapf( "authority: expected %s: received %s", authorityAddress, req.Authority, @@ -22,7 +22,7 @@ func (s Server) AddValidator(ctx context.Context, req *v1.MsgAddValidator) (*v1. } // insert validator into validator table - err := s.ss.ValidatorTable().Insert(ctx, &validatorv1.Validator{ + err := k.ss.ValidatorTable().Insert(ctx, &validatorv1.Validator{ Address: req.Address, Metadata: req.Metadata, }) @@ -31,7 +31,7 @@ func (s Server) AddValidator(ctx context.Context, req *v1.MsgAddValidator) (*v1. } // insert validator into validator signing info table - err = s.ss.ValidatorSigningInfoTable().Insert(ctx, &validatorv1.ValidatorSigningInfo{ + err = k.ss.ValidatorSigningInfoTable().Insert(ctx, &validatorv1.ValidatorSigningInfo{ Address: req.Address, }) if err != nil { diff --git a/validator/server/msg_add_validator_test.go b/validator/keeper/msg_add_validator_test.go similarity index 93% rename from validator/server/msg_add_validator_test.go rename to validator/keeper/msg_add_validator_test.go index 461f8f1..8770478 100644 --- a/validator/server/msg_add_validator_test.go +++ b/validator/keeper/msg_add_validator_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -37,7 +37,7 @@ func (s *msgAddValidator) MsgAddValidator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.AddValidator(s.sdkCtx, &msg) + s.res, s.err = s.k.AddValidator(s.sdkCtx, &msg) } func (s *msgAddValidator) ExpectNoError() { @@ -61,7 +61,7 @@ func (s *msgAddValidator) ExpectStateValidator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.ValidatorTable().Get(s.sdkCtx, expected.Address) + actual, err := s.k.ss.ValidatorTable().Get(s.sdkCtx, expected.Address) require.NoError(s.t, err) require.Equal(s.t, expected.Address, actual.Address) diff --git a/validator/server/msg_remove_validator.go b/validator/keeper/msg_remove_validator.go similarity index 80% rename from validator/server/msg_remove_validator.go rename to validator/keeper/msg_remove_validator.go index 7fcc131..cc837b6 100644 --- a/validator/server/msg_remove_validator.go +++ b/validator/keeper/msg_remove_validator.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,10 +11,10 @@ import ( ) // RemoveValidator implements Msg/RemoveValidator. -func (s Server) RemoveValidator(ctx context.Context, req *v1.MsgRemoveValidator) (*v1.MsgRemoveValidatorResponse, error) { +func (k Keeper) RemoveValidator(ctx context.Context, req *v1.MsgRemoveValidator) (*v1.MsgRemoveValidatorResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - authorityAddress := s.authority.String() + authorityAddress := k.authority.String() if authorityAddress != req.Authority { return nil, sdkerrors.ErrUnauthorized.Wrapf( "authority: expected %s: received %s", authorityAddress, req.Authority, @@ -22,7 +22,7 @@ func (s Server) RemoveValidator(ctx context.Context, req *v1.MsgRemoveValidator) } // get validator from validator table - validator, err := s.ss.ValidatorTable().Get(ctx, req.Address) + validator, err := k.ss.ValidatorTable().Get(ctx, req.Address) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf( @@ -33,7 +33,7 @@ func (s Server) RemoveValidator(ctx context.Context, req *v1.MsgRemoveValidator) } // get signing info from validator signing info table - signingInfo, err := s.ss.ValidatorSigningInfoTable().Get(ctx, req.Address) + signingInfo, err := k.ss.ValidatorSigningInfoTable().Get(ctx, req.Address) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf( @@ -44,13 +44,13 @@ func (s Server) RemoveValidator(ctx context.Context, req *v1.MsgRemoveValidator) } // delete validator from validator table - err = s.ss.ValidatorTable().Delete(ctx, validator) + err = k.ss.ValidatorTable().Delete(ctx, validator) if err != nil { return nil, err // internal error } // delete validator from validator signing info table - err = s.ss.ValidatorSigningInfoTable().Delete(ctx, signingInfo) + err = k.ss.ValidatorSigningInfoTable().Delete(ctx, signingInfo) if err != nil { return nil, err // internal error } diff --git a/validator/server/msg_remove_validator_test.go b/validator/keeper/msg_remove_validator_test.go similarity index 87% rename from validator/server/msg_remove_validator_test.go rename to validator/keeper/msg_remove_validator_test.go index 2c4c307..9dc359f 100644 --- a/validator/server/msg_remove_validator_test.go +++ b/validator/keeper/msg_remove_validator_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -37,7 +37,7 @@ func (s *msgRemoveValidator) Validator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &validator) require.NoError(s.t, err) - err = s.srv.ss.ValidatorTable().Insert(s.sdkCtx, &validatorv1.Validator{ + err = s.k.ss.ValidatorTable().Insert(s.sdkCtx, &validatorv1.Validator{ Address: validator.Address, }) require.NoError(s.t, err) @@ -48,7 +48,7 @@ func (s *msgRemoveValidator) ValidatorSigningInfo(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &missedBlocks) require.NoError(s.t, err) - err = s.srv.ss.ValidatorSigningInfoTable().Insert(s.sdkCtx, &validatorv1.ValidatorSigningInfo{ + err = s.k.ss.ValidatorSigningInfoTable().Insert(s.sdkCtx, &validatorv1.ValidatorSigningInfo{ Address: missedBlocks.Address, MissedBlocks: missedBlocks.MissedBlocks, }) @@ -60,7 +60,7 @@ func (s *msgRemoveValidator) MsgRemoveValidator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.RemoveValidator(s.sdkCtx, &msg) + s.res, s.err = s.k.RemoveValidator(s.sdkCtx, &msg) } func (s *msgRemoveValidator) ExpectNoError() { @@ -80,13 +80,13 @@ func (s *msgRemoveValidator) ExpectResponse(a gocuke.DocString) { } func (s *msgRemoveValidator) ExpectNoValidatorWithAddress(a string) { - found, err := s.srv.ss.ValidatorTable().Has(s.sdkCtx, a) + found, err := s.k.ss.ValidatorTable().Has(s.sdkCtx, a) require.NoError(s.t, err) require.False(s.t, found) } func (s *msgRemoveValidator) ExpectNoValidatorSigningInfoWithAddress(a string) { - found, err := s.srv.ss.ValidatorSigningInfoTable().Has(s.sdkCtx, a) + found, err := s.k.ss.ValidatorSigningInfoTable().Has(s.sdkCtx, a) require.NoError(s.t, err) require.False(s.t, found) } diff --git a/validator/server/msg_update_policy.go b/validator/keeper/msg_update_policy.go similarity index 85% rename from validator/server/msg_update_policy.go rename to validator/keeper/msg_update_policy.go index 083c486..8aa2bec 100644 --- a/validator/server/msg_update_policy.go +++ b/validator/keeper/msg_update_policy.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -10,10 +10,10 @@ import ( ) // UpdatePolicy implements Msg/UpdatePolicy. -func (s Server) UpdatePolicy(ctx context.Context, req *v1.MsgUpdatePolicy) (*v1.MsgUpdatePolicyResponse, error) { +func (k Keeper) UpdatePolicy(ctx context.Context, req *v1.MsgUpdatePolicy) (*v1.MsgUpdatePolicyResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - authorityAddress := s.authority.String() + authorityAddress := k.authority.String() if authorityAddress != req.Authority { return nil, sdkerrors.ErrUnauthorized.Wrapf( "authority: expected %s: received %s", authorityAddress, req.Authority, @@ -21,7 +21,7 @@ func (s Server) UpdatePolicy(ctx context.Context, req *v1.MsgUpdatePolicy) (*v1. } // get max missed blocks from max missed blocks table - policy, err := s.ss.PolicyTable().Get(ctx) + policy, err := k.ss.PolicyTable().Get(ctx) if err != nil { return nil, err // internal error } @@ -33,7 +33,7 @@ func (s Server) UpdatePolicy(ctx context.Context, req *v1.MsgUpdatePolicy) (*v1. policy.MinSignedPerWindow = req.MinSignedPerWindow // update max missed blocks in max missed blocks table - err = s.ss.PolicyTable().Save(ctx, policy) + err = k.ss.PolicyTable().Save(ctx, policy) if err != nil { return nil, err // internal error } diff --git a/validator/server/msg_update_policy_test.go b/validator/keeper/msg_update_policy_test.go similarity index 92% rename from validator/server/msg_update_policy_test.go rename to validator/keeper/msg_update_policy_test.go index 85fddcb..2561e24 100644 --- a/validator/server/msg_update_policy_test.go +++ b/validator/keeper/msg_update_policy_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -37,7 +37,7 @@ func (s *msgUpdatePolicy) Policy(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &policy) require.NoError(s.t, err) - err = s.srv.ss.PolicyTable().Save(s.sdkCtx, &policy) + err = s.k.ss.PolicyTable().Save(s.sdkCtx, &policy) require.NoError(s.t, err) } @@ -46,7 +46,7 @@ func (s *msgUpdatePolicy) MsgUpdatePolicy(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.UpdatePolicy(s.sdkCtx, &msg) + s.res, s.err = s.k.UpdatePolicy(s.sdkCtx, &msg) } func (s *msgUpdatePolicy) ExpectNoError() { @@ -62,7 +62,7 @@ func (s *msgUpdatePolicy) ExpectPolicy(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - policy, err := s.srv.ss.PolicyTable().Get(s.sdkCtx) + policy, err := s.k.ss.PolicyTable().Get(s.sdkCtx) require.NoError(s.t, err) require.Equal(s.t, expected.SignedBlocksWindow, policy.SignedBlocksWindow) require.Equal(s.t, expected.MinSignedPerWindow, policy.MinSignedPerWindow) diff --git a/validator/server/msg_update_validator.go b/validator/keeper/msg_update_validator.go similarity index 84% rename from validator/server/msg_update_validator.go rename to validator/keeper/msg_update_validator.go index 85c877b..e9480bf 100644 --- a/validator/server/msg_update_validator.go +++ b/validator/keeper/msg_update_validator.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,11 +11,11 @@ import ( ) // UpdateValidator implements the Msg/UpdateValidator method. -func (s Server) UpdateValidator(ctx context.Context, req *v1.MsgUpdateValidator) (*v1.MsgUpdateValidatorResponse, error) { +func (k Keeper) UpdateValidator(ctx context.Context, req *v1.MsgUpdateValidator) (*v1.MsgUpdateValidatorResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get validator from validator table - validator, err := s.ss.ValidatorTable().Get(ctx, req.Address) + validator, err := k.ss.ValidatorTable().Get(ctx, req.Address) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("validator with address %s: %s", req.Address, err) @@ -27,7 +27,7 @@ func (s Server) UpdateValidator(ctx context.Context, req *v1.MsgUpdateValidator) validator.Metadata = req.NewMetadata // update validator in validator table - err = s.ss.ValidatorTable().Update(ctx, validator) + err = k.ss.ValidatorTable().Update(ctx, validator) if err != nil { return nil, err // internal error } diff --git a/validator/server/msg_update_validator_test.go b/validator/keeper/msg_update_validator_test.go similarity index 90% rename from validator/server/msg_update_validator_test.go rename to validator/keeper/msg_update_validator_test.go index cf2f7bc..b85fe6b 100644 --- a/validator/server/msg_update_validator_test.go +++ b/validator/keeper/msg_update_validator_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgUpdateValidator) Validator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &validator) require.NoError(s.t, err) - err = s.srv.ss.ValidatorTable().Insert(s.sdkCtx, &validatorv1.Validator{ + err = s.k.ss.ValidatorTable().Insert(s.sdkCtx, &validatorv1.Validator{ Address: validator.Address, }) require.NoError(s.t, err) @@ -44,7 +44,7 @@ func (s *msgUpdateValidator) MsgUpdateValidator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.UpdateValidator(s.sdkCtx, &msg) + s.res, s.err = s.k.UpdateValidator(s.sdkCtx, &msg) } func (s *msgUpdateValidator) ExpectNoError() { @@ -68,7 +68,7 @@ func (s *msgUpdateValidator) ExpectStateValidator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.ValidatorTable().Get(s.sdkCtx, expected.Address) + actual, err := s.k.ss.ValidatorTable().Get(s.sdkCtx, expected.Address) require.NoError(s.t, err) require.Equal(s.t, expected.Address, actual.Address) diff --git a/validator/server/query_policy.go b/validator/keeper/query_policy.go similarity index 77% rename from validator/server/query_policy.go rename to validator/keeper/query_policy.go index 8cad189..7d40165 100644 --- a/validator/server/query_policy.go +++ b/validator/keeper/query_policy.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -7,10 +7,10 @@ import ( ) // Policy implements the Query/Policy method. -func (s Server) Policy(ctx context.Context, _ *v1.QueryPolicyRequest) (*v1.QueryPolicyResponse, error) { +func (k Keeper) Policy(ctx context.Context, _ *v1.QueryPolicyRequest) (*v1.QueryPolicyResponse, error) { // get policy from singleton table - policy, err := s.ss.PolicyTable().Get(ctx) + policy, err := k.ss.PolicyTable().Get(ctx) if err != nil { return nil, err // internal error } diff --git a/validator/server/query_policy_test.go b/validator/keeper/query_policy_test.go similarity index 91% rename from validator/server/query_policy_test.go rename to validator/keeper/query_policy_test.go index 59ee1ee..17dd121 100644 --- a/validator/server/query_policy_test.go +++ b/validator/keeper/query_policy_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryPolicy) Policy(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &policy) require.NoError(s.t, err) - err = s.srv.ss.PolicyTable().Save(s.sdkCtx, &validatorv1.Policy{ + err = s.k.ss.PolicyTable().Save(s.sdkCtx, &validatorv1.Policy{ SignedBlocksWindow: policy.SignedBlocksWindow, MinSignedPerWindow: policy.MinSignedPerWindow, }) @@ -41,7 +41,7 @@ func (s *queryPolicy) Policy(a gocuke.DocString) { func (s *queryPolicy) QueryPolicy() { var req v1.QueryPolicyRequest - s.res, s.err = s.srv.Policy(s.sdkCtx, &req) + s.res, s.err = s.k.Policy(s.sdkCtx, &req) } func (s *queryPolicy) ExpectNoError() { diff --git a/validator/server/query_validator.go b/validator/keeper/query_validator.go similarity index 81% rename from validator/server/query_validator.go rename to validator/keeper/query_validator.go index 978caa4..cd06d4d 100644 --- a/validator/server/query_validator.go +++ b/validator/keeper/query_validator.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -10,10 +10,10 @@ import ( ) // Validator implements the Query/Validator method. -func (s Server) Validator(ctx context.Context, req *v1.QueryValidatorRequest) (*v1.QueryValidatorResponse, error) { +func (k Keeper) Validator(ctx context.Context, req *v1.QueryValidatorRequest) (*v1.QueryValidatorResponse, error) { // get validator from validator table - validator, err := s.ss.ValidatorTable().Get(ctx, req.Address) + validator, err := k.ss.ValidatorTable().Get(ctx, req.Address) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("validator with address %s", req.Address) diff --git a/validator/server/query_validator_test.go b/validator/keeper/query_validator_test.go similarity index 91% rename from validator/server/query_validator_test.go rename to validator/keeper/query_validator_test.go index 91d3971..f79d62a 100644 --- a/validator/server/query_validator_test.go +++ b/validator/keeper/query_validator_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryValidator) Validator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &validator) require.NoError(s.t, err) - err = s.srv.ss.ValidatorTable().Insert(s.sdkCtx, &validatorv1.Validator{ + err = s.k.ss.ValidatorTable().Insert(s.sdkCtx, &validatorv1.Validator{ Address: validator.Address, Metadata: validator.Metadata, }) @@ -44,7 +44,7 @@ func (s *queryValidator) QueryValidator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Validator(s.sdkCtx, &req) + s.res, s.err = s.k.Validator(s.sdkCtx, &req) } func (s *queryValidator) ExpectNoError() { diff --git a/validator/server/query_validators.go b/validator/keeper/query_validators.go similarity index 90% rename from validator/server/query_validators.go rename to validator/keeper/query_validators.go index 0366946..ff4f0f9 100644 --- a/validator/server/query_validators.go +++ b/validator/keeper/query_validators.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,7 +11,7 @@ import ( ) // Validators implements the Query/Validators method. -func (s Server) Validators(ctx context.Context, req *v1.QueryValidatorsRequest) (*v1.QueryValidatorsResponse, error) { +func (k Keeper) Validators(ctx context.Context, req *v1.QueryValidatorsRequest) (*v1.QueryValidatorsResponse, error) { // set the index for table lookup index := validatorv1.ValidatorAddressIndexKey{} @@ -23,7 +23,7 @@ func (s Server) Validators(ctx context.Context, req *v1.QueryValidatorsRequest) } // get validators from validator table - it, err := s.ss.ValidatorTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.ValidatorTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/validator/server/query_validators_test.go b/validator/keeper/query_validators_test.go similarity index 91% rename from validator/server/query_validators_test.go rename to validator/keeper/query_validators_test.go index 0c13e7b..4d78029 100644 --- a/validator/server/query_validators_test.go +++ b/validator/keeper/query_validators_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryValidators) Validator(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &validator) require.NoError(s.t, err) - err = s.srv.ss.ValidatorTable().Insert(s.sdkCtx, &validatorv1.Validator{ + err = s.k.ss.ValidatorTable().Insert(s.sdkCtx, &validatorv1.Validator{ Address: validator.Address, Metadata: validator.Metadata, }) @@ -44,7 +44,7 @@ func (s *queryValidators) QueryValidators(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Validators(s.sdkCtx, &req) + s.res, s.err = s.k.Validators(s.sdkCtx, &req) } func (s *queryValidators) ExpectNoError() { diff --git a/validator/module/module.go b/validator/module/module.go index b58fa7e..067ba70 100644 --- a/validator/module/module.go +++ b/validator/module/module.go @@ -7,8 +7,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "cosmossdk.io/core/appmodule" - storetypes "cosmossdk.io/store/types" - sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -17,7 +15,7 @@ import ( "github.com/choraio/mods/validator" "github.com/choraio/mods/validator/genesis" - "github.com/choraio/mods/validator/server" + "github.com/choraio/mods/validator/keeper" v1 "github.com/choraio/mods/validator/types/v1" ) @@ -25,32 +23,29 @@ import ( const ConsensusVersion = 1 var ( - _ appmodule.AppModule = AppModule{} - _ module.AppModuleBasic = AppModule{} - _ module.HasGenesis = AppModule{} - _ module.HasServices = AppModule{} + _ appmodule.AppModule = AppModule{} + + _ module.AppModuleBasic = AppModule{} + _ module.HasConsensusVersion = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasInvariants = AppModule{} + _ module.HasServices = AppModule{} ) // AppModule implements the AppModule interface. type AppModule struct { - key storetypes.StoreKey - srv server.Server + cdc codec.BinaryCodec + k keeper.Keeper } -// NewAppModule returns a new module. -func NewAppModule(key storetypes.StoreKey, authority sdk.AccAddress) AppModule { - srv := server.NewServer(key, authority) +// NewAppModule returns a new AppModule instance. +func NewAppModule(cdc codec.BinaryCodec, k keeper.Keeper) AppModule { return AppModule{ - key: key, - srv: srv, + cdc: cdc, + k: k, } } -// ConsensusVersion returns ConsensusVersion. -func (am AppModule) ConsensusVersion() uint64 { - return ConsensusVersion -} - // IsAppModule implements the appmodule.AppModule/IsAppModule. func (am AppModule) IsAppModule() {} @@ -62,11 +57,6 @@ func (am AppModule) Name() string { return validator.ModuleName } -// RegisterInterfaces implements module.AppModuleBasic/RegisterInterfaces. -func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { - v1.RegisterInterfaces(registry) -} - // RegisterGRPCGatewayRoutes implements module.AppModuleBasic/RegisterGRPCGatewayRoutes. func (am AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { err := v1.RegisterQueryHandlerClient(context.Background(), mux, v1.NewQueryClient(clientCtx)) @@ -75,14 +65,24 @@ func (am AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux * } } +// RegisterInterfaces implements module.AppModuleBasic/RegisterInterfaces. +func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + v1.RegisterInterfaces(registry) +} + // RegisterLegacyAminoCodec implements module.AppModuleBasic/RegisterLegacyAminoCodec. func (am AppModule) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { v1.RegisterLegacyAminoCodec(amino) } +// ConsensusVersion implements module.HasConsensusVersion/ConsensusVersion. +func (am AppModule) ConsensusVersion() uint64 { + return ConsensusVersion +} + // InitGenesis implements module.HasGenesis/InitGenesis. func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, message json.RawMessage) { - err := am.srv.InitGenesis(ctx, jsonCodec, message) + err := am.k.InitGenesis(ctx, jsonCodec, message) if err != nil { panic(err) } @@ -90,7 +90,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, mess // ExportGenesis implements module.HasGenesis/ExportGenesis. func (am AppModule) ExportGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec) json.RawMessage { - export, err := am.srv.ExportGenesis(ctx, jsonCodec) + export, err := am.k.ExportGenesis(ctx, jsonCodec) if err != nil { panic(err) } @@ -107,8 +107,11 @@ func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ sdkclient.TxEncodingCon return genesis.ValidateGenesis(bz) } +// RegisterInvariants implements module.HasInvariants/RegisterInvariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + // RegisterServices implements module.HasServices/RegisterServices. func (am AppModule) RegisterServices(cfg module.Configurator) { - v1.RegisterMsgServer(cfg.MsgServer(), am.srv) - v1.RegisterQueryServer(cfg.QueryServer(), am.srv) + v1.RegisterMsgServer(cfg.MsgServer(), am.k) + v1.RegisterQueryServer(cfg.QueryServer(), am.k) } diff --git a/voucher/server/config.go b/voucher/keeper/config.go similarity index 90% rename from voucher/server/config.go rename to voucher/keeper/config.go index dcf49ef..d126fbd 100644 --- a/voucher/server/config.go +++ b/voucher/keeper/config.go @@ -1,4 +1,4 @@ -package server +package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/voucher/server/features/msg_create.feature b/voucher/keeper/features/msg_create.feature similarity index 100% rename from voucher/server/features/msg_create.feature rename to voucher/keeper/features/msg_create.feature diff --git a/voucher/server/features/msg_issue.feature b/voucher/keeper/features/msg_issue.feature similarity index 100% rename from voucher/server/features/msg_issue.feature rename to voucher/keeper/features/msg_issue.feature diff --git a/voucher/server/features/msg_update_issuer.feature b/voucher/keeper/features/msg_update_issuer.feature similarity index 100% rename from voucher/server/features/msg_update_issuer.feature rename to voucher/keeper/features/msg_update_issuer.feature diff --git a/voucher/server/features/msg_update_metadata.feature b/voucher/keeper/features/msg_update_metadata.feature similarity index 100% rename from voucher/server/features/msg_update_metadata.feature rename to voucher/keeper/features/msg_update_metadata.feature diff --git a/voucher/server/features/query_balance.feature b/voucher/keeper/features/query_balance.feature similarity index 100% rename from voucher/server/features/query_balance.feature rename to voucher/keeper/features/query_balance.feature diff --git a/voucher/server/features/query_balances_by_address.feature b/voucher/keeper/features/query_balances_by_address.feature similarity index 100% rename from voucher/server/features/query_balances_by_address.feature rename to voucher/keeper/features/query_balances_by_address.feature diff --git a/voucher/server/features/query_balances_by_voucher.feature b/voucher/keeper/features/query_balances_by_voucher.feature similarity index 100% rename from voucher/server/features/query_balances_by_voucher.feature rename to voucher/keeper/features/query_balances_by_voucher.feature diff --git a/voucher/server/features/query_voucher.feature b/voucher/keeper/features/query_voucher.feature similarity index 100% rename from voucher/server/features/query_voucher.feature rename to voucher/keeper/features/query_voucher.feature diff --git a/voucher/server/features/query_vouchers.feature b/voucher/keeper/features/query_vouchers.feature similarity index 100% rename from voucher/server/features/query_vouchers.feature rename to voucher/keeper/features/query_vouchers.feature diff --git a/voucher/server/features/query_vouchers_by_issuer.feature b/voucher/keeper/features/query_vouchers_by_issuer.feature similarity index 100% rename from voucher/server/features/query_vouchers_by_issuer.feature rename to voucher/keeper/features/query_vouchers_by_issuer.feature diff --git a/voucher/server/server.go b/voucher/keeper/keeper.go similarity index 67% rename from voucher/server/server.go rename to voucher/keeper/keeper.go index 58244d9..1a5b9d8 100644 --- a/voucher/server/server.go +++ b/voucher/keeper/keeper.go @@ -1,11 +1,10 @@ -package server +package keeper import ( "encoding/json" "time" "cosmossdk.io/orm/model/ormdb" - storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "google.golang.org/protobuf/types/known/timestamppb" @@ -16,36 +15,36 @@ import ( ) var ( - _ v1.MsgServer = &Server{} - _ v1.QueryServer = &Server{} + _ v1.MsgServer = &Keeper{} + _ v1.QueryServer = &Keeper{} ) -// Server is the server. -type Server struct { - db ormdb.ModuleDB - ss voucherv1.StateStore +// Keeper is the keeper. +type Keeper struct { + db ormdb.ModuleDB // module database + ss voucherv1.StateStore // module state store } -// NewServer creates a new server. -func NewServer(key storetypes.StoreKey) Server { - s := Server{} +// NewKeeper creates a new keeper. +func NewKeeper() Keeper { + k := Keeper{} var err error - s.db, err = ormdb.NewModuleDB(&voucher.ModuleSchema, ormdb.ModuleDBOptions{}) + k.db, err = ormdb.NewModuleDB(&voucher.ModuleSchema, ormdb.ModuleDBOptions{}) if err != nil { panic(err) } - s.ss, err = voucherv1.NewStateStore(s.db) + k.ss, err = voucherv1.NewStateStore(k.db) if err != nil { panic(err) } - return s + return k } // InitGenesis initializes genesis state. -func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error { +func (k Keeper) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMessage) error { //source, err := ormjson.NewRawMessageSource(data) //if err != nil { // return err @@ -60,7 +59,7 @@ func (s Server) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, data json.RawMes } // ExportGenesis exports genesis state. -func (s Server) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) { +func (k Keeper) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessage, error) { //target := ormjson.NewRawMessageTarget() // //err := s.db.ExportJSON(sdk.WrapSDKContext(ctx), target) @@ -74,7 +73,7 @@ func (s Server) ExportGenesis(ctx sdk.Context, _ codec.JSONCodec) (json.RawMessa } // PruneVouchers removes expired vouchers from state. -func (s Server) PruneVouchers(ctx sdk.Context) error { +func (k Keeper) PruneVouchers(ctx sdk.Context) error { sdkCtx := sdk.UnwrapSDKContext(ctx) minTime := timestamppb.New(time.Time{}) @@ -83,7 +82,7 @@ func (s Server) PruneVouchers(ctx sdk.Context) error { fromKey := voucherv1.BalanceExpirationIndexKey{}.WithExpiration(minTime) toKey := voucherv1.BalanceExpirationIndexKey{}.WithExpiration(blockTime) - it, err := s.ss.BalanceTable().ListRange(ctx, fromKey, toKey) + it, err := k.ss.BalanceTable().ListRange(ctx, fromKey, toKey) if err != nil { return err } @@ -94,7 +93,7 @@ func (s Server) PruneVouchers(ctx sdk.Context) error { return err } - err = s.ss.BalanceTable().Delete(ctx, balance) + err = k.ss.BalanceTable().Delete(ctx, balance) if err != nil { return err } diff --git a/voucher/server/server_test.go b/voucher/keeper/keeper_test.go similarity index 94% rename from voucher/server/server_test.go rename to voucher/keeper/keeper_test.go index 2f8c8d3..a82754d 100644 --- a/voucher/server/server_test.go +++ b/voucher/keeper/keeper_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "cosmossdk.io/log" @@ -19,7 +19,7 @@ import ( type baseSuite struct { t gocuke.TestingT sdkCtx sdk.Context - srv Server + k Keeper } func setupBase(t gocuke.TestingT) *baseSuite { @@ -46,8 +46,8 @@ func setupBase(t gocuke.TestingT) *baseSuite { // create and set sdk context from commit multi-store with orm context s.sdkCtx = sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()).WithContext(ormCtx) - // create and set server - s.srv = NewServer(key) + // create and set keeper + s.k = NewKeeper() return s } diff --git a/voucher/server/msg_create.go b/voucher/keeper/msg_create.go similarity index 84% rename from voucher/server/msg_create.go rename to voucher/keeper/msg_create.go index 002106b..fa6aed1 100644 --- a/voucher/server/msg_create.go +++ b/voucher/keeper/msg_create.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -10,7 +10,7 @@ import ( ) // Create implements Msg/Create. -func (s Server) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateResponse, error) { +func (k Keeper) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from issuer address @@ -20,7 +20,7 @@ func (s Server) Create(ctx context.Context, req *v1.MsgCreate) (*v1.MsgCreateRes } // insert voucher into voucher table - id, err := s.ss.VoucherTable().InsertReturningId(ctx, &voucherv1.Voucher{ + id, err := k.ss.VoucherTable().InsertReturningId(ctx, &voucherv1.Voucher{ Issuer: issuer, Metadata: req.Metadata, }) diff --git a/voucher/server/msg_create_test.go b/voucher/keeper/msg_create_test.go similarity index 93% rename from voucher/server/msg_create_test.go rename to voucher/keeper/msg_create_test.go index 8081f43..a51146c 100644 --- a/voucher/server/msg_create_test.go +++ b/voucher/keeper/msg_create_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgCreate) MsgCreate(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.Create(s.sdkCtx, &msg) + s.res, s.err = s.k.Create(s.sdkCtx, &msg) } func (s *msgCreate) ExpectNoError() { @@ -53,7 +53,7 @@ func (s *msgCreate) ExpectStateVoucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.VoucherTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.VoucherTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/voucher/server/msg_issue.go b/voucher/keeper/msg_issue.go similarity index 91% rename from voucher/server/msg_issue.go rename to voucher/keeper/msg_issue.go index e8e1285..27c41b5 100644 --- a/voucher/server/msg_issue.go +++ b/voucher/keeper/msg_issue.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -14,7 +14,7 @@ import ( ) // Issue implements Msg/Issue. -func (s Server) Issue(ctx context.Context, req *v1.MsgIssue) (*v1.MsgIssueResponse, error) { +func (k Keeper) Issue(ctx context.Context, req *v1.MsgIssue) (*v1.MsgIssueResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from issuer address @@ -24,7 +24,7 @@ func (s Server) Issue(ctx context.Context, req *v1.MsgIssue) (*v1.MsgIssueRespon } // get voucher from voucher table - voucher, err := s.ss.VoucherTable().Get(ctx, req.Id) + voucher, err := k.ss.VoucherTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("voucher with id %d: %s", req.Id, err) @@ -59,7 +59,7 @@ func (s Server) Issue(ctx context.Context, req *v1.MsgIssue) (*v1.MsgIssueRespon expiration := timestamppb.New(*req.Expiration) // get current balance from state - balance, err := s.ss.BalanceTable().Get(ctx, req.Id, recipient, expiration) + balance, err := k.ss.BalanceTable().Get(ctx, req.Id, recipient, expiration) if err != nil { if !ormerrors.NotFound.Is(err) { return nil, err // internal error @@ -91,7 +91,7 @@ func (s Server) Issue(ctx context.Context, req *v1.MsgIssue) (*v1.MsgIssueRespon balance.Amount = newBalance.String() // save balance to balance table - err = s.ss.BalanceTable().Save(ctx, balance) + err = k.ss.BalanceTable().Save(ctx, balance) if err != nil { return nil, err // internal error } diff --git a/voucher/server/msg_issue_test.go b/voucher/keeper/msg_issue_test.go similarity index 89% rename from voucher/server/msg_issue_test.go rename to voucher/keeper/msg_issue_test.go index b115caf..f77c21d 100644 --- a/voucher/server/msg_issue_test.go +++ b/voucher/keeper/msg_issue_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -41,7 +41,7 @@ func (s *msgIssue) Voucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &voucher) require.NoError(s.t, err) - id, err := s.srv.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ + id, err := s.k.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ Issuer: voucher.Issuer, Metadata: voucher.Metadata, }) @@ -54,7 +54,7 @@ func (s *msgIssue) Balance(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &balance) require.NoError(s.t, err) - err = s.srv.ss.BalanceTable().Insert(s.sdkCtx, &voucherv1.Balance{ + err = s.k.ss.BalanceTable().Insert(s.sdkCtx, &voucherv1.Balance{ Id: balance.Id, Address: balance.Address, Amount: balance.Amount, @@ -68,7 +68,7 @@ func (s *msgIssue) MsgIssue(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.Issue(s.sdkCtx, &msg) + s.res, s.err = s.k.Issue(s.sdkCtx, &msg) } func (s *msgIssue) ExpectNoError() { @@ -92,7 +92,7 @@ func (s *msgIssue) ExpectStateBalance(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.BalanceTable().Get(s.sdkCtx, expected.Id, expected.Address, expected.Expiration) + actual, err := s.k.ss.BalanceTable().Get(s.sdkCtx, expected.Id, expected.Address, expected.Expiration) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/voucher/server/msg_update_issuer.go b/voucher/keeper/msg_update_issuer.go similarity index 89% rename from voucher/server/msg_update_issuer.go rename to voucher/keeper/msg_update_issuer.go index 04e3dd6..6ddb17a 100644 --- a/voucher/server/msg_update_issuer.go +++ b/voucher/keeper/msg_update_issuer.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,7 +11,7 @@ import ( ) // UpdateIssuer implements the Msg/UpdateIssuer method. -func (s Server) UpdateIssuer(ctx context.Context, req *v1.MsgUpdateIssuer) (*v1.MsgUpdateIssuerResponse, error) { +func (k Keeper) UpdateIssuer(ctx context.Context, req *v1.MsgUpdateIssuer) (*v1.MsgUpdateIssuerResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from issuer address @@ -21,7 +21,7 @@ func (s Server) UpdateIssuer(ctx context.Context, req *v1.MsgUpdateIssuer) (*v1. } // get voucher from voucher table - voucher, err := s.ss.VoucherTable().Get(ctx, req.Id) + voucher, err := k.ss.VoucherTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("voucher with id %d: %s", req.Id, err) @@ -49,7 +49,7 @@ func (s Server) UpdateIssuer(ctx context.Context, req *v1.MsgUpdateIssuer) (*v1. voucher.Issuer = newIssuer // update voucher in voucher table - err = s.ss.VoucherTable().Update(ctx, voucher) + err = k.ss.VoucherTable().Update(ctx, voucher) if err != nil { return nil, err // internal error } diff --git a/voucher/server/msg_update_issuer_test.go b/voucher/keeper/msg_update_issuer_test.go similarity index 91% rename from voucher/server/msg_update_issuer_test.go rename to voucher/keeper/msg_update_issuer_test.go index 6a4033a..7629b42 100644 --- a/voucher/server/msg_update_issuer_test.go +++ b/voucher/keeper/msg_update_issuer_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgUpdateIssuer) Voucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &voucher) require.NoError(s.t, err) - id, err := s.srv.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ + id, err := s.k.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ Issuer: voucher.Issuer, Metadata: voucher.Metadata, }) @@ -46,7 +46,7 @@ func (s *msgUpdateIssuer) MsgUpdateIssuer(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.UpdateIssuer(s.sdkCtx, &msg) + s.res, s.err = s.k.UpdateIssuer(s.sdkCtx, &msg) } func (s *msgUpdateIssuer) ExpectNoError() { @@ -70,7 +70,7 @@ func (s *msgUpdateIssuer) ExpectStateVoucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.VoucherTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.VoucherTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/voucher/server/msg_update_metadata.go b/voucher/keeper/msg_update_metadata.go similarity index 88% rename from voucher/server/msg_update_metadata.go rename to voucher/keeper/msg_update_metadata.go index aed9195..2914469 100644 --- a/voucher/server/msg_update_metadata.go +++ b/voucher/keeper/msg_update_metadata.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,7 +11,7 @@ import ( ) // UpdateMetadata implements the Msg/UpdateMetadata method. -func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (*v1.MsgUpdateMetadataResponse, error) { +func (k Keeper) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) (*v1.MsgUpdateMetadataResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) // get account from issuer address @@ -21,7 +21,7 @@ func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) ( } // get voucher from voucher table - voucher, err := s.ss.VoucherTable().Get(ctx, req.Id) + voucher, err := k.ss.VoucherTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("voucher with id %d: %s", req.Id, err) @@ -43,7 +43,7 @@ func (s Server) UpdateMetadata(ctx context.Context, req *v1.MsgUpdateMetadata) ( voucher.Metadata = req.NewMetadata // update voucher in voucher table - err = s.ss.VoucherTable().Update(ctx, voucher) + err = k.ss.VoucherTable().Update(ctx, voucher) if err != nil { return nil, err // internal error } diff --git a/voucher/server/msg_update_metadata_test.go b/voucher/keeper/msg_update_metadata_test.go similarity index 91% rename from voucher/server/msg_update_metadata_test.go rename to voucher/keeper/msg_update_metadata_test.go index aab4a25..d400f0d 100644 --- a/voucher/server/msg_update_metadata_test.go +++ b/voucher/keeper/msg_update_metadata_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -33,7 +33,7 @@ func (s *msgUpdateMetadata) Voucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &voucher) require.NoError(s.t, err) - id, err := s.srv.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ + id, err := s.k.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ Issuer: voucher.Issuer, Metadata: voucher.Metadata, }) @@ -46,7 +46,7 @@ func (s *msgUpdateMetadata) MsgUpdateMetadata(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &msg) require.NoError(s.t, err) - s.res, s.err = s.srv.UpdateMetadata(s.sdkCtx, &msg) + s.res, s.err = s.k.UpdateMetadata(s.sdkCtx, &msg) } func (s *msgUpdateMetadata) ExpectNoError() { @@ -70,7 +70,7 @@ func (s *msgUpdateMetadata) ExpectStateVoucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &expected) require.NoError(s.t, err) - actual, err := s.srv.ss.VoucherTable().Get(s.sdkCtx, expected.Id) + actual, err := s.k.ss.VoucherTable().Get(s.sdkCtx, expected.Id) require.NoError(s.t, err) require.Equal(s.t, expected.Id, actual.Id) diff --git a/voucher/server/query_balance.go b/voucher/keeper/query_balance.go similarity index 92% rename from voucher/server/query_balance.go rename to voucher/keeper/query_balance.go index 1b0faf5..b72a780 100644 --- a/voucher/server/query_balance.go +++ b/voucher/keeper/query_balance.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -12,7 +12,7 @@ import ( ) // Balance implements the Query/Balance method. -func (s Server) Balance(ctx context.Context, req *v1.QueryBalanceRequest) (*v1.QueryBalanceResponse, error) { +func (k Keeper) Balance(ctx context.Context, req *v1.QueryBalanceRequest) (*v1.QueryBalanceResponse, error) { // get account from address address, err := sdk.AccAddressFromBech32(req.Address) @@ -24,7 +24,7 @@ func (s Server) Balance(ctx context.Context, req *v1.QueryBalanceRequest) (*v1.Q index := voucherv1.BalanceIdAddressExpirationIndexKey{}.WithIdAddress(req.Id, address) // get balance from balance table - it, err := s.ss.BalanceTable().List(ctx, index) + it, err := k.ss.BalanceTable().List(ctx, index) if err != nil { return nil, err // internal error } diff --git a/voucher/server/query_balance_test.go b/voucher/keeper/query_balance_test.go similarity index 91% rename from voucher/server/query_balance_test.go rename to voucher/keeper/query_balance_test.go index 10d725b..4903604 100644 --- a/voucher/server/query_balance_test.go +++ b/voucher/keeper/query_balance_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryBalance) Balance(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &balance) require.NoError(s.t, err) - err = s.srv.ss.BalanceTable().Insert(s.sdkCtx, &voucherv1.Balance{ + err = s.k.ss.BalanceTable().Insert(s.sdkCtx, &voucherv1.Balance{ Id: balance.Id, Address: balance.Address, Amount: balance.Amount, @@ -46,7 +46,7 @@ func (s *queryBalance) QueryBalance(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Balance(s.sdkCtx, &req) + s.res, s.err = s.k.Balance(s.sdkCtx, &req) } func (s *queryBalance) ExpectNoError() { diff --git a/voucher/server/query_balances_by_address.go b/voucher/keeper/query_balances_by_address.go similarity index 93% rename from voucher/server/query_balances_by_address.go rename to voucher/keeper/query_balances_by_address.go index b780af7..7101c2e 100644 --- a/voucher/server/query_balances_by_address.go +++ b/voucher/keeper/query_balances_by_address.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -14,7 +14,7 @@ import ( ) // BalancesByAddress implements the Query/BalancesByAddress method. -func (s Server) BalancesByAddress(ctx context.Context, req *v1.QueryBalancesByAddressRequest) (*v1.QueryBalancesByAddressResponse, error) { +func (k Keeper) BalancesByAddress(ctx context.Context, req *v1.QueryBalancesByAddressRequest) (*v1.QueryBalancesByAddressResponse, error) { // get account from address address, err := sdk.AccAddressFromBech32(req.Address) @@ -32,7 +32,7 @@ func (s Server) BalancesByAddress(ctx context.Context, req *v1.QueryBalancesByAd } // get balance from balance table - it, err := s.ss.BalanceTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.BalanceTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/voucher/server/query_balances_by_address_test.go b/voucher/keeper/query_balances_by_address_test.go similarity index 91% rename from voucher/server/query_balances_by_address_test.go rename to voucher/keeper/query_balances_by_address_test.go index 9008c26..75e42e8 100644 --- a/voucher/server/query_balances_by_address_test.go +++ b/voucher/keeper/query_balances_by_address_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryBalancesByAddress) Balance(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &balance) require.NoError(s.t, err) - err = s.srv.ss.BalanceTable().Insert(s.sdkCtx, &voucherv1.Balance{ + err = s.k.ss.BalanceTable().Insert(s.sdkCtx, &voucherv1.Balance{ Id: balance.Id, Address: balance.Address, Amount: balance.Amount, @@ -46,7 +46,7 @@ func (s *queryBalancesByAddress) QueryBalancesByAddress(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.BalancesByAddress(s.sdkCtx, &req) + s.res, s.err = s.k.BalancesByAddress(s.sdkCtx, &req) } func (s *queryBalancesByAddress) ExpectNoError() { diff --git a/voucher/server/query_balances_by_voucher.go b/voucher/keeper/query_balances_by_voucher.go similarity index 93% rename from voucher/server/query_balances_by_voucher.go rename to voucher/keeper/query_balances_by_voucher.go index 34245f9..ec3df1a 100644 --- a/voucher/server/query_balances_by_voucher.go +++ b/voucher/keeper/query_balances_by_voucher.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -13,7 +13,7 @@ import ( ) // BalancesByVoucher implements the Query/BalancesByVoucher method. -func (s Server) BalancesByVoucher(ctx context.Context, req *v1.QueryBalancesByVoucherRequest) (*v1.QueryBalancesByVoucherResponse, error) { +func (k Keeper) BalancesByVoucher(ctx context.Context, req *v1.QueryBalancesByVoucherRequest) (*v1.QueryBalancesByVoucherResponse, error) { // set index for table lookup index := voucherv1.BalanceIdAddressExpirationIndexKey{}.WithId(req.Id) @@ -25,7 +25,7 @@ func (s Server) BalancesByVoucher(ctx context.Context, req *v1.QueryBalancesByVo } // get balance from balance table - it, err := s.ss.BalanceTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.BalanceTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/voucher/server/query_balances_by_voucher_test.go b/voucher/keeper/query_balances_by_voucher_test.go similarity index 91% rename from voucher/server/query_balances_by_voucher_test.go rename to voucher/keeper/query_balances_by_voucher_test.go index 67f7802..59c22d9 100644 --- a/voucher/server/query_balances_by_voucher_test.go +++ b/voucher/keeper/query_balances_by_voucher_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryBalancesByVoucher) Balance(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &balance) require.NoError(s.t, err) - err = s.srv.ss.BalanceTable().Insert(s.sdkCtx, &voucherv1.Balance{ + err = s.k.ss.BalanceTable().Insert(s.sdkCtx, &voucherv1.Balance{ Id: balance.Id, Address: balance.Address, Amount: balance.Amount, @@ -46,7 +46,7 @@ func (s *queryBalancesByVoucher) QueryBalancesByVoucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.BalancesByVoucher(s.sdkCtx, &req) + s.res, s.err = s.k.BalancesByVoucher(s.sdkCtx, &req) } func (s *queryBalancesByVoucher) ExpectNoError() { diff --git a/voucher/server/query_voucher.go b/voucher/keeper/query_voucher.go similarity index 84% rename from voucher/server/query_voucher.go rename to voucher/keeper/query_voucher.go index a787252..a0c3826 100644 --- a/voucher/server/query_voucher.go +++ b/voucher/keeper/query_voucher.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -11,10 +11,10 @@ import ( ) // Voucher implements the Query/Voucher method. -func (s Server) Voucher(ctx context.Context, req *v1.QueryVoucherRequest) (*v1.QueryVoucherResponse, error) { +func (k Keeper) Voucher(ctx context.Context, req *v1.QueryVoucherRequest) (*v1.QueryVoucherResponse, error) { // get voucher from voucher table - voucher, err := s.ss.VoucherTable().Get(ctx, req.Id) + voucher, err := k.ss.VoucherTable().Get(ctx, req.Id) if err != nil { if ormerrors.NotFound.Is(err) { return nil, sdkerrors.ErrNotFound.Wrapf("voucher with id %d", req.Id) diff --git a/voucher/server/query_voucher_test.go b/voucher/keeper/query_voucher_test.go similarity index 90% rename from voucher/server/query_voucher_test.go rename to voucher/keeper/query_voucher_test.go index ad86071..44c34b4 100644 --- a/voucher/server/query_voucher_test.go +++ b/voucher/keeper/query_voucher_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryVoucher) Voucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &voucher) require.NoError(s.t, err) - id, err := s.srv.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ + id, err := s.k.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ Issuer: voucher.Issuer, Metadata: voucher.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryVoucher) QueryVoucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Voucher(s.sdkCtx, &req) + s.res, s.err = s.k.Voucher(s.sdkCtx, &req) } func (s *queryVoucher) ExpectNoError() { diff --git a/voucher/server/query_vouchers.go b/voucher/keeper/query_vouchers.go similarity index 90% rename from voucher/server/query_vouchers.go rename to voucher/keeper/query_vouchers.go index 6077d95..31db8de 100644 --- a/voucher/server/query_vouchers.go +++ b/voucher/keeper/query_vouchers.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -12,7 +12,7 @@ import ( ) // Vouchers implements the Query/Vouchers method. -func (s Server) Vouchers(ctx context.Context, req *v1.QueryVouchersRequest) (*v1.QueryVouchersResponse, error) { +func (k Keeper) Vouchers(ctx context.Context, req *v1.QueryVouchersRequest) (*v1.QueryVouchersResponse, error) { // set index for table lookup index := voucherv1.VoucherIdIndexKey{} @@ -24,7 +24,7 @@ func (s Server) Vouchers(ctx context.Context, req *v1.QueryVouchersRequest) (*v1 } // get vouchers from voucher table - it, err := s.ss.VoucherTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.VoucherTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/voucher/server/query_vouchers_by_issuer.go b/voucher/keeper/query_vouchers_by_issuer.go similarity index 92% rename from voucher/server/query_vouchers_by_issuer.go rename to voucher/keeper/query_vouchers_by_issuer.go index 37b5b14..26a1b12 100644 --- a/voucher/server/query_vouchers_by_issuer.go +++ b/voucher/keeper/query_vouchers_by_issuer.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "context" @@ -13,7 +13,7 @@ import ( ) // VouchersByIssuer implements the Query/VouchersByIssuer method. -func (s Server) VouchersByIssuer(ctx context.Context, req *v1.QueryVouchersByIssuerRequest) (*v1.QueryVouchersByIssuerResponse, error) { +func (k Keeper) VouchersByIssuer(ctx context.Context, req *v1.QueryVouchersByIssuerRequest) (*v1.QueryVouchersByIssuerResponse, error) { // get account from issuer address issuer, err := sdk.AccAddressFromBech32(req.Issuer) @@ -31,7 +31,7 @@ func (s Server) VouchersByIssuer(ctx context.Context, req *v1.QueryVouchersByIss } // get vouchers by issuer from voucher table - it, err := s.ss.VoucherTable().List(ctx, index, ormlist.Paginate(pgnReq)) + it, err := k.ss.VoucherTable().List(ctx, index, ormlist.Paginate(pgnReq)) if err != nil { return nil, err // internal error } diff --git a/voucher/server/query_vouchers_by_issuer_test.go b/voucher/keeper/query_vouchers_by_issuer_test.go similarity index 90% rename from voucher/server/query_vouchers_by_issuer_test.go rename to voucher/keeper/query_vouchers_by_issuer_test.go index 0505feb..a0aefd9 100644 --- a/voucher/server/query_vouchers_by_issuer_test.go +++ b/voucher/keeper/query_vouchers_by_issuer_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryVouchersByIssuer) Voucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &voucher) require.NoError(s.t, err) - id, err := s.srv.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ + id, err := s.k.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ Issuer: voucher.Issuer, Metadata: voucher.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryVouchersByIssuer) QueryVouchersByIssuer(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.VouchersByIssuer(s.sdkCtx, &req) + s.res, s.err = s.k.VouchersByIssuer(s.sdkCtx, &req) } func (s *queryVouchersByIssuer) ExpectNoError() { diff --git a/voucher/server/query_vouchers_test.go b/voucher/keeper/query_vouchers_test.go similarity index 90% rename from voucher/server/query_vouchers_test.go rename to voucher/keeper/query_vouchers_test.go index 05c4430..7724f99 100644 --- a/voucher/server/query_vouchers_test.go +++ b/voucher/keeper/query_vouchers_test.go @@ -1,4 +1,4 @@ -package server +package keeper import ( "testing" @@ -32,7 +32,7 @@ func (s *queryVouchers) Voucher(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &voucher) require.NoError(s.t, err) - id, err := s.srv.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ + id, err := s.k.ss.VoucherTable().InsertReturningId(s.sdkCtx, &voucherv1.Voucher{ Issuer: voucher.Issuer, Metadata: voucher.Metadata, }) @@ -45,7 +45,7 @@ func (s *queryVouchers) QueryVouchers(a gocuke.DocString) { err := jsonpb.UnmarshalString(a.Content, &req) require.NoError(s.t, err) - s.res, s.err = s.srv.Vouchers(s.sdkCtx, &req) + s.res, s.err = s.k.Vouchers(s.sdkCtx, &req) } func (s *queryVouchers) ExpectNoError() { diff --git a/voucher/module/module.go b/voucher/module/module.go index b6978d4..e139c5b 100644 --- a/voucher/module/module.go +++ b/voucher/module/module.go @@ -7,8 +7,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "cosmossdk.io/core/appmodule" - storetypes "cosmossdk.io/store/types" - sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -17,7 +15,7 @@ import ( "github.com/choraio/mods/voucher" "github.com/choraio/mods/voucher/genesis" - "github.com/choraio/mods/voucher/server" + "github.com/choraio/mods/voucher/keeper" v1 "github.com/choraio/mods/voucher/types/v1" ) @@ -25,32 +23,29 @@ import ( const ConsensusVersion = 1 var ( - _ appmodule.AppModule = AppModule{} - _ module.AppModuleBasic = AppModule{} - _ module.HasGenesis = AppModule{} - _ module.HasServices = AppModule{} + _ appmodule.AppModule = AppModule{} + + _ module.AppModuleBasic = AppModule{} + _ module.HasConsensusVersion = AppModule{} + _ module.HasGenesis = AppModule{} + _ module.HasInvariants = AppModule{} + _ module.HasServices = AppModule{} ) // AppModule implements the AppModule interface. type AppModule struct { - key storetypes.StoreKey - srv server.Server + cdc codec.BinaryCodec + k keeper.Keeper } -// NewAppModule returns a new module. -func NewAppModule(key storetypes.StoreKey) AppModule { - srv := server.NewServer(key) +// NewAppModule returns a new AppModule instance. +func NewAppModule(cdc codec.BinaryCodec, k keeper.Keeper) AppModule { return AppModule{ - key: key, - srv: srv, + cdc: cdc, + k: k, } } -// ConsensusVersion returns ConsensusVersion. -func (am AppModule) ConsensusVersion() uint64 { - return ConsensusVersion -} - // IsAppModule implements the appmodule.AppModule/IsAppModule. func (am AppModule) IsAppModule() {} @@ -62,11 +57,6 @@ func (am AppModule) Name() string { return voucher.ModuleName } -// RegisterInterfaces implements module.AppModuleBasic/RegisterInterfaces. -func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { - v1.RegisterInterfaces(registry) -} - // RegisterGRPCGatewayRoutes implements module.AppModuleBasic/RegisterGRPCGatewayRoutes. func (am AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) { err := v1.RegisterQueryHandlerClient(context.Background(), mux, v1.NewQueryClient(clientCtx)) @@ -75,14 +65,24 @@ func (am AppModule) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux * } } +// RegisterInterfaces implements module.AppModuleBasic/RegisterInterfaces. +func (am AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + v1.RegisterInterfaces(registry) +} + // RegisterLegacyAminoCodec implements module.AppModuleBasic/RegisterLegacyAminoCodec. func (am AppModule) RegisterLegacyAminoCodec(amino *codec.LegacyAmino) { v1.RegisterLegacyAminoCodec(amino) } +// ConsensusVersion implements module.HasConsensusVersion/ConsensusVersion. +func (am AppModule) ConsensusVersion() uint64 { + return ConsensusVersion +} + // InitGenesis implements module.HasGenesis/InitGenesis. func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, message json.RawMessage) { - err := am.srv.InitGenesis(ctx, jsonCodec, message) + err := am.k.InitGenesis(ctx, jsonCodec, message) if err != nil { panic(err) } @@ -90,7 +90,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec, mess // ExportGenesis implements module.HasGenesis/ExportGenesis. func (am AppModule) ExportGenesis(ctx sdk.Context, jsonCodec codec.JSONCodec) json.RawMessage { - export, err := am.srv.ExportGenesis(ctx, jsonCodec) + export, err := am.k.ExportGenesis(ctx, jsonCodec) if err != nil { panic(err) } @@ -107,8 +107,11 @@ func (am AppModule) ValidateGenesis(_ codec.JSONCodec, _ sdkclient.TxEncodingCon return genesis.ValidateGenesis(bz) } +// RegisterInvariants implements module.HasInvariants/RegisterInvariants. +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + // RegisterServices implements module.HasServices/RegisterServices. func (am AppModule) RegisterServices(cfg module.Configurator) { - v1.RegisterMsgServer(cfg.MsgServer(), am.srv) - v1.RegisterQueryServer(cfg.QueryServer(), am.srv) + v1.RegisterMsgServer(cfg.MsgServer(), am.k) + v1.RegisterQueryServer(cfg.QueryServer(), am.k) }