Skip to content

Commit

Permalink
Fix jsonrpc payload and response types (#4743)
Browse files Browse the repository at this point in the history
* Make JsonRpcPayload's `params` field optional

Currently jsonrpc.js uses `params: params || []` in the
`toPayload` function, so this type update makes the `params` field
optional to match.

* Fix JsonRpcResponse type

Update `id` to accept `string | number` - this now matches the
`isValidResponse` function in `jsonrpc.js`.

Update `error` to accept an object with optional `code`, `data`,
and non-optional `message` fields to more closely match the
[JSON RPC spec](https://www.jsonrpc.org/specification#error_object)
and the `ErrorResponse` function in `errors.js`.

* Remove errant spaces

* Add PR #443 to CHANGELOG

Co-authored-by: jdevcs <[email protected]>
  • Loading branch information
MicaiahReid and jdevcs authored Feb 8, 2022
1 parent 2a10e24 commit 63b5e62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ Released with 1.0.0-beta.37 code base.
- Update the documentation for `methods.myMethod.estimateGas` (#4702)
- Fix typos in REVIEW.md and TESTING.md (#4691)
- Fix encoding for "0x" string values (#4512)
- Fix jsonrpc payload and response types (#4743)


### Changed
Expand Down
10 changes: 7 additions & 3 deletions packages/web3-core-helpers/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,19 @@ export interface RequestItem {
export interface JsonRpcPayload {
jsonrpc: string;
method: string;
params: any[];
params?: any[];
id?: string | number;
}

export interface JsonRpcResponse {
jsonrpc: string;
id: number;
id: string | number;
result?: any;
error?: string;
error?: {
readonly code?: number;
readonly data?: unknown;
readonly message: string;
};
}

export interface RevertInstructionError extends Error {
Expand Down

0 comments on commit 63b5e62

Please sign in to comment.