Skip to content

Commit

Permalink
feat: Added nft module and denom feature (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuguen authored Mar 9, 2024
1 parent 2cd47d9 commit 14efd43
Show file tree
Hide file tree
Showing 33 changed files with 7,914 additions and 19 deletions.
21 changes: 11 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/group"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/cosmos-sdk/x/nft"
nftmodule "github.com/cosmos/cosmos-sdk/x/nft/module"
"github.com/cosmos/cosmos-sdk/x/upgrade"
"github.com/medibloc/panacea-core/v2/app/keepers"
"github.com/medibloc/panacea-core/v2/app/upgrades"
"github.com/medibloc/panacea-core/v2/x/pnft"
pnfttypes "github.com/medibloc/panacea-core/v2/x/pnft/types"
"github.com/spf13/cast"
"io"
"os"
Expand Down Expand Up @@ -140,7 +141,6 @@ var (
authzmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
vesting.AppModuleBasic{},
nftmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
// ibc
ibc.AppModuleBasic{},
Expand All @@ -151,6 +151,7 @@ var (
aol.AppModuleBasic{},
did.AppModuleBasic{},
burn.AppModuleBasic{},
pnft.AppModuleBasic{},
)

// module account permissions
Expand All @@ -161,9 +162,9 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
nft.ModuleName: nil,
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
burntypes.ModuleName: {authtypes.Burner},
nft.ModuleName: nil,
}

_ runtime.AppI = (*App)(nil)
Expand Down Expand Up @@ -284,13 +285,13 @@ func New(
params.NewAppModule(app.ParamsKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
ibc.NewAppModule(app.IBCKeeper),
transfer.NewAppModule(app.TransferKeeper),
aol.NewAppModule(appCodec, app.AolKeeper),
did.NewAppModule(appCodec, app.DidKeeper),
burn.NewAppModule(appCodec, app.BurnKeeper),
pnft.NewAppModule(appCodec, &app.PnftKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -302,21 +303,21 @@ func New(
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName,
authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName,
authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName,
authz.ModuleName, feegrant.ModuleName, group.ModuleName,
paramstypes.ModuleName, vestingtypes.ModuleName, consensusparamtypes.ModuleName,
ibcexported.ModuleName, ibctransfertypes.ModuleName,
aoltypes.ModuleName, didtypes.ModuleName, burntypes.ModuleName,
aoltypes.ModuleName, didtypes.ModuleName, burntypes.ModuleName, pnfttypes.ModuleName,
)

app.ModuleManager.SetOrderEndBlockers(
crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName,
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName,
slashingtypes.ModuleName, minttypes.ModuleName,
genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName,
feegrant.ModuleName, group.ModuleName,
paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, consensusparamtypes.ModuleName,
ibcexported.ModuleName, ibctransfertypes.ModuleName,
aoltypes.ModuleName, didtypes.ModuleName, burntypes.ModuleName,
aoltypes.ModuleName, didtypes.ModuleName, burntypes.ModuleName, pnfttypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -329,10 +330,10 @@ func New(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName,
distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName,
minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName,
feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
feegrant.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName,
vestingtypes.ModuleName, consensusparamtypes.ModuleName,
ibcexported.ModuleName, ibctransfertypes.ModuleName,
aoltypes.ModuleName, didtypes.ModuleName, burntypes.ModuleName,
aoltypes.ModuleName, didtypes.ModuleName, burntypes.ModuleName, pnfttypes.ModuleName,
}
app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...)
Expand Down
14 changes: 10 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper"
"github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
Expand All @@ -58,6 +57,8 @@ import (
burnkeeper "github.com/medibloc/panacea-core/v2/x/burn/keeper"
didkeeper "github.com/medibloc/panacea-core/v2/x/did/keeper"
didtypes "github.com/medibloc/panacea-core/v2/x/did/types"
pnftkeeper "github.com/medibloc/panacea-core/v2/x/pnft/keeper"
pnfttypes "github.com/medibloc/panacea-core/v2/x/pnft/types"
"github.com/spf13/cast"
)

Expand All @@ -77,7 +78,6 @@ type AppKeepersWithKey struct {
EvidenceKeeper evidencekeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
GroupKeeper groupkeeper.Keeper
NFTKeeper nftkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
Expand All @@ -90,6 +90,7 @@ type AppKeepersWithKey struct {
AolKeeper aolkeeper.Keeper
DidKeeper didkeeper.Keeper
BurnKeeper burnkeeper.Keeper
PnftKeeper pnftkeeper.Keeper

keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey
Expand Down Expand Up @@ -165,8 +166,6 @@ func (appKeepers *AppKeepersWithKey) InitKeyAndKeepers(
// set the governance module account as the authority for conducting upgrades
appKeepers.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, appKeepers.keys[upgradetypes.StoreKey], appCodec, homePath, bApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())

appKeepers.NFTKeeper = nftkeeper.NewKeeper(appKeepers.keys[nftkeeper.StoreKey], appCodec, appKeepers.AccountKeeper, appKeepers.BankKeeper)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, appKeepers.keys[evidencetypes.StoreKey], appKeepers.StakingKeeper, appKeepers.SlashingKeeper,
Expand Down Expand Up @@ -211,6 +210,13 @@ func (appKeepers *AppKeepersWithKey) InitKeyAndKeepers(
appKeepers.BankKeeper,
)

appKeepers.PnftKeeper = pnftkeeper.NewKeeper(
appCodec,
appKeepers.keys[pnfttypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
)

// Set router

// Register the proposal types
Expand Down
6 changes: 3 additions & 3 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/group"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -25,6 +24,7 @@ import (
aoltypes "github.com/medibloc/panacea-core/v2/x/aol/types"
burntypes "github.com/medibloc/panacea-core/v2/x/burn/types"
didtypes "github.com/medibloc/panacea-core/v2/x/did/types"
pnfttypes "github.com/medibloc/panacea-core/v2/x/pnft/types"
)

func (appKeepers *AppKeepersWithKey) GenerateKeys() {
Expand All @@ -33,9 +33,9 @@ func (appKeepers *AppKeepersWithKey) GenerateKeys() {
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey,
authzkeeper.StoreKey, group.StoreKey,
ibcexported.StoreKey, ibctransfertypes.StoreKey,
aoltypes.StoreKey, didtypes.StoreKey, burntypes.StoreKey,
aoltypes.StoreKey, didtypes.StoreKey, burntypes.StoreKey, pnfttypes.StoreKey,
)

appKeepers.tkeys = sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/cosmos/ibc-go/v7 v7.3.2
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.4.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pborman/uuid v1.2.1
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -93,7 +94,6 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion proto/panacea/aol/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "panacea/aol/v2/topic.proto";
option java_multiple_files = true;
option go_package = "github.com/medibloc/panacea-core/x/aol/types";

// Query defines the gRPC querier service.
// QueryService defines the gRPC querier service.
service QueryService {
// Topic returns topic details.
rpc Topic(QueryServiceTopicRequest) returns (QueryServiceTopicResponse) {
Expand Down
26 changes: 26 additions & 0 deletions proto/panacea/pnft/v2/event.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package panacea.pnft.v2;

option go_package = "github.com/medibloc/panacea-core/x/pnft/types";
option java_multiple_files = true;

message EventSaveDenom {
string id = 1;
string creator = 2;
}

message EventUpdateDenom {
string id = 1;
string updater = 2;
}

message EventDeleteDenom {
string id = 1;
string remover = 2;
}

message EventTransferDenom {
string id = 1;
string sender = 2;
string receiver = 3;
}
12 changes: 12 additions & 0 deletions proto/panacea/pnft/v2/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";
package panacea.pnft.v2;

import "panacea/pnft/v2/pnft.proto";

option go_package = "github.com/medibloc/panacea-core/x/pnft/types";
option java_multiple_files = true;

// GenesisState defines the nft module's genesis state.
message GenesisState {
repeated panacea.pnft.v2.Denom denoms = 1;
}
21 changes: 21 additions & 0 deletions proto/panacea/pnft/v2/pnft.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";
package panacea.pnft.v2;

option go_package = "github.com/medibloc/panacea-core/x/pnft/types";
option java_multiple_files = true;

message Denom {
string id = 1;
string name = 2;
string symbol = 3;
string description = 4;
string uri = 5;
string uri_hash = 6;
string owner = 7;
string data = 8;
}

message DenomMeta {
string owner = 1;
string data = 2;
}
60 changes: 60 additions & 0 deletions proto/panacea/pnft/v2/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
syntax = "proto3";
package panacea.pnft.v2;

import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "panacea/pnft/v2/pnft.proto";

option java_multiple_files = true;
option go_package = "github.com/medibloc/panacea-core/x/pnft/types";

// QueryService defines the gRPC querier service.
service QueryService {
// Denoms returns denom list.
rpc Denoms(QueryServiceDenomsRequest) returns (QueryServiceDenomsResponse) {
option (google.api.http).get =
"/panacea/pnft/v2/denoms";
}

rpc DenomsByCreator(QueryServiceDenomsByCreatorRequest) returns (QueryServiceDenomsByCreatorResponse) {
option (google.api.http).get =
"/panacea/pnft/v2/denoms/creators/{creator}";
}

// Denom returns denom detail.
rpc Denom(QueryServiceDenomRequest) returns (QueryServiceDenomResponse) {
option (google.api.http).get =
"/panacea/pnft/v2/denoms/{id}";
}
}

// QueryServiceDenomsRequest is the response type for the Query RPC method.
message QueryServiceDenomsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

// QueryServiceDenomsResponse is the response type for the Query RPC method.
message QueryServiceDenomsResponse {
repeated panacea.pnft.v2.Denom denoms = 1;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryServiceDenomsByCreatorRequest is the response type for the Query RPC method.
message QueryServiceDenomsByCreatorRequest {
string creator = 1;
}

// QueryServiceDenomsByCreatorResponse is the response type for the Query RPC method.
message QueryServiceDenomsByCreatorResponse {
repeated panacea.pnft.v2.Denom denoms = 1;
}

// QueryServiceDenomRequest is the response type for the Query RPC method.
message QueryServiceDenomRequest {
string id = 1;
}

// QueryServiceDenomResponse is the response type for the Query RPC method.
message QueryServiceDenomResponse {
panacea.pnft.v2.Denom denom = 1;
}
58 changes: 58 additions & 0 deletions proto/panacea/pnft/v2/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
syntax = "proto3";
package panacea.pnft.v2;

import "panacea/pnft/v2/pnft.proto";

option go_package = "github.com/medibloc/panacea-core/x/pnft/types";
option java_multiple_files = true;

service MsgService {
rpc CreateDenom(MsgServiceCreateDenomRequest) returns (MsgServiceCreateDenomResponse);

rpc UpdateDenom(MsgServiceUpdateDenomRequest) returns (MsgServiceUpdateDenomResponse);

rpc DeleteDenom(MsgServiceDeleteDenomRequest) returns (MsgServiceDeleteDenomResponse);

rpc TransferDenom(MsgServiceTransferDenomRequest) returns (MsgServiceTransferDenomResponse);
}

message MsgServiceCreateDenomRequest {
string id = 1;
string name = 2;
string symbol = 3;
string description = 4;
string uri = 5;
string uri_hash = 6;
string data = 7;
string creator = 8;
}

message MsgServiceCreateDenomResponse {}

message MsgServiceUpdateDenomRequest {
string id = 1;
string name = 2;
string symbol = 3;
string description = 4;
string uri = 5;
string uri_hash = 6;
string data = 7;
string updater = 8;
}

message MsgServiceUpdateDenomResponse {}

message MsgServiceDeleteDenomRequest {
string id = 1;
string remover = 2;
}

message MsgServiceDeleteDenomResponse {}

message MsgServiceTransferDenomRequest {
string id = 1;
string sender = 2;
string receiver = 3;
}

message MsgServiceTransferDenomResponse {}
Loading

0 comments on commit 14efd43

Please sign in to comment.