Skip to content

Commit 7c37ffe

Browse files
committed
feat: add rpc.discover method using @shardeum-foundation/api-specs
1 parent 1d18451 commit 7c37ffe

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

openrpc.json

Whitespace-only changes.

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
"author": "thantsintoe",
2828
"license": "ISC",
2929
"dependencies": {
30-
"@shardeum-foundation/lib-archiver-discovery": "1.3.0-prerelease.1",
31-
"@shardeum-foundation/lib-crypto-utils": "4.3.0-prerelease.1",
32-
"@shardeum-foundation/lib-types": "1.4.0-prerelease.2",
3330
"@ethereumjs/rlp": "5.0.2",
3431
"@ethereumjs/tx": "3.4.0",
3532
"@ethereumjs/util": "9.0.2",
3633
"@ethersproject/bignumber": "5.7.0",
3734
"@hapi/sntp": "4.0.0",
35+
"@shardeum-foundation/api-specs": "^1.0.1",
36+
"@shardeum-foundation/lib-archiver-discovery": "1.3.0-prerelease.1",
37+
"@shardeum-foundation/lib-crypto-utils": "4.3.0-prerelease.1",
38+
"@shardeum-foundation/lib-types": "1.4.0-prerelease.2",
3839
"axios": "1.6.1",
3940
"better-sqlite3": "7.6.2",
4041
"body-parser": "1.19.0",

src/methods/rpcDiscover.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import ShardeumOpenRPCDocument from "@shardeum-foundation/api-specs"
2+
3+
const rpcDiscover = async (): Promise<unknown> => {
4+
return ShardeumOpenRPCDocument
5+
}
6+
7+
export default rpcDiscover

src/middlewares/methodWhitelist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Request, Response, NextFunction } from 'express'
22
import { methods } from '../api'
33

4-
const allowedMethods = Object.keys(methods)
4+
const allowedMethods = [...Object.keys(methods), 'rpc.discover']
55

66
export const methodWhitelist = (req: Request, res: Response, next: NextFunction) => {
77
const body = req.body

src/server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { rateLimitMiddleware } from './middlewares/rateLimit'
3535
import requestLogger from './middlewares/requestLogger'
3636
import { loadFoundationNodes } from './utils/foundationNodes'
3737
import { setupNewHeadSubscriptionProviderConnectionStream } from './websocket/newhead_server'
38-
38+
import rpcDiscover from './methods/rpcDiscover'
3939
setDefaultResultOrder('ipv4first')
4040

4141
// const path = require('path');
@@ -51,6 +51,13 @@ setDefaultResultOrder('ipv4first')
5151
// }
5252
const app = express()
5353
const server = new jayson.Server(wrappedMethods)
54+
server._methods['rpc.discover'] = new jayson.Method((_args: unknown, done: jayson.JSONRPCCallbackTypePlain) => {
55+
rpcDiscover().then((res) => {
56+
done(null, res)
57+
}).catch((err) => {
58+
done(err, null)
59+
})
60+
});
5461
let port = config.port //8080
5562
const chainId = config.chainId //8080
5663
const verbose = config.verbose

0 commit comments

Comments
 (0)