Skip to content

Commit

Permalink
Query contract events.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw committed Mar 20, 2019
1 parent c7f3118 commit 91133a0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -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
Expand Down
40 changes: 39 additions & 1 deletion src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -204,6 +205,43 @@ impl<T: Transport> Contract<T> {
})
.unwrap_or_else(Into::into)
}

/// Find events matching the topics.
pub fn events<A, B, C>(
&self,
event: &str,
topic0: A,
topic1: B,
topic2: C,
) -> CallFuture<Vec<Log>, T::Out>
where
A: Tokenize,
B: Tokenize,
C: Tokenize,
{
fn to_topic<A: Tokenize>(x: A) -> ethabi::Topic<ethabi::Token> {
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)]
Expand Down
2 changes: 1 addition & 1 deletion src/types/traces.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down

0 comments on commit 91133a0

Please sign in to comment.