Struct eventify_idx::app::App

source ·
pub struct App<T, U>
where T: JsonRpcClient + Clone + Send + Sync, U: Storage + Auth + Clone + Send + Sync,
{ pub src_block: BlockNumber, pub dst_block: BlockNumber, /* private fields */ }
Expand description

The App struct represents an application with a JSON-RPC client (T) and storage (U). It manages the interaction between the blockchain and storage, keeping track of the source and destination block numbers for operations.

Type Parameters

  • T: A JSON-RPC client that implements JsonRpcClient, Clone, Send, and Sync.
  • U: A storage system that implements Storage, Auth, Clone, Send, and Sync.

Fields§

§src_block: BlockNumber

The starting block number from which the App operates.

§dst_block: BlockNumber

The ending block number up to which the App operates.

Implementations§

source§

impl<T, U> App<T, U>
where T: JsonRpcClient + Clone + Send + Sync, U: Storage + Auth + Clone + Send + Sync,

source

pub fn new( transport_node: Option<NodeProvider<T>>, transport_storage: Option<U>, src_block: BlockNumber, dst_block: BlockNumber ) -> Self

Create a new instance of the indexer

source

pub fn with_src_block(self, src_block: BlockNumber) -> Self

source

pub fn with_dst_block(self, dst_block: BlockNumber) -> Self

source

pub fn with_node_conn(self, transport: NodeProvider<T>) -> Self

source

pub fn with_storage(self, url: &str) -> Self

source

pub fn src_block(&self) -> u64

source

pub fn dst_block(&self) -> u64

source

pub fn storage_conn(&self) -> Result<&U, Error>

source

pub async fn fetch_block_with_txs( &self, block: BlockId ) -> Result<Block<Transaction>, Error>

Retrieves block details along with full transaction objects for a given block ID.

Arguments
  • block - The block ID for which to fetch details.
Returns

Returns a Result containing the block details on success, or an error if the block cannot be fetched or if the transport node is unavailable.

source

pub async fn fetch_block(&self, block: BlockId) -> Result<Block<TxHash>, Error>

Retrieves block details for a given block ID.

This function does not return transaction objects.

source

pub async fn fetch_logs( &self, criterias: &Criterias, block: BlockNumber ) -> Result<Vec<Log>, Error>

Fetches logs based on the specified filter.

Arguments
  • criteria - The filter criteria used to fetch the logs.
Returns

Returns a Result containing a vector of logs on success, or an error if the logs cannot be fetched or if the transport node is unavailable.

source

pub async fn fetch_transactions( &self, block: BlockNumber ) -> Result<Vec<Transaction>, Error>

Fetches transactions for a specified block number.

source

pub async fn fetch_indexed_data( &self, block: BlockNumber ) -> Result<(IndexedBlock, Vec<IndexedTransaction>), Error>

Fetches indexed block and transaction objects for a specified block number.

Arguments
  • block - The block number for which to fetch the data.
Returns

Returns a Result containing the indexed block and its transactions on success, or an error if the block cannot be fetched.

source

pub async fn get_latest_block(&self) -> Result<u64, Error>

Returns the latest finalized block number.

This function queries the underlying transport node for the current block number. If the transport node is not set, or if there is an error in fetching the block number, the function will return an appropriate error.

source

pub async fn is_latest_block(&self, block: u64) -> Result<bool, Error>

Checks whether the provided block number is the latest finalized block

source§

impl<U: Storage + Auth + Clone + Send + Sync> App<Http, U>

source

pub fn with_http(self, node_url: &str) -> Result<Self, Error>

Configures the application to use an HTTP transport node.

Example
use ethers_providers::Http;
use eventify_idx::App;
use eventify_primitives::storage::Postgres;
let app: App<Http, Postgres> = App::default().with_http("http://localhost:8545")?;
// Use `app` for further operations...
Arguments
  • node_url - The URL of the HTTP node.
Errors

Returns an error if the URL parsing fails or the HTTP transport cannot be created.

source§

impl<U: Storage + Auth + Clone + Send + Sync> App<Ipc, U>

source

pub async fn with_ipc(self, node_url: &str) -> Result<Self, Error>

Creates a new instance of the App with the IPC transport.

Example
use ethers_providers::Ipc;
use eventify_idx::App;
use eventify_primitives::storage::Postgres;
let app: App<Ipc, Postgres> = App::default().with_ipc("ipc://path/to/socket").await?;
// use app...
Arguments
  • node_url - The URL for the IPC node.
Errors

Returns an error if the IPC transport creation fails.

source

pub async fn subscribe_blocks( &self ) -> Result<SubscriptionStream<'_, Ipc, Block<TxHash>>, Error>

source

pub async fn subscribe_logs( &self, filter: Filter ) -> Result<SubscriptionStream<'_, Ipc, Log>, Error>

source§

impl<U: Storage + Auth + Clone + Send + Sync> App<Ws, U>

source

pub async fn with_websocket(self, node_url: &str) -> Result<Self, Error>

Creates a new instance of the App with the WebSocket transport.

Example
use ethers_providers::Ws;
use eventify_idx::App;
use eventify_primitives::storage::Postgres;
let app: App<Ws, Postgres> = App::default().with_websocket("ws://localhost:8546").await?;
// Use `app` for further operations...
Arguments
  • node_url - The URL for the WebSocket node.
Errors

Returns an error if the WebSocket transport creation fails.

source

pub async fn with_ws(self, node_url: &str) -> Result<Self, Error>

Creates a new instance of the App with the WebSocket transport

An alias for [with_websocket]

source

pub async fn subscribe_blocks( &self ) -> Result<SubscriptionStream<'_, Ws, Block<TxHash>>, Error>

source

pub async fn subscribe_logs( &self, filter: Filter ) -> Result<SubscriptionStream<'_, Ws, Log>, Error>

Trait Implementations§

source§

impl<T, U> Clone for App<T, U>
where T: JsonRpcClient + Clone + Send + Sync + Clone, U: Storage + Auth + Clone + Send + Sync + Clone,

source§

fn clone(&self) -> App<T, U>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, U> Debug for App<T, U>
where T: JsonRpcClient + Clone + Send + Sync + Debug, U: Storage + Auth + Clone + Send + Sync + Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<T, U> Default for App<T, U>
where T: JsonRpcClient + Clone + Send + Sync, U: Storage + Auth + Clone + Send + Sync,

source§

fn default() -> Self

Creates a new App instance with default values.

The src_block is set to 0, indicating the start of the blockchain, and dst_block is set to BlockNumber::MAX, representing the end of the blockchain.

Auto Trait Implementations§

§

impl<T, U> !RefUnwindSafe for App<T, U>

§

impl<T, U> Send for App<T, U>

§

impl<T, U> Sync for App<T, U>

§

impl<T, U> Unpin for App<T, U>

§

impl<T, U> !UnwindSafe for App<T, U>

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> Instrument for T

source§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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

impl<T> WithSubscriber for T

source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> JsonSchemaMaybe for T