Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 78d234f

Browse files
committed
Merge branch 'master' into hanyunx/celo_providers
2 parents 29ee4dd + ce20e31 commit 78d234f

File tree

5 files changed

+137
-8
lines changed

5 files changed

+137
-8
lines changed

Diff for: Cargo.lock

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

Diff for: ethers-contract/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ethers-contract-derive = { version = "0.2.2", path = "ethers-contract-derive", o
1919
serde = { version = "1.0.124", default-features = false }
2020
serde_json = { version = "1.0.64", default-features = false }
2121
thiserror = { version = "1.0.24", default-features = false }
22-
once_cell = { version = "1.7.2", default-features = false }
22+
once_cell = { version = "1.8.0", default-features = false }
2323
pin-project = {version = "1.0.7", default-features = false }
2424
futures-util = { version = "0.3.14", default-features = false }
2525
hex = { version = "0.4.3", default-features = false, features = ["std"] }

Diff for: ethers-core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ethers = { version = "0.2", path = "../ethers" }
4343

4444
serde_json = { version = "1.0.64", default-features = false }
4545
bincode = { version = "1.3.3", default-features = false }
46-
once_cell = { version = "1.7.2" }
46+
once_cell = { version = "1.8.0" }
4747

4848

4949
[features]

Diff for: ethers-core/src/types/log.rs

+126
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
utils::keccak256,
55
};
66
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
7+
use std::ops::{Range, RangeFrom, RangeTo};
78

89
/// A log produced by a transaction.
910
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -71,6 +72,65 @@ pub enum FilterBlockOption {
7172
AtBlockHash(H256),
7273
}
7374

