allow missing params in requests

This commit is contained in:
Bryan Stitt 2023-09-26 17:41:42 -07:00
parent f79c8adbf9
commit 5b0aebb6e5
3 changed files with 7 additions and 1 deletions

@ -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"]}

@ -11,6 +11,8 @@ db_url = "mysql://root:dev_web3_proxy@127.0.0.1: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"

@ -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;
@ -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,
}