Skip to content

Commit

Permalink
feat(dao): OwnersByCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
omniwired authored and WaDadidou committed Aug 17, 2023
1 parent bb05db7 commit 6c015f0
Show file tree
Hide file tree
Showing 6 changed files with 493 additions and 106 deletions.
9 changes: 9 additions & 0 deletions api/marketplace/v1/marketplace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ service MarketplaceService {
rpc DAppsGroups(DAppsGroupsRequest) returns (DAppsGroupsResponse);
rpc SearchNames(SearchNamesRequest) returns (SearchNamesResponse);
rpc SearchCollections(SearchCollectionsRequest) returns (SearchCollectionsResponse);
rpc OwnersByCollection(OwnersByCollectionRequest) returns (OwnersByCollectionResponse);
}

enum Sort {
Expand Down Expand Up @@ -310,3 +311,11 @@ message SearchCollectionsRequest {
message SearchCollectionsResponse {
repeated Collection collections = 1;
}

message OwnersByCollectionRequest {
string collection_id = 1;
}

message OwnersByCollectionResponse {
repeated string owners = 1;
}
31 changes: 31 additions & 0 deletions go/pkg/marketplace/marketplace_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,3 +1056,34 @@ func (s *MarkteplaceService) SearchCollections(ctx context.Context, req *marketp
}
return &marketplacepb.SearchCollectionsResponse{Collections: pbCollections}, nil
}

func (s *MarkteplaceService) OwnersByCollection(ctx context.Context, req *marketplacepb.OwnersByCollectionRequest) (*marketplacepb.OwnersByCollectionResponse, error) {

collectionId := req.CollectionId

type Owners struct {
Owner string
}
var owners []Owners

_ = s.conf.IndexerDB.Raw(`
select nfts.id, max(a.time) atime, COALESCE(m.buyer_id, t.buyer_id, tn.receiver) as owner
from nfts
join activities a on nfts.id = a.nft_id
left join mints m on a.id = m.activity_id
left join trades t on a.id = t.activity_id
left join transfer_nfts tn on a.id = tn.activity_id
where collection_id = ? and a.kind in ('mint', 'trade','transfer-nft') and a.kind != 'burn'
group by nfts.id, m.buyer_id, t.buyer_id, tn.receiver
order by atime desc`, collectionId).Scan(
&owners,
).Error

var out []string
for _, owner := range owners {
out = append(out, owner.Owner)
}

return &marketplacepb.OwnersByCollectionResponse{Owners: out}, nil

}
Loading

0 comments on commit 6c015f0

Please sign in to comment.