Fix clippy lints

This commit is contained in:
Paul Hauner
2021-09-25 11:26:54 +10:00
parent 9c8bf4965e
commit 95ef497e7b
5 changed files with 38 additions and 15 deletions

1
Cargo.lock generated
View File

@@ -2072,6 +2072,7 @@ dependencies = [
"eth1", "eth1",
"eth2_serde_utils 0.1.0", "eth2_serde_utils 0.1.0",
"futures", "futures",
"hex",
"reqwest", "reqwest",
"sensitive_url", "sensitive_url",
"serde", "serde",

View File

@@ -21,3 +21,4 @@ warp = { git = "https://github.com/paulhauner/warp ", branch = "cors-wildcard" }
environment = { path = "../../lighthouse/environment" } environment = { path = "../../lighthouse/environment" }
bytes = "1.1.0" bytes = "1.1.0"
task_executor = { path = "../../common/task_executor" } task_executor = { path = "../../common/task_executor" }
hex = "0.4.2"

View File

@@ -16,8 +16,8 @@ pub enum Error {
JsonRpc(RpcError), JsonRpc(RpcError),
Json(serde_json::Error), Json(serde_json::Error),
ServerMessage(String), ServerMessage(String),
Eip155Error, Eip155Failure,
NoResultOrError, NoErrorOrResult,
IsSyncing, IsSyncing,
} }

View File

@@ -7,7 +7,7 @@ use sensitive_url::SensitiveUrl;
use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::json; use serde_json::json;
use std::time::Duration; use std::time::Duration;
use types::{execution_payload::serde_logs_bloom, EthSpec, FixedVector, Transaction, VariableList}; use types::{EthSpec, FixedVector, Transaction, Unsigned, VariableList};
const STATIC_ID: u32 = 1; const STATIC_ID: u32 = 1;
const JSONRPC_VERSION: &str = "2.0"; const JSONRPC_VERSION: &str = "2.0";
@@ -51,7 +51,7 @@ impl HttpJsonRpc {
) -> Result<T, Error> { ) -> Result<T, Error> {
let body = JsonRequestBody { let body = JsonRequestBody {
jsonrpc: JSONRPC_VERSION, jsonrpc: JSONRPC_VERSION,
method: method, method,
params, params,
id: STATIC_ID, id: STATIC_ID,
}; };
@@ -72,12 +72,12 @@ impl HttpJsonRpc {
(Some(result), None) => serde_json::from_value(result).map_err(Into::into), (Some(result), None) => serde_json::from_value(result).map_err(Into::into),
(_, Some(error)) => { (_, Some(error)) => {
if error.contains(EIP155_ERROR_STR) { if error.contains(EIP155_ERROR_STR) {
Err(Error::Eip155Error) Err(Error::Eip155Failure)
} else { } else {
Err(Error::ServerMessage(error)) Err(Error::ServerMessage(error))
} }
} }
(None, None) => Err(Error::NoResultOrError), (None, None) => Err(Error::NoErrorOrResult),
} }
} }
} }
@@ -300,6 +300,35 @@ struct JsonForkChoiceUpdatedRequest {
finalized_block_hash: Hash256, finalized_block_hash: Hash256,
} }
// Serializes the `logs_bloom` field.
pub mod serde_logs_bloom {
use super::*;
use eth2_serde_utils::hex::PrefixedHexVisitor;
use serde::{Deserializer, Serializer};
pub fn serialize<S, U>(bytes: &FixedVector<u8, U>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
U: Unsigned,
{
let mut hex_string: String = "0x".to_string();
hex_string.push_str(&hex::encode(&bytes[..]));
serializer.serialize_str(&hex_string)
}
pub fn deserialize<'de, D, U>(deserializer: D) -> Result<FixedVector<u8, U>, D::Error>
where
D: Deserializer<'de>,
U: Unsigned,
{
let vec = deserializer.deserialize_string(PrefixedHexVisitor)?;
FixedVector::new(vec)
.map_err(|e| serde::de::Error::custom(format!("invalid logs bloom: {:?}", e)))
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
@@ -414,7 +443,7 @@ mod test {
coinbase: Address::repeat_byte(1), coinbase: Address::repeat_byte(1),
state_root: Hash256::repeat_byte(1), state_root: Hash256::repeat_byte(1),
receipt_root: Hash256::repeat_byte(0), receipt_root: Hash256::repeat_byte(0),
logs_bloom: vec![01; 256].into(), logs_bloom: vec![1; 256].into(),
random: Hash256::repeat_byte(1), random: Hash256::repeat_byte(1),
block_number: 0, block_number: 0,
gas_limit: 1, gas_limit: 1,

View File

@@ -68,11 +68,3 @@ impl ExecutionLayer {
.map_err(Error::EngineErrors) .map_err(Error::EngineErrors)
} }
} }
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}