chain_head: Rename runtimeUpdates flag to withRuntime (#14244)

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-05-27 23:13:00 +03:00
committed by GitHub
parent 6d120d1890
commit ed499bdec1
6 changed files with 76 additions and 76 deletions
@@ -64,7 +64,7 @@ pub struct RuntimeVersionEvent {
}
/// The runtime event generated if the `follow` subscription
/// has set the `runtime_updates` flag.
/// has set the `with_runtime` flag.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "type")]
@@ -88,7 +88,7 @@ impl From<ApiError> for RuntimeEvent {
/// This is the first event generated by the `follow` subscription
/// and is submitted only once.
///
/// If the `runtime_updates` flag is set, then this event contains
/// If the `with_runtime` flag is set, then this event contains
/// the `RuntimeEvent`, otherwise the `RuntimeEvent` is not present.
#[derive(Debug, Clone, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -99,23 +99,23 @@ pub struct Initialized<Hash> {
///
/// # Note
///
/// This is present only if the `runtime_updates` flag is set for
/// This is present only if the `with_runtime` flag is set for
/// the `follow` subscription.
pub finalized_block_runtime: Option<RuntimeEvent>,
/// Privately keep track if the `finalized_block_runtime` should be
/// serialized.
#[serde(default)]
pub(crate) runtime_updates: bool,
pub(crate) with_runtime: bool,
}
impl<Hash: Serialize> Serialize for Initialized<Hash> {
/// Custom serialize implementation to include the `RuntimeEvent` depending
/// on the internal `runtime_updates` flag.
/// on the internal `with_runtime` flag.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if self.runtime_updates {
if self.with_runtime {
let mut state = serializer.serialize_struct("Initialized", 2)?;
state.serialize_field("finalizedBlockHash", &self.finalized_block_hash)?;
state.serialize_field("finalizedBlockRuntime", &self.finalized_block_runtime)?;
@@ -140,23 +140,23 @@ pub struct NewBlock<Hash> {
///
/// # Note
///
/// This is present only if the `runtime_updates` flag is set for
/// This is present only if the `with_runtime` flag is set for
/// the `follow` subscription.
pub new_runtime: Option<RuntimeEvent>,
/// Privately keep track if the `finalized_block_runtime` should be
/// serialized.
#[serde(default)]
pub(crate) runtime_updates: bool,
pub(crate) with_runtime: bool,
}
impl<Hash: Serialize> Serialize for NewBlock<Hash> {
/// Custom serialize implementation to include the `RuntimeEvent` depending
/// on the internal `runtime_updates` flag.
/// on the internal `with_runtime` flag.
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if self.runtime_updates {
if self.with_runtime {
let mut state = serializer.serialize_struct("NewBlock", 3)?;
state.serialize_field("blockHash", &self.block_hash)?;
state.serialize_field("parentBlockHash", &self.parent_block_hash)?;
@@ -253,7 +253,7 @@ mod tests {
let event: FollowEvent<String> = FollowEvent::Initialized(Initialized {
finalized_block_hash: "0x1".into(),
finalized_block_runtime: None,
runtime_updates: false,
with_runtime: false,
});
let ser = serde_json::to_string(&event).unwrap();
@@ -278,7 +278,7 @@ mod tests {
let mut initialized = Initialized {
finalized_block_hash: "0x1".into(),
finalized_block_runtime: Some(runtime_event),
runtime_updates: true,
with_runtime: true,
};
let event: FollowEvent<String> = FollowEvent::Initialized(initialized.clone());
@@ -291,8 +291,8 @@ mod tests {
assert_eq!(ser, exp);
let event_dec: FollowEvent<String> = serde_json::from_str(exp).unwrap();
// The `runtime_updates` field is used for serialization purposes.
initialized.runtime_updates = false;
// The `with_runtime` field is used for serialization purposes.
initialized.with_runtime = false;
assert!(matches!(
event_dec, FollowEvent::Initialized(ref dec) if dec == &initialized
));
@@ -305,7 +305,7 @@ mod tests {
block_hash: "0x1".into(),
parent_block_hash: "0x2".into(),
new_runtime: None,
runtime_updates: false,
with_runtime: false,
});
let ser = serde_json::to_string(&event).unwrap();
@@ -331,7 +331,7 @@ mod tests {
block_hash: "0x1".into(),
parent_block_hash: "0x2".into(),
new_runtime: Some(runtime_event),
runtime_updates: true,
with_runtime: true,
};
let event: FollowEvent<String> = FollowEvent::NewBlock(new_block.clone());
@@ -345,8 +345,8 @@ mod tests {
assert_eq!(ser, exp);
let event_dec: FollowEvent<String> = serde_json::from_str(exp).unwrap();
// The `runtime_updates` field is used for serialization purposes.
new_block.runtime_updates = false;
// The `with_runtime` field is used for serialization purposes.
new_block.with_runtime = false;
assert!(matches!(
event_dec, FollowEvent::NewBlock(ref dec) if dec == &new_block
));
@@ -356,7 +356,7 @@ mod tests {
block_hash: "0x1".into(),
parent_block_hash: "0x2".into(),
new_runtime: None,
runtime_updates: true,
with_runtime: true,
};
let event: FollowEvent<String> = FollowEvent::NewBlock(new_block.clone());
@@ -364,7 +364,7 @@ mod tests {
let exp =
r#"{"event":"newBlock","blockHash":"0x1","parentBlockHash":"0x2","newRuntime":null}"#;
assert_eq!(ser, exp);
new_block.runtime_updates = false;
new_block.with_runtime = false;
let event_dec: FollowEvent<String> = serde_json::from_str(exp).unwrap();
assert!(matches!(
event_dec, FollowEvent::NewBlock(ref dec) if dec == &new_block