use super::{EthRpcLogFilter, Header, Log};
use cfx_types::H256;
use serde::{de::Error, Deserialize, Deserializer, Serialize};
use serde_json::{from_value, Value};
#[allow(dead_code)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(untagged, rename_all = "camelCase")]
pub enum Result {
Header(Header),
Log(Log),
TransactionHash(H256),
}
#[derive(Debug, Deserialize, PartialEq, Eq, Hash, Clone)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub enum Kind {
NewHeads,
Logs,
NewPendingTransactions,
Syncing,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum Params {
None,
Logs(EthRpcLogFilter),
}
impl Default for Params {
fn default() -> Self { Params::None }
}
impl<'a> Deserialize<'a> for Params {
fn deserialize<D>(
deserializer: D,
) -> ::std::result::Result<Params, D::Error>
where D: Deserializer<'a> {
let v: Value = Deserialize::deserialize(deserializer)?;
if v.is_null() {
return Ok(Params::None);
}
from_value(v.clone()).map(Params::Logs).map_err(|e| {
D::Error::custom(format!("Invalid Pub-Sub parameters: {}", e))
})
}
}