From 983d5b98b74cf2ee89dc18f4a022b480c6da7059 Mon Sep 17 00:00:00 2001 From: Chris Smith <1979423+chris13524@users.noreply.github.com> Date: Sat, 19 Oct 2024 07:46:08 -0700 Subject: [PATCH] fix: change printlns to proper logging & log sendUserOperation response (#46) --- crates/yttrium/Cargo.toml | 1 + crates/yttrium/src/bundler/client.rs | 13 +++++-- .../src/bundler/pimlico/paymaster/client.rs | 38 ++++++++----------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/crates/yttrium/Cargo.toml b/crates/yttrium/Cargo.toml index 9e8ebde..2197064 100644 --- a/crates/yttrium/Cargo.toml +++ b/crates/yttrium/Cargo.toml @@ -44,6 +44,7 @@ dotenvy = "0.15.7" # Other hex = "0.4.3" async-trait = "0.1.83" +tracing = "0.1.40" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/crates/yttrium/src/bundler/client.rs b/crates/yttrium/src/bundler/client.rs index 3310a97..59b4797 100644 --- a/crates/yttrium/src/bundler/client.rs +++ b/crates/yttrium/src/bundler/client.rs @@ -10,6 +10,7 @@ use alloy::transports::{Transport, TransportResult}; use alloy_provider::{Network, Provider, ReqwestProvider}; use eyre::Ok; use serde_json; +use tracing::debug; pub struct BundlerClient { client: reqwest::Client, @@ -36,15 +37,19 @@ impl BundlerClient { ], }; - let response: Response = self + let response = self .client .post(self.config.url()) .json(&send_body) .send() .await? - .json::>() - .await? - .into(); + .text() + .await?; + + debug!("response: {}", response); + + let response: Response = + serde_json::from_str::>(&response)?.into(); response?.ok_or(eyre::eyre!("send_user_operation got None")) } diff --git a/crates/yttrium/src/bundler/pimlico/paymaster/client.rs b/crates/yttrium/src/bundler/pimlico/paymaster/client.rs index c7d1d70..b25a2a3 100644 --- a/crates/yttrium/src/bundler/pimlico/paymaster/client.rs +++ b/crates/yttrium/src/bundler/pimlico/paymaster/client.rs @@ -5,8 +5,8 @@ use super::models::{ use crate::bundler::config::BundlerConfig; use crate::entry_point::EntryPointAddress; use crate::jsonrpc::{JSONRPCResponse, Request, Response}; - use serde_json; +use tracing::debug; pub struct PaymasterClient { client: reqwest::Client, @@ -24,49 +24,41 @@ impl PaymasterClient { entry_point: &EntryPointAddress, sponsorship_policy_id: Option, ) -> eyre::Result { - println!("sponsor_user_operation_v07 "); - - let bundler_url = self.config.url().clone(); - - let params: Vec = { - let user_operation_value = serde_json::to_value(user_operation)?; - let mut vec: Vec = vec![ - user_operation_value, + let params = { + let mut params = vec![ + serde_json::to_value(user_operation)?, entry_point.to_address().to_string().into(), ]; if let Some(sponsorship_policy_id) = sponsorship_policy_id { - vec.push(sponsorship_policy_id.into()); + params.push(sponsorship_policy_id.into()); } - vec + params }; - let req_body: Request> = Request { + let req_body = Request { jsonrpc: "2.0".into(), id: 1, method: "pm_sponsorUserOperation".into(), params, }; - println!("req_body: {:?}", serde_json::to_string(&req_body)?); + debug!("req_body: {:?}", serde_json::to_string(&req_body)?); - let post = self - .client - .post(bundler_url.as_str()) - .json(&req_body) - .send() - .await?; - println!("pm_sponsorUserOperation post: {:?}", post); + let post = + self.client.post(self.config.url()).json(&req_body).send().await?; + debug!("pm_sponsorUserOperation post: {:?}", post); let res = post.text().await?; - println!("pm_sponsorUserOperation res: {:?}", res); + debug!("pm_sponsorUserOperation res: {:?}", res); let v = serde_json::from_str::>( &res, )?; - println!("pm_sponsorUserOperation json: {:?}", v); + debug!("pm_sponsorUserOperation json: {:?}", v); let response: Response = v.into(); let response_estimate = response?; - let response_estimate = response_estimate.unwrap(); + let response_estimate = response_estimate + .ok_or(eyre::eyre!("response_estimate is None"))?; let result = SponsorshipResultV07 { call_gas_limit: response_estimate.call_gas_limit,