Skip to content

Commit

Permalink
updates services, introduces explore v2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrosGounis committed Dec 19, 2023
1 parent f771a72 commit 54dc9e8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/explore/handle-explore.ts
Original file line number Diff line number Diff line change
@@ -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'])
Expand All @@ -19,7 +20,8 @@ const HEADERS = {
export async function handleExpore(request: Request, _env: Env, _ctx: ExecutionContext): Promise<Response> {
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)

Expand Down
15 changes: 11 additions & 4 deletions src/explore/storage/dataset.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)
}

}
19 changes: 19 additions & 0 deletions src/explore/storage/environments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"mainnet": {
"blockList": [
"KT18j785rB3G4wXxEpqwwG2hJ2iZrjLAbeo7",
"KT1R8w6v13wt3yTeYUMxfZAWi7yXdNHepKHd",
"KT1WxUwHH1Ph7Gx6Ku7YLEfXh4przNGtMGqK"
],
"model3DAllowList": [
"KT1NVvPsNDChrLRH5K2cy6Sc9r1uuUwdiZQd",
"KT1AWoUQAuUudqpc75cGukWufbfim3GRn8h6",
"KT1Lz7Jd6Sh1zUE66nDGS7hGnjwcyTBCiYbF",
"KT1D1XtWFoQDPtuYzbkeRJhcDgH6CDem2FkZ"
]
},
"ghostnet": {
"blockList": [],
"model3DAllowList": []
}
}
2 changes: 2 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/utils/versioning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum VERSIONS {
V1 = "/v1/",
V2 = "/v2/"
}
5 changes: 3 additions & 2 deletions src/worker.ts
Original file line number Diff line number Diff line change
@@ -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<string>([VERSIONS.V1, VERSIONS.V2])

export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
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)
}

Expand Down

0 comments on commit 54dc9e8

Please sign in to comment.