Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
MexicanAce committed Sep 15, 2023
1 parent 4203294 commit 667c20e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
53 changes: 28 additions & 25 deletions src/logging_middleware.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use colored::Colorize;
use itertools::Itertools;
use jsonrpc_core::{Middleware, Metadata, Request, Response, middleware, FutureResponse, Call, Params};
use futures::future::Either;
use futures::Future;
use itertools::Itertools;
use jsonrpc_core::{
middleware, Call, FutureResponse, Metadata, Middleware, Params, Request, Response,
};
use log::LevelFilter;

#[derive(Clone, Debug, Default)]
Expand All @@ -23,14 +25,14 @@ impl LoggingMiddleware {
/// Logs out incoming requests and their parameters
/// Useful for debugging applications that are pointed at this service
impl Middleware<Meta> for LoggingMiddleware {
type Future = FutureResponse;
type CallFuture = middleware::NoopCallFuture;
type Future = FutureResponse;
type CallFuture = middleware::NoopCallFuture;

fn on_request<F, X>(&self, request: Request, meta: Meta, next: F) -> Either<Self::Future, X>
where
F: FnOnce(Request, Meta) -> X + Send,
X: Future<Output = Option<Response>> + Send + 'static,
{
fn on_request<F, X>(&self, request: Request, meta: Meta, next: F) -> Either<Self::Future, X>
where
F: FnOnce(Request, Meta) -> X + Send,
X: Future<Output = Option<Response>> + Send + 'static,
{
match &request {
Request::Single(call) => {
match call {
Expand All @@ -39,29 +41,30 @@ impl Middleware<Meta> for LoggingMiddleware {
LevelFilter::Debug => {
let full_params = match &method_call.params {
Params::Array(values) => {
if values.len() == 0 {
if values.is_empty() {
String::default()
} else {
format!("with [{}]", values.iter().join(", "))
}

},
_ => String::default()
}
_ => String::default(),
};

log::debug!(
"{} was called {}",
method_call.method.cyan(),
full_params);
},
full_params
);
}
_ => {
// Generate truncated params for requests with massive payloads
let truncated_params = match &method_call.params {
Params::Array(values) => {
if values.len() == 0 {
if values.is_empty() {
String::default()
} else {
format!("with [{}]",
format!(
"with [{}]",
values
.iter()
.map(|s| {
Expand All @@ -76,24 +79,24 @@ impl Middleware<Meta> for LoggingMiddleware {
.join(", ")
)
}

},
_ => String::default()
}
_ => String::default(),
};

log::info!(
"{} was called {}",
method_call.method.cyan(),
truncated_params);
truncated_params
);
}
}
},
}
_ => {}
}
},
}
_ => {}
};

Either::Left(Box::pin(next(request, meta)))
}
Either::Left(Box::pin(next(request, meta)))
}
}
6 changes: 3 additions & 3 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ mod tests {
.unwrap();
tx.set_input(vec![], H256::repeat_byte(0x01));

node.apply_txs(vec![tx.into()]).expect("failed applying tx");
node.apply_txs(vec![tx]).expect("failed applying tx");

let expected_block_hash =
H256::from_str("0x89c0aa770eba1f187235bdad80de9c01fe81bca415d442ca892f087da56fa109")
Expand Down Expand Up @@ -2120,7 +2120,7 @@ mod tests {
.unwrap();
tx.set_input(vec![], H256::repeat_byte(0x01));

node.apply_txs(vec![tx.into()]).expect("failed applying tx");
node.apply_txs(vec![tx]).expect("failed applying tx");

let expected_block_number = 1;
let actual_block = node
Expand Down Expand Up @@ -2197,7 +2197,7 @@ mod tests {
.unwrap();
tx.set_input(vec![], H256::repeat_byte(0x01));

node.apply_txs(vec![tx.into()]).expect("failed applying tx");
node.apply_txs(vec![tx]).expect("failed applying tx");

let latest_block_number = 1;
let actual_block = node
Expand Down

0 comments on commit 667c20e

Please sign in to comment.