From ead1ebecb4042c97f2927206658474619c0b0788 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 25 Sep 2023 08:27:22 +0000 Subject: [PATCH] WIP --- yarn-project/aztec-sandbox/src/bin/index.ts | 10 +++++++--- yarn-project/aztec-sandbox/src/routes.ts | 7 +++---- yarn-project/aztec-sandbox/src/server.ts | 22 ++++++++++----------- yarn-project/end-to-end/src/e2e_cli.test.ts | 4 ++-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index 8f906cf874da..65cfd4b1cc36 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -1,4 +1,6 @@ #!/usr/bin/env -S node --no-warnings +import { createAztecNodeRpcServer } from '@aztec/aztec-node'; +import { getHttpRpcServer } from '@aztec/aztec-rpc'; import { deployInitialSandboxAccounts } from '@aztec/aztec.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; @@ -12,7 +14,7 @@ import { createSandbox } from '../sandbox.js'; import { startHttpRpcServer } from '../server.js'; import { github, splash } from '../splash.js'; -const { SERVER_PORT = 8080 } = process.env; +const { NODE_PORT = 8079, SERVER_PORT = 8080 } = process.env; const logger = createDebugLogger('aztec:sandbox'); @@ -26,7 +28,7 @@ async function main() { logger.info(`Setting up Aztec Sandbox v${version} (nargo ${NoirVersion.tag}), please stand by...`); - const { l1Contracts, rpcServer, stop } = await createSandbox(); + const { node, rpcServer, l1Contracts, stop } = await createSandbox(); logger.info('Setting up test accounts...'); const accounts = await deployInitialSandboxAccounts(rpcServer); @@ -40,7 +42,9 @@ async function main() { process.once('SIGINT', shutdown); process.once('SIGTERM', shutdown); - startHttpRpcServer(rpcServer, l1Contracts, SERVER_PORT); + startHttpRpcServer(node, createAztecNodeRpcServer, l1Contracts, 8079); + logger.info(`Aztec Node JSON-RPC Server listening on port ${NODE_PORT}`); + startHttpRpcServer(rpcServer, getHttpRpcServer, l1Contracts, SERVER_PORT); logger.info(`Aztec Sandbox JSON-RPC Server listening on port ${SERVER_PORT}`); logger.info(`Debug logs will be written to ${logPath}`); const accountStrings = [`Initial Accounts:\n\n`]; diff --git a/yarn-project/aztec-sandbox/src/routes.ts b/yarn-project/aztec-sandbox/src/routes.ts index 43967f3bd82f..205bab8d3abc 100644 --- a/yarn-project/aztec-sandbox/src/routes.ts +++ b/yarn-project/aztec-sandbox/src/routes.ts @@ -4,11 +4,10 @@ import Koa from 'koa'; import Router from 'koa-router'; /** - * Creates a router for helper API endpoints of the Aztec RPC Server. - * @param aztecNode - An instance of the aztec node. - * @param config - The aztec node's configuration variables. + * Creates a router for helper API endpoints. + * @param l1Contracts - Object containing L1 contract addresses. */ -export function createApiRouter(l1Contracts: DeployL1Contracts) { +export function createHelperRouter(l1Contracts: DeployL1Contracts) { const router = new Router({ prefix: '/api' }); router.get('/status', (ctx: Koa.Context) => { // TODO: add `status` to Aztec node. diff --git a/yarn-project/aztec-sandbox/src/server.ts b/yarn-project/aztec-sandbox/src/server.ts index e749c4cc79c4..a54788d78ecd 100644 --- a/yarn-project/aztec-sandbox/src/server.ts +++ b/yarn-project/aztec-sandbox/src/server.ts @@ -1,29 +1,29 @@ -import { getHttpRpcServer } from '@aztec/aztec-rpc'; import { DeployL1Contracts } from '@aztec/ethereum'; -import { AztecRPC } from '@aztec/types'; +import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; import http from 'http'; -import { createApiRouter } from './routes.js'; +import { createHelperRouter } from './routes.js'; /** - * Creates an http server that forwards calls to the rpc server and starts it on the given port. - * @param aztecRpcServer - RPC server that answers queries to the created HTTP server. + * Creates an http server that forwards calls to the underlying instance and starts it on the given port. + * @param instance - RPC server that answers queries to the created HTTP server. * @param deployedL1Contracts - Info on L1 deployed contracts. * @param port - Port to listen in. * @returns A running http server. */ -export function startHttpRpcServer( - aztecRpcServer: AztecRPC, +export function startHttpRpcServer( + instance: T, + jsonRpcFactoryFunc: (instance: T) => JsonRpcServer, deployedL1Contracts: DeployL1Contracts, port: string | number, ): http.Server { - const rpcServer = getHttpRpcServer(aztecRpcServer); + const rpcServer = jsonRpcFactoryFunc(instance); const app = rpcServer.getApp(); - const apiRouter = createApiRouter(deployedL1Contracts); - app.use(apiRouter.routes()); - app.use(apiRouter.allowedMethods()); + const helperRouter = createHelperRouter(deployedL1Contracts); + app.use(helperRouter.routes()); + app.use(helperRouter.allowedMethods()); const httpServer = http.createServer(app.callback()); httpServer.listen(port); diff --git a/yarn-project/end-to-end/src/e2e_cli.test.ts b/yarn-project/end-to-end/src/e2e_cli.test.ts index 112748fe75b0..9f3ba081ba58 100644 --- a/yarn-project/end-to-end/src/e2e_cli.test.ts +++ b/yarn-project/end-to-end/src/e2e_cli.test.ts @@ -1,5 +1,5 @@ import { AztecNodeService } from '@aztec/aztec-node'; -import { AztecRPCServer } from '@aztec/aztec-rpc'; +import { AztecRPCServer, getHttpRpcServer } from '@aztec/aztec-rpc'; import { startHttpRpcServer } from '@aztec/aztec-sandbox'; import { AztecRPC, createDebugLogger } from '@aztec/aztec.js'; @@ -19,7 +19,7 @@ const testSetup = async () => { debug(`Environment set up`); const { deployL1ContractsValues } = context; ({ aztecNode, aztecRpcServer } = context); - http = startHttpRpcServer(aztecRpcServer, deployL1ContractsValues, HTTP_PORT); + http = startHttpRpcServer(aztecRpcServer, getHttpRpcServer, deployL1ContractsValues, HTTP_PORT); debug(`HTTP RPC server started in port ${HTTP_PORT}`); return aztecRpcServer; };