Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support games-std #82

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,20 @@ testcli:

protogen:
starport generate proto-go

run:
nibirud start --pruning nothing --grpc.address :9090 --home ./.chaindata --log_level warn

init:
rm -rf ./.chaindata/*
nibirud init gchain --chain-id localnet --home ./.chaindata
nibirud keys add alice --keyring-backend test --home ./.chaindata
nibirud keys add bob --keyring-backend test --home ./.chaindata
nibirud keys add tom --keyring-backend test --home ./.chaindata
nibirud add-genesis-account alice 400000000ugtn,100000000stake --home ./.chaindata
nibirud add-genesis-account bob 200000000ugtn --home ./.chaindata
nibirud gentx alice 100000000stake --keyring-backend test --chain-id localnet --home ./.chaindata --commission-rate 0.0 --commission-max-rate 0.1
nibirud collect-gentxs --home ./.chaindata

deploy:
source $(shell pwd)/.artifacts/deploy.sh
32 changes: 28 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ import (
// this line is used by starport scaffolding # stargate/app/moduleImport
"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
nftmodule "github.com/cosmos-gaminghub/nibiru/x/nft"
nftmodulekeeper "github.com/cosmos-gaminghub/nibiru/x/nft/keeper"
nftmoduletypes "github.com/cosmos-gaminghub/nibiru/x/nft/types"
nftmodulewasm "github.com/cosmos-gaminghub/nibiru/x/nft/wasm"
"github.com/tendermint/spm-extras/wasmcmd"

// unnamed import of statik for swagger UI support
Expand Down Expand Up @@ -355,15 +357,35 @@ func NewNibiruApp(
)
nftModule := nftmodule.NewAppModule(appCodec, app.NftKeeper)

wasmDir := filepath.Join(homePath, "wasm")
// custom message encoder
customEncoder := wasmkeeper.DefaultEncoders(appCodec, app.TransferKeeper)
customEncoder.Custom = nftmodulewasm.DefaultCustomEncoder().Encode
wasmMessageHandler := wasmkeeper.NewDefaultMessageHandler(
app.Router(),
app.IBCKeeper.ChannelKeeper,
scopedWasmKeeper,
app.BankKeeper,
appCodec,
app.TransferKeeper,
&customEncoder,
)

// custom queier
wasmVMQueryHandler := wasmkeeper.DefaultQueryPlugins(
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
app.IBCKeeper.ChannelKeeper,
app.GRPCQueryRouter(),
app.wasmKeeper,
)
wasmVMQueryHandler.Custom = nftmodulewasm.DefaultCustomQuerier(&app.NftKeeper).Querier()

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic("error while reading wasm config: " + err.Error())
}

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate"
app.wasmKeeper = wasm.NewKeeper(
appCodec,
Expand All @@ -382,6 +404,8 @@ func NewNibiruApp(
wasmDir,
wasmConfig,
supportedFeatures,
wasmkeeper.WithMessageHandler(wasmMessageHandler),
wasmkeeper.WithQueryHandler(wasmVMQueryHandler),
)

// The gov proposal types can be individually enabled
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ go 1.16

require (
github.com/CosmWasm/wasmd v0.20.0
github.com/CosmWasm/wasmvm v1.0.0-beta
github.com/cosmos/cosmos-sdk v0.42.10
github.com/davecgh/go-spew v1.1.1
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/irisnet/irismod v1.4.0
github.com/kr/text v0.2.0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand All @@ -262,6 +263,8 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0=
github.com/gogo/gateway v1.1.0/go.mod h1:S7rR8FRQyG3QFESeSv4l2WnsyzlCLG0CzBbUUo/mbic=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -374,6 +377,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0 h1:rgxjzoDmDXw5q8HONgyHhBas4to0/XWRo/gPpJhsUNQ=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.6.0/go.mod h1:qrJPVzv9YlhsrxJc3P/Q85nr0w1lIRikTl4JlhdDH5w=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down
16 changes: 16 additions & 0 deletions proto/nft/nft.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";
package cosmosgaminghub.nibiru.nft;

import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos-gaminghub/nibiru/x/nft/types";

message BaseNFT {
option (gogoproto.equal) = true;

string id = 1;
string name = 2;
string uri = 3 [ (gogoproto.customname) = "URI" ];
string data = 4;
string owner = 5;
}
13 changes: 13 additions & 0 deletions proto/nft/query.proto
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
syntax = "proto3";
package cosmosgaminghub.nibiru.nft;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "nft/nft.proto";
// this line is used by starport scaffolding # 1

option go_package = "github.com/cosmos-gaminghub/nibiru/x/nft/types";

// Query defines the gRPC querier service.
service Query {
rpc NFT(QueryNFTRequest) returns (QueryNFTResponse) {
option (google.api.http).get = "/cosmos-gaminghub/nibiru/nft/{denom_id}/{id}";
}
// this line is used by starport scaffolding # 2
}
message QueryNFTRequest {
string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ];
uint64 id = 2 [ (gogoproto.moretags) = "yaml:\"id\"" ];
}

// QueryNFTResponse is the response type for the Query/NFT RPC method
message QueryNFTResponse {
BaseNFT nft = 1 [ (gogoproto.customname) = "NFT" ];
}
// this line is used by starport scaffolding # 3
70 changes: 70 additions & 0 deletions proto/nft/wasm_message.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
syntax = "proto3";
package cosmosgaminghub.nibiru.nft;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";

option go_package = "github.com/cosmos-gaminghub/nibiru/x/nft/types";

message GameNftDenomIssueMessage {
NftDenomIssueMessage nft = 1;
}
message NftDenomIssueMessage {
DenomIssueMessage issue_denom = 1;
}
message DenomIssueMessage {
string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ];
string name = 2 [ (gogoproto.moretags) = "yaml:\"name\"" ];
string schema = 3 [ (gogoproto.moretags) = "yaml:\"schema\"" ];
}

message GameNftMintMessage {
NftMintMessage nft = 1;
}
message NftMintMessage {
MintMessage mint_nft = 1;
}
message MintMessage {
string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ];
string name = 2 [ (gogoproto.moretags) = "yaml:\"name\"" ];
string uri = 3 [ (gogoproto.moretags) = "yaml:\"uri\"", (gogoproto.customname) = "URI" ];
string data = 4 [ (gogoproto.moretags) = "yaml:\"data\"" ];
string recipient = 5 [ (gogoproto.moretags) = "yaml:\"recipient\"" ];
}

message GameNftEditMessage {
NftEditMessage nft = 1;
}
message NftEditMessage {
EditMessage edit_nft = 1;
}
message EditMessage {
string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ];
uint64 id = 2 [ (gogoproto.moretags) = "yaml:\"id\"" ];
string name = 3 [ (gogoproto.moretags) = "yaml:\"name\"" ];
string data = 4 [ (gogoproto.moretags) = "yaml:\"data\"" ];
}

message GameNftTransferMessage {
NftTransferMessage nft = 1;
}
message NftTransferMessage {
TransferMessage transfer_nft = 1;
}
message TransferMessage {
string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ];
uint64 id = 2 [ (gogoproto.moretags) = "yaml:\"id\"" ];
string recipient = 3 [ (gogoproto.moretags) = "yaml:\"recipient\"" ];
}

message GameNftBurnMessage {
NftBurnMessage nft = 1;
}
message NftBurnMessage {
BurnMessage burn_nft = 1;
}
message BurnMessage {
string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ];
uint64 id = 2 [ (gogoproto.moretags) = "yaml:\"id\"" ];
}
41 changes: 41 additions & 0 deletions proto/nft/wasm_request.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
syntax = "proto3";
package cosmosgaminghub.nibiru.nft;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";

option go_package = "github.com/cosmos-gaminghub/nibiru/x/nft/types";

// get denom
message WasmGameDenomReq {
WasmDenomReq nft = 1;
}
message WasmDenomReq {
WasmDenomQuery denom = 1;
}
message WasmDenomQuery {
string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ];
}

// get denom all
message WasmGameDenomAllReq {
WasmDenomAllReq nft = 1;
}
message WasmDenomAllReq {
WasmDenomAllQuery denom_all = 1;
}
message WasmDenomAllQuery {}


// get nft
message WasmGameNftReq {
WasmNftReq nft = 1;
}
message WasmNftReq {
WasmNftQuery nft = 1;
}
message WasmNftQuery {
string denom_id = 1 [ (gogoproto.moretags) = "yaml:\"denom_id\"" ];
uint64 id = 2 [ (gogoproto.moretags) = "yaml:\"id\"" ];
}
13 changes: 10 additions & 3 deletions x/nft/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/spf13/cast"

"github.com/cosmos-gaminghub/nibiru/x/nft/types"
"github.com/cosmos/cosmos-sdk/client"
iriscli "github.com/irisnet/irismod/modules/nft/client/cli"
Expand Down Expand Up @@ -57,10 +59,15 @@ func GetCmdQueryNFT() *cobra.Command {
return err
}

queryClient := irismodtypes.NewQueryClient(clientCtx)
resp, err := queryClient.NFT(context.Background(), &irismodtypes.QueryNFTRequest{
argsId, err := cast.ToUint64E(args[1])
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
resp, err := queryClient.NFT(context.Background(), &types.QueryNFTRequest{
DenomId: args[0],
TokenId: tokenID.ToIris(),
Id: argsId,
})
if err != nil {
return err
Expand Down
22 changes: 22 additions & 0 deletions x/nft/keeper/grpc_query.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
package keeper

import (
"context"

"github.com/cosmos-gaminghub/nibiru/x/nft/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
irismodtypes "github.com/irisnet/irismod/modules/nft/types"
)

var _ types.QueryServer = Keeper{}

func (k Keeper) NFT(c context.Context, request *types.QueryNFTRequest) (*types.QueryNFTResponse, error) {
ctx := sdk.UnwrapSDKContext(c)

nft, err := k.GetNFT(ctx, request.DenomId, request.Id)
if err != nil {
return nil, sdkerrors.Wrapf(irismodtypes.ErrUnknownNFT, "invalid NFT %d from collection %s", request.Id, request.DenomId)
}

return &types.QueryNFTResponse{NFT: &types.BaseNFT{
Id: nft.GetID(),
Name: nft.GetName(),
URI: nft.GetURI(),
Data: nft.GetData(),
Owner: nft.GetOwner().String(),
}}, nil
}
3 changes: 3 additions & 0 deletions x/nft/module.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nft

import (
"context"
"encoding/json"
"fmt"
// this line is used by starport scaffolding # 1
Expand Down Expand Up @@ -77,6 +78,7 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
// this line is used by starport scaffolding # 2
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}

// GetTxCmd returns the capability module's root tx command.
Expand Down Expand Up @@ -128,6 +130,7 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd
// 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)
irismodtypes.RegisterQueryServer(cfg.QueryServer(), am.keeper.IrisKeeper())
}

Expand Down
4 changes: 3 additions & 1 deletion x/nft/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

// x/nft module sentinel errors
var (
ErrRestricted = sdkerrors.Register(ModuleName, 1, "restricted")
ErrRestricted = sdkerrors.Register(ModuleName, 101, "restricted")
ErrUnexpectedMsg = sdkerrors.Register(ModuleName, 102, "unexpected msg")
ErrUnexpectedReq = sdkerrors.Register(ModuleName, 103, "unexpected request")
// this line is used by starport scaffolding # ibc/errors
)
Loading