pub struct BlockchainDataClientCore {
pub chain: SharedChain,
pub config: BlockchainDataClientConfig,
pub cache: BlockchainCache,
pub hypersync_client: HyperSyncClient,
pub rpc_client: Option<BlockchainRpcClientAny>,
pub subscription_manager: DefiDataSubscriptionManager,
/* private fields */
}
Expand description
Core blockchain data client responsible for fetching, processing, and caching blockchain data.
This struct encapsulates the core functionality for interacting with blockchain networks, including syncing historical data, processing real-time events, and managing cached entities.
Fields§
§chain: SharedChain
The blockchain being targeted by this client instance.
config: BlockchainDataClientConfig
The configuration for the data client.
cache: BlockchainCache
Local cache for blockchain entities.
hypersync_client: HyperSyncClient
Client for the HyperSync data indexing service.
rpc_client: Option<BlockchainRpcClientAny>
Optional WebSocket RPC client for direct blockchain node communication.
subscription_manager: DefiDataSubscriptionManager
Manages subscriptions for various DEX events (swaps, mints, burns).
Implementations§
Source§impl BlockchainDataClientCore
impl BlockchainDataClientCore
Sourcepub fn new(
config: BlockchainDataClientConfig,
hypersync_tx: Option<UnboundedSender<BlockchainMessage>>,
data_tx: Option<UnboundedSender<DataEvent>>,
) -> Self
pub fn new( config: BlockchainDataClientConfig, hypersync_tx: Option<UnboundedSender<BlockchainMessage>>, data_tx: Option<UnboundedSender<DataEvent>>, ) -> Self
Creates a new instance of BlockchainDataClientCore
.
§Panics
Panics if use_hypersync_for_live_data
is false but wss_rpc_url
is None.
Sourcepub async fn initialize_cache_database(&mut self)
pub async fn initialize_cache_database(&mut self)
Initializes the database connection for the blockchain cache.
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Establishes connections to all configured data sources and initializes the cache.
§Errors
Returns an error if cache initialization or connection setup fails.
Sourcepub async fn sync_blocks_checked(
&mut self,
from_block: u64,
to_block: Option<u64>,
) -> Result<()>
pub async fn sync_blocks_checked( &mut self, from_block: u64, to_block: Option<u64>, ) -> Result<()>
Syncs blocks with consistency checks to ensure data integrity.
§Errors
Returns an error if block syncing fails or if consistency checks fail.
Sourcepub async fn sync_blocks(
&mut self,
from_block: u64,
to_block: Option<u64>,
use_copy_command: bool,
) -> Result<()>
pub async fn sync_blocks( &mut self, from_block: u64, to_block: Option<u64>, use_copy_command: bool, ) -> Result<()>
Synchronizes blockchain data by fetching and caching all blocks from the starting block to the current chain head.
§Errors
Returns an error if block fetching, caching, or database operations fail.
Sourcepub async fn sync_pool_events(
&mut self,
dex: &DexType,
pool_address: Address,
from_block: Option<u64>,
to_block: Option<u64>,
reset: bool,
) -> Result<()>
pub async fn sync_pool_events( &mut self, dex: &DexType, pool_address: Address, from_block: Option<u64>, to_block: Option<u64>, reset: bool, ) -> Result<()>
Synchronizes all events for a specific pool within the given block range.
§Errors
Returns an error if event syncing, parsing, or database operations fail.
Sourcepub fn process_pool_swap_event(
&self,
swap_event: &SwapEvent,
pool: &SharedPool,
dex_extended: &DexExtended,
) -> Result<PoolSwap>
pub fn process_pool_swap_event( &self, swap_event: &SwapEvent, pool: &SharedPool, dex_extended: &DexExtended, ) -> Result<PoolSwap>
Returns an error if swap event processing fails.
§Panics
Panics if swap event conversion to trade data fails.
Sourcepub fn process_pool_mint_event(
&self,
mint_event: &MintEvent,
pool: &SharedPool,
dex_extended: &DexExtended,
) -> Result<PoolLiquidityUpdate>
pub fn process_pool_mint_event( &self, mint_event: &MintEvent, pool: &SharedPool, dex_extended: &DexExtended, ) -> Result<PoolLiquidityUpdate>
Processes a mint event (liquidity addition) and converts it to a PoolLiquidityUpdate
.
§Errors
Returns an error if mint event processing fails or if the liquidity update creation fails.
Sourcepub fn process_pool_burn_event(
&self,
burn_event: &BurnEvent,
pool: &SharedPool,
dex_extended: &DexExtended,
) -> Result<PoolLiquidityUpdate>
pub fn process_pool_burn_event( &self, burn_event: &BurnEvent, pool: &SharedPool, dex_extended: &DexExtended, ) -> Result<PoolLiquidityUpdate>
Processes a burn event (liquidity removal) and converts it to a PoolLiquidityUpdate
.
Processes a pool burn event and converts it to a liquidity update.
§Errors
Returns an error if the burn event processing fails or if the liquidity update creation fails.
Sourcepub fn process_pool_collect_event(
&self,
collect_event: &CollectEvent,
pool: &SharedPool,
dex_extended: &DexExtended,
) -> Result<PoolFeeCollect>
pub fn process_pool_collect_event( &self, collect_event: &CollectEvent, pool: &SharedPool, dex_extended: &DexExtended, ) -> Result<PoolFeeCollect>
Processes a pool collect event and converts it to a fee collection.
§Errors
Returns an error if the collect event processing fails or if the fee collection creation fails.
Sourcepub async fn sync_exchange_pools(
&mut self,
dex: &DexType,
from_block: u64,
to_block: Option<u64>,
reset: bool,
) -> Result<()>
pub async fn sync_exchange_pools( &mut self, dex: &DexType, from_block: u64, to_block: Option<u64>, reset: bool, ) -> Result<()>
Synchronizes all pools and their tokens for a specific DEX within the given block range.
This method performs a comprehensive sync of:
- Pool creation events from the DEX factory
- Token metadata for all tokens in discovered pools
- Pool entities with proper token associations
§Errors
Returns an error if syncing pools, tokens, or DEX operations fail.
Sourcepub async fn register_dex_exchange(&mut self, dex_id: DexType) -> Result<()>
pub async fn register_dex_exchange(&mut self, dex_id: DexType) -> Result<()>
Registers a decentralized exchange for data collection and event monitoring.
Registration involves:
- Adding the DEX to the cache
- Loading existing pools for the DEX
- Configuring event signatures for subscriptions
§Errors
Returns an error if DEX registration, cache operations, or pool loading fails.
Sourcepub fn get_pool(&self, pool_address: &Address) -> Result<&SharedPool>
pub fn get_pool(&self, pool_address: &Address) -> Result<&SharedPool>
Retrieves a pool from the cache by its address.
§Errors
Returns an error if the pool is not registered in the cache.
Sourcepub fn send_data(&self, data: DataEvent)
pub fn send_data(&self, data: DataEvent)
Sends a data event to all subscribers through the data channel.
Sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
Disconnects all active connections and cleanup resources.
This method should be called when shutting down the client to ensure proper cleanup of network connections and background tasks.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BlockchainDataClientCore
impl !RefUnwindSafe for BlockchainDataClientCore
impl Send for BlockchainDataClientCore
impl Sync for BlockchainDataClientCore
impl Unpin for BlockchainDataClientCore
impl !UnwindSafe for BlockchainDataClientCore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more