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:
James Prestwich 2022-07-17 11:26:16 -07:00 committed by GitHub
parent ba00f549dd
commit 13ce18fd3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View File

@ -106,7 +106,7 @@
- Make `ethers-solc` optional dependency of `ethers`, needs `ethers-solc` feature to activate
[#1463](https://github.com/gakonst/ethers-rs/pull/1463)
- Add `rawMetadata:String` field to configurable contract output
- Add `rawMetadata:String` field to configurable contract output
[#1365](https://github.com/gakonst/ethers-rs/pull/1365)
- Use relative source paths and `solc --base-path`
[#1317](https://github.com/gakonst/ethers-rs/pull/1317)
@ -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

View File

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