params are optional apparently

This commit is contained in:
Bryan Stitt 2022-05-12 03:40:41 +00:00
parent fffbda468d
commit 3427f5eab9
4 changed files with 12 additions and 10 deletions

@ -259,7 +259,11 @@ impl Web3ProxyApp {
let cache_key = (
best_head_block_number,
request.method.clone(),
request.params.to_string(),
request
.params
.clone()
.map(|x| x.to_string())
.unwrap_or_else(|| "[]".to_string()),
);
if let Some(cached) = self.response_cache.read().await.get(&cache_key) {

@ -293,11 +293,11 @@ impl ActiveRequestHandle {
pub async fn request(
self,
method: &str,
params: &serde_json::value::RawValue,
params: &Option<Box<serde_json::value::RawValue>>,
) -> Result<Box<RawValue>, ethers::prelude::ProviderError> {
// TODO: this should probably be trace level and use a span
// TODO: it would be nice to have the request id on this
trace!("Sending {}({}) to {}", method, params.to_string(), self.0);
trace!("Sending {}({:?}) to {}", method, params, self.0);
let response = match &self.0.provider {
Web3Provider::Http(provider) => provider.request(method, params).await,

@ -114,7 +114,7 @@ impl Web3Connections {
&self,
active_request_handle: ActiveRequestHandle,
method: &str,
params: &RawValue,
params: &Option<Box<RawValue>>,
) -> Result<Box<RawValue>, ethers::prelude::ProviderError> {
let response = active_request_handle.request(method, params).await;
@ -128,7 +128,7 @@ impl Web3Connections {
self: Arc<Self>,
active_request_handles: Vec<ActiveRequestHandle>,
method: String,
params: Box<RawValue>,
params: Option<Box<RawValue>>,
response_sender: flume::Sender<anyhow::Result<Box<RawValue>>>,
) -> anyhow::Result<()> {
let mut unordered_futures = FuturesUnordered::new();

@ -9,7 +9,7 @@ pub struct JsonRpcRequest {
// pub jsonrpc: Box<RawValue>,
pub id: Box<RawValue>,
pub method: String,
pub params: Box<RawValue>,
pub params: Option<Box<RawValue>>,
}
impl fmt::Debug for JsonRpcRequest {
@ -176,7 +176,7 @@ mod tests {
assert_eq!(output.id.to_string(), "1");
assert_eq!(output.method, "eth_blockNumber");
assert_eq!(output.params.to_string(), "[]");
assert_eq!(output.params.unwrap().to_string(), "[]");
// test deserializing it into an enum
let output: JsonRpcRequestEnum = serde_json::from_str(input).unwrap();
@ -196,7 +196,7 @@ mod tests {
assert_eq!(output[0].id.to_string(), "27");
assert_eq!(output[0].method, "eth_getCode");
assert_eq!(
output[0].params.to_string(),
output[0].params.as_ref().unwrap().to_string(),
r#"["0x5ba1e12693dc8f9c48aad8770482f4739beed696","0xe0e6a4"]"#
);
@ -207,7 +207,5 @@ mod tests {
let output: JsonRpcRequestEnum = serde_json::from_str(input).unwrap();
assert!(matches!(output, JsonRpcRequestEnum::Batch(_)));
assert_eq!(0, 1);
}
}