mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
refactor: use alloy_primitives::map for all HashMap/HashSet types (#21686)
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
committed by
GitHub
parent
98313a0bea
commit
f53f90d714
@@ -1,6 +1,6 @@
|
||||
//! An ExEx example that installs a new RPC subscription endpoint that emits storage changes for a
|
||||
//! requested address.
|
||||
use alloy_primitives::{Address, U256};
|
||||
use alloy_primitives::{map::AddressMap, Address, U256};
|
||||
use futures::TryStreamExt;
|
||||
use jsonrpsee::{
|
||||
core::SubscriptionResult, proc_macros::rpc, PendingSubscriptionSink, SubscriptionMessage,
|
||||
@@ -9,7 +9,6 @@ use reth_ethereum::{
|
||||
exex::{ExExContext, ExExEvent, ExExNotification},
|
||||
node::{api::FullNodeComponents, builder::NodeHandleFor, EthereumNode},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tracing::{error, info};
|
||||
|
||||
@@ -97,8 +96,8 @@ async fn my_exex<Node: FullNodeComponents>(
|
||||
mut ctx: ExExContext<Node>,
|
||||
mut subscription_requests: mpsc::UnboundedReceiver<SubscriptionRequest>,
|
||||
) -> eyre::Result<()> {
|
||||
let mut subscriptions: HashMap<Address, Vec<mpsc::UnboundedSender<StorageDiff>>> =
|
||||
HashMap::new();
|
||||
let mut subscriptions: AddressMap<Vec<mpsc::UnboundedSender<StorageDiff>>> =
|
||||
AddressMap::default();
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
|
||||
@@ -9,6 +9,7 @@ repository.workspace = true
|
||||
exclude.workspace = true
|
||||
|
||||
[dependencies]
|
||||
alloy-primitives.workspace = true
|
||||
reth-ethereum = { workspace = true, features = ["node"] }
|
||||
eyre.workspace = true
|
||||
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
//! 3. Get contract bytecode
|
||||
//! 4. Iterate through all storage slots for the contract
|
||||
|
||||
use alloy_primitives::map::B256Map;
|
||||
use reth_ethereum::{
|
||||
chainspec::ChainSpecBuilder,
|
||||
evm::revm::primitives::{Address, B256, U256},
|
||||
evm::revm::primitives::{Address, U256},
|
||||
node::EthereumNode,
|
||||
primitives::{Account, Bytecode},
|
||||
provider::{
|
||||
@@ -23,7 +24,7 @@ use reth_ethereum::{
|
||||
},
|
||||
storage::{DBProvider, StateProvider},
|
||||
};
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Represents the complete state of a contract including account info, bytecode, and storage
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -35,7 +36,7 @@ pub struct ContractState {
|
||||
/// Contract bytecode (None if not a contract or doesn't exist)
|
||||
pub bytecode: Option<Bytecode>,
|
||||
/// All storage slots for the contract
|
||||
pub storage: HashMap<B256, U256>,
|
||||
pub storage: B256Map<U256>,
|
||||
}
|
||||
|
||||
/// Extract the full state of a specific contract
|
||||
@@ -52,7 +53,7 @@ pub fn extract_contract_state<P: DBProvider>(
|
||||
let bytecode = state_provider.account_code(&contract_address)?;
|
||||
|
||||
let mut storage_cursor = provider.tx_ref().cursor_dup_read::<tables::PlainStorageState>()?;
|
||||
let mut storage = HashMap::new();
|
||||
let mut storage = B256Map::default();
|
||||
|
||||
if let Some((_, first_entry)) = storage_cursor.seek_exact(contract_address)? {
|
||||
storage.insert(first_entry.key, first_entry.value);
|
||||
|
||||
Reference in New Issue
Block a user