Skip to content

Commit a8c3d7e

Browse files
committed
api/rofl_apps: Filter by multiple name fragments
1 parent 355a68b commit a8c3d7e

18 files changed

Lines changed: 526 additions & 197 deletions

.changelog/1026.feature.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
api/rofl_apps: Support filtering by multiple name fragments

.changelog/1026.feature.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
api/emv_tokens: Support filtering by multiple name fragments

api/spec/v1.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,14 @@ paths:
10751075
- *runtime
10761076
- in: query
10771077
name: name
1078+
style: form
1079+
explode: false
10781080
schema:
1079-
type: string
1080-
description: A filter on the name, the name or symbol must contain this value as a substring.
1081+
type: array
1082+
items:
1083+
type: string
1084+
maxItems: 6
1085+
description: A filter on the name, the name or symbol must contain this value as a substring. If multiple names are provided, the token must match all of them.
10811086
- in: query
10821087
name: sort_by
10831088
schema:
@@ -1266,9 +1271,14 @@ paths:
12661271
- *runtime
12671272
- in: query
12681273
name: name
1274+
style: form
1275+
explode: false
12691276
schema:
1270-
type: string
1271-
description: A filter on the name of the ROFL app.
1277+
type: array
1278+
items:
1279+
type: string
1280+
maxItems: 6
1281+
description: A filter on the name of the ROFL app. If multiple names are provided, the ROFL App must match all of them.
12721282
responses:
12731283
'200':
12741284
description: A JSON object containing a list of ROFL apps.

storage/client/client.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const (
4444
blockCost = 1
4545

4646
defaultMaxTotalCount = 1000
47+
48+
// The maximum number of items that can be provided for name filters.
49+
// Keep this in sync with the maxItems in the API spec.
50+
maxFilterNameFragments = 6
4751
)
4852

4953
// StorageClient is a wrapper around a storage.TargetStorage
@@ -2199,6 +2203,10 @@ func fillInPrice(t *EvmToken, refSwapTokenAddr *apiTypes.Address) {
21992203
// If `address` is non-nil, it is used to filter the results to at most 1 token: the one
22002204
// with the correcponding contract address.
22012205
func (c *StorageClient) RuntimeTokens(ctx context.Context, runtime common.Runtime, p apiTypes.GetRuntimeEvmTokensParams, address *staking.Address) (*EvmTokenList, error) {
2206+
if p.Name != nil && len(*p.Name) > maxFilterNameFragments {
2207+
return nil, fmt.Errorf("too many names in the name filter: %w", apiCommon.ErrBadRequest)
2208+
}
2209+
22022210
var refSwapFactoryAddr *apiTypes.Address
22032211
var refSwapTokenAddr *apiTypes.Address
22042212
if rs, ok := c.referenceSwaps[runtime]; ok {
@@ -2217,20 +2225,14 @@ func (c *StorageClient) RuntimeTokens(ctx context.Context, runtime common.Runtim
22172225
}
22182226
}
22192227

2228+
args := []interface{}{runtime, address, tokenType, refSwapFactoryAddr, refSwapTokenAddr, p.SortBy, c.evmTokensCustomOrderAddresses[runtime], c.evmTokensCustomOrderGroups[runtime]}
2229+
query := queries.EVMTokens(p.Name, &args)
2230+
args = append(args, p.Limit, p.Offset)
2231+
22202232
res, err := c.withDefaultTotalCount(
22212233
ctx,
2222-
queries.EvmTokens,
2223-
runtime,
2224-
address,
2225-
p.Name,
2226-
tokenType,
2227-
refSwapFactoryAddr,
2228-
refSwapTokenAddr,
2229-
p.SortBy,
2230-
c.evmTokensCustomOrderAddresses[runtime],
2231-
c.evmTokensCustomOrderGroups[runtime],
2232-
p.Limit,
2233-
p.Offset,
2234+
query,
2235+
args...,
22342236
)
22352237
if err != nil {
22362238
return nil, wrapError(err)
@@ -2486,19 +2488,23 @@ func (c *StorageClient) RuntimeStatus(ctx context.Context, runtime common.Runtim
24862488

24872489
// RuntimeRoflApps returns a list of ROFL apps.
24882490
func (c *StorageClient) RuntimeRoflApps(ctx context.Context, runtime common.Runtime, params apiTypes.GetRuntimeRoflAppsParams, id *string) (*RoflAppList, error) { //nolint:gocyclo
2491+
if params.Name != nil && len(*params.Name) > maxFilterNameFragments {
2492+
return nil, fmt.Errorf("too many names in the name filter: %w", apiCommon.ErrBadRequest)
2493+
}
24892494
// Runtime ROFL apps uses a max limit of 100 (other endpoints default to 1000).
24902495
if *params.Limit > 100 {
24912496
*params.Limit = 100
24922497
}
2498+
2499+
args := []interface{}{runtime, id}
2500+
query := queries.RuntimeRoflApps(params.Name, &args)
2501+
args = append(args, params.Limit, params.Offset)
2502+
24932503
res, err := c.withTotalCount(
24942504
ctx,
2495-
queries.RuntimeRoflApps,
2505+
query,
24962506
100,
2497-
runtime,
2498-
id,
2499-
params.Name,
2500-
params.Limit,
2501-
params.Offset,
2507+
args...,
25022508
)
25032509
if err != nil {
25042510
return nil, wrapError(err)

0 commit comments

Comments
 (0)