Skip to content

Commit

Permalink
bump alloy & specify dep rev (bluealloy#1380)
Browse files Browse the repository at this point in the history
* bump alloy & specify dep rev

* satisfy fmt check
  • Loading branch information
halo3mic authored May 4, 2024
1 parent f0cfe77 commit f778a5d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 59 deletions.
55 changes: 30 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
alloy-primitives = { version = "0.7", default-features = false, features = [
alloy-primitives = { version = "0.7.2", default-features = false, features = [
"rlp",
] }
hashbrown = "0.14"
Expand Down
10 changes: 5 additions & 5 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ ethers-providers = { version = "2.0", optional = true }
ethers-core = { version = "2.0", optional = true }

# alloydb
alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", optional = true, default-features = false }
alloy-rpc-types = {git = "https://github.com/alloy-rs/alloy.git", optional = true, default-features = false }
alloy-transport = {git = "https://github.com/alloy-rs/alloy.git", optional = true, default-features = false }
alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d", optional = true, default-features = false }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d", optional = true, default-features = false }
alloy-transport = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d", optional = true, default-features = false }

[dev-dependencies]
alloy-sol-types = { version = "0.7.0", default-features = false, features = ["std"] }
Expand All @@ -53,9 +53,9 @@ criterion = "0.5"
indicatif = "0.17"
reqwest = { version = "0.12" }

alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", default-features = false, features = ["reqwest"] }
alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "44b8a6d", default-features = false, features = ["reqwest"] }
# needed for enabling TLS to use HTTPS connections when testing alloy DB
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git" }
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy.git" , rev = "44b8a6d" }

[features]
default = ["std", "c-kzg", "secp256k1", "portable"]
Expand Down
31 changes: 11 additions & 20 deletions crates/revm/src/db/alloydb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub struct AlloyDB<T: Transport + Clone, N: Network, P: Provider<T, N>> {
/// The provider to fetch the data from.
provider: P,
/// The block number on which the queries will be based on.
block_number: Option<BlockId>,
block_number: BlockId,
_marker: std::marker::PhantomData<fn() -> (T, N)>,
}

impl<T: Transport + Clone, N: Network, P: Provider<T, N>> AlloyDB<T, N, P> {
/// Create a new AlloyDB instance, with a [Provider] and a block (Use None for latest).
pub fn new(provider: P, block_number: Option<BlockId>) -> Self {
pub fn new(provider: P, block_number: BlockId) -> Self {
Self {
provider,
block_number,
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<T: Transport + Clone, N: Network, P: Provider<T, N>> AlloyDB<T, N, P> {
}

/// Set the block number on which the queries will be based on.
pub fn set_block_number(&mut self, block_number: Option<BlockId>) {
pub fn set_block_number(&mut self, block_number: BlockId) {
self.block_number = block_number;
}
}
Expand All @@ -77,9 +77,7 @@ impl<T: Transport + Clone, N: Network, P: Provider<T, N>> DatabaseRef for AlloyD
.provider
.get_transaction_count(address, self.block_number);
let balance = self.provider.get_balance(address, self.block_number);
let code = self
.provider
.get_code_at(address, self.block_number.unwrap_or_default());
let code = self.provider.get_code_at(address, self.block_number);
tokio::join!(nonce, balance, code)
};

Expand All @@ -90,12 +88,7 @@ impl<T: Transport + Clone, N: Network, P: Provider<T, N>> DatabaseRef for AlloyD
let code_hash = code.hash_slow();
let nonce = nonce?;

Ok(Some(AccountInfo::new(
balance,
nonce.to::<u64>(),
code_hash,
code,
)))
Ok(Some(AccountInfo::new(balance, nonce, code_hash, code)))
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
Expand Down Expand Up @@ -160,14 +153,12 @@ mod tests {

#[test]
fn can_get_basic() {
let client = ProviderBuilder::new()
.on_reqwest_http(
"https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"
.parse()
.unwrap(),
)
.unwrap();
let alloydb = AlloyDB::new(client, Some(BlockId::from(16148323)));
let client = ProviderBuilder::new().on_http(
"https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"
.parse()
.unwrap(),
);
let alloydb = AlloyDB::new(client, BlockId::from(16148323));

// ETH/USDT pair on Uniswap V2
let address: Address = "0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852"
Expand Down
15 changes: 7 additions & 8 deletions examples/uniswap_v2_usdc_swap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_provider::{network::Ethereum, ProviderBuilder, RootProvider};
use alloy_rpc_types::BlockId;
use alloy_sol_types::{sol, SolCall, SolValue};
use alloy_transport_http::Http;
use anyhow::{anyhow, Result};
Expand All @@ -17,15 +18,13 @@ type AlloyCacheDB = CacheDB<AlloyDB<Http<Client>, Ethereum, Arc<RootProvider<Htt

#[tokio::main]
async fn main() -> Result<()> {
let client = ProviderBuilder::new()
.on_reqwest_http(
"https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"
.parse()
.unwrap(),
)
.unwrap();
let client = ProviderBuilder::new().on_http(
"https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"
.parse()
.unwrap(),
);
let client = Arc::new(client);
let mut cache_db = CacheDB::new(AlloyDB::new(client, None));
let mut cache_db = CacheDB::new(AlloyDB::new(client, BlockId::default()));

// Random empty account
let account = address!("18B06aaF27d44B756FCF16Ca20C1f183EB49111f");
Expand Down

0 comments on commit f778a5d

Please sign in to comment.