-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functional endpoints (adapted from ERC20 API)
- Loading branch information
Showing
19 changed files
with
755 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// from: https://github.com/pinax-network/substreams-clock-api/blob/main/src/fetch/block.ts | ||
import { makeQuery } from "../clickhouse/makeQuery.js"; | ||
import { logger } from "../logger.js"; | ||
import { getBalanceChanges } from "../queries.js"; | ||
import * as prometheus from "../prometheus.js"; | ||
import { toJSON } from "./utils.js"; | ||
|
||
|
||
function verifyParams(searchParams: URLSearchParams) { | ||
const chain = searchParams.get("chain"); | ||
const owner = searchParams.get("owner"); | ||
const contract = searchParams.get("contract"); | ||
|
||
if (!chain) throw new Error("chain is required"); | ||
if (!owner && !contract) throw new Error("owner or contract is required"); | ||
} | ||
|
||
export default async function (req: Request) { | ||
try { | ||
const { searchParams } = new URL(req.url); | ||
logger.info({ searchParams: Object.fromEntries(Array.from(searchParams)) }); | ||
//Verify required params | ||
verifyParams(searchParams); | ||
const query = getBalanceChanges(searchParams); | ||
const response = await makeQuery(query) | ||
return toJSON(response.data); | ||
} catch (e: any) { | ||
logger.error(e); | ||
prometheus.request_error.inc({ pathname: "/balance", status: 400 }); | ||
return new Response(e.message, { status: 400 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
// from: https://github.com/pinax-network/substreams-clock-api/blob/main/src/fetch/chains.ts | ||
import { makeQuery } from "../clickhouse/makeQuery.js"; | ||
import { logger } from "../logger.js"; | ||
import * as prometheus from "../prometheus.js"; | ||
import { getChain } from "../queries.js"; | ||
import { toJSON } from "./utils.js"; | ||
|
||
export async function supportedChainsQuery() { | ||
const response = await makeQuery<{chain: string}>(getChain()); | ||
const response = await makeQuery<{ chain: string }>(getChain()); | ||
return response.data.map((r) => r.chain); | ||
} | ||
|
||
export default async function (req: Request) { | ||
export default async function (_req: Request) { | ||
try { | ||
const chains = await supportedChainsQuery(); | ||
return new Response(JSON.stringify(chains), { headers: { "Content-Type": "application/json" } }); | ||
return toJSON(chains); | ||
} catch (e: any) { | ||
logger.error(e); | ||
prometheus.request_error.inc({pathname: "/chains", status: 400}); | ||
prometheus.request_error.inc({ pathname: "/chains", status: 400 }); | ||
return new Response(e.message, { status: 400 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.