Skip to content

Commit

Permalink
Merge pull request #14 from lightclients/validation
Browse files Browse the repository at this point in the history
Validate input of RPC requests
  • Loading branch information
shresthagrawal authored Oct 31, 2022
2 parents c48f334 69351ad commit c85f199
Show file tree
Hide file tree
Showing 12 changed files with 474 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
{
"trailingComma": "all",
"useTabs": false,
"printWidth": 120,
"printWidth": 80,
"tabWidth": 2,
"arrowParens": "avoid",
"semi": true,
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 11,11 @@ Ethereum RPC proxy that verifies RPC responses against given trusted block hashe
```ts
import { VerifyingProvider, startServer } from 'patronum';

const provider = new VerifyingProvider(trustlessRPCURL, trustedBlockNumber, trustedBlockHash);
const provider = new VerifyingProvider(
trustlessRPCURL,
trustedBlockNumber,
trustedBlockHash,
);
await startServer(provider, PORT);
```

Expand All @@ -20,7 24,11 @@ await startServer(provider, PORT);
```ts
import { VerifyingProvider } from 'patronum';

const provider = new VerifyingProvider(trustlessRPCURL, trustedBlockNumber, trustedBlockHash);
const provider = new VerifyingProvider(
trustlessRPCURL,
trustedBlockNumber,
trustedBlockHash,
);

console.log(await provider.getBalance(address, blockTag));

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 59,6 @@
"rpc"
],
"lint-staged": {
"*.{js,css,md}": "prettier --write"
"*.{ts,js,md}": "prettier --write"
}
}
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@ export const ZERO_ADDR = '0x0000000000000000000000000000000000000000';
export const GAS_LIMIT = '0x1c9c380';
export const REQUEST_BATCH_SIZE = 10;
export const MAX_SOCKET = 10;
export const EMPTY_ACCOUNT_EXTCODEHASH = '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470';
export const EMPTY_ACCOUNT_EXTCODEHASH =
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470';
export const MAX_BLOCK_HISTORY = BigInt(256);
export const MAX_BLOCK_FUTURE = BigInt(3);
27 changes: 10 additions & 17 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,20 1,13 @@
const INVALID_PARAMS = -32602;
const INTERNAL_ERROR = -32603;
import { JSONRPCErrorCode, JSONRPCErrorException } from 'json-rpc-2.0';

export const PARSE_ERROR = -32700;
export const METHOD_NOT_FOUND = -32601;
export const INVALID_REQUEST = -32600;

export class InternalError extends Error {
public code = INTERNAL_ERROR
constructor(message: string) {
super(message);
}
export class InternalError extends JSONRPCErrorException {
constructor(message: string) {
super(message, JSONRPCErrorCode.InternalError);
}
}

export class InvalidParamsError extends Error {
public code = INVALID_PARAMS
constructor(message: string) {
super(message);
}
}
export class InvalidParamsError extends JSONRPCErrorException {
constructor(message: string) {
super(message, JSONRPCErrorCode.InvalidParams);
}
}
Loading

0 comments on commit c85f199

Please sign in to comment.