Skip to content

Commit

Permalink
Backport JSON-RPC change to index field in bestChainBlockIncluded (
Browse files Browse the repository at this point in the history
…#1097)

* Backport JSON-RPC change to `index` field in `bestChainBlockIncluded`

* PR number
  • Loading branch information
tomaka authored Sep 13, 2023
1 parent 40188db commit 1501ea5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
30 changes: 1 addition & 29 deletions lib/src/json_rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ pub enum TransactionWatchEvent<'a> {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct TransactionWatchEventBlock {
pub hash: HashHexString,
pub index: NumberAsString,
pub index: u32,
}

/// Unstable event.
Expand Down Expand Up @@ -933,34 +933,6 @@ pub enum NetworkEvent<'a> {
},
}

#[derive(Debug, Clone)]
pub struct NumberAsString(pub u32);

impl serde::Serialize for NumberAsString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.to_string().serialize(serializer)
}
}

impl<'a> serde::Deserialize<'a> for NumberAsString {
fn deserialize<D>(deserializer: D) -> Result<NumberAsString, D::Error>
where
D: serde::Deserializer<'a>,
{
let string = String::deserialize(deserializer)?;
match string.parse() {
Ok(num) => Ok(NumberAsString(num)),
Err(_) => Err(<D::Error as serde::de::Error>::invalid_value(
serde::de::Unexpected::Other("invalid number string"),
&"a valid number",
)),
}
}
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Header {
#[serde(rename = "parentHash")]
Expand Down
4 changes: 2 additions & 2 deletions light-base/src/json_rpc_service/background/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<TPlat: PlatformRef> Background<TPlat> {
methods::TransactionWatchEvent::BestChainBlockIncluded {
block: Some(methods::TransactionWatchEventBlock {
hash: methods::HashHexString(block_hash),
index: methods::NumberAsString(index),
index,
}),
},
}).await;
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<TPlat: PlatformRef> Background<TPlat> {
result: methods::TransactionWatchEvent::Finalized {
block: methods::TransactionWatchEventBlock {
hash: methods::HashHexString(block_hash),
index: methods::NumberAsString(index),
index,
},
},
}).await,
Expand Down
4 changes: 4 additions & 0 deletions wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Changed

- The `index` field of `bestChainBlockIncluded` events of `chainHead_unstable_follow` subscriptions is now a number rather than a string, in accordance with the latest changes in the JSON-RPC API specification. ([#1097](https://github.com/smol-dot/smoldot/pull/1097))

### Fixed

- Justifications are no longer downloaded for blocks that can't be finalized because an earlier block needs to be finalized first. ([#1127](https://github.com/smol-dot/smoldot/pull/1127))
Expand Down

0 comments on commit 1501ea5

Please sign in to comment.