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

feat: generate nft protobuf #9747

Merged
merged 21 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
473 changes: 473 additions & 0 deletions docs/core/proto-docs.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions proto/cosmos/nft/v1beta1/event.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package cosmos.nft.v1beta1;
import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/nft";

// EventSend is emitted on Msg/Send
message EventSend {
string class_id = 1;
string id = 2;
string sender = 3;
string receiver = 4;
}
24 changes: 24 additions & 0 deletions proto/cosmos/nft/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
syntax = "proto3";
package cosmos.nft.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/nft/v1beta1/nft.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/nft";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about putting genesis into a subpackage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that genesis output to github.com/cosmos/cosmos-sdk/x/nft/genesis?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. What do you think about this idea?

Copy link
Collaborator

@robert-zaremba robert-zaremba Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When thinking more about it - I would propose to split it in the following way:

  • x/nft -- for all things related to RPC
  • x/nft/dal -- for all things related to storage (data access layer)
    This way we have a clear domains.

PS: we think to do the same for eco-credit module

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: Aaron pointed in a chat, that this will require splitting the proto packages as well:

  • proto/cosmos/nft/v1beta1
  • proto/cosmos/nft/dal/v1beta1

Copy link
Collaborator

@robert-zaremba robert-zaremba Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main point for breaking down the proto into 2 (or more) packages is to have more freedom to upgrading it in the future:

  • the protobuf service API and related types should be rather stable and we want to avoid any breaking change. We will version it.
  • the storage types can be in an internal package and don't need to be versioned. If "tomorrow" we will find a better storage layout we can update the module without bumping the API version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, got it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please not use the term dal. I would use state instead. I also don't want to delay this PR unnecessarily, and would prefer to do this design in a more general way for the SDK.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, how can this PR be modified?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recently, @aaronc pointed that the store proto version is important for merkle proofs. So, we will probably need to discuss more about it.
TL;DR - let's merge this in one package.


// GenesisState defines the nft module's genesis state.
message GenesisState {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// class defines the class of the nft type.
repeated cosmos.nft.v1beta1.Class classes = 1 [(gogoproto.nullable) = false];
repeated Entry entries = 2 [(gogoproto.nullable) = false];
}

// Entry Defines all nft owned by a person
message Entry {
string owner = 1;
repeated cosmos.nft.v1beta1.NFT nfts = 2 [(gogoproto.customname) = "NFTs", (gogoproto.nullable) = false];
}
30 changes: 30 additions & 0 deletions proto/cosmos/nft/v1beta1/nft.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";
package cosmos.nft.v1beta1;

import "google/protobuf/any.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/nft";

// Class defines the class of the nft type.
message Class {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = false;

string id = 1;
string name = 2;
string symbol = 3;
string description = 4;
string uri = 5;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we add: uri_hash - this will be a hash of the document pointed by URI - similar to what we have in bank.proto metadata,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to the uri_hash

}

// NFT defines the nft.
message NFT {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = false;

string class_id = 1;
string id = 2;
string uri = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add uri_hash as well.

google.protobuf.Any data = 10;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add comment to the data field. Both data and any has almost no meaning.

}
125 changes: 125 additions & 0 deletions proto/cosmos/nft/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
syntax = "proto3";
package cosmos.nft.v1beta1;

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

option go_package = "github.com/cosmos/cosmos-sdk/x/nft";

