@eip-1193/jsonrpc-provider 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -3
- package/dist/index.mjs +6 -3
- package/package.json +3 -2
- package/src/JSONRPCHTTPProvider.ts +13 -4
package/dist/index.cjs
CHANGED
|
@@ -70,7 +70,7 @@ function ethereum_request(endpoint, req) {
|
|
|
70
70
|
}
|
|
71
71
|
let hasError = false;
|
|
72
72
|
for (const response3 of jsonArray) {
|
|
73
|
-
if (response3.error || !response3
|
|
73
|
+
if (response3.error || !("result" in response3)) {
|
|
74
74
|
hasError = true;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -106,8 +106,11 @@ function ethereum_request(endpoint, req) {
|
|
|
106
106
|
} catch (parsingError) {
|
|
107
107
|
throw new JSONRPCError("Failed To parse response json", parsingError);
|
|
108
108
|
}
|
|
109
|
-
if (json.error
|
|
110
|
-
throw json.error
|
|
109
|
+
if (json.error) {
|
|
110
|
+
throw json.error;
|
|
111
|
+
}
|
|
112
|
+
if (!("result" in json)) {
|
|
113
|
+
throw { code: 5e3, message: "No Result" };
|
|
111
114
|
}
|
|
112
115
|
return json.result;
|
|
113
116
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -68,7 +68,7 @@ function ethereum_request(endpoint, req) {
|
|
|
68
68
|
}
|
|
69
69
|
let hasError = false;
|
|
70
70
|
for (const response3 of jsonArray) {
|
|
71
|
-
if (response3.error || !response3
|
|
71
|
+
if (response3.error || !("result" in response3)) {
|
|
72
72
|
hasError = true;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -104,8 +104,11 @@ function ethereum_request(endpoint, req) {
|
|
|
104
104
|
} catch (parsingError) {
|
|
105
105
|
throw new JSONRPCError("Failed To parse response json", parsingError);
|
|
106
106
|
}
|
|
107
|
-
if (json.error
|
|
108
|
-
throw json.error
|
|
107
|
+
if (json.error) {
|
|
108
|
+
throw json.error;
|
|
109
|
+
}
|
|
110
|
+
if (!("result" in json)) {
|
|
111
|
+
throw { code: 5e3, message: "No Result" };
|
|
109
112
|
}
|
|
110
113
|
return json.result;
|
|
111
114
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eip-1193/jsonrpc-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"eip-1193",
|
|
6
6
|
"ethereum",
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"build": "pkgroll",
|
|
60
60
|
"dev": "pkgroll --watch",
|
|
61
61
|
"format:check": "prettier --check .",
|
|
62
|
+
"test": "pnpm build && node --test test/*.test.mjs",
|
|
62
63
|
"format": "prettier --write .",
|
|
63
|
-
"release:ci": "pnpm format:check && pnpm
|
|
64
|
+
"release:ci": "pnpm format:check && pnpm test && pnpm changeset publish"
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -59,7 +59,9 @@ export async function ethereum_request<U extends any, T>(
|
|
|
59
59
|
|
|
60
60
|
let hasError = false;
|
|
61
61
|
for (const response of jsonArray) {
|
|
62
|
-
|
|
62
|
+
// `null`, `false` and `0` are valid results (a pending receipt, `eth_syncing`,
|
|
63
|
+
// `hardhat_impersonateAccount`): only an error, or a missing `result` member, is a failure.
|
|
64
|
+
if (response.error || !('result' in response)) {
|
|
63
65
|
hasError = true;
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -99,10 +101,17 @@ export async function ethereum_request<U extends any, T>(
|
|
|
99
101
|
throw new JSONRPCError('Failed To parse response json', parsingError);
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
if (json.error
|
|
103
|
-
throw json.error
|
|
104
|
+
if (json.error) {
|
|
105
|
+
throw json.error;
|
|
104
106
|
}
|
|
105
|
-
|
|
107
|
+
// A JSON-RPC response carries EITHER `error` OR `result`, and `result` may legitimately be
|
|
108
|
+
// `null` or `false` (a pending `eth_getTransactionReceipt`, `eth_syncing`, and
|
|
109
|
+
// `hardhat_impersonateAccount`, which anvil and hardhat answer with `null`). Only a response
|
|
110
|
+
// with neither member is malformed.
|
|
111
|
+
if (!('result' in json)) {
|
|
112
|
+
throw {code: 5000, message: 'No Result'};
|
|
113
|
+
}
|
|
114
|
+
return json.result as T;
|
|
106
115
|
}
|
|
107
116
|
|
|
108
117
|
export class JSONRPCHTTPProvider implements EIP1193HttpNodeProvider {
|