Skip to content

Commit 4d24acd

Browse files
authored
Adds From<H160> trait to ValueOrArray<H160> (gakonst#1200)
* Adds From<H160> trait to ValueOrArray<H160> The trait From<H160> for ValueOrArray<H160> was not implemented which prevented compilation when using pub fn address<T: Into<ValueOrArray<Address>>>(self, address: T) for ethers_core::types::Filter. Fixes: gakonst#1199 * update CHANGELOG.md * Adds From<Vec<H160>> trait to ValueOrArray<H160> and documentation The trait From<Vec<H160>> for ValueOrArray<H160> was not implemented which prevented compilation when passing a Vec<H160> into pub fn address<T: Into<ValueOrArray<Address>>>(self, address: T) for ethers_core::types::Filter. This commit also includes documentation on how to use fn address for ethers_core::types::Filter. Fixes: gakonst#1199
1 parent c44872f commit 4d24acd

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Unreleased
66

7-
- Fix RLP decoding of `from` field for `Eip1559TransactionRequest` and
7+
- Fix RLP decoding of `from` field for `Eip1559TransactionRequest` and
88
`Eip2930TransactionRequest`, remove `Eip1559TransactionRequest` `sighash`
99
method [1180](https://github.com/gakonst/ethers-rs/pull/1180)
1010
- Fix RLP encoding of absent access list in `Transaction` [1137](https://github.com/gakonst/ethers-rs/pull/1137)
@@ -62,6 +62,7 @@
6262
[#996](https://github.com/gakonst/ethers-rs/pull/996)
6363
- Add `TransactionReceipt::to` and `TransactionReceipt::from`
6464
[#1184](https://github.com/gakonst/ethers-rs/pull/1184)
65+
- Add `From<H160>` and From<Vec<H160>> traits to `ValueOrArray<H160>` [#1199](https://github.com/gakonst/ethers-rs/pull/1200)
6566

6667
## ethers-contract-abigen
6768

ethers-core/src/types/log.rs

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Adapted from https://github.com/tomusdrw/rust-web3/blob/master/src/types/log.rs
22
use crate::{
3-
types::{Address, BlockNumber, Bytes, H256, U256, U64},
3+
types::{Address, BlockNumber, Bytes, H160, H256, U256, U64},
44
utils::keccak256,
55
};
66
use serde::{
@@ -306,7 +306,31 @@ impl Filter {
306306
self.block_option = self.block_option.set_hash(hash.into());
307307
self
308308
}
309-
309+
/// Sets the inner filter object
310+
///
311+
/// *NOTE:* ranges are always inclusive
312+
///
313+
/// # Examples
314+
///
315+
/// Match only a specific address `("0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF")`
316+
///
317+
/// ```rust
318+
/// # use ethers_core::types::{Filter, Address};
319+
/// # fn main() {
320+
/// let filter = Filter::new().address("0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF".parse::<Address>().unwrap());
321+
/// # }
322+
/// ```
323+
///
324+
/// Match all addresses in array `(vec!["0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF",
325+
/// "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8"])`
326+
///
327+
/// ```rust
328+
/// # use ethers_core::types::{Filter, Address, ValueOrArray};
329+
/// # fn main() {
330+
/// let addresses = vec!["0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF".parse::<Address>().unwrap(),"0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".parse::<Address>().unwrap()];
331+
/// let filter = Filter::new().address(addresses);
332+
/// # }
333+
/// ```
310334
#[must_use]
311335
pub fn address<T: Into<ValueOrArray<Address>>>(mut self, address: T) -> Self {
312336
self.address = Some(address.into());
@@ -360,6 +384,18 @@ pub enum ValueOrArray<T> {
360384

361385
// TODO: Implement more common types - or adjust this to work with all Tokenizable items
362386

387+
impl From<H160> for ValueOrArray<H160> {
388+
fn from(src: H160) -> Self {
389+
ValueOrArray::Value(src)
390+
}
391+
}
392+
393+
impl From<Vec<H160>> for ValueOrArray<H160> {
394+
fn from(src: Vec<H160>) -> Self {
395+
ValueOrArray::Array(src)
396+
}
397+
}
398+
363399
impl From<H256> for ValueOrArray<H256> {
364400
fn from(src: H256) -> Self {
365401
ValueOrArray::Value(src)

0 commit comments

Comments
 (0)