add nft assets endpoint (#298)

This commit is contained in:
Asim Aslam
2021-12-08 14:04:19 +00:00
committed by GitHub
parent 22ce7074a0
commit cc0a59aaf7
9 changed files with 1829 additions and 108 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -42,7 +42,8 @@ func NewNftEndpoints() []*api.Endpoint {
// Client API for Nft service
type NftService interface {
Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error)
Assets(ctx context.Context, in *AssetsRequest, opts ...client.CallOption) (*AssetsResponse, error)
Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error)
}
type nftService struct {
@@ -57,9 +58,19 @@ func NewNftService(name string, c client.Client) NftService {
}
}
func (c *nftService) Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error) {
req := c.c.NewRequest(c.name, "Nft.Vote", in)
out := new(VoteResponse)
func (c *nftService) Assets(ctx context.Context, in *AssetsRequest, opts ...client.CallOption) (*AssetsResponse, error) {
req := c.c.NewRequest(c.name, "Nft.Assets", in)
out := new(AssetsResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *nftService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) {
req := c.c.NewRequest(c.name, "Nft.Create", in)
out := new(CreateResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
@@ -70,12 +81,14 @@ func (c *nftService) Vote(ctx context.Context, in *VoteRequest, opts ...client.C
// Server API for Nft service
type NftHandler interface {
Vote(context.Context, *VoteRequest, *VoteResponse) error
Assets(context.Context, *AssetsRequest, *AssetsResponse) error
Create(context.Context, *CreateRequest, *CreateResponse) error
}
func RegisterNftHandler(s server.Server, hdlr NftHandler, opts ...server.HandlerOption) error {
type nft interface {
Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error
Assets(ctx context.Context, in *AssetsRequest, out *AssetsResponse) error
Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error
}
type Nft struct {
nft
@@ -88,6 +101,10 @@ type nftHandler struct {
NftHandler
}
func (h *nftHandler) Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error {
return h.NftHandler.Vote(ctx, in, out)
func (h *nftHandler) Assets(ctx context.Context, in *AssetsRequest, out *AssetsResponse) error {
return h.NftHandler.Assets(ctx, in, out)
}
func (h *nftHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error {
return h.NftHandler.Create(ctx, in, out)
}

View File

@@ -5,16 +5,144 @@ package nft;
option go_package = "./proto;nft";
service Nft {
rpc Vote(VoteRequest) returns (VoteResponse) {}
rpc Assets(AssetsRequest) returns (AssetsResponse) {}
rpc Create(CreateRequest) returns (CreateResponse) {}
}
// Vote to have the NFT api launched faster!
message VoteRequest {
// optional message
string message = 1;
// Create your own NFT (coming soon)
message CreateRequest {
// name of the NFT
string name = 1;
// description
string description = 2;
// image data
bytes image = 3;
// data if not image
bytes data = 4;
}
message VoteResponse {
// response message
string message = 2;
message CreateResponse {
Asset asset = 1;
}
message Asset {
// id of the asset
int32 id = 1;
// the token id
string token_id = 2;
// name of the asset
string name = 3;
// related description
string description = 4;
// the image url
string image_url = 5;
// number of sales
int32 sales = 6;
// the permalink
string permalink = 7;
// asset contract
Contract contract = 8;
// associated collection
Collection collection = 9;
// Creator of the NFT
User creator = 10;
// Owner of the NFT
User owner = 11;
// is it a presale
bool presale = 12;
// last time sold
Sale last_sale = 13;
// listing date
string listing_date = 14;
}
message Contract {
// name of contract
string name = 1;
// ethereum address
string address = 2;
// type of contract e.g "semi-fungible"
string type = 3;
// timestamp of creation
string created_at = 4;
// owner id
int32 owner = 5;
// aka "ERC1155"
string schema = 6;
// related symbol
string symbol = 7;
// description of contract
string description = 8;
// payout address
string payout_address = 9;
// seller fees
string seller_fees = 10;
}
message Collection {
string name = 1;
string description = 2;
string slug = 3;
string image_url = 4;
string created_at = 5;
string payout_address = 6;
}
message User {
string username = 1;
string profile_url = 2;
string address = 3;
}
message Sale {
string asset_token_id = 1;
int32 asset_decimals = 2;
string event_type = 3;
string event_timestamp = 4;
string total_price = 5;
string quantity = 6;
string created_at = 7;
Transaction transaction = 8;
Token payment_token = 9;
}
message Transaction {
int32 id = 1;
string timestamp = 2;
string block_hash = 3;
string block_number = 4;
User from_account = 5;
User to_account = 6;
string transaction_hash = 7;
string transaction_index = 8;
}
message Token {
int32 id = 1;
string name = 2;
string symbol = 3;
string address = 4;
string image_url = 5;
int32 decimals = 6;
string eth_price = 7;
string usd_price = 8;
}
// Return a list of NFT assets
message AssetsRequest {
// limit returned assets
int32 limit = 1;
// offset for pagination
int32 offset = 2;
// order "asc" or "desc"
string order = 3;
// order by "sale_date", "sale_count", "sale_price", "total_price"
string order_by = 4;
// limit to members of a collection by slug name (case sensitive)
string collection = 5;
}
message AssetsResponse {
// list of assets
repeated Asset assets = 1;
}