layer_climb_core/signing/middleware/
logger.rs

1use crate::{prelude::*, querier::tx::AnyTxResponse};
2
3use std::sync::Arc;
4
5#[derive(Clone)]
6pub struct SigningLoggerMiddlewareMapBody {
7    pub logger_fn: Arc<dyn Fn(&layer_climb_proto::tx::TxBody) + Send + Sync>,
8}
9impl SigningLoggerMiddlewareMapBody {
10    pub fn new<F>(logger_fn: F) -> Self
11    where
12        F: Fn(&layer_climb_proto::tx::TxBody) + Send + Sync + 'static,
13    {
14        Self {
15            logger_fn: Arc::new(logger_fn),
16        }
17    }
18}
19impl Default for SigningLoggerMiddlewareMapBody {
20    fn default() -> Self {
21        Self::new(|body| eprintln!("{:?}", body))
22    }
23}
24
25impl SigningLoggerMiddlewareMapBody {
26    pub async fn map_body(
27        &self,
28        body: layer_climb_proto::tx::TxBody,
29    ) -> Result<layer_climb_proto::tx::TxBody> {
30        (self.logger_fn)(&body);
31        Ok(body)
32    }
33}
34
35pub struct SigningLoggerMiddlewareMapResp {
36    pub logger_fn: Arc<dyn Fn(&AnyTxResponse) + Send + Sync>,
37}
38impl SigningLoggerMiddlewareMapResp {
39    pub fn new<F>(logger_fn: F) -> Self
40    where
41        F: Fn(&AnyTxResponse) + Send + Sync + 'static,
42    {
43        Self {
44            logger_fn: Arc::new(logger_fn),
45        }
46    }
47}
48impl Default for SigningLoggerMiddlewareMapResp {
49    fn default() -> Self {
50        Self::new(|resp| eprintln!("{:?}", resp))
51    }
52}
53
54impl SigningLoggerMiddlewareMapResp {
55    pub async fn map_resp(&self, resp: AnyTxResponse) -> Result<AnyTxResponse> {
56        (self.logger_fn)(&resp);
57        Ok(resp)
58    }
59}