graph: Implement `From<&Vec<DataSource>>` for `EthereumLogFilter`
@@ -8,6 +8,8 @@ use web3::error::Error as Web3Error;
use web3::types::*;
use super::types::*;
+use crate::prelude::DataSource;
+use crate::util::ethereum::string_to_h256;
/// A collection of attributes that (kind of) uniquely identify an Ethereum blockchain.
pub struct EthereumNetworkIdentifier {
@@ -146,6 +148,25 @@ impl FromIterator<(Option<Address>, H256)> for EthereumLogFilter {
}
}
+impl From<&Vec<DataSource>> for EthereumLogFilter {
+ fn from(data_sources: &Vec<DataSource>) -> Self {
+ data_sources
+ .iter()
+ .flat_map(|data_source| {
+ let contract_addr = data_source.source.address;
+ data_source
+ .mapping
+ .event_handlers
+ .iter()
+ .map(move |event_handler| {
+ let event_sig = string_to_h256(&event_handler.event);
+ (contract_addr, event_sig)
+ })
+ })
+ .collect::<EthereumLogFilter>()
+ }
+}
+
/// Common trait for components that watch and manage access to Ethereum.
///
/// Implementations may be implemented against an in-process Ethereum node
