Skip to content

Commit f96b306

Browse files
authored
Merge pull request #10 from HerodotusDev/chore/bump-alloy
bump all alloy dependencies into `0.1.0`, prepare for release
2 parents 22fcf5a + cf0ce51 commit f96b306

File tree

9 files changed

+760
-271
lines changed

9 files changed

+760
-271
lines changed

Cargo.lock

+574-96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+12-11
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@ exclude = [".github"]
1515

1616
[dependencies]
1717
tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread", "macros"] }
18-
# alloy is still yet stable, important to pin the revision
19-
alloy-network = { git = "https://github.com/alloy-rs/alloy", rev = "52d16d3" }
20-
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "52d16d3" }
21-
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "52d16d3" }
22-
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "52d16d3" }
23-
alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "52d16d3" }
24-
alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "52d16d3" }
25-
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "52d16d3", features = [
18+
alloy-primitives = { version = "0.7.6" }
19+
alloy = { version = "0.1.1", features = [
20+
"rpc",
21+
"rpc-types",
22+
"rpc-client",
23+
"network",
24+
"providers",
25+
"eips",
26+
"transports",
27+
"transport-http",
28+
"consensus",
2629
"k256",
2730
] }
28-
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "52d16d3" }
29-
alloy-primitives = "0.6.4"
3031
url = "2.5.0"
3132
reqwest = "0.11.26"
32-
alloy-rlp = "0.3.4"
33+
alloy-rlp = { version = "0.3.5" }
3334
eth_trie = "0.4.0"
3435
ethereum-types = "0.14.1"
3536
clap = { version = "4.5.4", features = ["derive"] }

src/bin/cli.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async fn main() -> Result<(), Error> {
7272
}
7373

7474
async fn generate_tx_proof(tx_hash: &str, rpc_url: &str) -> Result<(), Error> {
75+
let rpc_url = url::Url::parse(rpc_url).expect("Invalid URL");
7576
let mut txs_mpt_handler = TxsMptHandler::new(rpc_url)?;
7677
let tx_hash = B256::from_hex(tx_hash).unwrap();
7778
txs_mpt_handler.build_tx_tree_from_tx_hash(tx_hash).await?;
@@ -86,6 +87,7 @@ async fn generate_tx_proof(tx_hash: &str, rpc_url: &str) -> Result<(), Error> {
8687
}
8788

8889
async fn generate_receipt_proof(tx_hash: &str, rpc_url: &str) -> Result<(), Error> {
90+
let rpc_url = url::Url::parse(rpc_url).expect("Invalid URL");
8991
let mut tx_receipts_mpt_handler = TxReceiptsMptHandler::new(rpc_url)?;
9092
let tx_hash = B256::from_hex(tx_hash).unwrap();
9193
tx_receipts_mpt_handler

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy_transport::{RpcError, TransportErrorKind};
1+
use alloy::transports::{RpcError, TransportErrorKind};
22
use eth_trie::TrieError;
33

44
mod rpc;
@@ -10,6 +10,7 @@ pub mod tx_trie;
1010
#[derive(Debug)]
1111
pub enum Error {
1212
Trie(TrieError),
13+
Eip(alloy::eips::eip2718::Eip2718Error),
1314
Rlp(alloy_rlp::Error),
1415
RPC(RpcError<TransportErrorKind>),
1516
TxNotFound,

src/rpc.rs

+30-19
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
use crate::Error;
2-
use alloy_network::Ethereum;
3-
use alloy_primitives::B256;
4-
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
5-
use alloy_rpc_client::RpcClient;
6-
use alloy_rpc_types::{BlockTransactions, Transaction, TransactionReceipt};
7-
use alloy_transport::{RpcError, TransportErrorKind};
8-
use alloy_transport_http::Http;
9-
use reqwest::Client;
2+
use alloy::network::Ethereum;
3+
use alloy::primitives::B256;
4+
use alloy::providers::{Provider, RootProvider};
5+
6+
use alloy::rpc::types::{BlockTransactions, Transaction, TransactionReceipt};
7+
use alloy::transports::http::{Client, Http};
8+
use alloy::transports::{RpcError, TransportErrorKind};
109

1110
pub(crate) struct RpcProvider {
12-
provider: RootProvider<Ethereum, Http<Client>>,
11+
provider: RootProvider<Http<Client>, Ethereum>,
1312
}
1413

1514
impl RpcProvider {
16-
pub(crate) fn new(url: &str) -> Self {
17-
let http = Http::<Client>::new(url.to_string().parse().unwrap());
18-
let provider = ProviderBuilder::<_, Ethereum>::new()
19-
.provider(RootProvider::new(RpcClient::new(http, true)));
15+
pub(crate) fn new(rpc_url: url::Url) -> Self {
16+
let provider = RootProvider::new_http(rpc_url);
2017
Self { provider }
2118
}
2219

@@ -26,7 +23,10 @@ impl RpcProvider {
2623
) -> Result<(Vec<Transaction>, B256), Error> {
2724
let block = self
2825
.provider
29-
.get_block(block_number.into(), true)
26+
.get_block(
27+
block_number.into(),
28+
alloy::rpc::types::BlockTransactionsKind::Full,
29+
)
3030
.await?
3131
.ok_or_else(|| Error::BlockNotFound)?;
3232

@@ -44,7 +44,10 @@ impl RpcProvider {
4444
) -> Result<(Vec<TransactionReceipt>, B256), Error> {
4545
let block = self
4646
.provider
47-
.get_block(block_number.into(), true)
47+
.get_block(
48+
block_number.into(),
49+
alloy::rpc::types::BlockTransactionsKind::Full,
50+
)
4851
.await?
4952
.ok_or_else(|| Error::BlockNotFound)?;
5053

@@ -58,21 +61,29 @@ impl RpcProvider {
5861
}
5962

6063
pub(crate) async fn get_tx_index_by_hash(&self, tx_hash: B256) -> Result<u64, Error> {
61-
let tx = self.provider.get_transaction_by_hash(tx_hash).await?;
64+
let tx = self
65+
.provider
66+
.get_transaction_by_hash(tx_hash)
67+
.await?
68+
.expect("tx not found");
6269

6370
let index: u64 = match tx.transaction_index {
64-
Some(index) => index.try_into().map_err(|_| Error::TxNotFound)?,
71+
Some(index) => index,
6572
None => return Err(Error::TxNotFound),
6673
};
6774

6875
Ok(index)
6976
}
7077

7178
pub(crate) async fn get_tx_block_height(&self, tx_hash: B256) -> Result<u64, Error> {
72-
let tx = self.provider.get_transaction_by_hash(tx_hash).await?;
79+
let tx = self
80+
.provider
81+
.get_transaction_by_hash(tx_hash)
82+
.await?
83+
.expect("tx not found");
7384

7485
let height: u64 = match tx.block_number {
75-
Some(height) => height.try_into().map_err(|_| Error::TxNotFound)?,
86+
Some(height) => height,
7687
None => return Err(Error::TxNotFound),
7788
};
7889

0 commit comments

Comments
 (0)