diff --git a/Cargo.lock b/Cargo.lock index 43fab045..e085de31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,41 +109,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "alloy-contract" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git?rev=d68a6b7#d68a6b787b2904061f0ae7fcc02ece8513e3c500" -dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-network", - "alloy-primitives", - "alloy-provider", - "alloy-rpc-types", - "alloy-sol-types", - "alloy-transport", - "futures", - "futures-util", - "thiserror", -] - -[[package]] -name = "alloy-dyn-abi" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ab339ca7b4ea9115f0578c941abc80a171edf8e5eadd01e6c4237b68db8083" -dependencies = [ - "alloy-json-abi", - "alloy-primitives", - "alloy-sol-type-parser", - "alloy-sol-types", - "const-hex", - "itoa", - "serde", - "serde_json", - "winnow 0.6.5", -] - [[package]] name = "alloy-eips" version = "0.1.0" @@ -167,18 +132,6 @@ dependencies = [ "serde", ] -[[package]] -name = "alloy-json-abi" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44294729c145cf7ae65feab544b5b81fb2bb7e2fd060214842eb3989a1e9d882" -dependencies = [ - "alloy-primitives", - "alloy-sol-type-parser", - "serde", - "serde_json", -] - [[package]] name = "alloy-json-rpc" version = "0.1.0" @@ -207,21 +160,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "alloy-node-bindings" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy.git?rev=d68a6b7#d68a6b787b2904061f0ae7fcc02ece8513e3c500" -dependencies = [ - "alloy-genesis", - "alloy-primitives", - "k256", - "serde_json", - "tempfile", - "thiserror", - "tracing", - "url", -] - [[package]] name = "alloy-primitives" version = "0.7.1" @@ -400,15 +338,6 @@ dependencies = [ "syn-solidity", ] -[[package]] -name = "alloy-sol-type-parser" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c8d6e74e4feeaa2bcfdecfd3da247ab53c67bd654ba1907270c32e02b142331" -dependencies = [ - "winnow 0.6.5", -] - [[package]] name = "alloy-sol-types" version = "0.7.1" @@ -1349,12 +1278,6 @@ dependencies = [ "alloc-stdlib", ] -[[package]] -name = "bs58" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" - [[package]] name = "bs58" version = "0.5.1" @@ -1548,7 +1471,7 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b6be4a5df2098cd811f3194f64ddb96c267606bffd9689ac7b0160097b01ad3" dependencies = [ - "bs58 0.5.1", + "bs58", "coins-core", "digest 0.10.7", "hmac", @@ -1582,7 +1505,7 @@ checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" dependencies = [ "base64 0.21.7", "bech32", - "bs58 0.5.1", + "bs58", "digest 0.10.7", "generic-array", "hex", @@ -1809,34 +1732,6 @@ dependencies = [ "cipher", ] -[[package]] -name = "curve25519-dalek" -version = "4.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" -dependencies = [ - "cfg-if", - "cpufeatures", - "curve25519-dalek-derive", - "digest 0.10.7", - "fiat-crypto", - "platforms", - "rustc_version 0.4.0", - "subtle", - "zeroize", -] - -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" -dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", - "syn 2.0.57", -] - [[package]] name = "dashmap" version = "5.5.3" @@ -2048,31 +1943,6 @@ dependencies = [ "spki 0.7.3", ] -[[package]] -name = "ed25519" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" -dependencies = [ - "pkcs8 0.10.2", - "signature 2.2.0", -] - -[[package]] -name = "ed25519-dalek" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" -dependencies = [ - "curve25519-dalek", - "ed25519", - "rand_core", - "serde", - "sha2", - "subtle", - "zeroize", -] - [[package]] name = "either" version = "1.10.0" @@ -2192,6 +2062,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "erc6492" +version = "0.1.0" +source = "git+https://github.com/WalletConnect/erc6492.git#f2b37fda5ed9b43cb7e0ca9d547978c799779892" +dependencies = [ + "alloy-json-rpc", + "alloy-primitives", + "alloy-provider", + "alloy-rpc-types", + "alloy-sol-types", + "alloy-transport", + "serde_json", +] + [[package]] name = "errno" version = "0.3.8" @@ -2582,12 +2466,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "fiat-crypto" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38793c55593b33412e3ae40c2c9781ffaa6f438f6f8c10f24e71846fbd7ae01e" - [[package]] name = "finl_unicode" version = "1.2.0" @@ -4429,12 +4307,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" -[[package]] -name = "platforms" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" - [[package]] name = "pnet_base" version = "0.31.0" @@ -4848,42 +4720,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" -[[package]] -name = "relay_rpc" -version = "0.1.0" -source = "git+https://github.com/WalletConnect/WalletConnectRust.git?tag=v0.30.0#edd6b6bcaa360e0887b4930ba78d56c958700612" -dependencies = [ - "alloy-contract", - "alloy-json-abi", - "alloy-json-rpc", - "alloy-node-bindings", - "alloy-primitives", - "alloy-provider", - "alloy-rpc-types", - "alloy-sol-types", - "alloy-transport", - "alloy-transport-http", - "bs58 0.4.0", - "chrono", - "data-encoding", - "derive_more", - "ed25519-dalek", - "hex", - "jsonwebtoken", - "k256", - "once_cell", - "rand", - "regex", - "serde", - "serde-aux 4.5.0", - "serde_json", - "sha2", - "sha3", - "strum", - "thiserror", - "url", -] - [[package]] name = "reqwest" version = "0.11.27" @@ -5077,7 +4913,11 @@ dependencies = [ name = "rpc-proxy" version = "0.60.0" dependencies = [ + "alloy-json-rpc", "alloy-primitives", + "alloy-provider", + "alloy-rpc-client", + "alloy-transport", "anyhow", "async-trait", "async-tungstenite", @@ -5092,6 +4932,7 @@ dependencies = [ "derive_more", "dotenv", "envy", + "erc6492", "ethers", "futures-util", "hex", @@ -5108,11 +4949,10 @@ dependencies = [ "prometheus-http-query", "rand", "regex", - "relay_rpc", "reqwest 0.11.27", "rmp-serde", "serde", - "serde-aux 3.1.0", + "serde-aux", "serde_json", "serde_piecewise_default", "sha256", @@ -5506,16 +5346,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "serde-aux" -version = "4.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d2e8bfba469d06512e11e3311d4d051a4a387a5b42d010404fecf3200321c95" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "serde_derive" version = "1.0.197" diff --git a/Cargo.toml b/Cargo.toml index daa12e41..b7b4bfbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,11 @@ build = "build.rs" [dependencies] wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.9.0", features = ["alloc", "analytics", "future", "http", "metrics", "geoip", "geoblock", "rate_limit"] } -relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.30.0", features = ["cacao"] } +erc6492 = { git = "https://github.com/WalletConnect/erc6492.git" } +alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" } +alloy-transport = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" } +alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" } +alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" } # Async async-trait = "0.1.57" @@ -31,7 +35,7 @@ reqwest = { version= "0.11", features = ["deflate", "brotli", "gzip"] } # Serialization rmp-serde = "1.1" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" +serde_json = { version = "1.0", features = ["raw_value"] } serde_piecewise_default = "0.2" serde-aux = "3.1" validator = { version = "0.16", features = ["derive"] } diff --git a/README.md b/README.md index 2655bb5f..d9a2343a 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Endpoint: `https://rpc.walletconnect.com/v1?chainId=eip155:1&projectId=" --data '{"id":"1","jsonrpc":"2.0","method":"eth_chainId","params":[]}' +curl -H "Content-Type: application/json" -X POST "https://rpc.walletconnect.com/v1?chainId=eip155:1&projectId=" --data '{"id":"1","jsonrpc":"2.0","method":"eth_chainId","params":[]}' ``` Obtain a `projectId` from @@ -41,7 +41,7 @@ just run ```bash # projectId is not validated under default .env.example configuration -curl -X POST "http://localhost:3000/v1?chainId=eip155:1&projectId=someid" --data '{"id":"1","jsonrpc":"2.0","method":"eth_chainId","params":[]}' +curl -H "Content-Type: application/json" -X POST "http://localhost:3000/v1?chainId=eip155:1&projectId=someid" --data '{"id":"1","jsonrpc":"2.0","method":"eth_chainId","params":[]}' ``` ## Testing diff --git a/justfile b/justfile index e038402e..a02dc87a 100644 --- a/justfile +++ b/justfile @@ -132,7 +132,7 @@ cargo-build-docs: (_cargo-build-docs "" "nodeps") # Format the application code @cargo-fmt: _check-cmd-cargo-fmt printf '==> Running {{ color-cmd }}rustfmt{{ nocolor }}\n' - cargo +nightly fmt + cargo fmt # Build service for development cargo-build: _check-cmd-cargo @@ -164,7 +164,7 @@ cargo-test-default: _check-cmd-cargo # Run project tests with all features activated cargo-test-all: _check-cmd-cargo @printf '==> Testing project ({{ light-green }}all features{{ nocolor }})\n' - cargo +nightly test --all-features + cargo test --all-features # Run tests from project documentation cargo-test-doc: _check-cmd-cargo @@ -184,7 +184,7 @@ cargo-check: _check-cmd-cargo # Check rust project with clippy cargo-clippy: _check-cmd-cargo-clippy @printf '==> Running {{ color-cmd }}clippy{{ nocolor }}\n' - cargo +nightly clippy --all-features --tests -- -D clippy::all + cargo clippy --all-features --tests -- -D clippy::all # Check unused dependencies cargo-udeps: _check-cmd-cargo-udeps @@ -194,7 +194,7 @@ cargo-udeps: _check-cmd-cargo-udeps # Check the rust code formatting cargo-checkfmt: _check-cmd-cargo-fmt @printf '==> Running {{ color-cmd }}rustfmt{{ nocolor }} --check\n' - cargo +nightly fmt --check + cargo fmt --check ################################################################################ # Terraform recipes diff --git a/src/handlers/profile/address.rs b/src/handlers/profile/address.rs index cc05b2a8..bbf420de 100644 --- a/src/handlers/profile/address.rs +++ b/src/handlers/profile/address.rs @@ -9,31 +9,37 @@ use { types::SupportedNamespaces, }, error::RpcError, + handlers::RpcQueryParams, state::AppState, - utils::crypto::{ - constant_time_eq, convert_coin_type_to_evm_chain_id, is_coin_type_supported, - verify_message_signature, + utils::{ + crypto::{ + constant_time_eq, convert_coin_type_to_evm_chain_id, is_coin_type_supported, + verify_message_signature, + }, + self_transport::SelfTransport, }, }, axum::{ - extract::{Path, State}, + extract::{ConnectInfo, Path, State}, response::{IntoResponse, Response}, Json, }, ethers::types::H160, - hyper::StatusCode, + hyper::{HeaderMap, StatusCode}, sqlx::Error as SqlxError, - std::{str::FromStr, sync::Arc}, + std::{net::SocketAddr, str::FromStr, sync::Arc}, tracing::log::error, wc::future::FutureExt, }; pub async fn handler( state: State>, + connect_info: ConnectInfo, + headers: HeaderMap, name: Path, Json(request_payload): Json, ) -> Result { - handler_internal(state, name, request_payload) + handler_internal(state, connect_info, headers, name, request_payload) .with_metrics(HANDLER_TASK_METRICS.with_name("profile_address_update")) .await } @@ -41,6 +47,8 @@ pub async fn handler( #[tracing::instrument(skip(state))] pub async fn handler_internal( state: State>, + ConnectInfo(connect_info): ConnectInfo, + headers: HeaderMap, Path(name): Path, request_payload: RegisterRequest, ) -> Result { @@ -101,7 +109,7 @@ pub async fn handler_internal( .config .server .testing_project_id - .as_ref() + .clone() .ok_or_else(|| { RpcError::InvalidConfiguration( "Missing testing project id in the configuration for eip1271 lookups".to_string(), @@ -111,8 +119,16 @@ pub async fn handler_internal( raw_payload, &request_payload.signature, &request_payload.address, - &chain_id_caip2, - rpc_project_id, + SelfTransport { + state: state.0.clone(), + connect_info, + headers, + query: RpcQueryParams { + chain_id: chain_id_caip2, + project_id: rpc_project_id, + provider_id: None, + }, + }, ) .await { diff --git a/src/handlers/profile/attributes.rs b/src/handlers/profile/attributes.rs index b3a6f9e9..2e1eb4a3 100644 --- a/src/handlers/profile/attributes.rs +++ b/src/handlers/profile/attributes.rs @@ -7,19 +7,23 @@ use { crate::{ database::helpers::{get_name_and_addresses_by_name, update_name_attributes}, error::RpcError, + handlers::RpcQueryParams, state::AppState, - utils::crypto::{ - constant_time_eq, convert_coin_type_to_evm_chain_id, is_coin_type_supported, - verify_message_signature, + utils::{ + crypto::{ + constant_time_eq, convert_coin_type_to_evm_chain_id, is_coin_type_supported, + verify_message_signature, + }, + self_transport::SelfTransport, }, }, axum::{ - extract::{Path, State}, + extract::{ConnectInfo, Path, State}, response::{IntoResponse, Response}, Json, }, - hyper::StatusCode, - std::{str::FromStr, sync::Arc}, + hyper::{HeaderMap, StatusCode}, + std::{net::SocketAddr, str::FromStr, sync::Arc}, tracing::log::error, wc::future::FutureExt, }; @@ -27,9 +31,11 @@ use { pub async fn handler( state: State>, name: Path, + connect_info: ConnectInfo, + headers: HeaderMap, Json(request_payload): Json, ) -> Result { - handler_internal(state, name, request_payload) + handler_internal(state, name, connect_info, headers, request_payload) .with_metrics(HANDLER_TASK_METRICS.with_name("profile_attributes_update")) .await } @@ -38,6 +44,8 @@ pub async fn handler( pub async fn handler_internal( state: State>, Path(name): Path, + ConnectInfo(connect_info): ConnectInfo, + headers: HeaderMap, request_payload: RegisterRequest, ) -> Result { let raw_payload = &request_payload.message; @@ -77,7 +85,7 @@ pub async fn handler_internal( .config .server .testing_project_id - .as_ref() + .clone() .ok_or_else(|| { RpcError::InvalidConfiguration( "Missing testing project id in the configuration for eip1271 lookups".to_string(), @@ -87,8 +95,16 @@ pub async fn handler_internal( raw_payload, &request_payload.signature, &request_payload.address, - &chain_id_caip2, - rpc_project_id, + SelfTransport { + state: state.0.clone(), + connect_info, + headers, + query: RpcQueryParams { + chain_id: chain_id_caip2, + project_id: rpc_project_id, + provider_id: None, + }, + }, ) .await { diff --git a/src/handlers/profile/register.rs b/src/handlers/profile/register.rs index e97456d6..ad1dc262 100644 --- a/src/handlers/profile/register.rs +++ b/src/handlers/profile/register.rs @@ -13,28 +13,34 @@ use { types::{Address, ENSIP11AddressesMap, SupportedNamespaces}, }, error::RpcError, + handlers::RpcQueryParams, state::AppState, - utils::crypto::{ - convert_coin_type_to_evm_chain_id, is_coin_type_supported, verify_message_signature, + utils::{ + crypto::{ + convert_coin_type_to_evm_chain_id, is_coin_type_supported, verify_message_signature, + }, + self_transport::SelfTransport, }, }, axum::{ - extract::State, + extract::{ConnectInfo, State}, response::{IntoResponse, Response}, Json, }, - hyper::StatusCode, + hyper::{HeaderMap, StatusCode}, sqlx::Error as SqlxError, - std::{collections::HashMap, sync::Arc}, + std::{collections::HashMap, net::SocketAddr, sync::Arc}, tracing::log::error, wc::future::FutureExt, }; pub async fn handler( state: State>, + connect_info: ConnectInfo, + headers: HeaderMap, Json(register_request): Json, ) -> Result { - handler_internal(state, register_request) + handler_internal(state, connect_info, headers, register_request) .with_metrics(HANDLER_TASK_METRICS.with_name("profile_register")) .await } @@ -42,6 +48,8 @@ pub async fn handler( #[tracing::instrument(skip(state))] pub async fn handler_internal( state: State>, + ConnectInfo(connect_info): ConnectInfo, + headers: HeaderMap, register_request: RegisterRequest, ) -> Result { let raw_payload = ®ister_request.message; @@ -103,7 +111,7 @@ pub async fn handler_internal( .config .server .testing_project_id - .as_ref() + .clone() .ok_or_else(|| { RpcError::InvalidConfiguration( "Missing testing project id in the configuration for eip1271 lookups".to_string(), @@ -113,8 +121,16 @@ pub async fn handler_internal( raw_payload, ®ister_request.signature, ®ister_request.address, - &chain_id_caip2, - rpc_project_id, + SelfTransport { + state: state.0.clone(), + connect_info, + headers, + query: RpcQueryParams { + chain_id: chain_id_caip2, + project_id: rpc_project_id, + provider_id: None, + }, + }, ) .await { diff --git a/src/utils/crypto.rs b/src/utils/crypto.rs index b93a2a37..c716705c 100644 --- a/src/utils/crypto.rs +++ b/src/utils/crypto.rs @@ -1,14 +1,15 @@ use { + super::self_transport::SelfTransport, alloy_primitives::Address, + alloy_provider::RootProvider, + alloy_rpc_client::RpcClient, ethers::types::H256, once_cell::sync::Lazy, regex::Regex, - relay_rpc::auth::cacao::{signature::eip6492::verify_eip6492, CacaoError}, std::str::FromStr, strum::IntoEnumIterator, strum_macros::{Display, EnumIter, EnumString}, tracing::warn, - url::Url, }; const ENSIP11_MAINNET_COIN_TYPE: u32 = 60; @@ -58,45 +59,30 @@ pub async fn verify_message_signature( message: &str, signature: &str, address: &str, - chain_id: &str, - rpc_project_id: &str, + self_transport: SelfTransport, ) -> Result { - verify_eip6492_message_signature(message, signature, chain_id, address, rpc_project_id).await + verify_eip6492_message_signature(message, signature, address, self_transport).await } /// Veryfy message signature for eip6492 contract -#[tracing::instrument] +#[tracing::instrument(skip(self_transport))] pub async fn verify_eip6492_message_signature( message: &str, signature: &str, - chain_id: &str, address: &str, - rpc_project_id: &str, + self_transport: SelfTransport, ) -> Result { let message_hash: [u8; 32] = get_message_hash(message).into(); let address = Address::parse_checksummed(address, None) .map_err(|_| CryptoUitlsError::AddressChecksum(address.into()))?; - let mut provider = Url::parse("https://rpc.walletconnect.com/v1") - .map_err(|e| { - CryptoUitlsError::RpcUrlParseError(format!( - "Failed to parse RPC url: - {}", - e - )) - }) - .unwrap(); - provider.query_pairs_mut().append_pair("chainId", chain_id); - provider - .query_pairs_mut() - .append_pair("projectId", rpc_project_id); - let hexed_signature = hex::decode(&signature[2..]) .map_err(|e| CryptoUitlsError::SignatureFormat(format!("Wrong signature format: {}", e)))?; - match verify_eip6492(hexed_signature, address, &message_hash, provider).await { - Ok(_) => Ok(true), - Err(CacaoError::Verification) => Ok(false), + let provider = RootProvider::new(RpcClient::new(self_transport, false)); + + match erc6492::verify_signature(hexed_signature, address, &message_hash, provider).await { + Ok(verification) => Ok(verification.is_valid()), Err(e) => Err(CryptoUitlsError::ContractCallError(format!( "Failed to verify EIP-6492 signature: {}", e diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a4690f38..b0b04409 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -2,4 +2,5 @@ pub mod build; pub mod crypto; pub mod network; pub mod rate_limit; +pub mod self_transport; pub mod suggestions; diff --git a/src/utils/self_transport.rs b/src/utils/self_transport.rs new file mode 100644 index 00000000..95d94d49 --- /dev/null +++ b/src/utils/self_transport.rs @@ -0,0 +1,108 @@ +use { + crate::{ + handlers::{proxy::rpc_call, RpcQueryParams}, + state::AppState, + }, + alloy_json_rpc::{RequestPacket, Response, ResponsePacket}, + alloy_transport::{TransportError, TransportFut}, + hyper::{body::to_bytes, HeaderMap}, + std::{net::SocketAddr, sync::Arc, task::Poll}, + tower::Service, +}; + +#[derive(Clone)] +pub struct SelfTransport { + pub state: Arc, + pub connect_info: SocketAddr, + pub query: RpcQueryParams, + pub headers: HeaderMap, +} + +impl Service for SelfTransport { + type Error = TransportError; + type Future = TransportFut<'static>; + type Response = ResponsePacket; + + fn poll_ready( + &mut self, + _cx: &mut std::task::Context<'_>, + ) -> std::task::Poll> { + Poll::Ready(Ok(())) + } + + fn call(&mut self, req: RequestPacket) -> Self::Future { + let state = self.state.clone(); + let connect_info = self.connect_info; + let query = self.query.clone(); + let headers = self.headers.clone(); + + Box::pin(async move { + // TODO handle batch + let req = match req { + RequestPacket::Single(req) => req, + RequestPacket::Batch(_) => unimplemented!(), + }; + // let id = SystemTime::now() + // .duration_since(UNIX_EPOCH) + // .expect("Time should't go backwards") + // .as_millis() + // .to_string(); + + let body = req.serialized().to_string().into_bytes().into(); + let response = rpc_call(state, connect_info, query, headers, body) + .await + // .map_err(SelfProviderError::RpcError)?; + .unwrap(); + + // TODO handle error response status + + // if response.status() != StatusCode::OK { + // return Err(SelfProviderError::ProviderError { + // status: response.status(), + // body: format!("{:?}", response.body()), + // }); + // } + + // response.body(). + + let bytes = to_bytes(response.into_body()).await.unwrap(); + // .map_err(SelfProviderError::ProviderBody)?; + let body = String::from_utf8(bytes.to_vec()).unwrap(); + + // let response = serde_json::from_slice::(&bytes) + // .unwrap(); + // // .map_err(SelfProviderError::ProviderBodySerde)?; + + // let result = match response { + // JsonRpcResponse::Error(e) => return + // Err(SelfProviderError::JsonRpcError(e)), + // JsonRpcResponse::Result(r) => { + // // We shouldn't process with `0x` result because this leads to the + // ethers-rs // panic when looking for an avatar + // if r.result == EMPTY_RPC_RESPONSE { + // return Err(SelfProviderError::ProviderError { + // status: StatusCode::METHOD_NOT_ALLOWED, + // body: format!("JSON-RPC result is {}", EMPTY_RPC_RESPONSE), + // }); + // } else { + // r.result + // } + // } + // }; + // let result = serde_json::from_value(result).unwrap(); + // // .map_err(|_| { + // // SelfProviderError::GenericParameterError( + // // "Caller always provides generic parameter R=Bytes".into(), + // // ) + // // })?; + // Ok(result) + + Ok(ResponsePacket::Single(Response { + id: req.id().clone(), + payload: alloy_json_rpc::ResponsePayload::Success( + serde_json::value::RawValue::from_string(body).unwrap(), + ), + })) + }) + } +}