Skip to content

Commit 63179b9

Browse files
authored
Merge pull request #1056 from oasisprotocol/ptrus/feature/roflmarket-specific-instance-offer
api/roflmarket: Add api endpoints to fetch specific instance/offer
2 parents 0bb47c0 + 9b4dd6e commit 63179b9

File tree

10 files changed

+187
-10
lines changed

10 files changed

+187
-10
lines changed

.changelog/1056.feature.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
api/roflmarket: Add endpoints to fetch specific instance/offer
2+
3+
Added `/{runtime}/roflmarket_providers/{address}/instances/{id}` and
4+
`/{runtime}/roflmarket_providers/{address}/offers/{id}` api endpoints.

api/spec/v1.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,58 @@ paths:
14961496
$ref: '#/components/schemas/RoflMarketOfferList'
14971497
<<: *common_error_responses
14981498

1499+
/{runtime}/roflmarket_providers/{address}/offers/{id}:
1500+
get:
1501+
summary: Returns a specific ROFL market offer.
1502+
parameters:
1503+
- *runtime
1504+
- in: path
1505+
name: address
1506+
required: true
1507+
schema:
1508+
allOf: [$ref: '#/components/schemas/StakingAddress']
1509+
description: The address of the ROFL market provider to return offers for.
1510+
- in: path
1511+
name: id
1512+
required: true
1513+
schema:
1514+
type: string
1515+
description: The ID of the ROFL market offer to return.
1516+
responses:
1517+
'200':
1518+
description: A JSON object containing a ROFL market offer.
1519+
content:
1520+
application/json:
1521+
schema:
1522+
$ref: '#/components/schemas/RoflMarketOffer'
1523+
<<: *common_error_responses
1524+
1525+
/{runtime}/roflmarket_providers/{address}/instances/{id}:
1526+
get:
1527+
summary: Returns a specific ROFL market instance.
1528+
parameters:
1529+
- *runtime
1530+
- in: path
1531+
name: address
1532+
required: true
1533+
schema:
1534+
allOf: [$ref: '#/components/schemas/StakingAddress']
1535+
description: The address of the ROFL market provider to return an instance for.
1536+
- in: path
1537+
name: id
1538+
required: true
1539+
schema:
1540+
type: string
1541+
description: The ID of the ROFL market instance to return.
1542+
responses:
1543+
'200':
1544+
description: A JSON object containing a list of ROFL market offers.
1545+
content:
1546+
application/json:
1547+
schema:
1548+
$ref: '#/components/schemas/RoflMarketInstance'
1549+
<<: *common_error_responses
1550+
14991551
/{runtime}/roflmarket_instances:
15001552
get:
15011553
summary: Returns a list of ROFL market instances.

api/v1/strict_server.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67

78
apiTypes "github.com/oasisprotocol/nexus/api/v1/types"
@@ -610,19 +611,57 @@ func (srv *StrictServerImpl) GetRuntimeRoflmarketProvidersAddressOffers(ctx cont
610611
if err != nil {
611612
return nil, err
612613
}
613-
offers, err := srv.dbClient.RuntimeRoflmarketOffers(ctx, runtime, request.Params, &request.Address)
614+
offers, err := srv.dbClient.RuntimeRoflmarketOffers(ctx, runtime, request.Params, &request.Address, nil)
614615
if err != nil {
615616
return nil, err
616617
}
617618
return apiTypes.GetRuntimeRoflmarketProvidersAddressOffers200JSONResponse(*offers), nil
618619
}
619620

