Skip to content

Commit 1d6f494

Browse files
authored
feat: config rpc (#88)
* feat: config rpc * disable binary search * http codes * chore(release): v0.0.44
1 parent b96cc1f commit 1d6f494

19 files changed

Lines changed: 147 additions & 44 deletions

File tree

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"npmClient": "yarn",
66
"useWorkspaces": true,
7-
"version": "0.0.43",
7+
"version": "0.0.44",
88
"stream": "true",
99
"command": {
1010
"version": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "root",
33
"private": true,
4-
"version": "0.0.43",
4+
"version": "0.0.44",
55
"engines": {
66
"node": ">=18.0.0"
77
},

packages/api/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "api",
3-
"version": "0.0.43",
3+
"version": "0.0.44",
44
"description": "The API module of Etherspot bundler client",
55
"author": "Etherspot",
66
"homepage": "https://https://github.com/etherspot/skandha#readme",
@@ -35,12 +35,12 @@
3535
"class-transformer": "0.5.1",
3636
"class-validator": "0.14.0",
3737
"ethers": "5.7.2",
38-
"executor": "^0.0.43",
38+
"executor": "^0.0.44",
3939
"fastify": "4.14.1",
4040
"pino": "8.11.0",
4141
"pino-pretty": "10.0.0",
4242
"reflect-metadata": "0.1.13",
43-
"types": "^0.0.43"
43+
"types": "^0.0.44"
4444
},
4545
"devDependencies": {
4646
"@types/connect": "3.4.35"

packages/api/src/app.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import logger from "./logger";
99
import {
1010
BundlerRPCMethods,
1111
CustomRPCMethods,
12+
HttpStatus,
1213
RedirectedRPCMethods,
1314
} from "./constants";
1415
import { EthAPI, DebugAPI, Web3API, RedirectAPI } from "./modules";
@@ -139,9 +140,9 @@ export class ApiApp {
139140
if (this.redirectRpc && method in RedirectedRPCMethods) {
140141
const body = await redirectApi.redirect(method, params);
141142
if (body.error) {
142-
return res.status(200).send({ ...body, id });
143+
return res.status(HttpStatus.OK).send({ ...body, id });
143144
}
144-
return res.status(200).send({ jsonrpc, id, ...body });
145+
return res.status(HttpStatus.OK).send({ jsonrpc, id, ...body });
145146
}
146147

147148
if (result === undefined) {
@@ -197,6 +198,14 @@ export class ApiApp {
197198
newestBlock: params[2],
198199
});
199200
break;
201+
case CustomRPCMethods.skandha_config:
202+
result = await skandhaApi.getConfig();
203+
// skip hexlify for this particular rpc
204+
return res.status(HttpStatus.OK).send({
205+
jsonrpc,
206+
id,
207+
result,
208+
});
200209
default:
201210
throw new RpcError(
202211
`Method ${method} is not supported`,
@@ -206,7 +215,7 @@ export class ApiApp {
206215
}
207216

208217
result = deepHexlify(result);
209-
return res.status(200).send({
218+
return res.status(HttpStatus.OK).send({
210219
jsonrpc,
211220
id,
212221
result,

packages/api/src/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const CustomRPCMethods = {
22
skandha_validateUserOperation: "skandha_validateUserOperation",
33
skandha_getGasPrice: "skandha_getGasPrice",
4+
skandha_config: "skandha_config",
45
skandha_feeHistory: "skandha_feeHistory",
56
};
67

@@ -60,3 +61,8 @@ export const RedirectedRPCMethods = {
6061
eth_maxPriorityFeePerGas: "eth_maxPriorityFeePerGas",
6162
eth_sendRawTransaction: "eth_sendRawTransaction",
6263
};
64+
65+
export enum HttpStatus {
66+
OK = 200,
67+
INTERNAL_SERVER_ERROR = 500,
68+
}

packages/api/src/modules/skandha.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Eth } from "executor/lib/modules/eth";
22
import {
3+
GetConfigResponse,
34
GetFeeHistoryResponse,
45
GetGasPriceResponse,
56
} from "types/lib/api/interfaces";
@@ -46,4 +47,8 @@ export class SkandhaAPI {
4647
async getGasPrice(): Promise<GetGasPriceResponse> {
4748
return await this.skandhaModule.getGasPrice();
4849
}
50+
51+
async getConfig(): Promise<GetConfigResponse> {
52+
return await this.skandhaModule.getConfig();
53+
}
4954
}

packages/api/src/server.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import cors from "@fastify/cors";
33
import RpcError from "types/lib/api/errors/rpc-error";
44
import { ServerConfig } from "types/lib/api/interfaces";
55
import logger from "./logger";
6+
import { HttpStatus } from "./constants";
67

78
export class Server {
89
constructor(private app: FastifyInstance, private config: ServerConfig) {
@@ -70,16 +71,18 @@ export class Server {
7071
data: err.data,
7172
code: err.code,
7273
};
73-
return res.status(200).send({
74+
return res.status(HttpStatus.OK).send({
7475
jsonrpc: body.jsonrpc,
7576
id: body.id,
7677
error,
7778
});
7879
}
7980

80-
return res.status(err.statusCode ?? 500).send({
81-
error: "Unexpected behaviour",
82-
});
81+
return res
82+
.status(err.statusCode ?? HttpStatus.INTERNAL_SERVER_ERROR)
83+
.send({
84+
error: "Unexpected behaviour",
85+
});
8386
});
8487

8588
await this.app.listen({

packages/cli/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cli",
3-
"version": "0.0.43",
3+
"version": "0.0.44",
44
"description": "> TODO: description",
55
"author": "zincoshine <psramanuj@gmail.com>",
66
"homepage": "https://https://github.com/etherspot/skandha#readme",
@@ -31,13 +31,13 @@
3131
"url": "https://https://github.com/etherspot/skandha/issues"
3232
},
3333
"dependencies": {
34-
"api": "^0.0.43",
35-
"db": "^0.0.43",
36-
"executor": "^0.0.43",
34+
"api": "^0.0.44",
35+
"db": "^0.0.44",
36+
"executor": "^0.0.44",
3737
"find-up": "5.0.0",
3838
"got": "12.5.3",
3939
"js-yaml": "4.1.0",
40-
"types": "^0.0.43",
40+
"types": "^0.0.44",
4141
"yargs": "17.6.2"
4242
},
4343
"devDependencies": {

packages/cli/src/cmds/start/handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ export async function bundlerHandler(
2929
networks: configOptions.networks,
3030
testingMode,
3131
unsafeMode,
32+
redirectRpc,
3233
});
3334
} catch (err) {
3435
logger.debug("Config file not found. Proceeding with env vars...");
3536
config = new Config({
3637
networks: {},
3738
testingMode,
3839
unsafeMode,
40+
redirectRpc,
3941
});
4042
}
4143

packages/db/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "db",
3-
"version": "0.0.43",
3+
"version": "0.0.44",
44
"description": "The DB module of Etherspot bundler client",
55
"author": "Etherspot",
66
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
@@ -37,6 +37,6 @@
3737
"devDependencies": {
3838
"@types/rocksdb": "3.0.1",
3939
"prettier": "^2.8.4",
40-
"types": "^0.0.43"
40+
"types": "^0.0.44"
4141
}
4242
}

0 commit comments

Comments
 (0)