Skip to content

Commit

Permalink
update collection query
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Feb 6, 2023
1 parent 235dbf8 commit 5a66aaf
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,55 @@ func (k Keeper) Supply(c context.Context, request *types.QuerySupplyRequest) (*t
func (k Keeper) Collection(c context.Context, request *types.QueryCollectionRequest) (*types.QueryCollectionResponse, error) {
ctx := sdk.UnwrapSDKContext(c)

collection, pagination, err := k.GetPaginateCollection(ctx, request, request.DenomId)
denom, err := k.GetDenomInfo(ctx, request.DenomId)
if err != nil {
return nil, err
}

r := &nft.QueryNFTsRequest{
ClassId: request.DenomId,
Pagination: shapePageRequest(request.Pagination),
}

result, err := k.nk.NFTs(c, r)
if err != nil {
return nil, err
}
var onfts []types.ONFT
for _, _nft := range result.Nfts {
owner := k.nk.GetOwner(ctx, request.DenomId, _nft.Id)

nftMetadata, err := types.UnmarshalNFTMetadata(k.cdc, _nft.Data.GetValue())
if err != nil {
return nil, err
}

onfts = append(onfts, types.ONFT{
Id: _nft.Id,
Metadata: types.Metadata{
Name: nftMetadata.Name,
Description: nftMetadata.Description,
MediaURI: _nft.Uri,
UriHash: _nft.UriHash,
PreviewURI: nftMetadata.PreviewURI,
},
Owner: owner.String(),
Data: nftMetadata.Data,
Transferable: nftMetadata.Transferable,
Extensible: nftMetadata.Extensible,
CreatedAt: nftMetadata.CreatedAt,
Nsfw: nftMetadata.Nsfw,
RoyaltyShare: nftMetadata.RoyaltyShare,
})
}

collection := &types.Collection{
Denom: *denom,
ONFTs: onfts,
}
return &types.QueryCollectionResponse{
Collection: &collection,
Pagination: pagination,
Collection: collection,
Pagination: result.Pagination,
}, nil
}

Expand Down

0 comments on commit 5a66aaf

Please sign in to comment.