Skip to content

Commit

Permalink
feat: add skeleton code for datadeal module (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
inchori authored Dec 7, 2022
1 parent 2ae1eb3 commit ac668d4
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 47 deletions.
2 changes: 1 addition & 1 deletion proto/panacea/datadeal/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ message MsgCreateDeal {
repeated string data_schema = 1;
cosmos.base.v1beta1.Coin budget = 2;
uint64 max_num_data = 3;
string buyer_address = 4;
string consumer_address = 4;
}

// MsgCreateDealResponse defines the Msg/CreateDeal response type.
Expand Down
22 changes: 22 additions & 0 deletions x/datadeal/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cli

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/medibloc/panacea-core/v2/x/datadeal/types"
"github.com/spf13/cobra"
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group datadeal queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
return cmd
}
22 changes: 22 additions & 0 deletions x/datadeal/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cli

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/medibloc/panacea-core/v2/x/datadeal/types"
"github.com/spf13/cobra"
)

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

return cmd
}
18 changes: 18 additions & 0 deletions x/datadeal/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package datadeal

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/medibloc/panacea-core/v2/x/datadeal/keeper"
"github.com/medibloc/panacea-core/v2/x/datadeal/types"
)

// InitGenesis initializes the capability module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
//TODO
}

// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return nil
}
34 changes: 34 additions & 0 deletions x/datadeal/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package datadeal

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/medibloc/panacea-core/v2/x/datadeal/keeper"
"github.com/medibloc/panacea-core/v2/x/datadeal/types"
)

// NewHandler ...
func NewHandler(k keeper.Keeper) sdk.Handler {
msgServer := keeper.NewMsgServerImpl(k)

return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())

switch msg := msg.(type) {
case *types.MsgCreateDeal:
res, err := msgServer.CreateDeal(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
//case *types.MsgDeactivateDeal:
// res, err := msgServer.DeactivateDeal(sdk.WrapSDKContext(ctx), msg)
// return sdk.WrapServiceResult(ctx, res, err)
//case *types.MsgSubmitConsent:
// res, err := msgServer.SubmitConsent(sdk.WrapSDKContext(ctx), msg)
// return sdk.WrapServiceResult(ctx, res, err)
default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
}
}
}
5 changes: 5 additions & 0 deletions x/datadeal/keeper/grpc_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package keeper

import "github.com/medibloc/panacea-core/v2/x/datadeal/types"

var _ types.QueryServer = Keeper{}
27 changes: 27 additions & 0 deletions x/datadeal/keeper/grpc_query_deal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package keeper

import (
"context"

"github.com/medibloc/panacea-core/v2/x/datadeal/types"
)

func (k Keeper) Deals(ctx context.Context, request *types.QueryDealsRequest) (*types.QueryDealsResponse, error) {
//TODO implement me
panic("implement me")
}

func (k Keeper) Deal(ctx context.Context, request *types.QueryDealRequest) (*types.QueryDealResponse, error) {
//TODO implement me
panic("implement me")
}

func (k Keeper) Certificates(ctx context.Context, certificates *types.QueryCertificates) (*types.QueryCertificatesResponse, error) {
//TODO implement me
panic("implement me")
}

func (k Keeper) Certificate(ctx context.Context, certificate *types.QueryCertificate) (*types.QueryCertificateResponse, error) {
//TODO implement me
panic("implement me")
}
32 changes: 32 additions & 0 deletions x/datadeal/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package keeper

import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
Keeper struct {
cdc codec.Codec
storeKey sdk.StoreKey
memKey sdk.StoreKey

paramSpace paramtypes.Subspace
}
)

func NewKeeper(
cdc codec.Codec,
storeKey,
memKey sdk.StoreKey,
paramSpace paramtypes.Subspace,
) *Keeper {

return &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
paramSpace: paramSpace,
}
}
15 changes: 15 additions & 0 deletions x/datadeal/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package keeper

import "github.com/medibloc/panacea-core/v2/x/datadeal/types"

type msgServer struct {
Keeper
}

// NewMsgServerImpl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}

var _ types.MsgServer = msgServer{}
22 changes: 22 additions & 0 deletions x/datadeal/keeper/msg_server_deal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package keeper

import (
"context"

"github.com/medibloc/panacea-core/v2/x/datadeal/types"
)

func (m msgServer) CreateDeal(ctx context.Context, deal *types.MsgCreateDeal) (*types.MsgCreateDealResponse, error) {
//TODO implement me
panic("implement me")
}

func (m msgServer) DeactivateDeal(ctx context.Context, deal *types.MsgDeactivateDeal) (*types.MsgDeactivateDealResponse, error) {
//TODO implement me
panic("implement me")
}

func (m msgServer) SubmitConsent(ctx context.Context, consent *types.MsgSubmitConsent) (*types.MsgSubmitConsentResponse, error) {
//TODO implement me
panic("implement me")
}
166 changes: 166 additions & 0 deletions x/datadeal/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package datadeal

import (
"context"
"encoding/json"
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/medibloc/panacea-core/v2/x/datadeal/client/cli"
"github.com/medibloc/panacea-core/v2/x/datadeal/keeper"
"github.com/medibloc/panacea-core/v2/x/datadeal/types"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
)

var (
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)

// ----------------------------------------------------------------------------
// AppModuleBasic
// ----------------------------------------------------------------------------

// AppModuleBasic implements the AppModuleBasic interface for the capability module.
type AppModuleBasic struct {
cdc codec.Codec
}

func NewAppModuleBasic(cdc codec.Codec) AppModuleBasic {
return AppModuleBasic{cdc: cdc}
}

// Name returns the capability module's name.
func (AppModuleBasic) Name() string {
return types.ModuleName
}

func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
}

func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
}

// RegisterInterfaces registers the module's interface types
func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(reg)
}

// DefaultGenesis returns the capability module's default genesis state.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesis())
}

// ValidateGenesis performs genesis state validation for the capability module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
var genState types.GenesisState
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}
return genState.Validate()
}

// RegisterRESTRoutes registers the capability module's REST service handlers.
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err != nil {
panic("Error RegisterGRPCGatewayRoutes")
}
}

// GetTxCmd returns the capability module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}

// GetQueryCmd returns the capability module's root query command.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd(types.StoreKey)
}

// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------

// AppModule implements the AppModule interface for the capability module.
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
}

func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
return AppModule{
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
}
}

// Name returns the capability module's name.
func (am AppModule) Name() string {
return am.AppModuleBasic.Name()
}

// Route returns the capability module's message routing key.
func (am AppModule) Route() sdk.Route {
return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper))
}

// QuerierRoute returns the capability module's query routing key.
func (AppModule) QuerierRoute() string { return types.QuerierRoute }

// LegacyQuerierHandler returns the capability module's Querier.
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return nil
}

// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
}

// RegisterInvariants registers the capability module's invariants.
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// InitGenesis performs the capability module's genesis initialization It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate {
var genState types.GenesisState
// Initialize global index to index in genesis state
cdc.MustUnmarshalJSON(gs, &genState)

InitGenesis(ctx, am.keeper, genState)

return []abci.ValidatorUpdate{}
}

// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
genState := ExportGenesis(ctx, am.keeper)
return cdc.MustMarshalJSON(genState)
}

// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}

// EndBlock executes all ABCI EndBlock logic respective to the capability module. It
// returns no validator updates.
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
}

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
Loading

0 comments on commit ac668d4

Please sign in to comment.