diff --git a/web3-proxy/src/app.rs b/web3-proxy/src/app.rs index 11e4169c..e811e1a9 100644 --- a/web3-proxy/src/app.rs +++ b/web3-proxy/src/app.rs @@ -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) { diff --git a/web3-proxy/src/connection.rs b/web3-proxy/src/connection.rs index 28a55bfa..532c6454 100644 --- a/web3-proxy/src/connection.rs +++ b/web3-proxy/src/connection.rs @@ -293,11 +293,11 @@ impl ActiveRequestHandle { pub async fn request( self, method: &str, - params: &serde_json::value::RawValue, + params: &Option>, ) -> Result, 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, diff --git a/web3-proxy/src/connections.rs b/web3-proxy/src/connections.rs index a5c184b5..a7d98f53 100644 --- a/web3-proxy/src/connections.rs +++ b/web3-proxy/src/connections.rs @@ -114,7 +114,7 @@ impl Web3Connections { &self, active_request_handle: ActiveRequestHandle, method: &str, - params: &RawValue, + params: &Option>, ) -> Result, ethers::prelude::ProviderError> { let response = active_request_handle.request(method, params).await; @@ -128,7 +128,7 @@ impl Web3Connections { self: Arc, active_request_handles: Vec, method: String, - params: Box, + params: Option>, response_sender: flume::Sender>>, ) -> anyhow::Result<()> { let mut unordered_futures = FuturesUnordered::new(); diff --git a/web3-proxy/src/jsonrpc.rs b/web3-proxy/src/jsonrpc.rs index 6bcd2cad..d7e9966a 100644 --- a/web3-proxy/src/jsonrpc.rs +++ b/web3-proxy/src/jsonrpc.rs @@ -9,7 +9,7 @@ pub struct JsonRpcRequest { // pub jsonrpc: Box, pub id: Box, pub method: String, - pub params: Box, + pub params: Option>, } 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); } }