Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Misc ws fixes #2389

Merged
merged 3 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 2 additions & 7 deletions ethers-providers/src/rpc/transports/ws/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,8 @@ impl WsBackend {
match item {
Ok(item) => match item {
Message::Text(t) => self.handle_text(t).await,
Message::Ping(data) => {
if self.server.send(Message::Pong(data)).await.is_err() {
return Err(WsClientError::UnexpectedClose)
}
Ok(())
}

// https://github.com/snapview/tungstenite-rs/blob/42b8797e8b7f39efb7d9322dc8af3e9089db4f7d/src/protocol/mod.rs#L172-L175
Message::Ping(_) => Ok(()),
Message::Pong(_) => Ok(()),
Message::Frame(_) => Ok(()),

Expand Down
4 changes: 2 additions & 2 deletions ethers-providers/src/rpc/transports/ws/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::JsonRpcError;
use ethers_core::types::U256;
use futures_channel::{mpsc, oneshot};
use futures_util::{select_biased, StreamExt};
use serde_json::value::RawValue;
use serde_json::value::{to_raw_value, RawValue};
use std::{
collections::{BTreeMap, HashMap},
sync::{
Expand Down Expand Up @@ -126,7 +126,7 @@ impl SubscriptionManager {
tracing::debug!(id, server_id = %server_id.0, "Registering new sub alias");
self.add_alias(server_id.0, id);
let result = U256::from(id);
RawValue::from_string(format!("\"0x{result:x}\"")).unwrap()
to_raw_value(&format!("0x{result:x}")).expect("valid json")
} else {
result
}
Expand Down
6 changes: 2 additions & 4 deletions ethers-providers/src/rpc/transports/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use async_trait::async_trait;
use ethers_core::types::U256;
use futures_channel::{mpsc, oneshot};
use serde::{de::DeserializeOwned, Serialize};
use serde_json::value::RawValue;
use serde_json::value::{to_raw_value, RawValue};

#[cfg(not(target_arch = "wasm32"))]
use crate::Authorization;
Expand Down Expand Up @@ -85,9 +85,7 @@ impl JsonRpcClient for WsClient {
T: Serialize + Send + Sync,
R: DeserializeOwned,
{
let params = serde_json::to_string(&params)?;
let params = RawValue::from_string(params)?;

let params = to_raw_value(&params)?;
let res = self.make_request(method, params).await?;

Ok(res)
Expand Down
11 changes: 4 additions & 7 deletions ethers-providers/src/rpc/transports/ws/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt;
use ethers_core::types::U256;
use futures_channel::{mpsc, oneshot};
use serde::{de, Deserialize};
use serde_json::value::RawValue;
use serde_json::value::{to_raw_value, RawValue};

use crate::{common::Request, JsonRpcError};

Expand All @@ -15,8 +15,7 @@ pub struct SubId(pub U256);

impl SubId {
pub(super) fn serialize_raw(&self) -> Result<Box<RawValue>, serde_json::Error> {
let s = serde_json::to_string(&self)?;
RawValue::from_string(s)
to_raw_value(&self)
}
}

Expand Down Expand Up @@ -213,8 +212,7 @@ impl InFlight {
}

pub(super) fn serialize_raw(&self, id: u64) -> Result<Box<RawValue>, serde_json::Error> {
let s = serde_json::to_string(&self.to_request(id))?;
RawValue::from_string(s)
to_raw_value(&self.to_request(id))
}
}

Expand All @@ -231,8 +229,7 @@ impl ActiveSub {
}

pub(super) fn serialize_raw(&self, id: u64) -> Result<Box<RawValue>, serde_json::Error> {
let s = serde_json::to_string(&self.to_request(id))?;
RawValue::from_string(s)
to_raw_value(&self.to_request(id))
}
}

Expand Down