@nomicfoundation/edr 0.12.0-next.9 → 0.12.1

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.
Files changed (52) hide show
  1. package/coverage.sol +38 -0
  2. package/dist/src/ts/coverage.d.ts +6 -0
  3. package/dist/src/ts/coverage.d.ts.map +1 -0
  4. package/dist/src/ts/coverage.js +51 -0
  5. package/dist/src/ts/coverage.js.map +1 -0
  6. package/index.d.ts +286 -27
  7. package/index.js +6 -2
  8. package/package.json +21 -19
  9. package/src/account.rs +0 -124
  10. package/src/block.rs +0 -28
  11. package/src/call_override.rs +0 -116
  12. package/src/cast.rs +0 -165
  13. package/src/chains/generic.rs +0 -58
  14. package/src/chains/l1.rs +0 -268
  15. package/src/chains/op.rs +0 -424
  16. package/src/chains.rs +0 -7
  17. package/src/config.rs +0 -700
  18. package/src/context.rs +0 -447
  19. package/src/contract_decoder.rs +0 -57
  20. package/src/debug_trace.rs +0 -40
  21. package/src/gas_report.rs +0 -92
  22. package/src/instrument.rs +0 -109
  23. package/src/lib.rs +0 -50
  24. package/src/log.rs +0 -28
  25. package/src/logger.rs +0 -120
  26. package/src/mock/time.rs +0 -134
  27. package/src/mock.rs +0 -71
  28. package/src/precompile.rs +0 -50
  29. package/src/provider/factory.rs +0 -22
  30. package/src/provider/response.rs +0 -73
  31. package/src/provider.rs +0 -162
  32. package/src/result.rs +0 -212
  33. package/src/scenarios.rs +0 -53
  34. package/src/serde.rs +0 -57
  35. package/src/solidity_tests/artifact.rs +0 -184
  36. package/src/solidity_tests/config.rs +0 -793
  37. package/src/solidity_tests/factory.rs +0 -22
  38. package/src/solidity_tests/l1.rs +0 -68
  39. package/src/solidity_tests/op.rs +0 -69
  40. package/src/solidity_tests/runner.rs +0 -51
  41. package/src/solidity_tests/test_results.rs +0 -736
  42. package/src/solidity_tests.rs +0 -56
  43. package/src/subscription.rs +0 -32
  44. package/src/trace/debug.rs +0 -61
  45. package/src/trace/exit.rs +0 -89
  46. package/src/trace/library_utils.rs +0 -11
  47. package/src/trace/model.rs +0 -59
  48. package/src/trace/return_data.rs +0 -96
  49. package/src/trace/solidity_stack_trace.rs +0 -869
  50. package/src/trace.rs +0 -199
  51. package/src/ts/solidity_tests.ts +0 -46
  52. package/src/withdrawal.rs +0 -49
