Skip to content

Commit

Permalink
wip: in launchpad service: add sorts and LaunchpadProjects endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Jul 2, 2024
1 parent 4218321 commit 12cdc6b
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 5 deletions.
43 changes: 39 additions & 4 deletions api/launchpad/v1/launchpad.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,48 @@ option go_package = "./launchpadpb";
service LaunchpadService {
rpc UploadMetadatas(UploadMetadatasRequest) returns (UploadMetadatasResponse);
rpc CalculateCollectionMerkleRoot(CalculateCollectionMerkleRootRequest) returns (CalculateCollectionMerkleRootResponse);

rpc TokenMetadata(TokenMetadataRequest) returns (TokenMetadataResponse);

rpc CollectionsByCreator(CollectionsByCreatorRequest) returns (CollectionsByCreatorResponse);
// rpc UpdateCollectionWhitelists(UpdateCollectionWhitelistsRequest) returns(UpdateCollectionWhitelistsResponse);
// rpc WhitelistedAddressMerkleInfo(WhitelistedAddressMerkleInfoRequest) returns (WhitelistedAddressMerkleInfoResponse);
rpc LaunchpadProjects(LaunchpadProjectsRequest) returns (LaunchpadProjectsResponse);
}

enum Sort {
SORT_UNSPECIFIED = 0;
SORT_COLLECTION_NAME = 1;
}

enum SortDirection {
SORT_DIRECTION_UNSPECIFIED = 0;
SORT_DIRECTION_ASCENDING = 1;
SORT_DIRECTION_DESCENDING = 2;
}

message CollectionsByCreatorRequest {
string creator_id = 1;
string network_id = 2;
int32 limit = 3;
int32 offset = 4;
Sort sort = 5;
SortDirection sort_direction = 6;
}

message CollectionsByCreatorResponse {
repeated string collections = 1;
}

message LaunchpadProjectsRequest {
string creator_id = 1;
string network_id = 2;
int32 limit = 3;
int32 offset = 4;
Sort sort = 5;
SortDirection sort_direction = 6;
}

message LaunchpadProjectsResponse {
repeated LaunchpadProject projects = 1;
}

message UploadMetadatasRequest {
string sender = 1;
string network_id = 2;
Expand Down Expand Up @@ -56,6 +82,15 @@ message TokenMetadataResponse {
repeated string merkle_proof = 3;
}

message LaunchpadProject {
string id = 1;
string network_id = 2;
string collection_name = 3;
string creator_id = 4;
string collection_data = 5;
optional string merkle_root = 6;
}

// message UpdateCollectionWhitelistsRequest {
// string sender = 1;
// string network_id = 2;
Expand Down
92 changes: 91 additions & 1 deletion go/pkg/launchpad/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,27 @@ func (s *Launchpad) TokenMetadata(ctx context.Context, req *launchpadpb.TokenMet
}

func (s *Launchpad) CollectionsByCreator(ctx context.Context, req *launchpadpb.CollectionsByCreatorRequest) (*launchpadpb.CollectionsByCreatorResponse, error) {
creatorID := req.GetCreatorId()
limit := req.GetLimit()

Check failure on line 212 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

req.GetLimit undefined (type *launchpadpb.CollectionsByCreatorRequest has no field or method GetLimit)
if limit <= 0 {
return errors.New("limit must be a positive number")

Check failure on line 214 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

not enough return values
}

offset := req.GetOffset()

Check failure on line 217 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

req.GetOffset undefined (type *launchpadpb.CollectionsByCreatorRequest has no field or method GetOffset)
if offset < 0 {
return errors.New("offset must be greater or equal to 0")

Check failure on line 219 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

not enough return values
}

networkID := req.GetNetworkId()

Check failure on line 222 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

req.GetNetworkId undefined (type *launchpadpb.CollectionsByCreatorRequest has no field or method GetNetworkId)
if networkID == "" {
return errors.New("missing network id")

Check failure on line 224 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

not enough return values
}

network, err := s.conf.NetworkStore.GetNetwork(networkID)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("unknown network id '%s'", networkID))

Check failure on line 229 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

not enough return values
}

creatorID := req.GetCreatorId()
if creatorID == "" {
return nil, errors.New("creatorID is mandatory")
}
Expand All @@ -220,6 +239,31 @@ func (s *Launchpad) CollectionsByCreator(ctx context.Context, req *launchpadpb.C
return nil, errors.Wrap(err, "failed to get collection data")
}

orderDirection := ""
switch req.GetSortDirection() {

Check failure on line 243 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

req.GetSortDirection undefined (type *launchpadpb.CollectionsByCreatorRequest has no field or method GetSortDirection)
case launchpadpb.SortDirection_SORT_DIRECTION_UNSPECIFIED:
orderDirection = ""
case launchpadpb.SortDirection_SORT_DIRECTION_ASCENDING:
orderDirection = " ASC "
case launchpadpb.SortDirection_SORT_DIRECTION_DESCENDING:
orderDirection = " DESC "
}
orderSQL := ""
switch req.GetSort() {
case launchpadpb.Sort_SORT_COLLECTION_NAME:
orderSQL = "lp.collection_name" + orderDirection
case marketplacepb.Sort_SORT_STATUS:
orderSQL = "case when total_volume is null then 1 else 0 end, total_volume " + orderDirection
case marketplacepb.Sort_SORT_CREATED_AT:
orderSQL = "lp.time " + orderDirection


case marketplacepb.Sort_SORT_VOLUME_USD:
orderSQL = "case when total_volume_usd is null then 1 else 0 end, total_volume_usd " + orderDirection
case marketplacepb.Sort_SORT_UNSPECIFIED:
orderSQL = "volume DESC"
}

res := make([]string, len(projects))
for idx, pj := range projects {
res[idx] = pj.CollectionData.String()
Expand All @@ -229,3 +273,49 @@ func (s *Launchpad) CollectionsByCreator(ctx context.Context, req *launchpadpb.C
Collections: res,
}, nil
}

func (s *Launchpad) LaunchpadProjects(ctx context.Context, req *launchpadpb.CollectionsRequest) (*launchpadpb.CollectionsResponse, error) {

Check failure on line 277 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

undefined: launchpadpb.CollectionsRequest

Check failure on line 277 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

undefined: launchpadpb.CollectionsResponse


// TODO: Sort, control daoID, return LaunchpadProject[]

limit := req.GetLimit()
if limit <= 0 {
return errors.New("limit must be a positive number")
}

offset := req.GetOffset()
if offset < 0 {
return errors.New("offset must be greater or equal to 0")
}

networkID := req.GetNetworkId()
if networkID == "" {
return errors.New("missing network id")
}

network, err := s.conf.NetworkStore.GetNetwork(networkID)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("unknown network id '%s'", networkID))
}

daoID := req.GetCreatorId()

if creatorID == "" {
return nil, errors.New("creatorID is mandatory")
}

var projects []indexerdb.Collections
if err := s.conf.IndexerDB.Find(&projects, "creator_id = ?", creatorID).Error; err != nil {
return nil, errors.Wrap(err, "failed to get collection data")
}

res := make([]string, len(projects))
for idx, pj := range projects {
res[idx] = pj.CollectionData.String()
}

return &launchpadpb.CollectionsResponse{
Collections: res,
}, nil
}

0 comments on commit 12cdc6b

Please sign in to comment.