feature: allow event builder to stream with meta (#1483)
* feature: allow event builder to stream with meta * doc: improve rustdoc * feature: subscribe_with_meta * chore: fmt
This commit is contained in:
parent
ba00f549dd
commit
13ce18fd3b
|
@ -237,6 +237,8 @@
|
|||
|
||||
### Unreleased
|
||||
|
||||
- Add `Event::stream_with_meta` and `Event::subscribe_with_meta`
|
||||
[#1483](https://github.com/gakonst/ethers-rs/pull/1483)
|
||||
- Added tx builder methods to `ContractFactory`
|
||||
[#1289](https://github.com/gakonst/ethers-rs/pull/1289)
|
||||
- Relax Clone requirements when Arc<Middleware> is used
|
||||
|
|
|
@ -164,6 +164,26 @@ where
|
|||
self.provider.watch(&self.filter).await.map_err(ContractError::MiddlewareError)?;
|
||||
Ok(EventStream::new(filter.id, filter, Box::new(move |log| self.parse_log(log))))
|
||||
}
|
||||
|
||||
/// As [`Self::stream`], but does not discard [`Log`] metadata.
|
||||
pub async fn stream_with_meta(
|
||||
&'a self,
|
||||
) -> Result<
|
||||
// Wraps the FilterWatcher with a mapping to the event
|
||||
EventStream<'a, FilterWatcher<'a, M::Provider, Log>, (D, LogMeta), ContractError<M>>,
|
||||
ContractError<M>,
|
||||
> {
|
||||
let filter =
|
||||
self.provider.watch(&self.filter).await.map_err(ContractError::MiddlewareError)?;
|
||||
Ok(EventStream::new(
|
||||
filter.id,
|
||||
filter,
|
||||
Box::new(move |log| {
|
||||
let meta = LogMeta::from(&log);
|
||||
Ok((self.parse_log(log)?, meta))
|
||||
}),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, M, D> Event<'a, M, D>
|
||||
|
@ -189,6 +209,28 @@ where
|
|||
.map_err(ContractError::MiddlewareError)?;
|
||||
Ok(EventStream::new(filter.id, filter, Box::new(move |log| self.parse_log(log))))
|
||||
}
|
||||
|
||||
pub async fn subscribe_with_meta(
|
||||
&'a self,
|
||||
) -> Result<
|
||||
// Wraps the SubscriptionStream with a mapping to the event
|
||||
EventStream<'a, SubscriptionStream<'a, M::Provider, Log>, (D, LogMeta), ContractError<M>>,
|
||||
ContractError<M>,
|
||||
> {
|
||||
let filter = self
|
||||
.provider
|
||||
.subscribe_logs(&self.filter)
|
||||
.await
|
||||
.map_err(ContractError::MiddlewareError)?;
|
||||
Ok(EventStream::new(
|
||||
filter.id,
|
||||
filter,
|
||||
Box::new(move |log| {
|
||||
let meta = LogMeta::from(&log);
|
||||
Ok((self.parse_log(log)?, meta))
|
||||
}),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<M, D> Event<'_, M, D>
|
||||
|
|
Loading…
Reference in New Issue