diff --git a/api/launchpad/v1/launchpad.proto b/api/launchpad/v1/launchpad.proto index 37c1632074..3899f1ee34 100644 --- a/api/launchpad/v1/launchpad.proto +++ b/api/launchpad/v1/launchpad.proto @@ -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; @@ -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; diff --git a/go/pkg/launchpad/service.go b/go/pkg/launchpad/service.go index dd99d2cfb3..cb6f4ef453 100644 --- a/go/pkg/launchpad/service.go +++ b/go/pkg/launchpad/service.go @@ -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() + 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)) + } + creatorID := req.GetCreatorId() if creatorID == "" { return nil, errors.New("creatorID is mandatory") } @@ -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() { + 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() @@ -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) { + + + // 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 +}