feat: add events function to set multiple event filter (#1607)

This commit is contained in:
Matthias Seitz 2022-08-19 17:20:44 +02:00 committed by GitHub
parent 3681099af3
commit 4f6ccf70b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -254,13 +254,21 @@ impl Filter {
self self
} }
/// given the event in string form, it hashes it and adds it to the topics to monitor /// Given the event signature in string form, it hashes it and adds it to the topics to monitor
#[must_use] #[must_use]
pub fn event(self, event_name: &str) -> Self { pub fn event(self, event_name: &str) -> Self {
let hash = H256::from(keccak256(event_name.as_bytes())); let hash = H256::from(keccak256(event_name.as_bytes()));
self.topic0(hash) self.topic0(hash)
} }
/// Hashes all event signatures and sets them as array to topic0
#[must_use]
pub fn events(self, events: impl IntoIterator<Item = impl AsRef<[u8]>>) -> Self {
let events =
events.into_iter().map(|e| H256::from(keccak256(e.as_ref()))).collect::<Vec<_>>();
self.topic0(events)
}
/// Sets topic0 (the event name for non-anonymous events) /// Sets topic0 (the event name for non-anonymous events)
#[must_use] #[must_use]
pub fn topic0<T: Into<Topic>>(mut self, topic: T) -> Self { pub fn topic0<T: Into<Topic>>(mut self, topic: T) -> Self {
@ -544,6 +552,12 @@ impl From<H256> for Topic {
} }
} }
impl From<Vec<H256>> for ValueOrArray<H256> {
fn from(src: Vec<H256>) -> Self {
ValueOrArray::Array(src)
}
}
impl From<ValueOrArray<H256>> for Topic { impl From<ValueOrArray<H256>> for Topic {
fn from(src: ValueOrArray<H256>) -> Self { fn from(src: ValueOrArray<H256>) -> Self {
match src { match src {