Struct ethers_contract::Event

source ·
pub struct Event<'a, M, D> {
    pub filter: Filter,
    /* private fields */
}
Expand description

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

Fields§

§filter: Filter

The event filter’s state

Implementations§

Sets the filter’s from block

Sets the filter’s to block

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

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

Sets the filter’s 1st topic

Sets the filter’s 2nd topic

Sets the filter’s 3rd topic

Sets the filter’s address.

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;
}

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

Returns a subscription for the event

See also Self::stream().

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

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

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more