rpc/events: Add events for chainHead methods

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2022-11-25 18:48:54 +00:00
parent bfcdcc0ba9
commit 07638f39c3
2 changed files with 30 additions and 2 deletions
+5 -2
View File
@@ -41,7 +41,10 @@
use super::{
rpc_params,
subscription_events::FollowEvent,
subscription_events::{
ChainHeadEvent,
FollowEvent,
},
RpcClient,
RpcClientT,
Subscription,
@@ -629,7 +632,7 @@ impl<T: Config> Rpc<T> {
&self,
hash: T::Hash,
subscription_id: String,
) -> Result<Subscription<FollowEvent<T::Hash>>, Error> {
) -> Result<Subscription<ChainHeadEvent<String>>, Error> {
let subscription = self
.client
.subscribe(
+25
View File
@@ -125,3 +125,28 @@ pub enum FollowEvent<Hash> {
/// will be generated.
Stop,
}
/// The result of a chain head method.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChainHeadResult<T> {
/// Result of the method.
pub result: T,
}
/// The event generated by the body / call / storage methods.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "event")]
pub enum ChainHeadEvent<T> {
/// The request completed successfully.
Done(ChainHeadResult<T>),
/// The resources requested are inaccessible.
///
/// Resubmitting the request later might succeed.
Inaccessible(ErrorEvent),
/// An error occurred. This is definitive.
Error(ErrorEvent),
/// The provided subscription ID is stale or invalid.
Disjoint,
}