75+
impl From<BlockNumber> for FilterBlockOption {
76+
fn from(block: BlockNumber) -> Self {
77+
let block = Some(block);
78+
FilterBlockOption::Range {
79+
from_block: block,
80+
to_block: block,
81+
}
82+
}
83+
}
84+
85+
impl From<U64> for FilterBlockOption {
86+
fn from(block: U64) -> Self {
87+
BlockNumber::from(block).into()
88+
}
89+
}
90+
91+
impl From<u64> for FilterBlockOption {
92+
fn from(block: u64) -> Self {
93+
BlockNumber::from(block).into()
94+
}
95+
}
96+
97+
impl<T: Into<BlockNumber>> From<Range<T>> for FilterBlockOption {
98+
fn from(r: Range<T>) -> Self {
99+
let from_block = Some(r.start.into());
100+
let to_block = Some(r.end.into());
101+
FilterBlockOption::Range {
102+
from_block,
103+
to_block,
104+
}
105+
}
106+
}
107+
108+
impl<T: Into<BlockNumber>> From<RangeTo<T>> for FilterBlockOption {
109+
fn from(r: RangeTo<T>) -> Self {
110+
let to_block = Some(r.end.into());
111+
FilterBlockOption::Range {
112+
from_block: Some(BlockNumber::Earliest),
113+
to_block,
114+
}
115+
}
116+
}
117+
118+
impl<T: Into<BlockNumber>> From<RangeFrom<T>> for FilterBlockOption {
119+
fn from(r: RangeFrom<T>) -> Self {
120+
let from_block = Some(r.start.into());
121+
FilterBlockOption::Range {
122+
from_block,
123+
to_block: Some(BlockNumber::Latest),
124+
}
125+
}
126+
}
127+
128+
impl From<H256> for FilterBlockOption {
129+
fn from(hash: H256) -> Self {
130+
FilterBlockOption::AtBlockHash(hash)
131+
}
132+
}
133+
74134
impl Default for FilterBlockOption {
75135
fn default() -> Self {
76136
FilterBlockOption::Range {
@@ -187,6 +247,72 @@ impl Filter {
187247
Self::default()
188248
}
189249

250+
/// Sets the inner filter object
251+
///
252+
/// *NOTE:* ranges are always inclusive
253+
///
254+
/// # Examples
255+
///
256+
/// Match only a specific block
257+
///
258+
/// ```rust
259+
/// # use ethers::types::Filter;
260+
/// # fn main() {
261+
/// let filter = Filter::new().select(69u64);
262+
/// # }
263+
/// ```
264+
/// This is the same as `Filter::new().from_block(1337u64).to_block(1337u64)`
265+
///
266+
/// Match the latest block only
267+
///
268+
/// ```rust
269+
/// # use ethers::types::{Filter, BlockNumber};
270+
/// # fn main() {
271+
/// let filter = Filter::new().select(BlockNumber::Latest);
272+
/// # }
273+
/// ```
274+
///
275+
/// Match a block by its hash
276+
///
277+
/// ```rust
278+
/// # use ethers::types::{Filter, H256};
279+
/// # fn main() {
280+
/// let filter = Filter::new().select(H256::zero());
281+
/// # }
282+
/// ```
283+
/// This is the same as `at_block_hash`
284+
///
285+
/// Match a range of blocks
286+
///
287+
/// ```rust
288+
/// # use ethers::types::{Filter, H256};
289+
/// # fn main() {
290+
/// let filter = Filter::new().select(0u64..100u64);
291+
/// # }
292+
/// ```
293+
///
294+
/// Match all blocks in range `(1337..BlockNumber::Latest)`
295+
///
296+
/// ```rust
297+
/// # use ethers::types::{Filter, H256};
298+
/// # fn main() {
299+
/// let filter = Filter::new().select(1337u64..);
300+
/// # }
301+
/// ```
302+
///
303+
/// Match all blocks in range `(BlockNumber::Earliest..1337)`
304+
///
305+
/// ```rust
306+
/// # use ethers::types::{Filter, H256};
307+
/// # fn main() {
308+
/// let filter = Filter::new().select(..1337u64);
309+
/// # }
310+
/// ```
311+
pub fn select(mut self, filter: impl Into<FilterBlockOption>) -> Self {
312+
self.block_option = filter.into();
313+
self
314+
}
315+
190316
#[allow(clippy::wrong_self_convention)]
191317
pub fn from_block<T: Into<BlockNumber>>(mut self, block: T) -> Self {
192318
self.block_option = self.block_option.set_from_block(block.into());

Diff for: ethers-providers/src/transports/ws.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct Ws {
4343
requests: mpsc::UnboundedSender<TransportMessage>,
4444
}
4545

46-
type Pending = oneshot::Sender<serde_json::Value>;
46+
type Pending = oneshot::Sender<Result<serde_json::Value, JsonRpcError>>;
4747
type Subscription = mpsc::UnboundedSender<serde_json::Value>;
4848

4949
enum TransportMessage {
@@ -129,6 +129,9 @@ impl JsonRpcClient for Ws {
129129
// wait for the response
130130
let res = receiver.await?;
131131

132+
// in case the request itself has any errors
133+
let res = res?;
134+
132135
// parse it
133136
Ok(serde_json::from_value(res)?)
134137
}
@@ -268,7 +271,7 @@ where
268271
if let Ok(resp) = serde_json::from_str::<Response<serde_json::Value>>(&inner) {
269272
if let Some(request) = self.pending.remove(&resp.id) {
270273
request
271-
.send(resp.data.into_result()?)
274+
.send(resp.data.into_result())
272275
.map_err(to_client_error)?;
273276
}
274277
} else if let Ok(notification) =
@@ -286,8 +289,8 @@ where
286289
}
287290

288291
// TrySendError is private :(
289-
fn to_client_error<T: ToString>(err: T) -> ClientError {
290-
ClientError::ChannelError(err.to_string())
292+
fn to_client_error<T: Debug>(err: T) -> ClientError {
293+
ClientError::ChannelError(format!("{:?}", err))
291294
}
292295

293296
#[derive(Error, Debug)]

0 commit comments

Comments
 (0)