Skip to content

Commit

Permalink
allow missing params in requests
Browse files Browse the repository at this point in the history
  • Loading branch information
BlinkyStitt committed Sep 27, 2023
1 parent f79c8ad commit 5b0aebb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Check that the websocket is working:
```
$ websocat ws://127.0.0.1:8544
{"jsonrpc":"2.0","method":"web3_clientVersion","id":1}
{"jsonrpc": "2.0", "id": 1, "method": "eth_subscribe", "params": ["newHeads"]}
{"jsonrpc": "2.0", "id": 1, "method": "eth_subscribe", "params": ["newPendingTransactions"]}
Expand Down
2 changes: 2 additions & 0 deletions config/development_polygon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ db_url = "mysql://root:[email protected]:13306/dev_web3_proxy"
deposit_factory_contract = "0x4e3BC2054788De923A04936C6ADdB99A05B0Ea36"
deposit_topic = "0x45fdc265dc29885b9a485766b03e70978440d38c7c328ee0a14fa40c76c6af54"

free_subscriptions = true

# a timeseries database is optional. it is used for making pretty graphs
influxdb_host = "http://127.0.0.1:18086"
influxdb_org = "dev_org"
Expand Down
4 changes: 3 additions & 1 deletion web3_proxy/src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use axum::response::Response;
use derive_more::From;
use serde::de::{self, Deserializer, MapAccess, SeqAccess, Visitor};
use serde::{Deserialize, Serialize};
use serde_inline_default::serde_inline_default;
use serde_json::json;
use serde_json::value::{to_raw_value, RawValue};
use std::borrow::Cow;
Expand All @@ -19,13 +20,14 @@ pub trait JsonRpcResultData = serde::Serialize + serde::de::DeserializeOwned + f

// TODO: &str here instead of String should save a lot of allocations
// TODO: generic type for params?
#[serde_inline_default]
#[derive(Clone, Deserialize, Serialize)]
pub struct JsonRpcRequest {
pub jsonrpc: String,
/// id could be a stricter type, but many rpcs do things against the spec
pub id: Box<RawValue>,
pub method: String,
/// TODO: skip serializing if serde_json::Value::Null
#[serde_inline_default(serde_json::Value::Null)]
pub params: serde_json::Value,
}

Expand Down

0 comments on commit 5b0aebb

Please sign in to comment.