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 f1444e7
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 5 deletions.
45 changes: 41 additions & 4 deletions api/launchpad/v1/launchpad.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,50 @@ 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;
SORT_STATUS = 2;
SORT_CREATED_AT = 3;
}

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 +84,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
81 changes: 80 additions & 1 deletion go/pkg/launchpad/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,31 @@ 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()


// TODO: Sort, control creatorID, return CollectionData string

limit := req.GetLimit()

Check failure on line 216 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)

Check failure on line 216 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 218 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

not enough return values

Check failure on line 218 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 221 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)

Check failure on line 221 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 223 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

not enough return values

Check failure on line 223 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 226 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)

Check failure on line 226 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 228 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

not enough return values

Check failure on line 228 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 233 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

not enough return values

Check failure on line 233 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 +243,16 @@ 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 247 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)

Check failure on line 247 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 "
}

res := make([]string, len(projects))
for idx, pj := range projects {
res[idx] = pj.CollectionData.String()
Expand All @@ -229,3 +262,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 266 in go/pkg/launchpad/service.go

View workflow job for this annotation

GitHub Actions / go

undefined: launchpadpb.CollectionsRequest

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

View workflow job for this annotation

GitHub Actions / go

undefined: launchpadpb.CollectionsResponse

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

View workflow job for this annotation

GitHub Actions / go

undefined: launchpadpb.CollectionsRequest

Check failure on line 266 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 f1444e7

Please sign in to comment.