Skip to content

Commit

Permalink
Adds From<H160> trait to ValueOrArray<H160> (gakonst#1200)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CyMule authored May 2, 2022
1 parent c44872f commit 4d24acd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Unreleased

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

## ethers-contract-abigen

Expand Down
40 changes: 38 additions & 2 deletions ethers-core/src/types/log.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Adapted from https://github.com/tomusdrw/rust-web3/blob/master/src/types/log.rs
use crate::{
types::{Address, BlockNumber, Bytes, H256, U256, U64},
types::{Address, BlockNumber, Bytes, H160, H256, U256, U64},
utils::keccak256,
};
use serde::{
Expand Down Expand Up @@ -306,7 +306,31 @@ impl Filter {
self.block_option = self.block_option.set_hash(hash.into());
self
}

/// Sets the inner filter object
///
/// *NOTE:* ranges are always inclusive
///
/// # Examples
///
/// Match only a specific address `("0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF")`
///
/// ```rust
/// # use ethers_core::types::{Filter, Address};
/// # fn main() {
/// let filter = Filter::new().address("0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF".parse::<Address>().unwrap());
/// # }
/// ```
///
/// Match all addresses in array `(vec!["0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF",
/// "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8"])`
///
/// ```rust
/// # use ethers_core::types::{Filter, Address, ValueOrArray};
/// # fn main() {
/// let addresses = vec!["0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF".parse::<Address>().unwrap(),"0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".parse::<Address>().unwrap()];
/// let filter = Filter::new().address(addresses);
/// # }
/// ```
#[must_use]
pub fn address<T: Into<ValueOrArray<Address>>>(mut self, address: T) -> Self {
self.address = Some(address.into());
Expand Down Expand Up @@ -360,6 +384,18 @@ pub enum ValueOrArray<T> {

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

impl From<H160> for ValueOrArray<H160> {
fn from(src: H160) -> Self {
ValueOrArray::Value(src)
}
}

impl From<Vec<H160>> for ValueOrArray<H160> {
fn from(src: Vec<H160>) -> Self {
ValueOrArray::Array(src)
}
}

impl From<H256> for ValueOrArray<H256> {
fn from(src: H256) -> Self {
ValueOrArray::Value(src)
Expand Down

0 comments on commit 4d24acd

Please sign in to comment.