diff --git a/subxt/src/rpc/rpc.rs b/subxt/src/rpc/rpc.rs index d0aa8ffa12..58ef1a9376 100644 --- a/subxt/src/rpc/rpc.rs +++ b/subxt/src/rpc/rpc.rs @@ -41,7 +41,10 @@ use super::{ rpc_params, - subscription_events::FollowEvent, + subscription_events::{ + ChainHeadEvent, + FollowEvent, + }, RpcClient, RpcClientT, Subscription, @@ -629,7 +632,7 @@ impl Rpc { &self, hash: T::Hash, subscription_id: String, - ) -> Result>, Error> { + ) -> Result>, Error> { let subscription = self .client .subscribe( diff --git a/subxt/src/rpc/subscription_events.rs b/subxt/src/rpc/subscription_events.rs index 722d6d3aa5..96fc292c7d 100644 --- a/subxt/src/rpc/subscription_events.rs +++ b/subxt/src/rpc/subscription_events.rs @@ -125,3 +125,28 @@ pub enum FollowEvent { /// will be generated. Stop, } + +/// The result of a chain head method. +#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ChainHeadResult { + /// 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 { + /// The request completed successfully. + Done(ChainHeadResult), + /// 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, +}