Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions subxt/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ impl From<DispatchError> for Error {
/// An RPC error. Since we are generic over the RPC client that is used,
/// the error is boxed and could be casted.
#[derive(Debug, thiserror::Error)]
#[error("RPC error: {0}")]
#[error("RPC error")]
pub enum RpcError {
// Dev note: We need the error to be safely sent between threads
// for `subscribe_to_block_headers_filling_in_gaps` and friends.
/// Error related to the RPC client.
ClientError(Box<dyn std::error::Error + Send + 'static>),
/// Custom error.
Custom(String),
/// The RPC subscription dropped.
SubscriptionDropped,
}

/// This is our attempt to decode a runtime DispatchError. We either
Expand Down
20 changes: 8 additions & 12 deletions subxt/src/rpc/jsonrpsee_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl RpcClientT for Client {
params: Option<Box<RawValue>>,
) -> RpcFuture<'a, Box<RawValue>> {
Box::pin(async move {
let params = prep_params_for_jsonrpsee(params)?;
let params = prep_params_for_jsonrpsee(params);
let res = ClientT::request(self, method, Some(params))
.await
.map_err(|e| RpcError::ClientError(Box::new(e)))?;
Expand All @@ -47,7 +47,7 @@ impl RpcClientT for Client {
unsub: &'a str,
) -> RpcFuture<'a, RpcSubscription> {
Box::pin(async move {
let params = prep_params_for_jsonrpsee(params)?;
let params = prep_params_for_jsonrpsee(params);
let sub = SubscriptionClientT::subscribe::<Box<RawValue>>(
self,
sub,
Expand All @@ -65,22 +65,18 @@ impl RpcClientT for Client {

// This is ugly; we have to encode to Value's to be compat with the jsonrpc interface.
// Remove and simplify this once something like https://github.com/paritytech/jsonrpsee/issues/862 is in:
fn prep_params_for_jsonrpsee(
params: Option<Box<RawValue>>,
) -> Result<ParamsSer<'static>, RpcError> {
fn prep_params_for_jsonrpsee(params: Option<Box<RawValue>>) -> ParamsSer<'static> {
let params = match params {
Some(params) => params,
// No params? avoid any work and bail early.
None => return Ok(ParamsSer::Array(Vec::new())),
None => return ParamsSer::Array(Vec::new()),
};
let val = serde_json::to_value(&params).expect("RawValue guarantees valid JSON");
let arr = match val {
Value::Array(arr) => Ok(arr),
Value::Array(arr) => arr,
_ => {
Err(RpcError::Custom(format!(
"RPC Params are expected to be an array but got {params}"
)))
panic!("RPC Params are expected to be an array but got {params}");
}
}?;
Ok(ParamsSer::Array(arr))
};
ParamsSer::Array(arr)
}
5 changes: 5 additions & 0 deletions subxt/src/rpc/rpc_client_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ pub use serde_json::value::RawValue;
/// the caller. This is the case because we want the methods to be object-safe (which prohibits
/// generics), and want to avoid any unnecessary allocations in serializing/deserializing
/// parameters.
///
/// # Note
///
/// Implementations are free to panic if the provided parameters are not a valid
/// JSON Array.
pub trait RpcClientT: Send + Sync + 'static {
/// Make a raw request for which we expect a single response back from. Implementations
/// should expect that the params will either be `None`, or be an already-serialized
Expand Down
4 changes: 2 additions & 2 deletions subxt/src/tx/tx_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
_ => continue,
}
}
Err(RpcError::Custom("RPC subscription dropped".into()).into())
Err(RpcError::SubscriptionDropped.into())
}

/// Wait for the transaction to be finalized, and return a [`TxInBlock`]
Expand All @@ -133,7 +133,7 @@ where
_ => continue,
}
}
Err(RpcError::Custom("RPC subscription dropped".into()).into())
Err(RpcError::SubscriptionDropped.into())
}

/// Wait for the transaction to be finalized, and for the transaction events to indicate
Expand Down