@nomicfoundation/edr 0.3.7 → 0.3.8
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/LICENSE +21 -1
- package/package.json +14 -10
- package/src/call_override.rs +21 -11
- package/src/logger.rs +15 -7
- package/src/provider.rs +5 -2
- package/src/trace.rs +2 -4
package/LICENSE
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Nomic Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomicfoundation/edr",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -17,11 +17,15 @@
|
|
|
17
17
|
"napi": {
|
|
18
18
|
"name": "edr",
|
|
19
19
|
"triples": {
|
|
20
|
+
"defaults": false,
|
|
20
21
|
"additional": [
|
|
21
22
|
"aarch64-apple-darwin",
|
|
23
|
+
"x86_64-apple-darwin",
|
|
22
24
|
"aarch64-unknown-linux-gnu",
|
|
23
25
|
"aarch64-unknown-linux-musl",
|
|
24
|
-
"x86_64-unknown-linux-
|
|
26
|
+
"x86_64-unknown-linux-gnu",
|
|
27
|
+
"x86_64-unknown-linux-musl",
|
|
28
|
+
"x86_64-pc-windows-msvc"
|
|
25
29
|
]
|
|
26
30
|
}
|
|
27
31
|
},
|
|
@@ -41,14 +45,14 @@
|
|
|
41
45
|
"engines": {
|
|
42
46
|
"node": ">= 18"
|
|
43
47
|
},
|
|
44
|
-
"
|
|
45
|
-
"@nomicfoundation/edr-
|
|
46
|
-
"@nomicfoundation/edr-darwin-x64": "0.3.
|
|
47
|
-
"@nomicfoundation/edr-linux-
|
|
48
|
-
"@nomicfoundation/edr-
|
|
49
|
-
"@nomicfoundation/edr-linux-
|
|
50
|
-
"@nomicfoundation/edr-linux-
|
|
51
|
-
"@nomicfoundation/edr-
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@nomicfoundation/edr-darwin-arm64": "0.3.8",
|
|
50
|
+
"@nomicfoundation/edr-darwin-x64": "0.3.8",
|
|
51
|
+
"@nomicfoundation/edr-linux-arm64-gnu": "0.3.8",
|
|
52
|
+
"@nomicfoundation/edr-linux-arm64-musl": "0.3.8",
|
|
53
|
+
"@nomicfoundation/edr-linux-x64-gnu": "0.3.8",
|
|
54
|
+
"@nomicfoundation/edr-linux-x64-musl": "0.3.8",
|
|
55
|
+
"@nomicfoundation/edr-win32-x64-msvc": "0.3.8"
|
|
52
56
|
},
|
|
53
57
|
"scripts": {
|
|
54
58
|
"artifacts": "napi artifacts",
|
package/src/call_override.rs
CHANGED
|
@@ -2,10 +2,11 @@ use std::sync::mpsc::channel;
|
|
|
2
2
|
|
|
3
3
|
use edr_eth::{Address, Bytes};
|
|
4
4
|
use napi::{
|
|
5
|
-
bindgen_prelude::Buffer,
|
|
5
|
+
bindgen_prelude::{Buffer, Promise},
|
|
6
6
|
threadsafe_function::{
|
|
7
7
|
ErrorStrategy, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
|
|
8
8
|
},
|
|
9
|
+
tokio::runtime,
|
|
9
10
|
Env, JsFunction, Status,
|
|
10
11
|
};
|
|
11
12
|
use napi_derive::napi;
|
|
@@ -41,10 +42,15 @@ struct CallOverrideCall {
|
|
|
41
42
|
#[derive(Clone)]
|
|
42
43
|
pub struct CallOverrideCallback {
|
|
43
44
|
call_override_callback_fn: ThreadsafeFunction<CallOverrideCall, ErrorStrategy::Fatal>,
|
|
45
|
+
runtime: runtime::Handle,
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
impl CallOverrideCallback {
|
|
47
|
-
pub fn new(
|
|
49
|
+
pub fn new(
|
|
50
|
+
env: &Env,
|
|
51
|
+
call_override_callback: JsFunction,
|
|
52
|
+
runtime: runtime::Handle,
|
|
53
|
+
) -> napi::Result<Self> {
|
|
48
54
|
let mut call_override_callback_fn = call_override_callback.create_threadsafe_function(
|
|
49
55
|
0,
|
|
50
56
|
|ctx: ThreadSafeCallContext<CallOverrideCall>| {
|
|
@@ -68,6 +74,7 @@ impl CallOverrideCallback {
|
|
|
68
74
|
|
|
69
75
|
Ok(Self {
|
|
70
76
|
call_override_callback_fn,
|
|
77
|
+
runtime,
|
|
71
78
|
})
|
|
72
79
|
}
|
|
73
80
|
|
|
@@ -78,21 +85,24 @@ impl CallOverrideCallback {
|
|
|
78
85
|
) -> Option<edr_provider::CallOverrideResult> {
|
|
79
86
|
let (sender, receiver) = channel();
|
|
80
87
|
|
|
88
|
+
let runtime = self.runtime.clone();
|
|
81
89
|
let status = self.call_override_callback_fn.call_with_return_value(
|
|
82
90
|
CallOverrideCall {
|
|
83
91
|
contract_address,
|
|
84
92
|
data,
|
|
85
93
|
},
|
|
86
94
|
ThreadsafeFunctionCallMode::Blocking,
|
|
87
|
-
move |result: Option<CallOverrideResult
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
move |result: Promise<Option<CallOverrideResult>>| {
|
|
96
|
+
runtime.spawn(async move {
|
|
97
|
+
let result = result.await?.try_cast();
|
|
98
|
+
sender.send(result).map_err(|_error| {
|
|
99
|
+
napi::Error::new(
|
|
100
|
+
Status::GenericFailure,
|
|
101
|
+
"Failed to send result from call_override_callback",
|
|
102
|
+
)
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
Ok(())
|
|
96
106
|
},
|
|
97
107
|
);
|
|
98
108
|
|
package/src/logger.rs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
use std::{fmt::Display, sync::mpsc::channel};
|
|
2
2
|
|
|
3
3
|
use ansi_term::{Color, Style};
|
|
4
|
-
use edr_eth::{Bytes, B256, U256};
|
|
4
|
+
use edr_eth::{transaction::Transaction, Bytes, B256, U256};
|
|
5
5
|
use edr_evm::{
|
|
6
6
|
blockchain::BlockchainError,
|
|
7
7
|
precompile::{self, Precompiles},
|
|
@@ -506,7 +506,7 @@ impl LogCollector {
|
|
|
506
506
|
result.transaction_traces.iter()
|
|
507
507
|
)
|
|
508
508
|
.find(|(block_transaction, _, _)| {
|
|
509
|
-
*block_transaction.
|
|
509
|
+
*block_transaction.transaction_hash() == *transaction.transaction_hash()
|
|
510
510
|
})
|
|
511
511
|
.map(|(_, transaction_result, trace)| (result, transaction_result, trace))
|
|
512
512
|
})
|
|
@@ -514,7 +514,11 @@ impl LogCollector {
|
|
|
514
514
|
|
|
515
515
|
if mining_results.len() > 1 {
|
|
516
516
|
self.log_multiple_blocks_warning();
|
|
517
|
-
self.log_auto_mined_block_results(
|
|
517
|
+
self.log_auto_mined_block_results(
|
|
518
|
+
spec_id,
|
|
519
|
+
mining_results,
|
|
520
|
+
transaction.transaction_hash(),
|
|
521
|
+
);
|
|
518
522
|
self.log_currently_sent_transaction(
|
|
519
523
|
spec_id,
|
|
520
524
|
sent_block_result,
|
|
@@ -526,7 +530,11 @@ impl LogCollector {
|
|
|
526
530
|
let transactions = result.block.transactions();
|
|
527
531
|
if transactions.len() > 1 {
|
|
528
532
|
self.log_multiple_transactions_warning();
|
|
529
|
-
self.log_auto_mined_block_results(
|
|
533
|
+
self.log_auto_mined_block_results(
|
|
534
|
+
spec_id,
|
|
535
|
+
mining_results,
|
|
536
|
+
transaction.transaction_hash(),
|
|
537
|
+
);
|
|
530
538
|
self.log_currently_sent_transaction(
|
|
531
539
|
spec_id,
|
|
532
540
|
sent_block_result,
|
|
@@ -659,7 +667,7 @@ impl LogCollector {
|
|
|
659
667
|
transaction_traces
|
|
660
668
|
) {
|
|
661
669
|
let should_highlight_hash =
|
|
662
|
-
*transaction.
|
|
670
|
+
*transaction.transaction_hash() == *transaction_hash_to_highlight;
|
|
663
671
|
logger.log_block_transaction(
|
|
664
672
|
spec_id,
|
|
665
673
|
transaction,
|
|
@@ -706,7 +714,7 @@ impl LogCollector {
|
|
|
706
714
|
console_log_inputs: &[Bytes],
|
|
707
715
|
should_highlight_hash: bool,
|
|
708
716
|
) {
|
|
709
|
-
let transaction_hash = transaction.
|
|
717
|
+
let transaction_hash = transaction.transaction_hash();
|
|
710
718
|
if should_highlight_hash {
|
|
711
719
|
self.log_with_title(
|
|
712
720
|
"Transaction",
|
|
@@ -1090,7 +1098,7 @@ impl LogCollector {
|
|
|
1090
1098
|
self.indented(|logger| {
|
|
1091
1099
|
logger.log_contract_and_function_name::<false>(spec_id, trace);
|
|
1092
1100
|
|
|
1093
|
-
let transaction_hash = transaction.
|
|
1101
|
+
let transaction_hash = transaction.transaction_hash();
|
|
1094
1102
|
logger.log_with_title("Transaction", transaction_hash);
|
|
1095
1103
|
|
|
1096
1104
|
logger.log_with_title("From", format!("0x{:x}", transaction.caller()));
|
package/src/provider.rs
CHANGED
|
@@ -20,6 +20,7 @@ use crate::{
|
|
|
20
20
|
#[napi]
|
|
21
21
|
pub struct Provider {
|
|
22
22
|
provider: Arc<edr_provider::Provider<LoggerError>>,
|
|
23
|
+
runtime: runtime::Handle,
|
|
23
24
|
#[cfg(feature = "scenarios")]
|
|
24
25
|
scenario_file: Option<napi::tokio::sync::Mutex<napi::tokio::fs::File>>,
|
|
25
26
|
}
|
|
@@ -53,7 +54,7 @@ impl Provider {
|
|
|
53
54
|
))?;
|
|
54
55
|
|
|
55
56
|
let result = edr_provider::Provider::new(
|
|
56
|
-
runtime,
|
|
57
|
+
runtime.clone(),
|
|
57
58
|
logger,
|
|
58
59
|
subscriber_callback,
|
|
59
60
|
config,
|
|
@@ -64,6 +65,7 @@ impl Provider {
|
|
|
64
65
|
|provider| {
|
|
65
66
|
Ok(Provider {
|
|
66
67
|
provider: Arc::new(provider),
|
|
68
|
+
runtime,
|
|
67
69
|
#[cfg(feature = "scenarios")]
|
|
68
70
|
scenario_file,
|
|
69
71
|
})
|
|
@@ -185,7 +187,8 @@ impl Provider {
|
|
|
185
187
|
) -> napi::Result<()> {
|
|
186
188
|
let provider = self.provider.clone();
|
|
187
189
|
|
|
188
|
-
let call_override_callback =
|
|
190
|
+
let call_override_callback =
|
|
191
|
+
CallOverrideCallback::new(&env, call_override_callback, self.runtime.clone())?;
|
|
189
192
|
let call_override_callback =
|
|
190
193
|
Arc::new(move |address, data| call_override_callback.call_override(address, data));
|
|
191
194
|
|
package/src/trace.rs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
use std::sync::Arc;
|
|
2
2
|
|
|
3
|
-
use edr_evm::{interpreter::
|
|
3
|
+
use edr_evm::{interpreter::OpCode, trace::BeforeMessage};
|
|
4
4
|
use napi::{
|
|
5
5
|
bindgen_prelude::{BigInt, Buffer, Either3},
|
|
6
6
|
Env, JsBuffer, JsBufferValue,
|
|
@@ -96,9 +96,7 @@ impl TracingStep {
|
|
|
96
96
|
Self {
|
|
97
97
|
depth: step.depth as u8,
|
|
98
98
|
pc: BigInt::from(step.pc),
|
|
99
|
-
opcode:
|
|
100
|
-
.unwrap_or("")
|
|
101
|
-
.to_string(),
|
|
99
|
+
opcode: OpCode::name_by_op(step.opcode).to_string(),
|
|
102
100
|
stack_top: step.stack_top.map(|v| BigInt {
|
|
103
101
|
sign_bit: false,
|
|
104
102
|
words: v.into_limbs().to_vec(),
|