From 4d24acdd8480dc8c21628e973c6b3468627fc14f Mon Sep 17 00:00:00 2001 From: CyMule <46548427+CyMule@users.noreply.github.com> Date: Mon, 2 May 2022 15:33:33 -0400 Subject: [PATCH] Adds From trait to ValueOrArray (#1200) * Adds From trait to ValueOrArray The trait From for ValueOrArray was not implemented which prevented compilation when using pub fn address>>(self, address: T) for ethers_core::types::Filter. Fixes: #1199 * update CHANGELOG.md * Adds From> trait to ValueOrArray and documentation The trait From> for ValueOrArray was not implemented which prevented compilation when passing a Vec into pub fn 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 --- CHANGELOG.md | 3 ++- ethers-core/src/types/log.rs | 40 ++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13570658..5def5468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` and From> traits to `ValueOrArray` [#1199](https://github.com/gakonst/ethers-rs/pull/1200) ## ethers-contract-abigen diff --git a/ethers-core/src/types/log.rs b/ethers-core/src/types/log.rs index 3815f158..89758434 100644 --- a/ethers-core/src/types/log.rs +++ b/ethers-core/src/types/log.rs @@ -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::
().unwrap()); + /// # } + /// ``` + /// + /// Match all addresses in array `(vec!["0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF", + /// "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8"])` + /// + /// ```rust + /// # use ethers_core::types::{Filter, Address, ValueOrArray}; + /// # fn main() { + /// let addresses = vec!["0xAc4b3DacB91461209Ae9d41EC517c2B9Cb1B7DAF".parse::
().unwrap(),"0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".parse::
().unwrap()]; + /// let filter = Filter::new().address(addresses); + /// # } + /// ``` #[must_use] pub fn address>>(mut self, address: T) -> Self { self.address = Some(address.into()); @@ -360,6 +384,18 @@ pub enum ValueOrArray { // TODO: Implement more common types - or adjust this to work with all Tokenizable items +impl From for ValueOrArray { + fn from(src: H160) -> Self { + ValueOrArray::Value(src) + } +} + +impl From> for ValueOrArray { + fn from(src: Vec) -> Self { + ValueOrArray::Array(src) + } +} + impl From for ValueOrArray { fn from(src: H256) -> Self { ValueOrArray::Value(src)