BlockchainCache

Struct BlockchainCache 

Source
pub struct BlockchainCache { /* private fields */ }
Expand description

Provides caching functionality for various blockchain domain objects.

Implementations§

Source§

impl BlockchainCache

Source

pub fn new(chain: SharedChain) -> Self

Creates a new in-memory blockchain cache for the specified chain.

Source

pub async fn get_cache_block_consistency_status( &self, ) -> Option<CachedBlocksConsistencyStatus>

Returns the highest continuous block number currently cached, if any.

Source

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.

Source

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.

Source

pub async fn initialize_database( &mut self, pg_connect_options: PgConnectOptions, )

Initializes the database connection for persistent storage.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn add_token(&mut self, token: Token) -> Result<()>

Adds a Token to the cache.

§Errors

Returns an error if adding the token to the database fails.

Source

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.

Source

pub async fn add_pool_swap(&self, swap: &PoolSwap) -> Result<()>

Adds a PoolSwap to the cache database if available.

§Errors

Returns an error if adding the swap to the database fails.

Source

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.

Source

pub async fn add_pool_swaps_batch( &self, swaps: &[PoolSwap], use_copy_command: bool, ) -> Result<()>

Adds multiple PoolSwaps to the cache database in a single batch operation if available.

§Errors

Returns an error if adding the swaps to the database fails.

Source

pub async fn add_pool_liquidity_updates_batch( &self, updates: &[PoolLiquidityUpdate], use_copy_command: bool, ) -> Result<()>

Adds multiple PoolLiquidityUpdates to the cache database in a single batch operation if available.

§Errors

Returns an error if adding the liquidity updates to the database fails.

Source

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.

Source

pub async fn update_pool_initialize_price_tick( &self, initialize_event: &InitializeEvent, ) -> Result<()>

Source

pub fn get_dex(&self, dex_id: &DexType) -> Option<SharedDex>

Returns a reference to the DexExtended associated with the given name.

Source

pub fn get_registered_dexes(&self) -> HashSet<DexType>

Returns a list of registered DexType in the cache.

Source

pub fn get_pool(&self, address: &Address) -> Option<&SharedPool>

Returns a reference to the pool associated with the given address.

Source

pub fn get_token(&self, address: &Address) -> Option<&Token>

Returns a reference to the Token associated with the given address.

Source

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.

Source

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.

Source

pub async fn update_pool_last_synced_block( &self, dex: &DexType, pool_address: &Address, block_number: u64, ) -> Result<()>

Source

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.

Source

pub async fn get_pool_last_synced_block( &self, dex: &DexType, pool_address: &Address, ) -> Result<Option<u64>>

Source

pub async fn get_pool_event_tables_last_block( &self, pool_address: &Address, ) -> Result<Option<u64>>

Retrieves the maximum block number across all pool event tables for a given pool.

§Errors

Returns an error if any of the database queries fail.

Trait Implementations§

Source§

impl Debug for BlockchainCache

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,