Skip to content

Commit a50392f

Browse files
authored
Merge branch 'master' into feat/browser-wallet-support
2 parents 20997e3 + e6de72c commit a50392f

File tree

35 files changed

+1053
-364
lines changed

35 files changed

+1053
-364
lines changed

Cargo.lock

Lines changed: 20 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,17 @@ alloy-hardforks = { version = "0.2.6", default-features = false }
239239
alloy-op-hardforks = { version = "0.2.6", default-features = false }
240240

241241
## alloy-core
242-
alloy-dyn-abi = "1.1"
243-
alloy-json-abi = "1.1"
244-
alloy-primitives = { version = "1.1", features = [
242+
alloy-dyn-abi = "1.2.1"
243+
alloy-json-abi = "1.2.1"
244+
alloy-primitives = { version = "1.2.1", features = [
245245
"getrandom",
246246
"rand",
247247
"map-fxhash",
248248
"map-foldhash",
249249
] }
250-
alloy-sol-macro-expander = "1.1"
251-
alloy-sol-macro-input = "1.1"
252-
alloy-sol-types = "1.1"
250+
alloy-sol-macro-expander = "1.2.1"
251+
alloy-sol-macro-input = "1.2.1"
252+
alloy-sol-types = "1.2.1"
253253

254254
alloy-chains = "0.2"
255255
alloy-rlp = "0.3"
@@ -349,6 +349,8 @@ yansi = { version = "1.0", features = ["detect-tty", "detect-env"] }
349349
path-slash = "0.2"
350350
jiff = "0.2"
351351
heck = "0.5"
352+
uuid = "1.17.0"
353+
flate2 = "1.1"
352354

353355
## Pinned dependencies. Enabled for the workspace in crates/test-utils.
354356

crates/anvil/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ futures.workspace = true
8484
async-trait.workspace = true
8585

8686
# misc
87-
flate2 = "1.1"
87+
flate2.workspace = true
8888
serde_json.workspace = true
8989
serde.workspace = true
9090
thiserror.workspace = true

crates/anvil/core/src/eth/serde_helpers.rs

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,58 +52,19 @@ pub mod empty_params {
5252

5353
/// A module that deserializes either a BlockNumberOrTag, or a simple number.
5454
pub mod lenient_block_number {
55+
pub use alloy_eips::eip1898::LenientBlockNumberOrTag;
5556
use alloy_rpc_types::BlockNumberOrTag;
5657
use serde::{Deserialize, Deserializer};
5758

58-
/// Following the spec the block parameter is either:
59-
///
60-
/// > HEX String - an integer block number
61-
/// > String "earliest" for the earliest/genesis block
62-
/// > String "latest" - for the latest mined block
63-
/// > String "pending" - for the pending state/transactions
64-
///
65-
/// and with EIP-1898:
66-
/// > blockNumber: QUANTITY - a block number
67-
/// > blockHash: DATA - a block hash
68-
///
69-
/// <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1898.md>
70-
///
71-
/// EIP-1898 does not all calls that use `BlockNumber` like `eth_getBlockByNumber` and doesn't
72-
/// list raw integers as supported.
73-
///
74-
/// However, there are dev node implementations that support integers, such as ganache: <https://github.com/foundry-rs/foundry/issues/1868>
75-
///
76-
/// N.B.: geth does not support ints in `eth_getBlockByNumber`
77-
pub fn lenient_block_number<'de, D>(deserializer: D) -> Result<BlockNumberOrTag, D::Error>
78-
where
79-
D: Deserializer<'de>,
80-
{
81-
LenientBlockNumber::deserialize(deserializer).map(Into::into)
82-
}
59+
/// deserializes either a BlockNumberOrTag, or a simple number.
60+
pub use alloy_eips::eip1898::lenient_block_number_or_tag::deserialize as lenient_block_number;
8361

8462
/// Same as `lenient_block_number` but requires to be `[num; 1]`
8563
pub fn lenient_block_number_seq<'de, D>(deserializer: D) -> Result<BlockNumberOrTag, D::Error>
8664
where
8765
D: Deserializer<'de>,
8866
{
89-
let num = <[LenientBlockNumber; 1]>::deserialize(deserializer)?[0].into();
67+
let num = <[LenientBlockNumberOrTag; 1]>::deserialize(deserializer)?[0].into();
9068
Ok(num)
9169
}
92-
93-
/// Various block number representations, See [`lenient_block_number()`]
94-
#[derive(Clone, Copy, Deserialize)]
95-
#[serde(untagged)]
96-
pub enum LenientBlockNumber {
97-
BlockNumber(BlockNumberOrTag),
98-
Num(u64),
99-
}
100-
101-
impl From<LenientBlockNumber> for BlockNumberOrTag {
102-
fn from(b: LenientBlockNumber) -> Self {
103-
match b {
104-
LenientBlockNumber::BlockNumber(b) => b,
105-
LenientBlockNumber::Num(b) => b.into(),
106-
}
107-
}
108-
}
10970
}

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::{
2424
macros::node_info,
2525
pool::transactions::PoolTransaction,
2626
sign::build_typed_transaction,
27-
util::get_precompiles_for,
2827
},
2928
inject_precompiles,
3029
mem::{
@@ -516,10 +515,6 @@ impl Backend {
516515
self.fork.read().is_some()
517516
}
518517

519-
pub fn precompiles(&self) -> Vec<Address> {
520-
get_precompiles_for(self.env.read().evm_env.cfg_env.spec)
521-
}
522-
523518
/// Resets the fork to a fresh state
524519
pub async fn reset_fork(&self, forking: Forking) -> Result<(), BlockchainError> {
525520
if !self.is_fork() {

crates/anvil/src/eth/otterscan/api.rs

Lines changed: 17 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,73 +15,12 @@ use alloy_rpc_types::{
1515
BlockDetails, ContractCreator, InternalOperation, OtsBlock, OtsBlockTransactions,
1616
OtsReceipt, OtsSlimBlock, OtsTransactionReceipt, TraceEntry, TransactionsWithReceipts,
1717
},
18-
parity::{
19-
Action, CallAction, CallType, CreateAction, CreateOutput, LocalizedTransactionTrace,
20-
RewardAction, TraceOutput,
21-
},
18+
parity::{Action, CreateAction, CreateOutput, TraceOutput},
2219
},
2320
Block, BlockId, BlockNumberOrTag as BlockNumber, BlockTransactions,
2421
};
25-
use itertools::Itertools;
26-
2722
use futures::future::join_all;
28-
29-
pub fn mentions_address(trace: LocalizedTransactionTrace, address: Address) -> Option<B256> {
30-
match (trace.trace.action, trace.trace.result) {
31-
(Action::Call(CallAction { from, to, .. }), _) if from == address || to == address => {
32-
trace.transaction_hash
33-
}
34-
(_, Some(TraceOutput::Create(CreateOutput { address: created_address, .. })))
35-
if created_address == address =>
36-
{
37-
trace.transaction_hash
38-
}
39-
(Action::Create(CreateAction { from, .. }), _) if from == address => trace.transaction_hash,
40-
(Action::Reward(RewardAction { author, .. }), _) if author == address => {
41-
trace.transaction_hash
42-
}
43-
_ => None,
44-
}
45-
}
46-
47-
/// Converts the list of traces for a transaction into the expected Otterscan format.
48-
///
49-
/// Follows format specified in the [`ots_traceTransaction`](https://docs.otterscan.io/api-docs/ots-api#ots_tracetransaction) spec.
50-
pub fn batch_build_ots_traces(traces: Vec<LocalizedTransactionTrace>) -> Vec<TraceEntry> {
51-
traces
52-
.into_iter()
53-
.filter_map(|trace| {
54-
let output = trace
55-
.trace
56-
.result
57-
.map(|r| match r {
58-
TraceOutput::Call(output) => output.output,
59-
TraceOutput::Create(output) => output.code,
60-
})
61-
.unwrap_or_default();
62-
match trace.trace.action {
63-
Action::Call(call) => Some(TraceEntry {
64-
r#type: match call.call_type {
65-
CallType::Call => "CALL",
66-
CallType::CallCode => "CALLCODE",
67-
CallType::DelegateCall => "DELEGATECALL",
68-
CallType::StaticCall => "STATICCALL",
69-
CallType::AuthCall => "AUTHCALL",
70-
CallType::None => "NONE",
71-
}
72-
.to_string(),
73-
depth: trace.trace.trace_address.len() as u32,
74-
from: call.from,
75-
to: call.to,
76-
value: Some(call.value),
77-
input: call.input,
78-
output,
79-
}),
80-
Action::Create(_) | Action::Selfdestruct(_) | Action::Reward(_) => None,
81-
}
82-
})
83-
.collect()
84-
}
23+
use itertools::Itertools;
8524

8625
impl EthApi {
8726
/// Otterscan currently requires this endpoint, even though it's not part of the `ots_*`.
@@ -126,10 +65,19 @@ impl EthApi {
12665
}
12766

12867
/// Trace a transaction and generate a trace call tree.
68+
/// Converts the list of traces for a transaction into the expected Otterscan format.
69+
///
70+
/// Follows format specified in the [`ots_traceTransaction`](https://docs.otterscan.io/api-docs/ots-api#ots_tracetransaction) spec.
12971
pub async fn ots_trace_transaction(&self, hash: B256) -> Result<Vec<TraceEntry>> {
13072
node_info!("ots_traceTransaction");
131-
132-
Ok(batch_build_ots_traces(self.backend.trace_transaction(hash).await?))
73+
let traces = self
74+
.backend
75+
.trace_transaction(hash)
76+
.await?
77+
.into_iter()
78+
.filter_map(|trace| TraceEntry::from_transaction_trace(&trace.trace))
79+
.collect();
80+
Ok(traces)
13381
}
13482

13583
/// Given a transaction hash, returns its raw revert reason.
@@ -220,7 +168,8 @@ impl EthApi {
220168
let hashes = traces
221169
.into_iter()
222170
.rev()
223-
.filter_map(|trace| mentions_address(trace, address))
171+
.filter(|trace| trace.contains_address(address))
172+
.filter_map(|trace| trace.transaction_hash)
224173
.unique();
225174

226175
if res.len() >= page_size {
@@ -267,7 +216,8 @@ impl EthApi {
267216
let hashes = traces
268217
.into_iter()
269218
.rev()
270-
.filter_map(|trace| mentions_address(trace, address))
219+
.filter(|trace| trace.contains_address(address))
220+
.filter_map(|trace| trace.transaction_hash)
271221
.unique();
272222

273223
if res.len() >= page_size {

0 commit comments

Comments
 (0)