From 54dc9e82c4ba853642c7a7a20fb020e1513cb65a Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 19 Dec 2023 17:48:44 +0200 Subject: [PATCH] updates services, introduces explore v2 --- src/explore/handle-explore.ts | 4 +++- src/explore/storage/dataset.ts | 15 +++++++++++---- src/explore/storage/environments.json | 19 +++++++++++++++++++ src/router.ts | 2 ++ src/utils/versioning.ts | 4 ++++ src/worker.ts | 5 +++-- 6 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/explore/storage/environments.json create mode 100644 src/utils/versioning.ts diff --git a/src/explore/handle-explore.ts b/src/explore/handle-explore.ts index 3c46fb1..b0c5bb1 100644 --- a/src/explore/handle-explore.ts +++ b/src/explore/handle-explore.ts @@ -1,4 +1,5 @@ import { Env } from '../../worker-configuration' +import { VERSIONS } from '../utils/versioning' import { Dataset } from "./storage/dataset" const ArrayTypes = new Set(['contractAddresses', 'discover.category']) @@ -19,7 +20,8 @@ const HEADERS = { export async function handleExpore(request: Request, _env: Env, _ctx: ExecutionContext): Promise { try { const params = getParams(request.url) - const dataset = new Dataset() + const version = request.url.includes(VERSIONS.V2) ? VERSIONS.V2 : VERSIONS.V1 + const dataset = new Dataset({ version }) const paramKeys = Object.keys(params) diff --git a/src/explore/storage/dataset.ts b/src/explore/storage/dataset.ts index f9a8101..3acee1a 100644 --- a/src/explore/storage/dataset.ts +++ b/src/explore/storage/dataset.ts @@ -1,10 +1,16 @@ +import { VERSIONS } from '../../utils/versioning' import ContractAliases from './contracts.json' +import environment from './environments.json' +interface props { + version: VERSIONS +} export class Dataset { private storage = Object.values(ContractAliases) + private version = VERSIONS.V1 - constructor() { - // no-op + constructor({ version }: props) { + this.version = version } addFilter(filter: (value: any) => any) { @@ -13,7 +19,8 @@ export class Dataset { } getSnapshot() { - return JSON.stringify(this.storage) + return this.version === VERSIONS.V2 + ? JSON.stringify({ environment, contractAliases: this.storage }) + : JSON.stringify(this.storage) } - } \ No newline at end of file diff --git a/src/explore/storage/environments.json b/src/explore/storage/environments.json new file mode 100644 index 0000000..7d82fb7 --- /dev/null +++ b/src/explore/storage/environments.json @@ -0,0 +1,19 @@ +{ + "mainnet": { + "blockList": [ + "KT18j785rB3G4wXxEpqwwG2hJ2iZrjLAbeo7", + "KT1R8w6v13wt3yTeYUMxfZAWi7yXdNHepKHd", + "KT1WxUwHH1Ph7Gx6Ku7YLEfXh4przNGtMGqK" + ], + "model3DAllowList": [ + "KT1NVvPsNDChrLRH5K2cy6Sc9r1uuUwdiZQd", + "KT1AWoUQAuUudqpc75cGukWufbfim3GRn8h6", + "KT1Lz7Jd6Sh1zUE66nDGS7hGnjwcyTBCiYbF", + "KT1D1XtWFoQDPtuYzbkeRJhcDgH6CDem2FkZ" + ] + }, + "ghostnet": { + "blockList": [], + "model3DAllowList": [] + } +} \ No newline at end of file diff --git a/src/router.ts b/src/router.ts index cba92e1..dd335ee 100644 --- a/src/router.ts +++ b/src/router.ts @@ -8,6 +8,7 @@ import { handleProxy } from './proxy/handle-proxy'; export enum ROUTES { DISCOVER = '/v1/discover', EXPLORE = '/v1/explore', + EXPLORE_V2 = '/v2/explore', METADATA = '/v1/metadata/*', PROXY = '/v1/proxy', VERSION = '/v1/version', @@ -17,6 +18,7 @@ const router = Router(); router.get(ROUTES.DISCOVER, handleDiscover as unknown as RouteHandler) router.get(ROUTES.EXPLORE, handleExpore as unknown as RouteHandler) +router.get(ROUTES.EXPLORE_V2, handleExpore as unknown as RouteHandler) router.get(ROUTES.METADATA, handleMetadata as unknown as RouteHandler) router.get(ROUTES.PROXY, handleProxy as unknown as RouteHandler) router.get(ROUTES.VERSION, handleVersion as unknown as RouteHandler) diff --git a/src/utils/versioning.ts b/src/utils/versioning.ts new file mode 100644 index 0000000..085bec8 --- /dev/null +++ b/src/utils/versioning.ts @@ -0,0 +1,4 @@ +export enum VERSIONS { + V1 = "/v1/", + V2 = "/v2/" +} \ No newline at end of file diff --git a/src/worker.ts b/src/worker.ts index 70018cc..0c9d19e 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -1,13 +1,14 @@ import { Env } from '../worker-configuration'; import apiRouter from './router'; +import { VERSIONS } from './utils/versioning'; -const BASE_ENDPOINT = '/v1/' +const ALLOWED_VERSIONS = new Set([VERSIONS.V1, VERSIONS.V2]) export default { async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise { const url = new URL(request.url); - if (url.pathname.startsWith(BASE_ENDPOINT)) { + if (ALLOWED_VERSIONS.has(url.pathname.substring(0, 4))) { return apiRouter.handle(request, env, ctx) }