BlockchainDataClientCore

Struct BlockchainDataClientCore 

Source
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

Source

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.

Source

pub async fn initialize_cache_database(&mut self)

Initializes the database connection for the blockchain cache.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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:

  1. Pool creation events from the DEX factory
  2. Token metadata for all tokens in discovered pools
  3. Pool entities with proper token associations
§Errors

Returns an error if syncing pools, tokens, or DEX operations fail.

Source

pub async fn register_dex_exchange(&mut self, dex_id: DexType) -> Result<()>

Registers a decentralized exchange for data collection and event monitoring.

Registration involves:

  1. Adding the DEX to the cache
  2. Loading existing pools for the DEX
  3. Configuring event signatures for subscriptions
§Errors

Returns an error if DEX registration, cache operations, or pool loading fails.

Source

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.

Source

pub fn send_data(&self, data: DataEvent)

Sends a data event to all subscribers through the data channel.

Source

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§

Source§

impl Debug for BlockchainDataClientCore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Ungil for T
where T: Send,