MCPcopy Create free account
hub / github.com/ChainSecurity/deployment_validation / get_eth_events

Function get_eth_events

lib/web3.rs:859–908  ·  view source on GitHub ↗

Fetches events, does multiple calls if necessary Inclusive for from_block and to_block

(
    config: &DVFConfig,
    address: &Address,
    from_block: u64,
    to_block: u64,
    topics: &Vec<H256>,
)

Source from the content-addressed store, hash-verified

857// Fetches events, does multiple calls if necessary
858// Inclusive for from_block and to_block
859pub fn get_eth_events(
860 config: &DVFConfig,
861 address: &Address,
862 from_block: u64,
863 to_block: u64,
864 topics: &Vec<H256>,
865) -> Result<Vec<Log>, ValidationError> {
866 if to_block - from_block > config.max_blocks_per_event_query {
867 let pb = ProgressBar::new(to_block - from_block);
868 if to_block - from_block > LARGE_BLOCK_RANGE {
869 let mut num_events = String::new();
870 if topics.is_empty() {
871 num_events.push_str("all");
872 } else {
873 num_events.push_str(&topics.len().to_string());
874 }
875 info!(
876 "You are querying {} event(s) for a range of {} blocks. This will take some time.",
877 num_events,
878 to_block - from_block + 1
879 );
880 }
881 let mut last_block = from_block + config.max_blocks_per_event_query;
882 let mut events = get_eth_events(config, address, from_block, last_block, topics)?;
883 while last_block < to_block {
884 let next_last_block =
885 std::cmp::min(last_block + config.max_blocks_per_event_query - 1, to_block);
886 let mut next_events =
887 get_eth_events(config, address, last_block + 1, next_last_block, topics)?;
888 last_block = next_last_block;
889 pb.set_position(next_last_block - from_block);
890 events.append(&mut next_events);
891 }
892 pb.finish_and_clear();
893 return Ok(events);
894 }
895 let from_block_hex = format!("{:#x}", from_block);
896 let to_block_hex = format!("{:#x}", to_block);
897 let request_body = json!({
898 "jsonrpc": "2.0",
899 "method": "eth_getLogs",
900 "params": [{"address": address, "fromBlock": from_block_hex, "toBlock": to_block_hex, "topics": topics}],
901 "id": 1
902 });
903 let result = send_blocking_web3_post(config, &request_body)?;
904 let events: Vec<Log> = serde_json::from_value(result)?;
905 debug!("Found {} events.", events.len());
906 debug!("{:?}", events);
907 Ok(events)
908}
909
910#[derive(Debug, Serialize, Deserialize)]
911struct StorageRangeEntry {

Callers 2

validate_dvfFunction · 0.85
processFunction · 0.85

Calls 2

send_blocking_web3_postFunction · 0.85
to_stringMethod · 0.80

Tested by

no test coverage detected