Skip to content

Commit

Permalink
cargo fmt --all
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw committed Jun 16, 2020
1 parent c6cb588 commit 3975e6d
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use crate::api::{Accounts, Eth, Namespace};
use crate::confirm;
use crate::contract::tokens::{Detokenize, Tokenize};
use crate::types::{
Address, BlockId, Bytes, CallRequest, TransactionCondition, TransactionParameters, TransactionReceipt,
TransactionRequest, H256, U256, FilterBuilder,
Address, BlockId, Bytes, CallRequest, FilterBuilder, TransactionCondition, TransactionParameters,
TransactionReceipt, TransactionRequest, H256, U256,
};
use crate::Transport;
use futures::{Future, FutureExt, TryFutureExt, future::{self, Either}};
use futures::{
future::{self, Either},
Future, FutureExt, TryFutureExt,
};
use secp256k1::key::SecretKey;
use std::{collections::HashMap, hash::Hash, time};

Expand Down Expand Up @@ -307,12 +310,13 @@ impl<T: Transport> Contract<T> {

/// Find events matching the topics.
pub fn events<A, B, C, R>(
&self,
event: &str,
topic0: A,
topic1: B,
topic2: C,
) -> impl Future<Output = Result<Vec<R>>> where
&self,
event: &str,
topic0: A,
topic1: B,
topic2: C,
) -> impl Future<Output = Result<Vec<R>>>
where
A: Tokenize,
B: Tokenize,
C: Tokenize,
Expand All @@ -327,34 +331,39 @@ impl<T: Transport> Contract<T> {
}
}

let res = self.abi.event(event)
.and_then(|ev| {
let filter = ev.filter(ethabi::RawTopicFilter {
topic0: to_topic(topic0),
topic1: to_topic(topic1),
topic2: to_topic(topic2),
})?;
Ok((ev.clone(), filter))
});
let res = self.abi.event(event).and_then(|ev| {
let filter = ev.filter(ethabi::RawTopicFilter {
topic0: to_topic(topic0),
topic1: to_topic(topic1),
topic2: to_topic(topic2),
})?;
Ok((ev.clone(), filter))
});
let (ev, filter) = match res {
Ok(x) => x,
Err(e) => return Either::Left(future::ready(Err(e.into()))),
};

Either::Right(self.eth.logs(FilterBuilder::default().topic_filter(filter).build())
.map_err(Into::into)
.map(move |logs| logs.and_then(|logs| logs
.into_iter()
.map(move |l| {
let log = ev.parse_log(ethabi::RawLog {
topics: l.topics,
data: l.data.0,
})?;

Ok(R::from_tokens(log.params.into_iter().map(|x| x.value).collect::<Vec<_>>())?)
Either::Right(
self.eth
.logs(FilterBuilder::default().topic_filter(filter).build())
.map_err(Into::into)
.map(move |logs| {
logs.and_then(|logs| {
logs.into_iter()
.map(move |l| {
let log = ev.parse_log(ethabi::RawLog {
topics: l.topics,
data: l.data.0,
})?;

Ok(R::from_tokens(
log.params.into_iter().map(|x| x.value).collect::<Vec<_>>(),
)?)
})
.collect::<Result<Vec<R>>>()
})
.collect::<Result<Vec<R>>>()
))
}),
)
}
}
Expand Down

0 comments on commit 3975e6d

Please sign in to comment.