From cedc53ea62f6b317303bb66717e80fbb09ed6623 Mon Sep 17 00:00:00 2001 From: Joshua Oladele Date: Sat, 23 Dec 2023 12:32:36 +0100 Subject: [PATCH] Remove NoSharedState struct proxy in favor of unit type undefined --- chaindexing-tests/src/factory/contracts.rs | 4 ++-- chaindexing-tests/src/factory/event_handlers.rs | 6 +++--- chaindexing-tests/src/factory/events.rs | 4 ++-- chaindexing-tests/src/tests/contract_states.rs | 8 ++++---- chaindexing-tests/src/tests/events_ingester.rs | 4 ++-- chaindexing/src/event_handlers.rs | 3 --- chaindexing/src/lib.rs | 4 +--- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/chaindexing-tests/src/factory/contracts.rs b/chaindexing-tests/src/factory/contracts.rs index a123ce8..e6fbf39 100644 --- a/chaindexing-tests/src/factory/contracts.rs +++ b/chaindexing-tests/src/factory/contracts.rs @@ -1,4 +1,4 @@ -use chaindexing::{Chain, Contract, NoSharedState}; +use chaindexing::{Chain, Contract}; use super::{ApprovalForAllTestEventHandler, TransferTestEventHandler}; @@ -10,7 +10,7 @@ pub const APPROCAL_EVENT_ABI: &str = pub const BAYC_CONTRACT_ADDRESS: &str = "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"; pub const BAYC_CONTRACT_START_BLOCK_NUMBER: u32 = 17773490; -pub fn bayc_contract() -> Contract { +pub fn bayc_contract() -> Contract<()> { Contract::new("BoredApeYachtClub") .add_event(TRANSFER_EVENT_ABI, TransferTestEventHandler) .add_event(APPROCAL_EVENT_ABI, ApprovalForAllTestEventHandler) diff --git a/chaindexing-tests/src/factory/event_handlers.rs b/chaindexing-tests/src/factory/event_handlers.rs index 4876e21..09f9a97 100644 --- a/chaindexing-tests/src/factory/event_handlers.rs +++ b/chaindexing-tests/src/factory/event_handlers.rs @@ -1,4 +1,4 @@ -use chaindexing::{EventContext, EventHandler, NoSharedState}; +use chaindexing::{EventContext, EventHandler}; #[derive(Clone, Debug)] pub struct NftState; @@ -7,7 +7,7 @@ pub struct TransferTestEventHandler; #[async_trait::async_trait] impl EventHandler for TransferTestEventHandler { - type SharedState = NoSharedState; + type SharedState = (); async fn handle_event<'a>(&self, _event_context: EventContext<'a, Self::SharedState>) {} } @@ -16,7 +16,7 @@ pub struct ApprovalForAllTestEventHandler; #[async_trait::async_trait] impl EventHandler for ApprovalForAllTestEventHandler { - type SharedState = NoSharedState; + type SharedState = (); async fn handle_event<'a>(&self, _event_context: EventContext<'a, Self::SharedState>) {} } diff --git a/chaindexing-tests/src/factory/events.rs b/chaindexing-tests/src/factory/events.rs index a8cdfb4..3c18791 100644 --- a/chaindexing-tests/src/factory/events.rs +++ b/chaindexing-tests/src/factory/events.rs @@ -1,11 +1,11 @@ use std::collections::HashMap; -use chaindexing::{Contract, Event, Events, NoSharedState}; +use chaindexing::{Contract, Event, Events}; use ethers::types::Block; use super::{transfer_log, BAYC_CONTRACT_ADDRESS}; -pub fn transfer_event_with_contract(contract: Contract) -> Event { +pub fn transfer_event_with_contract(contract: Contract<()>) -> Event { let contract_address = BAYC_CONTRACT_ADDRESS; let transfer_log = transfer_log(contract_address); let blocks_by_number = HashMap::from([( diff --git a/chaindexing-tests/src/tests/contract_states.rs b/chaindexing-tests/src/tests/contract_states.rs index f69b575..8fdb524 100644 --- a/chaindexing-tests/src/tests/contract_states.rs +++ b/chaindexing-tests/src/tests/contract_states.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod tests { - use chaindexing::{ChaindexingRepo, EventContext, HasRawQueryClient, NoSharedState}; + use chaindexing::{ChaindexingRepo, EventContext, HasRawQueryClient}; use super::*; use crate::factory::{bayc_contract, transfer_event_with_contract}; @@ -12,7 +12,7 @@ mod tests { let mut raw_query_client = test_runner::new_repo().get_raw_query_client().await; let raw_query_txn_client = ChaindexingRepo::get_raw_query_txn_client(&mut raw_query_client).await; - let event_context: EventContext<'_, NoSharedState> = EventContext::new( + let event_context: EventContext<'_, ()> = EventContext::new( transfer_event_with_contract(bayc_contract), &raw_query_txn_client, None, @@ -38,7 +38,7 @@ mod tests { let mut raw_query_client = test_runner::new_repo().get_raw_query_client().await; let raw_query_txn_client = ChaindexingRepo::get_raw_query_txn_client(&mut raw_query_client).await; - let event_context: EventContext<'_, NoSharedState> = EventContext::new( + let event_context: EventContext<'_, ()> = EventContext::new( transfer_event_with_contract(bayc_contract), &raw_query_txn_client, None, @@ -70,7 +70,7 @@ mod tests { let mut raw_query_client = test_runner::new_repo().get_raw_query_client().await; let raw_query_txn_client = ChaindexingRepo::get_raw_query_txn_client(&mut raw_query_client).await; - let event_context: EventContext<'_, NoSharedState> = EventContext::new( + let event_context: EventContext<'_, ()> = EventContext::new( transfer_event_with_contract(bayc_contract), &raw_query_txn_client, None, diff --git a/chaindexing-tests/src/tests/events_ingester.rs b/chaindexing-tests/src/tests/events_ingester.rs index 0f25ffd..868dd8e 100644 --- a/chaindexing-tests/src/tests/events_ingester.rs +++ b/chaindexing-tests/src/tests/events_ingester.rs @@ -11,7 +11,7 @@ mod tests { }; use chaindexing::{ Chain, ChaindexingRepo, Contract, EventsIngester, HasRawQueryClient, MinConfirmationCount, - NoSharedState, Repo, + Repo, }; #[tokio::test] @@ -152,7 +152,7 @@ mod tests { let pool = test_runner::get_pool().await; test_runner::run_test(&pool, |conn| async move { - let contracts: Vec> = vec![]; + let contracts: Vec> = vec![]; let json_rpc = Arc::new(empty_json_rpc()); let blocks_per_batch = 10; let conn = Arc::new(Mutex::new(conn)); diff --git a/chaindexing/src/event_handlers.rs b/chaindexing/src/event_handlers.rs index 26a97f9..582308f 100644 --- a/chaindexing/src/event_handlers.rs +++ b/chaindexing/src/event_handlers.rs @@ -40,9 +40,6 @@ impl<'a, SharedState: Sync + Send + Clone> EventHandlerContext<'a, SharedState> } } -#[derive(Clone, Debug)] -pub struct NoSharedState; - #[async_trait::async_trait] pub trait EventHandler: Send + Sync { type SharedState: Send + Sync + Clone + Debug; diff --git a/chaindexing/src/lib.rs b/chaindexing/src/lib.rs index 5bb4f3d..e5030c9 100644 --- a/chaindexing/src/lib.rs +++ b/chaindexing/src/lib.rs @@ -19,9 +19,7 @@ use config::ConfigError; pub use contract_states::{ContractState, ContractStateMigrations, ContractStates}; pub use contracts::{Contract, ContractAddress, ContractEvent, Contracts, UnsavedContractAddress}; pub use ethers::prelude::Chain; -pub use event_handlers::{ - EventHandler, EventHandlerContext as EventContext, EventHandlers, NoSharedState, -}; +pub use event_handlers::{EventHandler, EventHandlerContext as EventContext, EventHandlers}; pub use events::{Event, Events}; pub use events_ingester::{EventsIngester, EventsIngesterJsonRpc}; pub use repos::*;