pub struct BlockchainCache { /* private fields */ }
Expand description
Provides caching functionality for various blockchain domain objects.
Implementations§
Source§impl BlockchainCache
impl BlockchainCache
Sourcepub fn new(chain: SharedChain) -> Self
pub fn new(chain: SharedChain) -> Self
Creates a new in-memory blockchain cache for the specified chain.
Sourcepub async fn get_cache_block_consistency_status(
&self,
) -> Option<CachedBlocksConsistencyStatus>
pub async fn get_cache_block_consistency_status( &self, ) -> Option<CachedBlocksConsistencyStatus>
Returns the highest continuous block number currently cached, if any.
Sourcepub fn min_dex_creation_block(&self) -> Option<u64>
pub fn min_dex_creation_block(&self) -> Option<u64>
Returns the earliest block number where any DEX in the cache was created on the blockchain.
Sourcepub fn get_block_timestamp(&self, block_number: u64) -> Option<&UnixNanos>
pub fn get_block_timestamp(&self, block_number: u64) -> Option<&UnixNanos>
Returns the timestamp for the specified block number if it exists in the cache.
Sourcepub async fn initialize_database(
&mut self,
pg_connect_options: PgConnectOptions,
)
pub async fn initialize_database( &mut self, pg_connect_options: PgConnectOptions, )
Initializes the database connection for persistent storage.
Sourcepub async fn toggle_performance_settings(&self, enable: bool) -> Result<()>
pub async fn toggle_performance_settings(&self, enable: bool) -> Result<()>
Toggles performance optimization settings in the database.
§Errors
Returns an error if the database is not initialized or the operation fails.
Sourcepub async fn initialize_chain(&mut self)
pub async fn initialize_chain(&mut self)
Initializes the chain by seeding it in the database and creating necessary partitions.
This method sets up the blockchain chain in the database, creates block and token partitions for optimal performance, and loads existing tokens into the cache.
Sourcepub async fn connect(&mut self, from_block: u64) -> Result<()>
pub async fn connect(&mut self, from_block: u64) -> Result<()>
Connects to the database and loads initial data.
§Errors
Returns an error if database seeding, token loading, or block loading fails.
Sourcepub async fn load_pools(&mut self, dex_id: &DexType) -> Result<()>
pub async fn load_pools(&mut self, dex_id: &DexType) -> Result<()>
Loads DEX exchange pools from the database into the in-memory cache.
§Errors
Returns an error if the DEX has not been registered or if database operations fail.
Sourcepub async fn add_block(&mut self, block: Block) -> Result<()>
pub async fn add_block(&mut self, block: Block) -> Result<()>
Adds a block to the cache and persists it to the database if available.
§Errors
Returns an error if adding the block to the database fails.
Sourcepub async fn add_blocks_batch(
&mut self,
blocks: Vec<Block>,
use_copy_command: bool,
) -> Result<()>
pub async fn add_blocks_batch( &mut self, blocks: Vec<Block>, use_copy_command: bool, ) -> Result<()>
Adds multiple blocks to the cache and persists them to the database in batch if available.
§Errors
Returns an error if adding the blocks to the database fails.
Sourcepub async fn add_dex(&mut self, dex: SharedDex) -> Result<()>
pub async fn add_dex(&mut self, dex: SharedDex) -> Result<()>
Adds a DEX to the cache with the specified identifier.
§Errors
Returns an error if adding the DEX to the database fails.
Sourcepub async fn add_pool(&mut self, pool: Pool) -> Result<()>
pub async fn add_pool(&mut self, pool: Pool) -> Result<()>
Adds a liquidity pool/pair to the cache.
§Errors
Returns an error if adding the pool to the database fails.
Sourcepub async fn add_pools_batch(&mut self, pools: Vec<Pool>) -> Result<()>
pub async fn add_pools_batch(&mut self, pools: Vec<Pool>) -> Result<()>
Adds multiple pools to the cache and persists them to the database in batch if available.
§Errors
Returns an error if adding the pools to the database fails.
Sourcepub async fn add_invalid_token(
&mut self,
address: Address,
error_string: &str,
) -> Result<()>
pub async fn add_invalid_token( &mut self, address: Address, error_string: &str, ) -> Result<()>
Adds an invalid token address with associated error information to the cache.
§Errors
Returns an error if adding the invalid token to the database fails.
Sourcepub async fn add_pool_swap(&self, swap: &PoolSwap) -> Result<()>
pub async fn add_pool_swap(&self, swap: &PoolSwap) -> Result<()>
Sourcepub async fn add_liquidity_update(
&self,
liquidity_update: &PoolLiquidityUpdate,
) -> Result<()>
pub async fn add_liquidity_update( &self, liquidity_update: &PoolLiquidityUpdate, ) -> Result<()>
Adds a PoolLiquidityUpdate
to the cache database if available.
§Errors
Returns an error if adding the liquidity update to the database fails.
Sourcepub async fn add_pool_swaps_batch(
&self,
swaps: &[PoolSwap],
use_copy_command: bool,
) -> Result<()>
pub async fn add_pool_swaps_batch( &self, swaps: &[PoolSwap], use_copy_command: bool, ) -> Result<()>
Sourcepub async fn add_pool_liquidity_updates_batch(
&self,
updates: &[PoolLiquidityUpdate],
use_copy_command: bool,
) -> Result<()>
pub async fn add_pool_liquidity_updates_batch( &self, updates: &[PoolLiquidityUpdate], use_copy_command: bool, ) -> Result<()>
Adds multiple PoolLiquidityUpdate
s to the cache database in a single batch operation if available.
§Errors
Returns an error if adding the liquidity updates to the database fails.
Sourcepub async fn add_pool_fee_collects_batch(
&self,
collects: &[PoolFeeCollect],
use_copy_command: bool,
) -> Result<()>
pub async fn add_pool_fee_collects_batch( &self, collects: &[PoolFeeCollect], use_copy_command: bool, ) -> Result<()>
Adds a batch of pool fee collect events to the cache.
§Errors
Returns an error if adding the fee collects to the database fails.
pub async fn update_pool_initialize_price_tick( &self, initialize_event: &InitializeEvent, ) -> Result<()>
Sourcepub fn get_dex(&self, dex_id: &DexType) -> Option<SharedDex>
pub fn get_dex(&self, dex_id: &DexType) -> Option<SharedDex>
Returns a reference to the DexExtended
associated with the given name.
Sourcepub fn get_registered_dexes(&self) -> HashSet<DexType>
pub fn get_registered_dexes(&self) -> HashSet<DexType>
Returns a list of registered DexType
in the cache.
Sourcepub fn get_pool(&self, address: &Address) -> Option<&SharedPool>
pub fn get_pool(&self, address: &Address) -> Option<&SharedPool>
Returns a reference to the pool associated with the given address.
Sourcepub fn get_token(&self, address: &Address) -> Option<&Token>
pub fn get_token(&self, address: &Address) -> Option<&Token>
Returns a reference to the Token
associated with the given address.
Sourcepub fn is_invalid_token(&self, address: &Address) -> bool
pub fn is_invalid_token(&self, address: &Address) -> bool
Checks if a token address is marked as invalid in the cache.
Returns true
if the address was previously recorded as invalid due to
validation or processing failures.
Sourcepub async fn update_dex_last_synced_block(
&self,
dex: &DexType,
block_number: u64,
) -> Result<()>
pub async fn update_dex_last_synced_block( &self, dex: &DexType, block_number: u64, ) -> Result<()>
Saves the checkpoint block number indicating the last completed pool synchronization for a specific DEX.
§Errors
Returns an error if the database operation fails.
pub async fn update_pool_last_synced_block( &self, dex: &DexType, pool_address: &Address, block_number: u64, ) -> Result<()>
Sourcepub async fn get_dex_last_synced_block(
&self,
dex: &DexType,
) -> Result<Option<u64>>
pub async fn get_dex_last_synced_block( &self, dex: &DexType, ) -> Result<Option<u64>>
Retrieves the saved checkpoint block number from the last completed pool synchronization for a specific DEX.
§Errors
Returns an error if the database query fails.
pub async fn get_pool_last_synced_block( &self, dex: &DexType, pool_address: &Address, ) -> Result<Option<u64>>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BlockchainCache
impl !RefUnwindSafe for BlockchainCache
impl Send for BlockchainCache
impl Sync for BlockchainCache
impl Unpin for BlockchainCache
impl !UnwindSafe for BlockchainCache
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