621+
func (srv *StrictServerImpl) GetRuntimeRoflmarketProvidersAddressOffersId(ctx context.Context, request apiTypes.GetRuntimeRoflmarketProvidersAddressOffersIdRequestObject) (apiTypes.GetRuntimeRoflmarketProvidersAddressOffersIdResponseObject, error) {
622+
runtime, err := request.Runtime.Validate()
623+
if err != nil {
624+
return nil, err
625+
}
626+
offerID, err := hex.DecodeString(request.Id)
627+
if err != nil {
628+
return nil, err
629+
}
630+
offers, err := srv.dbClient.RuntimeRoflmarketOffers(ctx, runtime, apiTypes.GetRuntimeRoflmarketProvidersAddressOffersParams{Limit: common.Ptr(uint64(1)), Offset: common.Ptr(uint64(0))}, &request.Address, offerID)
631+
if err != nil {
632+
return nil, err
633+
}
634+
if len(offers.Offers) != 1 {
635+
return apiTypes.GetRuntimeRoflmarketProvidersAddressOffersId404JSONResponse{}, nil
636+
}
637+
return apiTypes.GetRuntimeRoflmarketProvidersAddressOffersId200JSONResponse(offers.Offers[0]), nil
638+
}
639+
640+
func (srv *StrictServerImpl) GetRuntimeRoflmarketProvidersAddressInstancesId(ctx context.Context, request apiTypes.GetRuntimeRoflmarketProvidersAddressInstancesIdRequestObject) (apiTypes.GetRuntimeRoflmarketProvidersAddressInstancesIdResponseObject, error) {
641+
runtime, err := request.Runtime.Validate()
642+
if err != nil {
643+
return nil, err
644+
}
645+
instanceID, err := hex.DecodeString(request.Id)
646+
if err != nil {
647+
return nil, err
648+
}
649+
instances, err := srv.dbClient.RuntimeRoflmarketInstances(ctx, runtime, apiTypes.GetRuntimeRoflmarketInstancesParams{Limit: common.Ptr(uint64(1)), Offset: common.Ptr(uint64(0)), Provider: &request.Address}, instanceID)
650+
if err != nil {
651+
return nil, err
652+
}
653+
if len(instances.Instances) != 1 {
654+
return apiTypes.GetRuntimeRoflmarketProvidersAddressInstancesId404JSONResponse{}, nil
655+
}
656+
return apiTypes.GetRuntimeRoflmarketProvidersAddressInstancesId200JSONResponse(instances.Instances[0]), nil
657+
}
658+
620659
func (srv *StrictServerImpl) GetRuntimeRoflmarketInstances(ctx context.Context, request apiTypes.GetRuntimeRoflmarketInstancesRequestObject) (apiTypes.GetRuntimeRoflmarketInstancesResponseObject, error) {
621660
runtime, err := request.Runtime.Validate()
622661
if err != nil {
623662
return nil, err
624663
}
625-
instances, err := srv.dbClient.RuntimeRoflmarketInstances(ctx, runtime, request.Params)
664+
instances, err := srv.dbClient.RuntimeRoflmarketInstances(ctx, runtime, request.Params, nil)
626665
if err != nil {
627666
return nil, err
628667
}

storage/client/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,12 +2795,13 @@ func (c *StorageClient) RuntimeRoflmarketProviders(ctx context.Context, runtime
27952795
return &providers, nil
27962796
}
27972797

2798-
func (c *StorageClient) RuntimeRoflmarketOffers(ctx context.Context, runtime common.Runtime, params apiTypes.GetRuntimeRoflmarketProvidersAddressOffersParams, address *staking.Address) (*RoflMarketOfferList, error) {
2798+
func (c *StorageClient) RuntimeRoflmarketOffers(ctx context.Context, runtime common.Runtime, params apiTypes.GetRuntimeRoflmarketProvidersAddressOffersParams, address *staking.Address, id []byte) (*RoflMarketOfferList, error) {
27992799
res, err := c.withDefaultTotalCount(
28002800
ctx,
28012801
queries.RuntimeRoflmarketProviderOffers,
28022802
runtime,
28032803
address,
2804+
id,
28042805
params.Limit,
28052806
params.Offset,
28062807
)
@@ -2835,7 +2836,7 @@ func (c *StorageClient) RuntimeRoflmarketOffers(ctx context.Context, runtime com
28352836
return &offers, nil
28362837
}
28372838

2838-
func (c *StorageClient) RuntimeRoflmarketInstances(ctx context.Context, runtime common.Runtime, params apiTypes.GetRuntimeRoflmarketInstancesParams) (*RoflMarketInstanceList, error) {
2839+
func (c *StorageClient) RuntimeRoflmarketInstances(ctx context.Context, runtime common.Runtime, params apiTypes.GetRuntimeRoflmarketInstancesParams, id []byte) (*RoflMarketInstanceList, error) {
28392840
ocAddrAdmin, err := apiTypes.UnmarshalToOcAddress(params.Admin)
28402841
if err != nil {
28412842
return nil, wrapError(err)
@@ -2846,6 +2847,7 @@ func (c *StorageClient) RuntimeRoflmarketInstances(ctx context.Context, runtime
28462847
queries.RuntimeRoflmarketProviderInstances,
28472848
runtime,
28482849
params.Provider,
2850+
id,
28492851
ocAddrAdmin,
28502852
params.Limit,
28512853
params.Offset,

storage/client/queries/queries.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,11 +1068,12 @@ const (
10681068
removed
10691069
FROM chain.roflmarket_offers
10701070
WHERE runtime = $1::runtime AND
1071-
provider = $2::oasis_addr
1071+
provider = $2::oasis_addr AND
1072+
($3::bytea IS NULL OR id = $3::bytea)
10721073
-- TODO: Should probably sort by something else.
10731074
ORDER BY id DESC
1074-
LIMIT $3::bigint
1075-
OFFSET $4::bigint`
1075+
LIMIT $4::bigint
1076+
OFFSET $5::bigint`
10761077

10771078
RuntimeRoflmarketProviderInstances = `
10781079
SELECT
@@ -1100,11 +1101,12 @@ const (
11001101
FROM chain.roflmarket_instances
11011102
WHERE runtime = $1::runtime AND
11021103
($2::oasis_addr IS NULL OR provider = $2::oasis_addr) AND
1103-
($3::oasis_addr IS NULL OR admin = $3::oasis_addr)
1104+
($3::bytea IS NULL OR id = $3::bytea) AND
1105+
($4::oasis_addr IS NULL OR admin = $4::oasis_addr)
11041106
-- TODO: Should probably sort by something else.
11051107
ORDER BY id DESC
1106-
LIMIT $4::bigint
1107-
OFFSET $5::bigint`
1108+
LIMIT $5::bigint
1109+
OFFSET $6::bigint`
11081110

11091111
// FineTxVolumes returns the fine-grained query for 5-minute sampled tx volume windows.
11101112
FineTxVolumes = `
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"admin": "oasis1qpspm8q6pk0lndcjf28ene5sgjgzex4aqcqh2kdh",
3+
"cmd_count": 0,
4+
"cmd_next_id": "0000000000000001",
5+
"cmds": [],
6+
"created_at": "2025-05-06T16:05:49Z",
7+
"creator": "oasis1qpspm8q6pk0lndcjf28ene5sgjgzex4aqcqh2kdh",
8+
"deployment": {
9+
"app_id": "rofl1qqtnmq89xgyychrtj26wjmuugmusk2l4vynvymgm",
10+
"manifest_hash": "aa14d6725dbe0c461c19bdc5394bb7d6db6f0ca680d8fd1294f332166d854798",
11+
"metadata": {
12+
"net.oasis.deployment.orc.ref": "rofl.sh/0f1afaeb-b50f-42d9-aff6-e51ced0aaf6a:1746547447@sha256:5667b40164706b26dff8d7c37fae5d8905c74a5b1d2ac592de516ac30a22f0c1"
13+
}
14+
},
15+
"id": "0000000000000007",
16+
"metadata": {},
17+
"node_id": "bOlqho9R3JHP64kJk+SfMxZt5fNkYWf6gdhErWlY60E=",
18+
"offer_id": "0000000000000001",
19+
"paid_from": "2025-05-06T16:05:49Z",
20+
"paid_until": "2025-05-06T17:05:49Z",
21+
"payment": {
22+
"native": {
23+
"denomination": "",
24+
"terms": {
25+
"1": "10000000000000000000"
26+
}
27+
}
28+
},
29+
"payment_address": "daaa9ac2c78166470d905653f76588ab4e13a4f5",
30+
"provider": "oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz",
31+
"refund_data": "00601d9c1a0d9ff9b7124a8f99e69044902c9abd06",
32+
"removed": false,
33+
"resources": {
34+
"cpus": 1,
35+
"memory": 2048,
36+
"storage": 10000,
37+
"tee": 2
38+
},
39+
"status": 1,
40+
"updated_at": "2025-05-06T16:08:48Z"
41+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
Vary: Origin
4+
Date: UNINTERESTING
5+
Content-Length: UNINTERESTING
6+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"capacity": 49,
3+
"id": "0000000000000001",
4+
"metadata": {
5+
"net.oasis.scheduler.offer": "playground_short"
6+
},
7+
"payment": {
8+
"native": {
9+
"denomination": "",
10+
"terms": {
11+
"1": "10000000000000000000"
12+
}
13+
}
14+
},
15+
"provider": "oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz",
16+
"removed": false,
17+
"resources": {
18+
"cpus": 1,
19+
"memory": 2048,
20+
"storage": 10000,
21+
"tee": 2
22+
}
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HTTP/1.1 200 OK
2+
Content-Type: application/json
3+
Vary: Origin
4+
Date: UNINTERESTING
5+
Content-Length: UNINTERESTING
6+

tests/e2e_regression/eden_testnet_2025/test_cases.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ testCases=(
4646
'sapphire_roflmarket_provider_offers /v1/sapphire/roflmarket_providers/oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz/offers'
4747
'sapphire_roflmarket_instances_by_provider /v1/sapphire/roflmarket_instances?provider=oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz'
4848
'sapphire_roflmarket_instances_by_admin /v1/sapphire/roflmarket_instances?admin=oasis1qpspm8q6pk0lndcjf28ene5sgjgzex4aqcqh2kdh'
49+
'sapphire_roflmarket_instance_by_id /v1/sapphire/roflmarket_providers/oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz/instances/0000000000000007'
50+
'sapphire_roflmarket_offer_by_id /v1/sapphire/roflmarket_providers/oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz/offers/0000000000000001'
4951
)

0 commit comments

Comments
 (0)