Skip to content

Commit 4c2bf7c

Browse files
authored
Merge pull request #1054 from oasisprotocol/ptrus/feature/roflmarket-instances-admin
api/roflmarket_instances: Support filtering by admin
2 parents 86ef98f + e0af4ac commit 4c2bf7c

20 files changed

+160
-17
lines changed

.changelog/1048.feature.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
api/roflmarket_apps: Support filtering by admin
1+
api/rofl_apps: Support filtering by admin

.changelog/1054.feature.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
api/roflmarket_instances: Support filtering by admin address
2+
3+
- The old endpoint `/{runtime}/roflmarket_providers/{address}/instances` has
4+
been removed.
5+
6+
- Clients should now use: `/{runtime}/roflmarket_instances?provider={address}`
7+
to filter instances by provider address.

api/spec/v1.yaml

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

1499-
/{runtime}/roflmarket_providers/{address}/instances:
1499+
/{runtime}/roflmarket_instances:
15001500
get:
1501-
summary: Returns a list of ROFL market instances for a specific provider.
1501+
summary: Returns a list of ROFL market instances.
15021502
parameters:
15031503
- *limit
15041504
- *offset
15051505
- *runtime
1506-
- in: path
1507-
name: address
1508-
required: true
1506+
- in: query
1507+
name: provider
15091508
schema:
15101509
allOf: [$ref: '#/components/schemas/StakingAddress']
1511-
description: The address of the ROFL market provider to return instances for.
1510+
description: A filter on the provider of the ROFL market instance.
1511+
- in: query
1512+
name: admin
1513+
schema:
1514+
allOf: [$ref: '#/components/schemas/EthOrOasisAddress']
1515+
description: A filter on the admin of the ROFL market instance.
15121516
responses:
15131517
'200':
15141518
description: A JSON object containing a list of ROFL market instances.

api/v1/strict_server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,14 @@ func (srv *StrictServerImpl) GetRuntimeRoflmarketProvidersAddressOffers(ctx cont
617617
return apiTypes.GetRuntimeRoflmarketProvidersAddressOffers200JSONResponse(*offers), nil
618618
}
619619

620-
func (srv *StrictServerImpl) GetRuntimeRoflmarketProvidersAddressInstances(ctx context.Context, request apiTypes.GetRuntimeRoflmarketProvidersAddressInstancesRequestObject) (apiTypes.GetRuntimeRoflmarketProvidersAddressInstancesResponseObject, error) {
620+
func (srv *StrictServerImpl) GetRuntimeRoflmarketInstances(ctx context.Context, request apiTypes.GetRuntimeRoflmarketInstancesRequestObject) (apiTypes.GetRuntimeRoflmarketInstancesResponseObject, error) {
621621
runtime, err := request.Runtime.Validate()
622622
if err != nil {
623623
return nil, err
624624
}
625-
instances, err := srv.dbClient.RuntimeRoflmarketInstances(ctx, runtime, request.Params, &request.Address)
625+
instances, err := srv.dbClient.RuntimeRoflmarketInstances(ctx, runtime, request.Params)
626626
if err != nil {
627627
return nil, err
628628
}
629-
return apiTypes.GetRuntimeRoflmarketProvidersAddressInstances200JSONResponse(*instances), nil
629+
return apiTypes.GetRuntimeRoflmarketInstances200JSONResponse(*instances), nil
630630
}

storage/client/client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,12 +2835,18 @@ func (c *StorageClient) RuntimeRoflmarketOffers(ctx context.Context, runtime com
28352835
return &offers, nil
28362836
}
28372837

2838-
func (c *StorageClient) RuntimeRoflmarketInstances(ctx context.Context, runtime common.Runtime, params apiTypes.GetRuntimeRoflmarketProvidersAddressInstancesParams, address *staking.Address) (*RoflMarketInstanceList, error) {
2838+
func (c *StorageClient) RuntimeRoflmarketInstances(ctx context.Context, runtime common.Runtime, params apiTypes.GetRuntimeRoflmarketInstancesParams) (*RoflMarketInstanceList, error) {
2839+
ocAddrAdmin, err := apiTypes.UnmarshalToOcAddress(params.Admin)
2840+
if err != nil {
2841+
return nil, wrapError(err)
2842+
}
2843+
28392844
res, err := c.withDefaultTotalCount(
28402845
ctx,
28412846
queries.RuntimeRoflmarketProviderInstances,
28422847
runtime,
2843-
address,
2848+
params.Provider,
2849+
ocAddrAdmin,
28442850
params.Limit,
28452851
params.Offset,
28462852
)

storage/client/queries/queries.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,11 +1099,12 @@ const (
10991099
removed
11001100
FROM chain.roflmarket_instances
11011101
WHERE runtime = $1::runtime AND
1102-
provider = $2::oasis_addr
1102+
($2::oasis_addr IS NULL OR provider = $2::oasis_addr) AND
1103+
($3::oasis_addr IS NULL OR admin = $3::oasis_addr)
11031104
-- TODO: Should probably sort by something else.
11041105
ORDER BY id DESC
1105-
LIMIT $3::bigint
1106-
OFFSET $4::bigint`
1106+
LIMIT $4::bigint
1107+
OFFSET $5::bigint`
11071108

11081109
// FineTxVolumes returns the fine-grained query for 5-minute sampled tx volume windows.
11091110
FineTxVolumes = `

storage/migrations/25_runtime_roflmarket.up.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ CREATE TABLE chain.roflmarket_instances (
8989
removed BOOLEAN NOT NULL DEFAULT FALSE
9090
);
9191
CREATE INDEX ix_roflmarket_instances_provider ON chain.roflmarket_instances (runtime, provider);
92+
-- CREATE INDEX ix_roflmarket_instances_admin ON chain.roflmarket_instances (runtime, admin); -- Added in 38_runtime_roflmarket_instances_admin.up.sql.
9293

9394
-- Grant others read-only use.
9495
-- (We granted already in 00_consensus.up.sql, but the grant does not apply to new tables.)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BEGIN;
2+
3+
CREATE INDEX IF NOT EXISTS ix_roflmarket_instances_admin ON chain.roflmarket_instances (runtime, admin);
4+
5+
COMMIT;

tests/e2e_regression/common_test_cases.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@ commonSapphireTestCases=(
107107
'sapphire_tx_volume /v1/sapphire/stats/tx_volume'
108108
'sapphire_rofl_apps /v1/sapphire/rofl_apps'
109109
'sapphire_roflmarket_providers /v1/sapphire/roflmarket_providers'
110+
'sapphire_roflmarket_instances /v1/sapphire/roflmarket_instances'
110111
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"instances": [],
3+
"is_total_count_clipped": false,
4+
"total_count": 0
5+
}

0 commit comments

Comments
 (0)