diff --git a/cli/Makefile b/cli/Makefile index d3aa385..2f29aa4 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -47,7 +47,7 @@ start_sophon: start_xenea: RUSTFLAGS='-C target-cpu=native' RUST_BACKTRACE='full' cargo run --release --features jemalloc -- start --path $(CURDIR)/../examples/xenea-bug graphql codegen_typings_lens: - RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path $(CURDIR)/../../lens-backend/crates/indexer typings + cargo run -- codegen --path $(CURDIR)/../../lens-backend/crates/lens-indexer typings codegen_indexer_lens: RUSTFLAGS='-C target-cpu=native' cargo run --release --features jemalloc -- codegen --path $(CURDIR)/../../lens-backend/crates/indexer indexer start_uniswap_base: diff --git a/core/src/event/callback_registry.rs b/core/src/event/callback_registry.rs index fa05770..4751718 100644 --- a/core/src/event/callback_registry.rs +++ b/core/src/event/callback_registry.rs @@ -14,6 +14,7 @@ use tracing::{debug, error}; use crate::{ event::contract_setup::{ContractInformation, NetworkContract}, indexer::start::ProcessedNetworkContract, + provider::WrappedLog, }; pub type Decoder = Arc, Bytes) -> Arc + Send + Sync>; @@ -30,6 +31,7 @@ pub struct TxInformation { pub address: Address, pub block_hash: H256, pub block_number: U64, + pub block_timestamp: Option, pub transaction_hash: H256, pub log_index: U256, pub transaction_index: U64, @@ -52,20 +54,21 @@ pub struct EventResult { impl EventResult { pub fn new( network_contract: Arc, - log: Log, + log: WrappedLog, start_block: U64, end_block: U64, ) -> Self { - let log_meta = LogMeta::from(&log); - let log_address = log.address; + let log_meta = LogMeta::from(&log.inner); + let log_address = log.inner.address; Self { - log: log.clone(), - decoded_data: network_contract.decode_log(log), + log: log.inner.clone(), + decoded_data: network_contract.decode_log(log.inner), tx_information: TxInformation { network: network_contract.network.to_string(), address: log_address, block_hash: log_meta.block_hash, block_number: log_meta.block_number, + block_timestamp: log.block_timestamp, transaction_hash: log_meta.transaction_hash, transaction_index: log_meta.transaction_index, log_index: log_meta.log_index, diff --git a/core/src/indexer/fetch_logs.rs b/core/src/indexer/fetch_logs.rs index 1144554..abe44a0 100644 --- a/core/src/indexer/fetch_logs.rs +++ b/core/src/indexer/fetch_logs.rs @@ -3,7 +3,7 @@ use std::{error::Error, str::FromStr, sync::Arc, time::Duration}; use ethers::{ addressbook::Address, middleware::MiddlewareError, - prelude::{BlockNumber, JsonRpcError, Log, ValueOrArray, H256, U64}, + prelude::{BlockNumber, JsonRpcError, ValueOrArray, H256, U64}, }; use regex::Regex; use tokio::{ @@ -16,11 +16,11 @@ use tracing::{debug, error, info, warn}; use crate::{ event::{config::EventProcessingConfig, RindexerEventFilter}, indexer::{log_helpers::is_relevant_block, IndexingEventProgressStatus}, - provider::JsonRpcCachedProvider, + provider::{JsonRpcCachedProvider, WrappedLog}, }; pub struct FetchLogsResult { - pub logs: Vec, + pub logs: Vec, pub from_block: U64, pub to_block: U64, } @@ -243,6 +243,7 @@ async fn fetch_historic_logs_stream( if let Some(last_log) = last_log { let next_from_block = last_log + .inner .block_number .expect("block number should always be present in a log") + U64::from(1); @@ -466,7 +467,9 @@ async fn live_indexing_stream( to_block ); } else if let Some(last_log) = last_log { - if let Some(last_log_block_number) = last_log.block_number { + if let Some(last_log_block_number) = + last_log.inner.block_number + { current_filter = current_filter.set_from_block( last_log_block_number + U64::from(1), ); diff --git a/core/src/indexer/no_code.rs b/core/src/indexer/no_code.rs index 66ca9b4..dae75a9 100644 --- a/core/src/indexer/no_code.rs +++ b/core/src/indexer/no_code.rs @@ -241,6 +241,7 @@ fn no_code_callback(params: Arc) -> EventCallbackType { block_hash, block_number, transaction_hash, + block_timestamp: None, log_index, transaction_index, }, diff --git a/core/src/indexer/process.rs b/core/src/indexer/process.rs index 7c6ab8b..251f96c 100644 --- a/core/src/indexer/process.rs +++ b/core/src/indexer/process.rs @@ -409,7 +409,7 @@ async fn live_indexing_for_contract_event_dependencies<'a>( ); } else if let Some(last_log) = last_log { if let Some(last_log_block_number) = - last_log.block_number + last_log.inner.block_number { ordering_live_indexing_details.filter = ordering_live_indexing_details diff --git a/core/src/provider.rs b/core/src/provider.rs index 02da4f4..e569321 100644 --- a/core/src/provider.rs +++ b/core/src/provider.rs @@ -10,6 +10,7 @@ use ethers::{ types::{Block, BlockNumber, H256, U256, U64}, }; use reqwest::header::HeaderMap; +use serde::{Deserialize, Serialize}; use thiserror::Error; use tokio::sync::Mutex; use url::Url; @@ -23,6 +24,16 @@ pub struct JsonRpcCachedProvider { pub max_block_range: Option, } +/// TODO: This is a temporary type until we migrate to alloy +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] +pub struct WrappedLog { + #[serde(flatten)] + pub inner: Log, + #[serde(rename = "blockTimestamp")] + #[serde(skip_serializing_if = "Option::is_none")] + pub block_timestamp: Option, +} + impl JsonRpcCachedProvider { pub fn new(provider: Provider>, max_block_range: Option) -> Self { JsonRpcCachedProvider { @@ -58,8 +69,11 @@ impl JsonRpcCachedProvider { self.provider.get_block_number().await } - pub async fn get_logs(&self, filter: &RindexerEventFilter) -> Result, ProviderError> { - self.provider.get_logs(filter.raw_filter()).await + pub async fn get_logs( + &self, + filter: &RindexerEventFilter, + ) -> Result, ProviderError> { + self.provider.request("eth_getLogs", [filter.raw_filter()]).await } pub async fn get_chain_id(&self) -> Result { diff --git a/documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx b/documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx index a2eb452..6c1971f 100644 --- a/documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx +++ b/documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx @@ -272,6 +272,7 @@ pub struct TxInformation { pub address: Address, pub block_hash: H256, pub block_number: U64, + pub block_timestamp: Option, pub transaction_hash: H256, pub log_index: U256, pub transaction_index: U64,