pub struct BlockchainDataClient {
pub chain: SharedChain,
pub config: BlockchainDataClientConfig,
/* private fields */
}
Expand description
A comprehensive client for interacting with blockchain data from multiple sources.
The BlockchainDataClient
serves as a facade that coordinates between different blockchain
data providers, caching mechanisms, and contract interactions. It provides a unified interface
for retrieving and processing blockchain data, particularly focused on DeFi protocols.
This client supports two primary data sources:
- Direct RPC connections to blockchain nodes (via WebSocket).
- HyperSync API for efficient historical data queries.
Fields§
§chain: SharedChain
The blockchain being targeted by this client instance.
config: BlockchainDataClientConfig
The configuration for the data client.
Implementations§
Source§impl BlockchainDataClient
impl BlockchainDataClient
Sourcepub fn new(config: BlockchainDataClientConfig) -> Self
pub fn new(config: BlockchainDataClientConfig) -> Self
Creates a new BlockchainDataClient
instance for the specified configuration.
§Panics
Panics if use_hypersync_for_live_data
is false and wss_rpc_url
is None
in the provided config.
Sourcepub async fn initialize_cache_database(
&mut self,
pg_connect_options: Option<PostgresConnectOptions>,
)
pub async fn initialize_cache_database( &mut self, pg_connect_options: Option<PostgresConnectOptions>, )
Initializes the database connection for the blockchain cache.
Sourcepub async fn sync_blocks(&mut self, from_block: Option<u64>) -> Result<()>
pub async fn sync_blocks(&mut self, from_block: Option<u64>) -> Result<()>
Synchronizes blockchain data by fetching and caching all blocks from the starting block to the current chain head.
Sourcepub async fn sync_pool_swaps(
&mut self,
dex_id: &str,
pool_address: String,
from_block: Option<u64>,
to_block: Option<u64>,
) -> Result<()>
pub async fn sync_pool_swaps( &mut self, dex_id: &str, pool_address: String, from_block: Option<u64>, to_block: Option<u64>, ) -> Result<()>
Fetches and caches all swap events for a specific liquidity pool within the given block range.
Sourcepub async fn sync_pool_mints(
&self,
dex_id: &str,
pool_address: String,
from_block: Option<u64>,
to_block: Option<u64>,
) -> Result<()>
pub async fn sync_pool_mints( &self, dex_id: &str, pool_address: String, from_block: Option<u64>, to_block: Option<u64>, ) -> Result<()>
Fetches and caches all mint events for a specific liquidity pool within the given block range.
Sourcepub async fn sync_pool_burns(
&self,
dex_id: &str,
pool_address: String,
from_block: Option<u64>,
to_block: Option<u64>,
) -> Result<()>
pub async fn sync_pool_burns( &self, dex_id: &str, pool_address: String, from_block: Option<u64>, to_block: Option<u64>, ) -> Result<()>
Fetches and caches all burn events for a specific liquidity pool within the given block range.
Sourcepub async fn sync_exchange_pools(
&mut self,
dex_id: &str,
from_block: Option<u64>,
to_block: Option<u64>,
) -> Result<()>
pub async fn sync_exchange_pools( &mut self, dex_id: &str, from_block: Option<u64>, to_block: Option<u64>, ) -> Result<()>
Synchronizes token and pool data for a specific DEX from the specified block.
Sourcepub async fn process_token(&mut self, token_address: String) -> Result<()>
pub async fn process_token(&mut self, token_address: String) -> Result<()>
Processes a token by address, fetching and caching its metadata if not already cached.
§Errors
Returns an error if fetching token info or adding to cache fails.
Sourcepub async fn register_exchange(&mut self, dex: DexExtended) -> Result<()>
pub async fn register_exchange(&mut self, dex: DexExtended) -> Result<()>
Registers a decentralized exchange with the client.
Sourcepub async fn process_hypersync_messages(&mut self)
pub async fn process_hypersync_messages(&mut self)
Processes incoming messages from the HyperSync client.
Sourcepub async fn process_rpc_messages(&mut self)
pub async fn process_rpc_messages(&mut self)
Processes incoming messages from the RPC client.
Sourcepub async fn subscribe_blocks_async(&mut self) -> Result<()>
pub async fn subscribe_blocks_async(&mut self) -> Result<()>
Subscribes to new blockchain blocks from the available data source.
Sourcepub async fn subscribe_pool_swaps_async(&mut self) -> Result<()>
pub async fn subscribe_pool_swaps_async(&mut self) -> Result<()>
Subscribes to new blockchain blocks from the available data source.
Sourcepub async fn unsubscribe_blocks_async(&mut self) -> Result<()>
pub async fn unsubscribe_blocks_async(&mut self) -> Result<()>
Unsubscribes from block events.
Sourcepub async fn unsubscribe_pool_swaps_async(&mut self) -> Result<()>
pub async fn unsubscribe_pool_swaps_async(&mut self) -> Result<()>
Unsubscribes from swap events.
Trait Implementations§
Source§impl DataClient for BlockchainDataClient
impl DataClient for BlockchainDataClient
Source§fn connect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn connect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn disconnect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn disconnect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
true
if the client is currently connected.Source§fn is_disconnected(&self) -> bool
fn is_disconnected(&self) -> bool
true
if the client is currently disconnected.Source§fn subscribe_blocks(&mut self, cmd: &SubscribeBlocks) -> Result<()>
fn subscribe_blocks(&mut self, cmd: &SubscribeBlocks) -> Result<()>
Source§fn subscribe_pool(&mut self, cmd: &SubscribePool) -> Result<()>
fn subscribe_pool(&mut self, cmd: &SubscribePool) -> Result<()>
Source§fn subscribe_pool_swaps(&mut self, cmd: &SubscribePoolSwaps) -> Result<()>
fn subscribe_pool_swaps(&mut self, cmd: &SubscribePoolSwaps) -> Result<()>
Source§fn subscribe_pool_liquidity_updates(
&mut self,
cmd: &SubscribePoolLiquidityUpdates,
) -> Result<()>
fn subscribe_pool_liquidity_updates( &mut self, cmd: &SubscribePoolLiquidityUpdates, ) -> Result<()>
Source§fn unsubscribe_blocks(&mut self, cmd: &UnsubscribeBlocks) -> Result<()>
fn unsubscribe_blocks(&mut self, cmd: &UnsubscribeBlocks) -> Result<()>
Source§fn unsubscribe_pool(&mut self, cmd: &UnsubscribePool) -> Result<()>
fn unsubscribe_pool(&mut self, cmd: &UnsubscribePool) -> Result<()>
Source§fn unsubscribe_pool_swaps(&mut self, cmd: &UnsubscribePoolSwaps) -> Result<()>
fn unsubscribe_pool_swaps(&mut self, cmd: &UnsubscribePoolSwaps) -> Result<()>
Source§fn unsubscribe_pool_liquidity_updates(
&mut self,
cmd: &UnsubscribePoolLiquidityUpdates,
) -> Result<()>
fn unsubscribe_pool_liquidity_updates( &mut self, cmd: &UnsubscribePoolLiquidityUpdates, ) -> Result<()>
§fn subscribe(&mut self, cmd: &SubscribeCustomData) -> Result<(), Error>
fn subscribe(&mut self, cmd: &SubscribeCustomData) -> Result<(), Error>
§fn subscribe_instruments(
&mut self,
cmd: &SubscribeInstruments,
) -> Result<(), Error>
fn subscribe_instruments( &mut self, cmd: &SubscribeInstruments, ) -> Result<(), Error>
§fn subscribe_instrument(
&mut self,
cmd: &SubscribeInstrument,
) -> Result<(), Error>
fn subscribe_instrument( &mut self, cmd: &SubscribeInstrument, ) -> Result<(), Error>
§fn subscribe_book_deltas(
&mut self,
cmd: &SubscribeBookDeltas,
) -> Result<(), Error>
fn subscribe_book_deltas( &mut self, cmd: &SubscribeBookDeltas, ) -> Result<(), Error>
§fn subscribe_book_depth10(
&mut self,
cmd: &SubscribeBookDepth10,
) -> Result<(), Error>
fn subscribe_book_depth10( &mut self, cmd: &SubscribeBookDepth10, ) -> Result<(), Error>
§fn subscribe_book_snapshots(
&mut self,
cmd: &SubscribeBookSnapshots,
) -> Result<(), Error>
fn subscribe_book_snapshots( &mut self, cmd: &SubscribeBookSnapshots, ) -> Result<(), Error>
§fn subscribe_quotes(&mut self, cmd: &SubscribeQuotes) -> Result<(), Error>
fn subscribe_quotes(&mut self, cmd: &SubscribeQuotes) -> Result<(), Error>
§fn subscribe_trades(&mut self, cmd: &SubscribeTrades) -> Result<(), Error>
fn subscribe_trades(&mut self, cmd: &SubscribeTrades) -> Result<(), Error>
§fn subscribe_mark_prices(
&mut self,
cmd: &SubscribeMarkPrices,
) -> Result<(), Error>
fn subscribe_mark_prices( &mut self, cmd: &SubscribeMarkPrices, ) -> Result<(), Error>
§fn subscribe_index_prices(
&mut self,
cmd: &SubscribeIndexPrices,
) -> Result<(), Error>
fn subscribe_index_prices( &mut self, cmd: &SubscribeIndexPrices, ) -> Result<(), Error>
§fn subscribe_bars(&mut self, cmd: &SubscribeBars) -> Result<(), Error>
fn subscribe_bars(&mut self, cmd: &SubscribeBars) -> Result<(), Error>
§fn subscribe_instrument_status(
&mut self,
cmd: &SubscribeInstrumentStatus,
) -> Result<(), Error>
fn subscribe_instrument_status( &mut self, cmd: &SubscribeInstrumentStatus, ) -> Result<(), Error>
§fn subscribe_instrument_close(
&mut self,
cmd: &SubscribeInstrumentClose,
) -> Result<(), Error>
fn subscribe_instrument_close( &mut self, cmd: &SubscribeInstrumentClose, ) -> Result<(), Error>
§fn unsubscribe(&mut self, cmd: &UnsubscribeCustomData) -> Result<(), Error>
fn unsubscribe(&mut self, cmd: &UnsubscribeCustomData) -> Result<(), Error>
§fn unsubscribe_instruments(
&mut self,
cmd: &UnsubscribeInstruments,
) -> Result<(), Error>
fn unsubscribe_instruments( &mut self, cmd: &UnsubscribeInstruments, ) -> Result<(), Error>
§fn unsubscribe_instrument(
&mut self,
cmd: &UnsubscribeInstrument,
) -> Result<(), Error>
fn unsubscribe_instrument( &mut self, cmd: &UnsubscribeInstrument, ) -> Result<(), Error>
§fn unsubscribe_book_deltas(
&mut self,
cmd: &UnsubscribeBookDeltas,
) -> Result<(), Error>
fn unsubscribe_book_deltas( &mut self, cmd: &UnsubscribeBookDeltas, ) -> Result<(), Error>
§fn unsubscribe_book_depth10(
&mut self,
cmd: &UnsubscribeBookDepth10,
) -> Result<(), Error>
fn unsubscribe_book_depth10( &mut self, cmd: &UnsubscribeBookDepth10, ) -> Result<(), Error>
§fn unsubscribe_book_snapshots(
&mut self,
cmd: &UnsubscribeBookSnapshots,
) -> Result<(), Error>
fn unsubscribe_book_snapshots( &mut self, cmd: &UnsubscribeBookSnapshots, ) -> Result<(), Error>
§fn unsubscribe_quotes(&mut self, cmd: &UnsubscribeQuotes) -> Result<(), Error>
fn unsubscribe_quotes(&mut self, cmd: &UnsubscribeQuotes) -> Result<(), Error>
§fn unsubscribe_trades(&mut self, cmd: &UnsubscribeTrades) -> Result<(), Error>
fn unsubscribe_trades(&mut self, cmd: &UnsubscribeTrades) -> Result<(), Error>
§fn unsubscribe_mark_prices(
&mut self,
cmd: &UnsubscribeMarkPrices,
) -> Result<(), Error>
fn unsubscribe_mark_prices( &mut self, cmd: &UnsubscribeMarkPrices, ) -> Result<(), Error>
§fn unsubscribe_index_prices(
&mut self,
cmd: &UnsubscribeIndexPrices,
) -> Result<(), Error>
fn unsubscribe_index_prices( &mut self, cmd: &UnsubscribeIndexPrices, ) -> Result<(), Error>
§fn unsubscribe_bars(&mut self, cmd: &UnsubscribeBars) -> Result<(), Error>
fn unsubscribe_bars(&mut self, cmd: &UnsubscribeBars) -> Result<(), Error>
§fn unsubscribe_instrument_status(
&mut self,
cmd: &UnsubscribeInstrumentStatus,
) -> Result<(), Error>
fn unsubscribe_instrument_status( &mut self, cmd: &UnsubscribeInstrumentStatus, ) -> Result<(), Error>
§fn unsubscribe_instrument_close(
&mut self,
cmd: &UnsubscribeInstrumentClose,
) -> Result<(), Error>
fn unsubscribe_instrument_close( &mut self, cmd: &UnsubscribeInstrumentClose, ) -> Result<(), Error>
§fn request_data(&self, request: &RequestCustomData) -> Result<(), Error>
fn request_data(&self, request: &RequestCustomData) -> Result<(), Error>
§fn request_instruments(&self, request: &RequestInstruments) -> Result<(), Error>
fn request_instruments(&self, request: &RequestInstruments) -> Result<(), Error>
§fn request_instrument(&self, request: &RequestInstrument) -> Result<(), Error>
fn request_instrument(&self, request: &RequestInstrument) -> Result<(), Error>
§fn request_book_snapshot(
&self,
request: &RequestBookSnapshot,
) -> Result<(), Error>
fn request_book_snapshot( &self, request: &RequestBookSnapshot, ) -> Result<(), Error>
§fn request_quotes(&self, request: &RequestQuotes) -> Result<(), Error>
fn request_quotes(&self, request: &RequestQuotes) -> Result<(), Error>
Auto Trait Implementations§
impl Freeze for BlockchainDataClient
impl !RefUnwindSafe for BlockchainDataClient
impl Send for BlockchainDataClient
impl Sync for BlockchainDataClient
impl Unpin for BlockchainDataClient
impl !UnwindSafe for BlockchainDataClient
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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