@nomicfoundation/edr 0.5.0 → 0.5.2
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/index.d.ts +3 -1
- package/package.json +11 -10
- package/src/provider.rs +34 -9
package/index.d.ts
CHANGED
|
@@ -418,7 +418,9 @@ export class Provider {
|
|
|
418
418
|
setVerboseTracing(verboseTracing: boolean): void
|
|
419
419
|
}
|
|
420
420
|
export class Response {
|
|
421
|
-
|
|
421
|
+
/** Returns the response data as a JSON string or a JSON object. */
|
|
422
|
+
get data(): string | any
|
|
423
|
+
get json(): string | any
|
|
422
424
|
get solidityTrace(): RawTrace | null
|
|
423
425
|
get traces(): Array<RawTrace>
|
|
424
426
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomicfoundation/edr",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"@types/node": "^18.0.0",
|
|
39
39
|
"chai": "^4.3.6",
|
|
40
40
|
"chai-as-promised": "^7.1.1",
|
|
41
|
+
"json-stream-stringify": "^3.1.4",
|
|
41
42
|
"mocha": "^10.0.0",
|
|
42
43
|
"ts-node": "^10.8.0",
|
|
43
44
|
"typescript": "~4.5.2"
|
|
@@ -46,13 +47,13 @@
|
|
|
46
47
|
"node": ">= 18"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
|
-
"@nomicfoundation/edr-darwin-arm64": "0.5.
|
|
50
|
-
"@nomicfoundation/edr-darwin-x64": "0.5.
|
|
51
|
-
"@nomicfoundation/edr-linux-arm64-gnu": "0.5.
|
|
52
|
-
"@nomicfoundation/edr-linux-arm64-musl": "0.5.
|
|
53
|
-
"@nomicfoundation/edr-linux-x64-gnu": "0.5.
|
|
54
|
-
"@nomicfoundation/edr-linux-x64-musl": "0.5.
|
|
55
|
-
"@nomicfoundation/edr-win32-x64-msvc": "0.5.
|
|
50
|
+
"@nomicfoundation/edr-darwin-arm64": "0.5.2",
|
|
51
|
+
"@nomicfoundation/edr-darwin-x64": "0.5.2",
|
|
52
|
+
"@nomicfoundation/edr-linux-arm64-gnu": "0.5.2",
|
|
53
|
+
"@nomicfoundation/edr-linux-arm64-musl": "0.5.2",
|
|
54
|
+
"@nomicfoundation/edr-linux-x64-gnu": "0.5.2",
|
|
55
|
+
"@nomicfoundation/edr-linux-x64-musl": "0.5.2",
|
|
56
|
+
"@nomicfoundation/edr-win32-x64-msvc": "0.5.2"
|
|
56
57
|
},
|
|
57
58
|
"scripts": {
|
|
58
59
|
"artifacts": "napi artifacts",
|
|
@@ -63,8 +64,8 @@
|
|
|
63
64
|
"universal": "napi universal",
|
|
64
65
|
"version": "napi version",
|
|
65
66
|
"pretest": "pnpm build",
|
|
66
|
-
"test": "pnpm tsc && mocha --recursive \"test/**/*.ts\"",
|
|
67
|
-
"testNoBuild": "pnpm tsc && mocha --recursive \"test/**/*.ts\"",
|
|
67
|
+
"test": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"",
|
|
68
|
+
"testNoBuild": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"",
|
|
68
69
|
"clean": "rm -rf @nomicfoundation/edr.node"
|
|
69
70
|
}
|
|
70
71
|
}
|
package/src/provider.rs
CHANGED
|
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
|
|
4
4
|
|
|
5
5
|
use edr_provider::{time::CurrentTime, InvalidRequestReason};
|
|
6
6
|
use edr_rpc_eth::jsonrpc;
|
|
7
|
-
use napi::{tokio::runtime, Env, JsFunction, JsObject, Status};
|
|
7
|
+
use napi::{tokio::runtime, Either, Env, JsFunction, JsObject, Status};
|
|
8
8
|
use napi_derive::napi;
|
|
9
9
|
|
|
10
10
|
use self::config::ProviderConfig;
|
|
@@ -120,9 +120,9 @@ impl Provider {
|
|
|
120
120
|
format!("Invalid JSON `{json_request}` due to: {error}"),
|
|
121
121
|
)
|
|
122
122
|
})
|
|
123
|
-
.map(|
|
|
123
|
+
.map(|json| Response {
|
|
124
124
|
solidity_trace: None,
|
|
125
|
-
|
|
125
|
+
data: Either::A(json),
|
|
126
126
|
traces: Vec::new(),
|
|
127
127
|
});
|
|
128
128
|
}
|
|
@@ -168,10 +168,25 @@ impl Provider {
|
|
|
168
168
|
let response = jsonrpc::ResponseData::from(response.map(|response| response.result));
|
|
169
169
|
|
|
170
170
|
serde_json::to_string(&response)
|
|
171
|
-
.
|
|
172
|
-
|
|
171
|
+
.and_then(|json| {
|
|
172
|
+
// We experimentally determined that 500_000_000 was the maximum string length
|
|
173
|
+
// that can be returned without causing the error:
|
|
174
|
+
//
|
|
175
|
+
// > Failed to convert rust `String` into napi `string`
|
|
176
|
+
//
|
|
177
|
+
// To be safe, we're limiting string lengths to half of that.
|
|
178
|
+
const MAX_STRING_LENGTH: usize = 250_000_000;
|
|
179
|
+
|
|
180
|
+
if json.len() <= MAX_STRING_LENGTH {
|
|
181
|
+
Ok(Either::A(json))
|
|
182
|
+
} else {
|
|
183
|
+
serde_json::to_value(response).map(Either::B)
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
.map_err(|error| napi::Error::new(Status::GenericFailure, error.to_string()))
|
|
187
|
+
.map(|data| Response {
|
|
173
188
|
solidity_trace,
|
|
174
|
-
|
|
189
|
+
data,
|
|
175
190
|
traces: traces.into_iter().map(Arc::new).collect(),
|
|
176
191
|
})
|
|
177
192
|
}
|
|
@@ -209,7 +224,10 @@ impl Provider {
|
|
|
209
224
|
|
|
210
225
|
#[napi]
|
|
211
226
|
pub struct Response {
|
|
212
|
-
|
|
227
|
+
// N-API is known to be slow when marshalling `serde_json::Value`s, so we try to return a
|
|
228
|
+
// `String`. If the object is too large to be represented as a `String`, we return a `Buffer`
|
|
229
|
+
// instead.
|
|
230
|
+
data: Either<String, serde_json::Value>,
|
|
213
231
|
/// When a transaction fails to execute, the provider returns a trace of the
|
|
214
232
|
/// transaction.
|
|
215
233
|
solidity_trace: Option<Arc<edr_evm::trace::Trace>>,
|
|
@@ -219,9 +237,16 @@ pub struct Response {
|
|
|
219
237
|
|
|
220
238
|
#[napi]
|
|
221
239
|
impl Response {
|
|
240
|
+
/// Returns the response data as a JSON string or a JSON object.
|
|
241
|
+
#[napi(getter)]
|
|
242
|
+
pub fn data(&self) -> Either<String, serde_json::Value> {
|
|
243
|
+
self.data.clone()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Temporary alias for data to prevent breaking change
|
|
222
247
|
#[napi(getter)]
|
|
223
|
-
pub fn json(&self) -> String {
|
|
224
|
-
self.
|
|
248
|
+
pub fn json(&self) -> Either<String, serde_json::Value> {
|
|
249
|
+
self.data.clone()
|
|
225
250
|
}
|
|
226
251
|
|
|
227
252
|
#[napi(getter)]
|