Struct ethers_contract::Event

source ·
pub struct Event<B, M, D> {
    pub filter: Filter,
    /* private fields */
}
Available on crate feature providers only.
Expand description

Helper for managing the event filter before querying or streaming its logs

Fields§

§filter: Filter

The event filter’s state

Implementations§

source§

impl<B, M, D> Event<B, M, D>
where B: Borrow<M>, M: Middleware, D: EthLogDecode,

source

pub fn from_block<T: Into<BlockNumber>>(self, block: T) -> Self

Sets the filter’s from block

source

pub fn to_block<T: Into<BlockNumber>>(self, block: T) -> Self

Sets the filter’s to block

source

pub fn at_block_hash<T: Into<H256>>(self, hash: T) -> Self

Sets the filter’s blockHash. Setting this will override previously set from_block and to_block fields.

source

pub fn topic0<T: Into<Topic>>(self, topic: T) -> Self

Sets the filter’s 0th topic (typically the event name for non-anonymous events)

source

pub fn topic1<T: Into<Topic>>(self, topic: T) -> Self

Sets the filter’s 1st topic

source

pub fn topic2<T: Into<Topic>>(self, topic: T) -> Self

Sets the filter’s 2nd topic

source

pub fn topic3<T: Into<Topic>>(self, topic: T) -> Self

Sets the filter’s 3rd topic

source

pub fn address(self, address: ValueOrArray<Address>) -> Self

Sets the filter’s address.

source§

impl<B, M, D> Event<B, M, D>
where B: Borrow<M>, M: Middleware, D: EthLogDecode,

source

pub async fn stream( &self ) -> Result<EventStream<'_, FilterWatcher<'_, M::Provider, Log>, D, ContractError<M>>, ContractError<M>>

Turns this event filter into Stream that yields decoded events.

This will first install a new logs filter via eth_newFilter using the configured filter object. See also FilterWatcher.

Once the filter is created, this will periodically call eth_getFilterChanges to get the newest logs and decode them.

Note: Compared to Self::subscribe, which is only available on PubsubClients, such as Websocket, this is a poll-based subscription, as the node does not notify us when a new matching log is available, instead we have to actively ask for new logs using additional RPC requests, and this is done on an interval basis.

§Example

// The event we want to get
#[derive(Clone, Debug, EthEvent)]
pub struct Approval {
    #[ethevent(indexed)]
    pub token_owner: Address,
    #[ethevent(indexed)]
    pub spender: Address,
    pub tokens: U256,
}

let ev = contract.event::<Approval>().from_block(1337).to_block(2000);
let mut event_stream = ev.stream().await.unwrap();

 while let Some(Ok(approval)) = event_stream.next().await {
     let Approval{token_owner,spender,tokens} = approval;
}
source

pub async fn stream_with_meta( &self ) -> Result<EventStream<'_, FilterWatcher<'_, M::Provider, Log>, (D, LogMeta), ContractError<M>>, ContractError<M>>

As Self::stream, but does not discard Log metadata.

source§

impl<B, M, D> Event<B, M, D>

source

pub async fn subscribe( &self ) -> Result<EventStream<'_, SubscriptionStream<'_, M::Provider, Log>, D, ContractError<M>>, ContractError<M>>

Returns a subscription for the event

See also Self::stream().

source

pub async fn subscribe_with_meta( &self ) -> Result<EventStream<'_, SubscriptionStream<'_, M::Provider, Log>, (D, LogMeta), ContractError<M>>, ContractError<M>>

As Self::subscribe, but includes event metadata

source§

impl<B, M, D> Event<B, M, D>
where B: Borrow<M>, M: Middleware, D: EthLogDecode,

source

pub async fn query(&self) -> Result<Vec<D>, ContractError<M>>

Queries the blockchain for the selected filter and returns a vector of matching event logs

source

pub async fn query_with_meta( &self ) -> Result<Vec<(D, LogMeta)>, ContractError<M>>

Queries the blockchain for the selected filter and returns a vector of logs along with their metadata

Trait Implementations§

source§

impl<B: Debug, M: Debug, D: Debug> Debug for Event<B, M, D>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B, M, D> RefUnwindSafe for Event<B, M, D>

§

impl<B, M, D> Send for Event<B, M, D>
where B: Send, D: Send, M: Send,

§

impl<B, M, D> Sync for Event<B, M, D>
where B: Sync, D: Sync, M: Sync,

§

impl<B, M, D> Unpin for Event<B, M, D>
where B: Unpin, D: Unpin, M: Unpin,

§

impl<B, M, D> UnwindSafe for Event<B, M, D>
where B: UnwindSafe, D: UnwindSafe, M: UnwindSafe,

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.

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

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

source§

fn vzip(self) -> V

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

impl<T> JsonSchemaMaybe for T