Sitelet https://github.com/SharkHand3/examples/commit/5eb9b3ad30673b21528894d10ddddcde9df238c7
Skip to content

Commit 5eb9b3a

Browse files
fix: bump alloy to 0.15 (alloy-rs#199)
* bump Reth to 1.3.2 * bump to alloy 0.15 * start porting * fix clippy * fix clippy * start porting revm * patch crates-io doesnt work with dev deps? * fix clippy * fix clippy * clean up * fix clippy * ignore foundry-fork-db, reth * fix clippy * fix clippy * comment out temp * bump aws-sdk-kms * bump deps and use alloy-evm::Evm in fork-db example * uncomment reth examples * clippy --------- Co-authored-by: Yash Atreya <44857776+yash-atreya@users.noreply.github.com>
1 parent 38143f5 commit 5eb9b3a

89 files changed

Lines changed: 196 additions & 187 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resolver = "2"
55
[workspace.package]
66
version = "0.1.0"
77
edition = "2021"
8-
rust-version = "1.81"
8+
rust-version = "1.83"
99
authors = ["Alloy Contributors"]
1010
license = "MIT OR Apache-2.0"
1111
homepage = "https://github.com/alloy-rs/examples"
@@ -95,7 +95,7 @@ significant_drop_tightening = "allow"
9595
needless_return = "allow"
9696

9797
[workspace.dependencies]
98-
alloy = { version = "0.14", features = [
98+
alloy = { version = "0.15", features = [
9999
"eips",
100100
"full",
101101
"json-rpc",
@@ -114,7 +114,7 @@ alloy = { version = "0.14", features = [
114114

115115
# async
116116
futures-util = "0.3"
117-
tokio = "1.44"
117+
tokio = "1.45"
118118

119119
# misc
120120
eyre = "0.6"

‎benches/benches/rlp.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ fn rlp(c: &mut Criterion) {
2828
g.bench_with_input("Alloy-Rlp/Encoding", &my_struct, |b, my_struct| {
2929
b.iter(|| {
3030
let mut out = Vec::new();
31-
let _ = my_struct.encode(&mut out);
31+
my_struct.encode(&mut out);
3232
black_box(out);
3333
})
3434
});
3535

3636
let mut encoded = Vec::new();
37-
let _ = my_struct.encode(&mut encoded);
37+
my_struct.encode(&mut encoded);
3838

3939
// Parity RLP decoding
4040
g.bench_with_input("Parity-Rlp/Decoding", &encoded, |b, encoded| {

‎clippy.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.81"
1+
msrv = "1.83"

‎examples/advanced/Cargo.toml‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ repository.workspace = true
1313
workspace = true
1414

1515
[dev-dependencies]
16+
foundry-fork-db = "0.13"
1617
alloy.workspace = true
17-
# foundry-fork-db = "0.12"
18+
alloy-evm = "0.7.2"
1819

19-
# # reth
20-
# revm-primitives = { version = "17.0.0", default-features = false }
21-
# revm = { version = "21.0.0", default-features = false }
22-
# reth-db = { git = "https://github.com/paradigmxyz/reth", package = "reth-db", rev = "v1.3.8" }
23-
# reth-provider = { git = "https://github.com/paradigmxyz/reth", package = "reth-provider", rev = "v1.3.8" }
24-
# reth-node-types = { git = "https://github.com/paradigmxyz/reth", package = "reth-node-types", rev = "v1.3.8" }
25-
# reth-chainspec = { git = "https://github.com/paradigmxyz/reth", package = "reth-chainspec", rev = "v1.3.8" }
26-
# reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", package = "reth-node-ethereum", rev = "v1.3.8" }
20+
# reth
21+
revm = { version = "23.1.0", default-features = false }
22+
revm-primitives = { version = "19.0.0", default-features = false }
23+
reth-db = { git = "https://github.com/paradigmxyz/reth", package = "reth-db", rev = "55f4b0b" }
24+
reth-provider = { git = "https://github.com/paradigmxyz/reth", package = "reth-provider", rev = "55f4b0b" }
25+
reth-node-types = { git = "https://github.com/paradigmxyz/reth", package = "reth-node-types", rev = "55f4b0b" }
26+
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", package = "reth-chainspec", rev = "55f4b0b" }
27+
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth", package = "reth-node-ethereum", rev = "55f4b0b" }
2728

2829
eyre.workspace = true
2930
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

‎examples/advanced/examples/any_network.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ async fn main() -> Result<()> {
4848

4949
// Create a provider with the Arbitrum Sepolia network and the wallet.
5050
let rpc_url = "https://sepolia-rollup.arbitrum.io/rpc".parse()?;
51-
let provider = ProviderBuilder::new().network::<AnyNetwork>().wallet(signer).on_http(rpc_url);
51+
let provider =
52+
ProviderBuilder::new().network::<AnyNetwork>().wallet(signer).connect_http(rpc_url);
5253

5354
// Create a contract instance.
5455
let contract = Counter::new(COUNTER_CONTRACT_ADDRESS, &provider);
@@ -62,8 +63,8 @@ async fn main() -> Result<()> {
6263
let l1_gas = arb_fields.gas_used_for_l1.to::<u128>();
6364
let l1_block_number = arb_fields.l1_block_number.to::<u64>();
6465

65-
println!("Gas used for L1: {}", l1_gas);
66-
println!("L1 block number: {}", l1_block_number);
66+
println!("Gas used for L1: {l1_gas}");
67+
println!("L1 block number: {l1_block_number}");
6768

6869
Ok(())
6970
}

‎examples/advanced/examples/decoding_json_abi.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2323
// Functions
2424
println!("Functions:");
2525
for (name, functions) in &abi.functions {
26-
println!("\n>> {}:", name);
26+
println!("\n>> {name}:");
2727
for function in functions {
2828
println!(" Inputs: {:?}", function.inputs);
2929
println!(" Outputs: {:?}", function.outputs);
@@ -36,7 +36,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3636
// Events
3737
println!("Events:");
3838
for (name, events) in &abi.events {
39-
println!("\n>> {}:", name);
39+
println!("\n>> {name}:");
4040
for event in events {
4141
println!(" Inputs: {:?}", event.inputs);
4242
println!(" Anonymous: {}", event.anonymous);
@@ -48,7 +48,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4848
// Errors
4949
println!("Errors:");
5050
for (name, errors) in &abi.errors {
51-
println!(">> {}:", name);
51+
println!(">> {name}:");
5252
for error in errors {
5353
println!(" Inputs: {:?}", error.inputs);
5454
}

‎examples/advanced/examples/encoding_dyn_abi.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7575

7676
// Verify the signature
7777
let recovered_address = signature.recover_address_from_prehash(&eip712_hash)?;
78-
println!("Recovered address: {}", recovered_address);
78+
println!("Recovered address: {recovered_address}");
7979

8080
assert_eq!(recovered_address, wallet.address(), "Signature verification failed");
8181
println!("Signature verified successfully!");
@@ -87,7 +87,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
8787
fn print_tuple(value: &DynSolValue, field_names: &[&str]) {
8888
if let DynSolValue::Tuple(values) = value {
8989
for (value, name) in values.iter().zip(field_names.iter()) {
90-
println!(" {}: {:?}", name, value);
90+
println!(" {name}: {value:?}");
9191
}
9292
}
9393
}

‎examples/advanced/examples/encoding_sol_static.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4444

4545
let encoded = hex::encode(swapExactTokensForTokensCall::abi_encode(&swap_data));
4646

47-
println!("Encoded: 0x{}", encoded);
47+
println!("Encoded: 0x{encoded}");
4848

4949
Ok(())
5050
}

‎examples/advanced/examples/foundry_fork_db.rs‎

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,29 @@ use alloy::{
1717
providers::{Provider, ProviderBuilder},
1818
rpc::types::TransactionRequest,
1919
};
20+
use alloy_evm::{eth::EthEvmContext, EthEvm, Evm};
2021
use eyre::Result;
2122
use foundry_fork_db::{cache::BlockchainDbMeta, BlockchainDb, SharedBackend};
22-
use revm::{db::CacheDB, DatabaseRef, Evm};
23-
use revm_primitives::{BlobExcessGasAndPrice, BlockEnv, TxEnv};
23+
use revm::{
24+
context::{BlockEnv, Evm as RevmEvm, TxEnv},
25+
context_interface::block::BlobExcessGasAndPrice,
26+
database::WrapDatabaseRef,
27+
handler::{instructions::EthInstructions, EthPrecompiles},
28+
inspector::NoOpInspector,
29+
DatabaseRef,
30+
};
2431

2532
#[tokio::main]
2633
async fn main() -> Result<()> {
2734
let anvil = Anvil::new().spawn();
28-
let provider = ProviderBuilder::new().network::<AnyNetwork>().on_http(anvil.endpoint_url());
35+
let provider =
36+
ProviderBuilder::new().network::<AnyNetwork>().connect_http(anvil.endpoint_url());
2937

3038
let block = provider.get_block(BlockId::latest()).await?.unwrap();
3139

3240
// The `BlockchainDbMeta` is used a identifier when the db is flushed to the disk.
3341
// This aids in cases where the disk contains data from multiple forks.
34-
let meta = BlockchainDbMeta::default()
35-
.with_chain_id(31337)
36-
.with_block(&block.inner)
37-
.with_url(&anvil.endpoint());
42+
let meta = BlockchainDbMeta::default().with_block(&block.inner).with_url(&anvil.endpoint());
3843

3944
let db = BlockchainDb::new(meta, None);
4045

@@ -45,9 +50,8 @@ async fn main() -> Result<()> {
4550
//
4651
// For example, if we send two requests to get_full_block(0) simultaneously, the
4752
// `BackendHandler` is smart enough to only send one request to the RPC provider, and queue the
48-
// other request until the response is received.
49-
// Once the response from RPC provider is received it relays the response to both the requests
50-
// over their respective channels.
53+
// other request until the response is received. Once the response from RPC provider is
54+
// received it relays the response to both the requests // over their respective channels.
5155
//
5256
// The `SharedBackend` and `BackendHandler` communicate over an unbounded channel.
5357
let shared = SharedBackend::spawn_backend(Arc::new(provider.clone()), db, None).await;
@@ -69,9 +73,9 @@ async fn main() -> Result<()> {
6973

7074
println!("-------get_full_block--------");
7175
// The backend handle falls back to the RPC provider if the block is not in the cache.
72-
println!("1st request (via rpc): {:?}", time_rpc);
76+
println!("1st request (via rpc): {time_rpc:?}");
7377
// The block is cached due to the previous request and can be fetched from db.
74-
println!("2nd request (via fork db): {:?}\n", time_cache);
78+
println!("2nd request (via fork db): {time_cache:?}\n");
7579

7680
let alice = anvil.addresses()[0];
7781
let bob = anvil.addresses()[1];
@@ -87,15 +91,15 @@ async fn main() -> Result<()> {
8791
.with_gas_limit(21000)
8892
.with_nonce(0);
8993

90-
let mut evm = configure_evm_env(block, shared.clone(), configure_tx_env(tx_req));
94+
let mut evm = configure_evm(block, shared.clone());
9195

9296
// Fetches accounts from the RPC
9397
let start_t = std::time::Instant::now();
9498
let alice_bal = shared.basic_ref(alice)?.unwrap().balance;
9599
let bob_bal = shared.basic_ref(bob)?.unwrap().balance;
96100
let time_rpc = start_t.elapsed();
97101

98-
let res = evm.transact().unwrap();
102+
let res = evm.transact(configure_tx_env(tx_req)).unwrap();
99103

100104
let total_spent = U256::from(res.result.gas_used()) * U256::from(basefee) + U256::from(100);
101105

@@ -108,27 +112,25 @@ async fn main() -> Result<()> {
108112
let time_cache = start_t.elapsed();
109113

110114
println!("-------get_account--------");
111-
println!("1st request (via rpc): {:?}", time_rpc);
112-
println!("2nd request (via fork db): {:?}\n", time_cache);
115+
println!("1st request (via rpc): {time_rpc:?}");
116+
println!("2nd request (via fork db): {time_cache:?}\n");
113117

114118
assert_eq!(alice_bal_after, alice_bal - total_spent);
115119
assert_eq!(bob_bal_after, bob_bal + U256::from(100));
116120

117121
Ok(())
118122
}
119123

120-
fn configure_evm_env(
124+
fn configure_evm(
121125
block: AnyRpcBlock,
122126
shared: SharedBackend,
123-
tx_env: TxEnv,
124-
) -> Evm<'static, (), CacheDB<SharedBackend>> {
125-
let basefee = block.header.base_fee_per_gas().map(U256::from).unwrap_or_default();
127+
) -> EthEvm<WrapDatabaseRef<SharedBackend>, NoOpInspector> {
126128
let block_env = BlockEnv {
127-
number: U256::from(block.header.number()),
128-
coinbase: block.header.beneficiary(),
129-
timestamp: U256::from(block.header.timestamp()),
130-
gas_limit: U256::from(block.header.gas_limit()),
131-
basefee,
129+
number: block.header.number(),
130+
beneficiary: block.header.beneficiary(),
131+
timestamp: block.header.timestamp(),
132+
gas_limit: block.header.gas_limit(),
133+
basefee: block.header.base_fee_per_gas().unwrap_or(0),
132134
prevrandao: block.header.mix_hash(),
133135
difficulty: block.header.difficulty(),
134136
blob_excess_gas_and_price: Some(BlobExcessGasAndPrice::new(
@@ -137,19 +139,22 @@ fn configure_evm_env(
137139
)),
138140
};
139141

140-
let db = CacheDB::new(shared);
142+
let context =
143+
EthEvmContext::new(WrapDatabaseRef(shared), revm_primitives::hardfork::SpecId::PRAGUE)
144+
.with_block(block_env);
141145

142-
let evm = Evm::builder().with_block_env(block_env).with_db(db).with_tx_env(tx_env).build();
146+
let evm = RevmEvm::new(context, EthInstructions::default(), EthPrecompiles::default())
147+
.with_inspector(NoOpInspector);
143148

144-
evm
149+
EthEvm::new(evm, false)
145150
}
146151

147152
fn configure_tx_env(tx_req: TransactionRequest) -> TxEnv {
148153
TxEnv {
149154
caller: tx_req.from.unwrap(),
150-
transact_to: tx_req.to.unwrap(),
155+
kind: tx_req.to.unwrap(),
151156
value: tx_req.value.unwrap(),
152-
gas_price: U256::from(tx_req.max_fee_per_gas.unwrap()),
157+
gas_price: tx_req.max_fee_per_gas.unwrap(),
153158
gas_limit: tx_req.gas.unwrap_or_default(),
154159
..Default::default()
155160
}

‎examples/advanced/examples/reth_db_provider.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ async fn main() -> Result<()> {
5555
// Initialize the provider with the reth-db layer. The reth-db layer intercepts the rpc
5656
// requests and returns the results from the reth-db database.
5757
// Any RPC method that is not implemented in the RethDbProvider gracefully falls back to the
58-
// RPC provider specified in the `on_http` method.
59-
let provider =
60-
ProviderBuilder::new().layer(RethDbLayer::new(db_path)).on_http(reth.endpoint_url());
58+
// RPC provider specified in the `connect_http` method.
59+
let provider = ProviderBuilder::new()
60+
.layer(RethDbLayer::new(db_path))
61+
.connect_http(reth.endpoint_url());
6162

6263
// Initialize the RPC provider to compare the time taken to fetch the results.
63-
let rpc_provider = ProviderBuilder::new().on_http(reth.endpoint_url());
64+
let rpc_provider = ProviderBuilder::new().connect_http(reth.endpoint_url());
6465

6566
println!("--------get_block_number---------");
6667

0 commit comments

Comments
 (0)