Skip to content

Commit

Permalink
Remove NoSharedState struct proxy in favor of unit type
Browse files Browse the repository at this point in the history
undefined
  • Loading branch information
Jurshsmith committed Dec 23, 2023
1 parent 69754df commit cedc53e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 19 deletions.
4 changes: 2 additions & 2 deletions chaindexing-tests/src/factory/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chaindexing::{Chain, Contract, NoSharedState};
use chaindexing::{Chain, Contract};

use super::{ApprovalForAllTestEventHandler, TransferTestEventHandler};

Expand All @@ -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<NoSharedState> {
pub fn bayc_contract() -> Contract<()> {
Contract::new("BoredApeYachtClub")
.add_event(TRANSFER_EVENT_ABI, TransferTestEventHandler)
.add_event(APPROCAL_EVENT_ABI, ApprovalForAllTestEventHandler)
Expand Down
6 changes: 3 additions & 3 deletions chaindexing-tests/src/factory/event_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chaindexing::{EventContext, EventHandler, NoSharedState};
use chaindexing::{EventContext, EventHandler};

#[derive(Clone, Debug)]
pub struct NftState;
Expand All @@ -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>) {}
}
Expand All @@ -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>) {}
}
4 changes: 2 additions & 2 deletions chaindexing-tests/src/factory/events.rs
Original file line number Diff line number Diff line change
@@ -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<NoSharedState>) -> 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([(
Expand Down
8 changes: 4 additions & 4 deletions chaindexing-tests/src/tests/contract_states.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions chaindexing-tests/src/tests/events_ingester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod tests {
};
use chaindexing::{
Chain, ChaindexingRepo, Contract, EventsIngester, HasRawQueryClient, MinConfirmationCount,
NoSharedState, Repo,
Repo,
};

#[tokio::test]
Expand Down Expand Up @@ -152,7 +152,7 @@ mod tests {
let pool = test_runner::get_pool().await;

test_runner::run_test(&pool, |conn| async move {
let contracts: Vec<Contract<NoSharedState>> = vec![];
let contracts: Vec<Contract<()>> = vec![];
let json_rpc = Arc::new(empty_json_rpc());
let blocks_per_batch = 10;
let conn = Arc::new(Mutex::new(conn));
Expand Down
3 changes: 0 additions & 3 deletions chaindexing/src/event_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions chaindexing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down

0 comments on commit cedc53e

Please sign in to comment.