Adds From<H160> trait to ValueOrArray<H160> (#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: #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: #1199
This commit is contained in:
parent
c44872f62e
commit
4d24acdd84
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -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::{
|
||||
|
@ -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());
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue