Expand the subscribe_and_watch example (#361)

* Expand the subscribe_and_watch example

* Fix comment typos

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* Add note about error on decoding events

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
This commit is contained in:
James Wilson
2021-12-10 11:20:58 +00:00
committed by GitHub
parent d0a1a79c5f
commit dd9bb11fae
2 changed files with 137 additions and 3 deletions
+5 -3
View File
@@ -414,7 +414,8 @@ impl<T: Config> TransactionEvents<T> {
&self.events
}
/// Find all of the events matching the event type provided as a generic parameter.
/// Find all of the events matching the event type provided as a generic parameter. This
/// will return an error if a matching event is found but cannot be properly decoded.
pub fn find_events<E: crate::Event>(&self) -> Result<Vec<E>, Error> {
self.events
.iter()
@@ -422,7 +423,8 @@ impl<T: Config> TransactionEvents<T> {
.collect()
}
/// Find the first event that matches the event type provided as a generic parameter.
/// Find the first event that matches the event type provided as a generic parameter. This
/// will return an error if a matching event is found but cannot be properly decoded.
///
/// Use [`TransactionEvents::find_events`], or iterate over [`TransactionEvents`] yourself
/// if you'd like to handle multiple events of the same type.
@@ -436,7 +438,7 @@ impl<T: Config> TransactionEvents<T> {
}
/// Find an event. Returns true if it was found.
pub fn has_event<E: crate::Event>(self) -> Result<bool, Error> {
pub fn has_event<E: crate::Event>(&self) -> Result<bool, Error> {
Ok(self.find_first_event::<E>()?.is_some())
}
}