diff --git a/.editorconfig b/.editorconfig index 37ed9966..9810695a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,7 @@ root = true [*] indent_style=space -indent_size=2 +indent_size=4 tab_width=4 end_of_line=lf charset=utf-8 diff --git a/src/contract/mod.rs b/src/contract/mod.rs index 93801b20..4446013e 100644 --- a/src/contract/mod.rs +++ b/src/contract/mod.rs @@ -6,7 +6,8 @@ use std::time; use api::{Eth, Namespace}; use confirm; use contract::tokens::{Detokenize, Tokenize}; -use types::{Address, BlockNumber, Bytes, CallRequest, H256, TransactionCondition, TransactionRequest, U256}; +use types::{Address, BlockNumber, Bytes, CallRequest, H256, TransactionCondition, TransactionRequest, U256, Log, +FilterBuilder}; use Transport; mod error; @@ -204,6 +205,43 @@ impl Contract { }) .unwrap_or_else(Into::into) } + + /// Find events matching the topics. + pub fn events( + &self, + event: &str, + topic0: A, + topic1: B, + topic2: C, + ) -> CallFuture, T::Out> + where + A: Tokenize, + B: Tokenize, + C: Tokenize, + { + fn to_topic(x: A) -> ethabi::Topic { + let tokens = x.into_tokens(); + if tokens.is_empty() { + ethabi::Topic::Any + } else { + tokens.into() + } + } + + self.abi + .event(event) + .and_then(|ev| { + ev.filter(ethabi::RawTopicFilter { + topic0: to_topic(topic0), + topic1: to_topic(topic1), + topic2: to_topic(topic2), + }) + }) + .map(|filter| { + self.eth.logs(FilterBuilder::default().topic_filter(filter).build()).into() + }) + .unwrap_or_else(Into::into) + } } #[cfg(test)] diff --git a/src/types/traces.rs b/src/types/traces.rs index 2336668d..f3496eac 100644 --- a/src/types/traces.rs +++ b/src/types/traces.rs @@ -1,5 +1,5 @@ //! Types for the Parity Ad-Hoc Trace API -use types::{H160, H256, U256, Bytes, Action, Res, Address}; +use types::{H160, H256, U256, Bytes, Action, Res}; use std::collections::BTreeMap; use serde_derive::{Deserialize, Serialize};