5 changed files with 70 additions and 48 deletions
@ -0,0 +1,7 @@ |
|||
import { RouterMiddleware } from "https://deno.land/x/oak/mod.ts"; |
|||
import { getBlocks } from "../blocks.ts"; |
|||
|
|||
export const GetBlocks: RouterMiddleware = (context) => { |
|||
const blocks = getBlocks(); |
|||
context.response.body = blocks; |
|||
}; |
@ -0,0 +1,24 @@ |
|||
import { Router } from "https://deno.land/x/oak/mod.ts"; |
|||
|
|||
import Pageviews from "../pageviews/index.ts"; |
|||
import { GetBlocks } from "./blocks.ts"; |
|||
import { LnurlPayRequest, LnurlPayRequestCallback } from "./donate.ts"; |
|||
import { GetBlockchainInfo, GetBlockCount, GetBlockHash } from "./misc.ts"; |
|||
|
|||
const router = new Router(); |
|||
|
|||
router.use(Pageviews); |
|||
|
|||
router.get("/blocks", GetBlocks); |
|||
|
|||
router.get("/invoice", LnurlPayRequest); |
|||
|
|||
router.get("/invoice/callback", LnurlPayRequestCallback); |
|||
|
|||
router.get("/getblockchaininfo", GetBlockchainInfo); |
|||
|
|||
router.get<{ height: string }>("/getblockhash/:height", GetBlockHash); |
|||
|
|||
router.get("/getblockcount", GetBlockCount); |
|||
|
|||
export default router; |
@ -0,0 +1,28 @@ |
|||
import { RouterMiddleware } from "https://deno.land/x/oak/mod.ts"; |
|||
|
|||
import { getblockhash } from "../jsonrpc/index.ts"; |
|||
import { getblockchaininfo, getblockcount } from "../jsonrpc/index.ts"; |
|||
|
|||
export const GetBlockchainInfo: RouterMiddleware = async (context) => { |
|||
const info = await getblockchaininfo(); |
|||
console.log(info); |
|||
context.response.body = info; |
|||
}; |
|||
|
|||
export const GetBlockHash: RouterMiddleware<{ height: string }> = async (context) => { |
|||
if (!context.params || !context.params.height) { |
|||
context.response.status = 400; |
|||
context.response.body = JSON.stringify({ |
|||
status: "ERROR", |
|||
reason: "Missing param height", |
|||
}); |
|||
return; |
|||
} |
|||
const blockhash = await getblockhash(Number.parseInt(context.params.height)); |
|||
context.response.body = blockhash; |
|||
}; |
|||
|
|||
export const GetBlockCount: RouterMiddleware = async (context) => { |
|||
const blockCount = await getblockcount(); |
|||
context.response.body = blockCount; |
|||
}; |
Loading…
Reference in new issue