Skip to content

Commit

Permalink
Add a flag to enable ETH RPC server
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Sep 13, 2024
1 parent 7869b72 commit 36c56da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions packages/util/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ export interface ServerConfig {
// Flag to specify whether RPC endpoint supports block hash as block tag parameter
// https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block
rpcSupportsBlockHashParam: boolean;

// Enable ETH JSON RPC server at /rpc
enableEthRPCServer: boolean;
}

export interface FundingAmountsConfig {
Expand Down
29 changes: 18 additions & 11 deletions packages/util/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { PaymentsManager, paymentsPlugin } from './payments';
const log = debug('vulcanize:server');

const DEFAULT_GQL_PATH = '/graphql';
const ETH_RPC_PATH = '/rpc';

export const createAndStartServer = async (
app: Application,
Expand Down Expand Up @@ -101,19 +102,25 @@ export const createAndStartServer = async (
path: gqlPath
});

// Create a JSON-RPC server to handle ETH RPC calls at /rpc
const rpcServer = jayson.Server(ethRPCHandlers);

// Mount the JSON-RPC server to /rpc path
app.use(
'/rpc',
jsonParser(),
// TODO: Handle GET requests as well to match Geth's behaviour
rpcServer.middleware()
);
if (serverConfig.enableEthRPCServer) {
// Create a JSON-RPC server to handle ETH RPC calls
const rpcServer = jayson.Server(ethRPCHandlers);

// Mount the JSON-RPC server to ETH_RPC_PATH
app.use(
ETH_RPC_PATH,
jsonParser(),
// TODO: Handle GET requests as well to match Geth's behaviour
rpcServer.middleware()
);
}

httpServer.listen(port, host, () => {
log(`Server is listening on ${host}:${port}${server.graphqlPath}`);
log(`GQL server is listening on http://${host}:${port}${server.graphqlPath}`);

if (serverConfig.enableEthRPCServer) {
log(`ETH JSON RPC server is listening on http://${host}:${port}${ETH_RPC_PATH}`);
}
});

return server;
Expand Down

0 comments on commit 36c56da

Please sign in to comment.