mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 03:55:40 +00:00
backend/rpc: Allow older version of the initialized event
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::config::BlockHash;
|
|||||||
use crate::{Config, Error};
|
use crate::{Config, Error};
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
|
|
||||||
@@ -378,8 +378,7 @@ pub enum FollowEvent<Hash> {
|
|||||||
///
|
///
|
||||||
/// This is the first event generated by the `follow` subscription
|
/// This is the first event generated by the `follow` subscription
|
||||||
/// and is submitted only once.
|
/// and is submitted only once.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct Initialized<Hash> {
|
pub struct Initialized<Hash> {
|
||||||
/// The hashes of the last finalized blocks.
|
/// The hashes of the last finalized blocks.
|
||||||
pub finalized_block_hashes: Vec<Hash>,
|
pub finalized_block_hashes: Vec<Hash>,
|
||||||
@@ -392,6 +391,30 @@ pub struct Initialized<Hash> {
|
|||||||
pub finalized_block_runtime: Option<RuntimeEvent>,
|
pub finalized_block_runtime: Option<RuntimeEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'de, Hash: Deserialize<'de>> Deserialize<'de> for Initialized<Hash> {
|
||||||
|
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
|
// Custom struct that can deserialize both `finalizedBlockHash` and `finalizedBlockHashes`.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct InitializedIR<Hash> {
|
||||||
|
finalized_block_hashes: Option<Vec<Hash>>,
|
||||||
|
finalized_block_hash: Option<Hash>,
|
||||||
|
finalized_block_runtime: Option<RuntimeEvent>,
|
||||||
|
}
|
||||||
|
|
||||||
|
let ir = InitializedIR::deserialize(deserializer)?;
|
||||||
|
let finalized_block_hashes = ir
|
||||||
|
.finalized_block_hashes
|
||||||
|
.or_else(|| ir.finalized_block_hash.map(|hash| vec![hash]))
|
||||||
|
.ok_or_else(|| serde::de::Error::custom("Missing finalized block hashes"))?;
|
||||||
|
|
||||||
|
Ok(Initialized {
|
||||||
|
finalized_block_hashes,
|
||||||
|
finalized_block_runtime: ir.finalized_block_runtime,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The runtime event generated if the `follow` subscription
|
/// The runtime event generated if the `follow` subscription
|
||||||
/// has set the `with_runtime` flag.
|
/// has set the `with_runtime` flag.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user