Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport JSON-RPC change to index field in bestChainBlockIncluded #1097

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions lib/src/json_rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,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 @@ -927,34 +927,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))

## 1.0.17 - 2023-08-25

### Changed
Expand Down