Skip to content

Commit

Permalink
feat(core-api): add additional fields to bridgechains search sc… (#3165)
Browse files Browse the repository at this point in the history
  • Loading branch information
spkjp committed Nov 21, 2019
1 parent 03c2ea3 commit 34b7e34
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/core-api/src/routes/bridgechains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ export const register = (server: Hapi.Server): void => {
bridgechainId: Joi.number()
.integer()
.min(1),
bridgechainRepository: Joi.string().max(80),
genesisHash: Joi.string()
.hex()
.length(64),
name: Joi.string()
.regex(/^[a-zA-Z0-9_-]+$/)
.max(40),
seedNodes: Joi.array()
.unique()
.min(1)
.max(10)
.items(Joi.string().ip()),

},
},
},
Expand Down
17 changes: 17 additions & 0 deletions packages/core-state/src/wallets/utils/filter-rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ export = <T = any>(
}
}

if (filters.hasOwnProperty("every")) {
for (const elem of filters.every) {
if (params[elem] && getProperty(item, elem)) {
if (Array.isArray(item[elem])) {
if (Array.isArray(params[elem])) {
// @ts-ignore
return params[elem].every(a => item[elem].includes(a));
} else {
throw new Error('Filtering by "every" requires an Array');
}
} else {
throw new Error("Property must be an array");
}
}
}
}

// NOTE: it was used to filter by `votes`, but that field was rejected and
// replaced by `vote`. This filter is kept here just in case
if (filters.hasOwnProperty("any")) {
Expand Down
4 changes: 3 additions & 1 deletion packages/core-state/src/wallets/wallet-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ export class WalletRepository implements Contracts.State.WalletRepository {

private searchBridgechains(params: Contracts.Database.QueryParameters = {}): Contracts.State.SearchContext<any> {
const query: Record<string, string[]> = {
exact: ["bridgechainId", "businessId", "name", "genesishash"],
exact: ["bridgechainId", "businessId", "genesisHash"],
like: ["bridgechainRepository", "name"],
every: ["seedNodes"],
};

const entries: any[] = this.getIndex("bridgechains")
Expand Down

0 comments on commit 34b7e34

Please sign in to comment.