package/src/config.rs DELETED
@@ -1,700 +0,0 @@
1
- use core::fmt::{Debug, Display};
2
- use std::{
3
- num::NonZeroU64,
4
- path::PathBuf,
5
- time::{Duration, SystemTime},
6
- };
7
-
8
- use edr_coverage::reporter::SyncOnCollectedCoverageCallback;
9
- use edr_eip1559::{BaseFeeActivation, ConstantBaseFeeParams};
10
- use edr_gas_report::SyncOnCollectedGasReportCallback;
11
- use edr_primitives::{Bytes, HashMap, HashSet};
12
- use edr_signer::{secret_key_from_str, SecretKey};
13
- use napi::{
14
- bindgen_prelude::{BigInt, Promise, Reference, Uint8Array},
15
- threadsafe_function::{
16
- ErrorStrategy, ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode,
17
- },
18
- tokio::runtime,
19
- Either, JsFunction, JsString, JsStringUtf8,
20
- };
21
- use napi_derive::napi;
22
-
23
- use crate::{
24
- account::AccountOverride, block::BlobGas, cast::TryCast, gas_report::GasReport,
25
- logger::LoggerConfig, precompile::Precompile, subscription::SubscriptionConfig,
26
- };
27
-
28
- /// Configuration for EIP-1559 parameters
29
- #[napi(object)]
30
- pub struct BaseFeeParamActivation {
31
- pub activation: Either<BaseFeeActivationByBlockNumber, BaseFeeActivationByHardfork>,
32
- pub max_change_denominator: BigInt,
33
- pub elasticity_multiplier: BigInt,
34
- }
35
-
36
- #[napi(object)]
37
- pub struct BaseFeeActivationByBlockNumber {
38
- /// The block number at which the `base_fee_params` is activated
39
- pub block_number: BigInt,
40
- }
41
- #[napi(object)]
42
- pub struct BaseFeeActivationByHardfork {
43
- /// The hardfork at which the `base_fee_params` is activated
44
- pub hardfork: String,
45
- }
46
-
47
- impl TryFrom<BaseFeeParamActivation> for (BaseFeeActivation<String>, ConstantBaseFeeParams) {
48
- type Error = napi::Error;
49
-
50
- fn try_from(value: BaseFeeParamActivation) -> Result<Self, Self::Error> {
51
- let base_fee_params = ConstantBaseFeeParams {
52
- max_change_denominator: value.max_change_denominator.try_cast()?,
53
- elasticity_multiplier: value.elasticity_multiplier.try_cast()?,
54
- };
55
-
56
- match value.activation {
57
- Either::A(BaseFeeActivationByBlockNumber { block_number }) => {
58
- let activation_block_number: u64 = block_number.try_cast()?;
59
- Ok((
60
- BaseFeeActivation::BlockNumber(activation_block_number),
61
- base_fee_params,
62
- ))
63
- }
64
- Either::B(BaseFeeActivationByHardfork { hardfork }) => {
65
- Ok((BaseFeeActivation::Hardfork(hardfork), base_fee_params))
66
- }
67
- }
68
- }
69
- }
70
-
71
- /// Specification of a chain with possible overrides.
72
- #[napi(object)]
73
- pub struct ChainOverride {
74
- /// The chain ID
75
- pub chain_id: BigInt,
76
- /// The chain's name
77
- pub name: String,
78
- /// If present, overrides for the chain's supported hardforks
79
- pub hardfork_activation_overrides: Option<Vec<HardforkActivation>>,
80
- }
81
-
82
- /// Configuration for a code coverage reporter.
83
- #[napi(object)]
84
- pub struct CodeCoverageConfig {
85
- /// The callback to be called when coverage has been collected.
86
- ///
87
- /// The callback receives an array of unique coverage hit markers (i.e. no
88
- /// repetition) per transaction.
89
- ///
90
- /// Exceptions thrown in the callback will be propagated to the original
91
- /// caller.
92
- #[napi(ts_type = "(coverageHits: Uint8Array[]) => Promise<void>")]
93
- pub on_collected_coverage_callback: JsFunction,
94
- }
95
-
96
- #[napi(object)]
97
- pub struct GasReportConfig {
98
- /// Gas reports are collected after a block is mined or `eth_call` is
99
- /// executed.
100
- ///
101
- /// Exceptions thrown in the callback will be propagated to the original
102
- /// caller.
103
- #[napi(ts_type = "(gasReport: GasReport) => Promise<void>")]
104
- pub on_collected_gas_report_callback: JsFunction,
105
- }
106
-
107
- /// Configuration for forking a blockchain
108
- #[napi(object)]
109
- pub struct ForkConfig {
110
- /// The block number to fork from. If not provided, the latest safe block is
111
- /// used.
112
- pub block_number: Option<BigInt>,
113
- /// The directory to cache remote JSON-RPC responses
114
- pub cache_dir: Option<String>,
115
- /// Overrides for the configuration of chains.
116
- pub chain_overrides: Option<Vec<ChainOverride>>,
117
- /// The HTTP headers to use when making requests to the JSON-RPC endpoint
118
- pub http_headers: Option<Vec<HttpHeader>>,
119
- /// The URL of the JSON-RPC endpoint to fork from
120
- pub url: String,
121
- }
122
-
123
- #[napi(object)]
124
- pub struct HttpHeader {
125
- pub name: String,
126
- pub value: String,
127
- }
128
-
129
- /// Configuration for a hardfork activation
130
- #[napi(object)]
131
- pub struct HardforkActivation {
132
- /// The condition for the hardfork activation
133
- pub condition: Either<HardforkActivationByBlockNumber, HardforkActivationByTimestamp>,
134
- /// The activated hardfork
135
- pub hardfork: String,
136
- }
137
-
138
- #[napi(object)]
139
- pub struct HardforkActivationByBlockNumber {
140
- /// The block number at which the hardfork is activated
141
- pub block_number: BigInt,
142
- }
143
-
144
- #[napi(object)]
145
- pub struct HardforkActivationByTimestamp {
146
- /// The timestamp at which the hardfork is activated
147
- pub timestamp: BigInt,
148
- }
149
-
150
- #[napi(string_enum)]
151
- #[doc = "The type of ordering to use when selecting blocks to mine."]
152
- pub enum MineOrdering {
153
- #[doc = "Insertion order"]
154
- Fifo,
155
- #[doc = "Effective miner fee"]
156
- Priority,
157
- }
158
-
159
- /// Configuration for the provider's mempool.
160
- #[napi(object)]
161
- pub struct MemPoolConfig {
162
- pub order: MineOrdering,
163
- }
164
-
165
- #[napi(object)]
166
- pub struct IntervalRange {
167
- pub min: BigInt,
168
- pub max: BigInt,
169
- }
170
-
171
- /// Configuration for the provider's miner.
172
- #[napi(object)]
173
- pub struct MiningConfig {
174
- pub auto_mine: bool,
175
- pub interval: Option<Either<BigInt, IntervalRange>>,
176
- pub mem_pool: MemPoolConfig,
177
- }
178
-
179
- /// Configuration for runtime observability.
180
- #[napi(object)]
181
- pub struct ObservabilityConfig {
182
- /// If present, configures runtime observability to collect code coverage.
183
- pub code_coverage: Option<CodeCoverageConfig>,
184
- /// If present, configures runtime observability to collect gas reports.
185
- pub gas_report: Option<GasReportConfig>,
186
- }
187
-
188
- /// Configuration for a provider
189
- #[napi(object)]
190
- pub struct ProviderConfig {
191
- /// Whether to allow blocks with the same timestamp
192
- pub allow_blocks_with_same_timestamp: bool,
193
- /// Whether to allow unlimited contract size
194
- pub allow_unlimited_contract_size: bool,
195
- /// Whether to return an `Err` when `eth_call` fails
196
- pub bail_on_call_failure: bool,
197
- /// Whether to return an `Err` when a `eth_sendTransaction` fails
198
- pub bail_on_transaction_failure: bool,
199
- /// EIP-1559 base fee parameters activations to be used to calculate the
200
- /// block base fee.
201
- ///
202
- /// Provide an ordered list of `base_fee_params` to be
203
- /// used starting from the specified activation point (hardfork or block
204
- /// number).
205
- /// If not provided, the default values from the chain spec
206
- /// will be used.
207
- pub base_fee_config: Option<Vec<BaseFeeParamActivation>>,
208
- /// The gas limit of each block
209
- pub block_gas_limit: BigInt,
210
- /// The chain ID of the blockchain
211
- pub chain_id: BigInt,
212
- /// The address of the coinbase
213
- pub coinbase: Uint8Array,
214
- /// The configuration for forking a blockchain. If not provided, a local
215
- /// blockchain will be created
216
- pub fork: Option<ForkConfig>,
217
- /// The genesis state of the blockchain
218
- pub genesis_state: Vec<AccountOverride>,
219
- /// The hardfork of the blockchain
220
- pub hardfork: String,
221
- /// The initial base fee per gas of the blockchain. Required for EIP-1559
222
- /// transactions and later
223
- pub initial_base_fee_per_gas: Option<BigInt>,
224
- /// The initial blob gas of the blockchain. Required for EIP-4844
225
- pub initial_blob_gas: Option<BlobGas>,
226
- /// The initial date of the blockchain, in seconds since the Unix epoch
227
- pub initial_date: Option<BigInt>,
228
- /// The initial parent beacon block root of the blockchain. Required for
229
- /// EIP-4788
230
- pub initial_parent_beacon_block_root: Option<Uint8Array>,
231
- /// The minimum gas price of the next block.
232
- pub min_gas_price: BigInt,
233
- /// The configuration for the miner
234
- pub mining: MiningConfig,
235
- /// The network ID of the blockchain
236
- pub network_id: BigInt,
237
- /// The configuration for the provider's observability
238
- pub observability: ObservabilityConfig,
239
- // Using JsString here as it doesn't have `Debug`, `Display` and `Serialize` implementation
240
- // which prevents accidentally leaking the secret keys to error messages and logs.
241
- /// Secret keys of owned accounts
242
- pub owned_accounts: Vec<JsString>,
243
- /// Overrides for precompiles
244
- pub precompile_overrides: Vec<Reference<Precompile>>,
245
- }
246
-
247
- impl TryFrom<ForkConfig> for edr_provider::ForkConfig<String> {
248
- type Error = napi::Error;
249
-
250
- fn try_from(value: ForkConfig) -> Result<Self, Self::Error> {
251
- let block_number: Option<u64> = value.block_number.map(TryCast::try_cast).transpose()?;
252
-
253
- let cache_dir = PathBuf::from(
254
- value
255
- .cache_dir
256
- .unwrap_or(edr_defaults::CACHE_DIR.to_owned()),
257
- );
258
-
259
- let chain_overrides = value
260
- .chain_overrides
261
- .map(|chain_overrides| {
262
- chain_overrides
263
- .into_iter()
264
- .map(
265
- |ChainOverride {
266
- chain_id,
267
- name,
268
- hardfork_activation_overrides,
269
- }| {
270
- let hardfork_activation_overrides =
271
- hardfork_activation_overrides
272
- .map(|hardfork_activations| {
273
- hardfork_activations
274
- .into_iter()
275
- .map(
276
- |HardforkActivation {
277
- condition,
278
- hardfork,
279
- }| {
280
- let condition = match condition {
281
- Either::A(HardforkActivationByBlockNumber {
282
- block_number,
283
- }) => edr_evm::hardfork::ForkCondition::Block(
284
- block_number.try_cast()?,
285
- ),
286
- Either::B(HardforkActivationByTimestamp {
287
- timestamp,
288
- }) => edr_evm::hardfork::ForkCondition::Timestamp(
289
- timestamp.try_cast()?,
290
- ),
291
- };
292
-
293
- Ok(edr_evm::hardfork::Activation {
294
- condition,
295
- hardfork,
296
- })
297
- },
298
- )
299
- .collect::<napi::Result<Vec<_>>>()
300
- .map(edr_evm::hardfork::Activations::new)
301
- })
302
- .transpose()?;
303
-
304
- let chain_config = edr_evm::hardfork::ChainOverride {
305
- name,
306
- hardfork_activation_overrides,
307
- };
308
-
309
- let chain_id = chain_id.try_cast()?;
310
- Ok((chain_id, chain_config))
311
- },
312
- )
313
- .collect::<napi::Result<_>>()
314
- })
315
- .transpose()?;
316
-
317
- let http_headers = value.http_headers.map(|http_headers| {
318
- http_headers
319
- .into_iter()
320
- .map(|HttpHeader { name, value }| (name, value))
321
- .collect()
322
- });
323
-
324
- Ok(Self {
325
- block_number,
326
- cache_dir,
327
- chain_overrides: chain_overrides.unwrap_or_default(),
328
- http_headers,
329
- url: value.url,
330
- })
331
- }
332
- }
333
-
334
- impl From<MemPoolConfig> for edr_provider::MemPoolConfig {
335
- fn from(value: MemPoolConfig) -> Self {
336
- Self {
337
- order: value.order.into(),
338
- }
339
- }
340
- }
341
-
342
- impl From<MineOrdering> for edr_evm::MineOrdering {
343
- fn from(value: MineOrdering) -> Self {
344
- match value {
345
- MineOrdering::Fifo => Self::Fifo,
346
- MineOrdering::Priority => Self::Priority,
347
- }
348
- }
349
- }
350
-
351
- impl TryFrom<MiningConfig> for edr_provider::MiningConfig {
352
- type Error = napi::Error;
353
-
354
- fn try_from(value: MiningConfig) -> Result<Self, Self::Error> {
355
- let mem_pool = value.mem_pool.into();
356
-
357
- let interval = value
358
- .interval
359
- .map(|interval| {
360
- let interval = match interval {
361
- Either::A(interval) => {
362
- let interval = interval.try_cast()?;
363
- let interval = NonZeroU64::new(interval).ok_or_else(|| {
364
- napi::Error::new(
365
- napi::Status::GenericFailure,
366
- "Interval must be greater than 0",
367
- )
368
- })?;
369
-
370
- edr_provider::IntervalConfig::Fixed(interval)
371
- }
372
- Either::B(IntervalRange { min, max }) => edr_provider::IntervalConfig::Range {
373
- min: min.try_cast()?,
374
- max: max.try_cast()?,
375
- },
376
- };
377
-
378
- napi::Result::Ok(interval)
379
- })
380
- .transpose()?;
381
-
382
- Ok(Self {
383
- auto_mine: value.auto_mine,
384
- interval,
385
- mem_pool,
386
- })
387
- }
388
- }
389
-
390
- impl ObservabilityConfig {
391
- /// Resolves the instance, converting it to a
392
- /// [`edr_provider::observability::Config`].
393
- pub fn resolve(
394
- self,
395
- env: &napi::Env,
396
- runtime: runtime::Handle,
397
- ) -> napi::Result<edr_provider::observability::Config> {
398
- let on_collected_coverage_fn = self
399
- .code_coverage
400
- .map(
401
- |code_coverage| -> napi::Result<Box<dyn SyncOnCollectedCoverageCallback>> {
402
- let runtime = runtime.clone();
403
-
404
- let mut on_collected_coverage_callback: ThreadsafeFunction<
405
- _,
406
- ErrorStrategy::Fatal,
407
- > = code_coverage
408
- .on_collected_coverage_callback
409
- .create_threadsafe_function(
410
- 0,
411
- |ctx: ThreadSafeCallContext<HashSet<Bytes>>| {
412
- let hits = ctx
413
- .env
414
- .create_array_with_length(ctx.value.len())
415
- .and_then(|mut hits| {
416
- for (idx, hit) in ctx.value.into_iter().enumerate() {
417
- ctx.env
418
- .create_buffer_with_data(hit.to_vec())
419
- .and_then(|hit| {
420
- let idx = u32::try_from(idx).unwrap_or_else(|_| panic!("Number of hits should not exceed '{}'",
421
- u32::MAX));
422
-
423
- hits.set_element(idx, hit.into_raw())
424
- })?;
425
- }
426
- Ok(hits)
427
- })?;
428
-
429
- Ok(vec![hits])
430
- },
431
- )?;
432
-
433
- // Maintain a weak reference to the function to avoid blocking the event loop
434
- // from exiting.
435
- on_collected_coverage_callback.unref(env)?;
436
-
437
- let on_collected_coverage_fn: Box<dyn SyncOnCollectedCoverageCallback> =
438
- Box::new(move |hits| {
439
- let runtime = runtime.clone();
440
-
441
- let (sender, receiver) = std::sync::mpsc::channel();
442
-
443
- let status = on_collected_coverage_callback
444
- .call_with_return_value(hits, ThreadsafeFunctionCallMode::Blocking, move |result: Promise<()>| {
445
- // We spawn a background task to handle the async callback
446
- runtime.spawn(async move {
447
- let result = result.await;
448
- sender.send(result).map_err(|_error| {
449
- napi::Error::new(
450
- napi::Status::GenericFailure,
451
- "Failed to send result from on_collected_coverage_callback",
452
- )
453
- })
454
- });
455
- Ok(())
456
- });
457
-
458
- assert_eq!(status, napi::Status::Ok);
459
-
460
- let () = receiver.recv().expect("Receive can only fail if the channel is closed")?;
461
-
462
- Ok(())
463
- });
464
-
465
- Ok(on_collected_coverage_fn)
466
- },
467
- )
468
- .transpose()?;
469
- let on_collected_gas_report_fn = self.gas_report.map(
470
- |gas_report| -> napi::Result<Box<dyn SyncOnCollectedGasReportCallback>> {
471
- let mut on_collected_gas_report_callback: ThreadsafeFunction<
472
- _,
473
- ErrorStrategy::Fatal,
474
- > = gas_report
475
- .on_collected_gas_report_callback
476
- .create_threadsafe_function(
477
- 0,
478
- |ctx: ThreadSafeCallContext<GasReport>| {
479
- let report = ctx.value;
480
- Ok(vec![report])
481
- }
482
- ,
483
- )?;
484
- // Maintain a weak reference to the function to avoid blocking the event loop
485
- // from exiting.
486
- on_collected_gas_report_callback.unref(env)?;
487
-
488
- let on_collected_gas_report_fn: Box<dyn SyncOnCollectedGasReportCallback> =
489
- Box::new(move |report| {
490
- let runtime = runtime.clone();
491
-
492
- let (sender, receiver) = std::sync::mpsc::channel();
493
-
494
- // Convert the report to the N-API representation
495
- let status = on_collected_gas_report_callback
496
- .call_with_return_value(GasReport::from(report), ThreadsafeFunctionCallMode::Blocking, move |result: Promise<()>| {
497
- // We spawn a background task to handle the async callback
498
- runtime.spawn(async move {
499
- let result = result.await;
500
- sender.send(result).map_err(|_error| {
501
- napi::Error::new(
502
- napi::Status::GenericFailure,
503
- "Failed to send result from on_collected_gas_report_callback",
504
- )
505
- })
506
- });
507
- Ok(())
508
- });
509
-
510
- assert_eq!(status, napi::Status::Ok);
511
-
512
- let () = receiver.recv().expect("Receive can only fail if the channel is closed")?;
513
-
514
- Ok(())
515
- });
516
-
517
- Ok(on_collected_gas_report_fn)
518
- },
519
- ).transpose()?;
520
-
521
- Ok(edr_provider::observability::Config {
522
- on_collected_coverage_fn,
523
- on_collected_gas_report_fn,
524
- ..edr_provider::observability::Config::default()
525
- })
526
- }
527
- }
528
-
529
- impl ProviderConfig {
530
- /// Resolves the instance to a [`edr_napi_core::provider::Config`].
531
- pub fn resolve(
532
- self,
533
- env: &napi::Env,
534
- runtime: runtime::Handle,
535
- ) -> napi::Result<edr_napi_core::provider::Config> {
536
- let owned_accounts = self
537
- .owned_accounts
538
- .into_iter()
539
- .map(|secret_key| {
540
- // This is the only place in production code where it's allowed to use
541
- // `DangerousSecretKeyStr`.
542
- #[allow(deprecated)]
543
- use edr_signer::DangerousSecretKeyStr;
544
-
545
- static_assertions::assert_not_impl_all!(JsString: Debug, Display, serde::Serialize);
546
- static_assertions::assert_not_impl_all!(JsStringUtf8: Debug, Display, serde::Serialize);
547
- // `SecretKey` has `Debug` implementation, but it's opaque (only shows the
548
- // type name)
549
- static_assertions::assert_not_impl_any!(SecretKey: Display, serde::Serialize);
550
-
551
- let secret_key = secret_key.into_utf8()?;
552
- // This is the only place in production code where it's allowed to use
553
- // `DangerousSecretKeyStr`.
554
- #[allow(deprecated)]
555
- let secret_key_str = DangerousSecretKeyStr(secret_key.as_str()?);
556
- let secret_key: SecretKey = secret_key_from_str(secret_key_str)
557
- .map_err(|error| napi::Error::new(napi::Status::InvalidArg, error))?;
558
-
559
- Ok(secret_key)
560
- })
561
- .collect::<napi::Result<Vec<_>>>()?;
562
-
563
- let base_fee_params: Option<Vec<(BaseFeeActivation<String>, ConstantBaseFeeParams)>> = self
564
- .base_fee_config
565
- .map(|vec| vec.into_iter().map(TryInto::try_into).collect())
566
- .transpose()?;
567
-
568
- let block_gas_limit =
569
- NonZeroU64::new(self.block_gas_limit.try_cast()?).ok_or_else(|| {
570
- napi::Error::new(
571
- napi::Status::GenericFailure,
572
- "Block gas limit must be greater than 0",
573
- )
574
- })?;
575
-
576
- let genesis_state = self
577
- .genesis_state
578
- .into_iter()
579
- .map(TryInto::try_into)
580
- .collect::<napi::Result<HashMap<edr_primitives::Address, edr_provider::AccountOverride>>>()?;
581
-
582
- let precompile_overrides = self
583
- .precompile_overrides
584
- .into_iter()
585
- .map(|precompile| precompile.to_tuple())
586
- .collect();
587
-
588
- Ok(edr_napi_core::provider::Config {
589
- allow_blocks_with_same_timestamp: self.allow_blocks_with_same_timestamp,
590
- allow_unlimited_contract_size: self.allow_unlimited_contract_size,
591
- bail_on_call_failure: self.bail_on_call_failure,
592
- bail_on_transaction_failure: self.bail_on_transaction_failure,
593
- base_fee_params,
594
- block_gas_limit,
595
- chain_id: self.chain_id.try_cast()?,
596
- coinbase: self.coinbase.try_cast()?,
597
- fork: self.fork.map(TryInto::try_into).transpose()?,
598
- genesis_state,
599
- hardfork: self.hardfork,
600
- initial_base_fee_per_gas: self
601
- .initial_base_fee_per_gas
602
- .map(TryCast::try_cast)
603
- .transpose()?,
604
- initial_blob_gas: self.initial_blob_gas.map(TryInto::try_into).transpose()?,
605
- initial_date: self
606
- .initial_date
607
- .map(|date| {
608
- let elapsed_since_epoch = Duration::from_secs(date.try_cast()?);
609
- napi::Result::Ok(SystemTime::UNIX_EPOCH + elapsed_since_epoch)
610
- })
611
- .transpose()?,
612
- initial_parent_beacon_block_root: self
613
- .initial_parent_beacon_block_root
614
- .map(TryCast::try_cast)
615
- .transpose()?,
616
- mining: self.mining.try_into()?,
617
- min_gas_price: self.min_gas_price.try_cast()?,
618
- network_id: self.network_id.try_cast()?,
619
- observability: self.observability.resolve(env, runtime)?,
620
- owned_accounts,
621
- precompile_overrides,
622
- })
623
- }
624
- }
625
-
626
- /// Tracing config for Solidity stack trace generation.
627
- #[napi(object)]
628
- pub struct TracingConfigWithBuffers {
629
- /// Build information to use for decoding contracts. Either a Hardhat v2
630
- /// build info file that contains both input and output or a Hardhat v3
631
- /// build info file that doesn't contain output and a separate output file.
632
- pub build_infos: Option<Either<Vec<Uint8Array>, Vec<BuildInfoAndOutput>>>,
633
- /// Whether to ignore contracts whose name starts with "Ignored".
634
- pub ignore_contracts: Option<bool>,
635
- }
636
-
637
- impl From<TracingConfigWithBuffers> for edr_napi_core::solidity::config::TracingConfigWithBuffers {
638
- fn from(value: TracingConfigWithBuffers) -> Self {
639
- edr_napi_core::solidity::config::TracingConfigWithBuffers {
640
- build_infos: value.build_infos.map(|infos| match infos {
641
- Either::A(with_output) => Either::A(with_output),
642
- Either::B(separate_output) => Either::B(
643
- separate_output
644
- .into_iter()
645
- .map(edr_napi_core::solidity::config::BuildInfoAndOutput::from)
646
- .collect(),
647
- ),
648
- }),
649
- ignore_contracts: value.ignore_contracts,
650
- }
651
- }
652
- }
653
-
654
- /// Hardhat V3 build info where the compiler output is not part of the build
655
- /// info file.
656
- #[napi(object)]
657
- pub struct BuildInfoAndOutput {
658
- /// The build info input file
659
- pub build_info: Uint8Array,
660
- /// The build info output file
661
- pub output: Uint8Array,
662
- }
663
-
664
- impl From<BuildInfoAndOutput> for edr_napi_core::solidity::config::BuildInfoAndOutput {
665
- fn from(value: BuildInfoAndOutput) -> Self {
666
- Self {
667
- build_info: value.build_info,
668
- output: value.output,
669
- }
670
- }
671
- }
672
-
673
- /// Result of [`resolve_configs`].
674
- pub struct ConfigResolution {
675
- pub logger_config: edr_napi_core::logger::Config,
676
- pub provider_config: edr_napi_core::provider::Config,
677
- pub subscription_callback: edr_napi_core::subscription::Callback,
678
- }
679
-
680
- /// Helper function for resolving the provided N-API configs.
681
- pub fn resolve_configs(
682
- env: &napi::Env,
683
- runtime: runtime::Handle,
684
- provider_config: ProviderConfig,
685
- logger_config: LoggerConfig,
686
- subscription_config: SubscriptionConfig,
687
- ) -> napi::Result<ConfigResolution> {
688
- let provider_config = provider_config.resolve(env, runtime)?;
689
- let logger_config = logger_config.resolve(env)?;
690
-
691
- let subscription_config = edr_napi_core::subscription::Config::from(subscription_config);
692
- let subscription_callback =
693
- edr_napi_core::subscription::Callback::new(env, subscription_config.subscription_callback)?;
694
-
695
- Ok(ConfigResolution {
696
- logger_config,
697
- provider_config,
698
- subscription_callback,
699
- })
700
- }