// Query defines the gRPC querier service.
service Query {
// Balance queries the number of NFTs of a given class owned by the owner, same as balanceOf in ERC721
rpc Balance(QueryBalanceRequest) returns (QueryBalanceResponse) {
option (google.api.http).get = "/cosmos/nft/v1beta1/balance/{class_id}/{owner}";
}

// Owner queries the owner of the NFT based on its class and id, same as ownerOf in ERC721
rpc Owner(QueryOwnerRequest) returns (QueryOwnerResponse) {
option (google.api.http).get = "/cosmos/nft/v1beta1/owner/{class_id}/{id}";
}

// Supply queries the number of nft based on the class, same as totalSupply of ERC721
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Supply queries the number of nft based on the class, same as totalSupply of ERC721
// Supply queries the number of NFTs from the given class, same as totalSupply of ERC721.

rpc Supply(QuerySupplyRequest) returns (QuerySupplyResponse) {
option (google.api.http).get = "/cosmos/nft/v1beta1/supply/{class_id}";
}

// NFTsOfClass queries all NFTs of a given class or optional owner, similar to tokenByIndex in ERC721Enumerable
rpc NFTsOfClass(QueryNFTsOfClassRequest) returns (QueryNFTsOfClassResponse) {
option (google.api.http).get = "/cosmos/nft/v1beta1/nfts/{class_id}";
}

// NFT queries an NFT based on its class and id.
rpc NFT(QueryNFTRequest) returns (QueryNFTResponse) {
option (google.api.http).get = "/cosmos/nft/v1beta1/nfts/{class_id}/{id}";
}

// Class queries an NFT class based on its id
rpc Class(QueryClassRequest) returns (QueryClassResponse) {
option (google.api.http).get = "/cosmos/nft/v1beta1/classes/{class_id}";
}

// Classes queries all NFT classes
rpc Classes(QueryClassesRequest) returns (QueryClassesResponse) {
option (google.api.http).get = "/cosmos/nft/v1beta1/classes";
}
}

// QueryBalanceRequest is the request type for the Query/Balance RPC method
message QueryBalanceRequest {
string class_id = 1;
string owner = 2;
}

// QueryBalanceResponse is the response type for the Query/Balance RPC method
message QueryBalanceResponse {
uint64 amount = 1;
}

// QueryOwnerRequest is the request type for the Query/Owner RPC method
message QueryOwnerRequest {
string class_id = 1;
string id = 2;
}

// QueryOwnerResponse is the response type for the Query/Owner RPC method
message QueryOwnerResponse {
string owner = 1;
}

// QuerySupplyRequest is the request type for the Query/Supply RPC method
message QuerySupplyRequest {
string class_id = 1;
}

// QuerySupplyResponse is the response type for the Query/Supply RPC method
message QuerySupplyResponse {
uint64 amount = 1;
}

// QueryNFTsOfClassRequest is the request type for the Query/NFTsOfClass RPC method
message QueryNFTsOfClassRequest {
string class_id = 1;
string owner = 2;
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

// QueryNFTsOfClassResponse is the response type for the Query/NFTsOfClass and Query/NFTsOfClassByOwner RPC methods
message QueryNFTsOfClassResponse {
repeated cosmos.nft.v1beta1.NFT nfts = 1;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryNFTRequest is the request type for the Query/NFT RPC method
message QueryNFTRequest {
string class_id = 1;
string id = 2;
}

// QueryNFTResponse is the response type for the Query/NFT RPC method
message QueryNFTResponse {
cosmos.nft.v1beta1.NFT nft = 1;
}

// QueryClassRequest is the request type for the Query/Class RPC method
message QueryClassRequest {
string class_id = 1;
}

// QueryClassResponse is the response type for the Query/Class RPC method
message QueryClassResponse {
cosmos.nft.v1beta1.Class class = 1;
}

// QueryClassesRequest is the request type for the Query/Classes RPC method
message QueryClassesRequest {
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

// QueryClassesResponse is the response type for the Query/Classes RPC method
message QueryClassesResponse {
repeated cosmos.nft.v1beta1.Class classes = 1;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
25 changes: 25 additions & 0 deletions proto/cosmos/nft/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package cosmos.nft.v1beta1;

import "cosmos/nft/v1beta1/nft.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/cosmos/cosmos-sdk/x/nft";

// Msg defines the nft Msg service.
service Msg {
// Send defines a method to send a nft from one account to another account.
rpc Send(MsgSend) returns (MsgSendResponse);
}
// MsgSend represents a message to send a nft from one account to another account.
message MsgSend {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = true;

string class_id = 1;
string id = 2;
string sender = 3;
string receiver = 4;
}
// MsgSendResponse defines the Msg/Send response type.
message MsgSendResponse {}
Loading