Skip to content
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

Validate input of RPC requests #14

Merged
merged 9 commits into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierrc.json
@@ -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
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
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
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
@@ -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);
}
}