Skip to content

Feat/add rpc discover #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@ethereumjs/util": "9.0.2",
"@ethersproject/bignumber": "5.7.0",
"@hapi/sntp": "4.0.0",
"@shardeum-foundation/api-specs": "^1.0.1",
"axios": "1.6.1",
"better-sqlite3": "7.6.2",
"body-parser": "1.19.0",
Expand Down
7 changes: 7 additions & 0 deletions src/methods/rpcDiscover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ShardeumOpenRPCDocument from "@shardeum-foundation/api-specs"

const rpcDiscover = async (): Promise<unknown> => {
return ShardeumOpenRPCDocument
}

export default rpcDiscover
2 changes: 1 addition & 1 deletion src/middlewares/methodWhitelist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from 'express'
import { methods } from '../api'

const allowedMethods = Object.keys(methods)
const allowedMethods = [...Object.keys(methods), 'rpc.discover']

export const methodWhitelist = (req: Request, res: Response, next: NextFunction) => {
const body = req.body
Expand Down
9 changes: 8 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { rateLimitMiddleware } from './middlewares/rateLimit'
import requestLogger from './middlewares/requestLogger'
import { loadFoundationNodes } from './utils/foundationNodes'
import { setupNewHeadSubscriptionProviderConnectionStream } from './websocket/newhead_server'

import rpcDiscover from './methods/rpcDiscover'
setDefaultResultOrder('ipv4first')

// const path = require('path');
Expand All @@ -51,6 +51,13 @@ setDefaultResultOrder('ipv4first')
// }
const app = express()
const server = new jayson.Server(wrappedMethods)
server._methods['rpc.discover'] = new jayson.Method((_args: unknown, done: jayson.JSONRPCCallbackTypePlain) => {
rpcDiscover().then((res) => {
done(null, res)
}).catch((err) => {
done(err, null)
})
});
Comment on lines +54 to +60
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The current implementation exposes the rpc.discover method without any authentication or rate limiting, which could allow abuse or information leakage. Consider adding appropriate access controls or rate limiting to this method to prevent misuse. [security, importance: 8]

Suggested change
server._methods['rpc.discover'] = new jayson.Method((_args: unknown, done: jayson.JSONRPCCallbackTypePlain) => {
rpcDiscover().then((res) => {
done(null, res)
}).catch((err) => {
done(err, null)
})
});
// Apply rate limiting or authentication as appropriate before exposing rpc.discover
server._methods['rpc.discover'] = new jayson.Method((_args: unknown, done: jayson.JSONRPCCallbackTypePlain) => {
// Example: check authentication or apply rate limiting here
rpcDiscover().then((res) => {
done(null, res)
}).catch((err) => {
done(err, null)
})
});

let port = config.port //8080
const chainId = config.chainId //8080
const verbose = config.verbose
Expand Down
Loading