Skip to content

Commit

Permalink
Symbol Code parameter verification against dynamic enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelotfr committed Nov 9, 2023
1 parent ac9196f commit 003918b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/fetch/aggregate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeQuery } from "../clickhouse/makeQuery.js";
import { logger } from "../logger.js";
import { store } from "../clickhouse/stores.js";
import { parseCollectionName } from "../utils.js";
import { parseCollectionName, parseListingPriceSymcode } from "../utils.js";
import { getAggregate } from "../queries.js";
import * as prometheus from "../prometheus.js";
import { BadRequest, toJSON, toText } from "./cors.js";
Expand All @@ -28,10 +28,19 @@ export default async function (req: Request) {
async function verifyParameters(req: Request) {
const url = new URL(req.url);
const collection_name = url.searchParams.get("collection_name");
const symbol_code = url.searchParams.get("listing_price_symcode");

if (collection_name && (parseCollectionName(collection_name) == undefined)) {
return toText("Invalid EOSIO name type: collection_name=" + collection_name, 400);
}
else if (collection_name && !(await store.collection_names).includes(collection_name)) {
return toText("Collection not found: " + collection_name, 404);
}
}

if (symbol_code && (parseListingPriceSymcode(symbol_code) == undefined)) {
return toText("Invalid EOSIO Symbol code: listing_price_symcode=" + symbol_code, 400);
}
else if (symbol_code && !(await store.symbol_codes).includes(symbol_code)) {
return toText("Symbol code not found: " + symbol_code, 404);
}
}
11 changes: 10 additions & 1 deletion src/fetch/sales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { store } from "../clickhouse/stores.js";
import { Sale, getSale } from "../queries.js";
import * as prometheus from "../prometheus.js";
import { BadRequest, toJSON, toText } from "./cors.js";
import { parseCollectionName } from "../utils.js";
import { parseCollectionName, parseListingPriceSymcode } from "../utils.js";

export default async function (req: Request) {
const parametersResult = await verifyParameters(req);
Expand All @@ -27,10 +27,19 @@ export default async function (req: Request) {
async function verifyParameters(req: Request) {
const url = new URL(req.url);
const collection_name = url.searchParams.get("collection_name");
const symbol_code = url.searchParams.get("listing_price_symcode");

if (collection_name && (parseCollectionName(collection_name) == undefined)) {
return toText("Invalid EOSIO name type: collection_name=" + collection_name, 400);
}
else if (collection_name && !(await store.collection_names).includes(collection_name)) {
return toText("Collection not found: " + collection_name, 404);
}

if (symbol_code && (parseListingPriceSymcode(symbol_code) == undefined)) {
return toText("Invalid EOSIO Symbol code: listing_price_symcode=" + symbol_code, 400);
}
else if (symbol_code && !(await store.symbol_codes).includes(symbol_code)) {
return toText("Symbol code not found: " + symbol_code, 404);
}
}

0 comments on commit 003918b

Please sign in to comment.