diff --git a/Cargo.lock b/Cargo.lock index 8211b330..bd479d42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2450,14 +2450,15 @@ dependencies = [ [[package]] name = "gloo-net" -version = "0.2.6" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9902a044653b26b99f7e3693a42f171312d9be8b26b5697bd1e43ad1f8a35e10" +checksum = "a66b4e3c7d9ed8d315fd6b97c8b1f74a7c6ecbbc2320e65ae7ed38b7068cc620" dependencies = [ "futures-channel", "futures-core", "futures-sink", "gloo-utils", + "http 0.2.12", "js-sys", "pin-project", "serde", @@ -3097,9 +3098,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b971ce0f6cd1521ede485afc564b95b2c8e7079b9da41d4273bd9b55140a55d" +checksum = "e5f3783308bddc49d0218307f66a09330c106fbd792c58bac5c8dc294fdd0f98" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -3114,9 +3115,9 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca00d975eda834826b04ad57d4e690c67439bb51b02eb0f8b7e4c30fcef8ab9" +checksum = "abc5630e4fa0096f00ec7b44d520701fda4504170cb85e22dca603ae5d7ad0d7" dependencies = [ "futures-channel", "futures-util", @@ -3131,14 +3132,14 @@ dependencies = [ "tokio-rustls 0.24.1", "tokio-util", "tracing", - "webpki-roots 0.23.1", + "webpki-roots 0.24.0", ] [[package]] name = "jsonrpsee-core" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b83cca7a5a7899eed8b2935d5f755c8c4052ad66ab5b328bd34ac2b3ffd3515f" +checksum = "5aaa4c4d5fb801dcc316d81f76422db259809037a86b3194ae538dd026b05ed7" dependencies = [ "anyhow", "async-lock", @@ -3164,9 +3165,9 @@ dependencies = [ [[package]] name = "jsonrpsee-http-client" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6483fea826f62260a88a132fa750a47b40d4218d41e3391936579533c6c67509" +checksum = "aa7165efcbfbc951d180162ff28fe91b657ed81925e37a35e4a396ce12109f96" dependencies = [ "async-trait", "hyper 0.14.30", @@ -3183,9 +3184,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d814a21d9a819f8de1a41b819a263ffd68e4bb5f043d936db1c49b54684bde0a" +checksum = "21dc12b1d4f16a86e8c522823c4fab219c88c03eb7c924ec0501a64bf12e058b" dependencies = [ "heck 0.4.1", "proc-macro-crate 1.3.1", @@ -3196,9 +3197,9 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cf8b28bb9b0248d1ece5923c97355a4defc81c06b4b7a0097c61e412c716ca1" +checksum = "6e79d78cfd5abd8394da10753723093c3ff64391602941c9c4b1d80a3414fd53" dependencies = [ "futures-util", "hyper 0.14.30", @@ -3216,9 +3217,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd301ccc3e08718393432d1961539d78c4580dcca86014dfe6769c308b2c08b2" +checksum = "00aa7cc87bc42e04e26c8ac3e7186142f7fd2949c763d9b6a7e64a69672d8fb2" dependencies = [ "anyhow", "beef", @@ -3230,9 +3231,9 @@ dependencies = [ [[package]] name = "jsonrpsee-wasm-client" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85dc3aea8bbb844dacc45cd98d01f624e4485184149a045761888c2e5fa5a0c6" +checksum = "0fe953c2801356f214d3f4051f786b3d11134512a46763ee8c39a9e3fa2cc1c0" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -3241,9 +3242,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.17.1" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89a69852133d549b07cb37ff2d0ec540eae0d20abb75ae923f5d39bc7536d987" +checksum = "5c71b2597ec1c958c6d5bc94bb61b44d74eb28e69dc421731ab0035706f13882" dependencies = [ "http 0.2.12", "jsonrpsee-client-transport", @@ -3260,7 +3261,7 @@ dependencies = [ "base64 0.21.7", "js-sys", "pem", - "ring 0.17.8", + "ring", "serde", "serde_json", "simple_asn1", @@ -3321,7 +3322,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin 0.9.8", + "spin", ] [[package]] @@ -4399,21 +4400,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi", -] - [[package]] name = "ring" version = "0.17.8" @@ -4424,8 +4410,8 @@ dependencies = [ "cfg-if", "getrandom 0.2.15", "libc", - "spin 0.9.8", - "untrusted 0.9.0", + "spin", + "untrusted", "windows-sys 0.52.0", ] @@ -4544,7 +4530,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.17.8", + "ring", "rustls-webpki 0.101.7", "sct", ] @@ -4556,7 +4542,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "once_cell", - "ring 0.17.8", + "ring", "rustls-pki-types", "rustls-webpki 0.102.6", "subtle", @@ -4600,24 +4586,14 @@ version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" -[[package]] -name = "rustls-webpki" -version = "0.100.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6a5fc258f1c1276dfe3016516945546e2d5383911efc0fc4f1cdc5df3a4ae3" -dependencies = [ - "ring 0.16.20", - "untrusted 0.7.1", -] - [[package]] name = "rustls-webpki" version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -4626,9 +4602,9 @@ version = "0.102.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" dependencies = [ - "ring 0.17.8", + "ring", "rustls-pki-types", - "untrusted 0.9.0", + "untrusted", ] [[package]] @@ -4691,8 +4667,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -5039,12 +5015,6 @@ dependencies = [ "sha-1", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -5765,12 +5735,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "untrusted" version = "0.9.0" @@ -5961,11 +5925,11 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.23.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" +checksum = "b291546d5d9d1eab74f069c77749f2cb8504a12caa20f0f2de93ddbf6f411888" dependencies = [ - "rustls-webpki 0.100.3", + "rustls-webpki 0.101.7", ] [[package]] diff --git a/client/Cargo.toml b/client/Cargo.toml index 9e069380..45a88f3f 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -20,7 +20,7 @@ config = { path = "../config" } common = { path = "../common" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -jsonrpsee = { version = "0.17.1", features = ["full"] } +jsonrpsee = { version = "0.19.0", features = ["full"] } [target.'cfg(target_arch = "wasm32")'.dependencies] gloo-timers = "0.3.0" diff --git a/client/src/errors.rs b/client/src/errors.rs index 18640050..200f3f10 100644 --- a/client/src/errors.rs +++ b/client/src/errors.rs @@ -40,7 +40,7 @@ pub enum NodeError { #[cfg(not(target_arch = "wasm32"))] impl NodeError { - pub fn to_json_rpsee_error(self) -> jsonrpsee::core::Error { + pub fn to_json_rpsee_error(self) -> jsonrpsee::types::error::ErrorObjectOwned { match self { NodeError::ExecutionEvmError(evm_err) => match evm_err { EvmError::Revert(data) => { @@ -48,17 +48,15 @@ impl NodeError { if let Some(reason) = data.as_ref().and_then(EvmError::decode_revert_reason) { msg = format!("{msg}: {reason}") } - jsonrpsee::core::Error::Call(jsonrpsee::types::error::CallError::Custom( - jsonrpsee::types::error::ErrorObject::owned( - 3, - msg, - data.map(|data| format!("0x{}", hex::encode(data))), - ), - )) + jsonrpsee::types::error::ErrorObject::owned( + 3, + msg, + data.map(|data| format!("0x{}", hex::encode(data))), + ) } - _ => jsonrpsee::core::Error::Custom(evm_err.to_string()), + _ => jsonrpsee::types::error::ErrorObject::owned(1, evm_err.to_string(), None::<()>), }, - _ => jsonrpsee::core::Error::Custom(self.to_string()), + _ => jsonrpsee::types::error::ErrorObject::owned(1, self.to_string(), None::<()>), } } } diff --git a/client/src/rpc.rs b/client/src/rpc.rs index c87f14ce..6301e2cb 100644 --- a/client/src/rpc.rs +++ b/client/src/rpc.rs @@ -7,9 +7,10 @@ use alloy::rpc::types::{ }; use eyre::Result; use jsonrpsee::{ - core::{async_trait, server::Methods, Error}, + core::{async_trait, server::Methods}, proc_macros::rpc, server::{ServerBuilder, ServerHandle}, + types::error::{ErrorObject, ErrorObjectOwned}, }; use tracing::info; @@ -55,79 +56,79 @@ impl Rpc { #[rpc(server, namespace = "eth")] trait EthRpc { #[method(name = "getBalance")] - async fn get_balance(&self, address: Address, block: BlockTag) -> Result; + async fn get_balance(&self, address: Address, block: BlockTag) -> Result; #[method(name = "getTransactionCount")] - async fn get_transaction_count(&self, address: Address, block: BlockTag) -> Result; + async fn get_transaction_count(&self, address: Address, block: BlockTag) -> Result; #[method(name = "getBlockTransactionCountByHash")] - async fn get_block_transaction_count_by_hash(&self, hash: B256) -> Result; + async fn get_block_transaction_count_by_hash(&self, hash: B256) -> Result; #[method(name = "getBlockTransactionCountByNumber")] - async fn get_block_transaction_count_by_number(&self, block: BlockTag) -> Result; + async fn get_block_transaction_count_by_number(&self, block: BlockTag) -> Result; #[method(name = "getCode")] - async fn get_code(&self, address: Address, block: BlockTag) -> Result; + async fn get_code(&self, address: Address, block: BlockTag) -> Result; #[method(name = "call")] - async fn call(&self, tx: TransactionRequest, block: BlockTag) -> Result; + async fn call(&self, tx: TransactionRequest, block: BlockTag) -> Result; #[method(name = "estimateGas")] - async fn estimate_gas(&self, tx: TransactionRequest) -> Result; + async fn estimate_gas(&self, tx: TransactionRequest) -> Result; #[method(name = "chainId")] - async fn chain_id(&self) -> Result; + async fn chain_id(&self) -> Result; #[method(name = "gasPrice")] - async fn gas_price(&self) -> Result; + async fn gas_price(&self) -> Result; #[method(name = "maxPriorityFeePerGas")] - async fn max_priority_fee_per_gas(&self) -> Result; + async fn max_priority_fee_per_gas(&self) -> Result; #[method(name = "blockNumber")] - async fn block_number(&self) -> Result; + async fn block_number(&self) -> Result; #[method(name = "getBlockByNumber")] async fn get_block_by_number( &self, block: BlockTag, full_tx: bool, - ) -> Result, Error>; + ) -> Result, ErrorObjectOwned>; #[method(name = "getBlockByHash")] - async fn get_block_by_hash(&self, hash: B256, full_tx: bool) -> Result, Error>; + async fn get_block_by_hash(&self, hash: B256, full_tx: bool) -> Result, ErrorObjectOwned>; #[method(name = "sendRawTransaction")] - async fn send_raw_transaction(&self, bytes: Bytes) -> Result; + async fn send_raw_transaction(&self, bytes: Bytes) -> Result; #[method(name = "getTransactionReceipt")] async fn get_transaction_receipt( &self, hash: B256, - ) -> Result, Error>; + ) -> Result, ErrorObjectOwned>; #[method(name = "getTransactionByHash")] - async fn get_transaction_by_hash(&self, hash: B256) -> Result, Error>; + async fn get_transaction_by_hash(&self, hash: B256) -> Result, ErrorObjectOwned>; #[method(name = "getTransactionByBlockHashAndIndex")] async fn get_transaction_by_block_hash_and_index( &self, hash: B256, index: U64, - ) -> Result, Error>; + ) -> Result, ErrorObjectOwned>; #[method(name = "getLogs")] - async fn get_logs(&self, filter: Filter) -> Result, Error>; + async fn get_logs(&self, filter: Filter) -> Result, ErrorObjectOwned>; #[method(name = "getFilterChanges")] - async fn get_filter_changes(&self, filter_id: U256) -> Result, Error>; + async fn get_filter_changes(&self, filter_id: U256) -> Result, ErrorObjectOwned>; #[method(name = "uninstallFilter")] - async fn uninstall_filter(&self, filter_id: U256) -> Result; + async fn uninstall_filter(&self, filter_id: U256) -> Result; #[method(name = "getNewFilter")] - async fn get_new_filter(&self, filter: Filter) -> Result; + async fn get_new_filter(&self, filter: Filter) -> Result; #[method(name = "getNewBlockFilter")] - async fn get_new_block_filter(&self) -> Result; + async fn get_new_block_filter(&self) -> Result; #[method(name = "getNewPendingTransactionFilter")] - async fn get_new_pending_transaction_filter(&self) -> Result; + async fn get_new_pending_transaction_filter(&self) -> Result; #[method(name = "getStorageAt")] async fn get_storage_at( &self, address: Address, slot: B256, block: BlockTag, - ) -> Result; + ) -> Result; #[method(name = "coinbase")] - async fn coinbase(&self) -> Result; + async fn coinbase(&self) -> Result; #[method(name = "syncing")] - async fn syncing(&self) -> Result; + async fn syncing(&self) -> Result; } #[rpc(client, server, namespace = "net")] trait NetRpc { #[method(name = "version")] - async fn version(&self) -> Result; + async fn version(&self) -> Result; } #[derive(Clone)] @@ -138,34 +139,34 @@ struct RpcInner { #[async_trait] impl EthRpcServer for RpcInner { - async fn get_balance(&self, address: Address, block: BlockTag) -> Result { + async fn get_balance(&self, address: Address, block: BlockTag) -> Result { convert_err(self.node.get_balance(address, block).await) } - async fn get_transaction_count(&self, address: Address, block: BlockTag) -> Result { + async fn get_transaction_count(&self, address: Address, block: BlockTag) -> Result { convert_err(self.node.get_nonce(address, block).await).map(U64::from) } - async fn get_block_transaction_count_by_hash(&self, hash: B256) -> Result { + async fn get_block_transaction_count_by_hash(&self, hash: B256) -> Result { convert_err(self.node.get_block_transaction_count_by_hash(hash).await).map(U64::from) } - async fn get_block_transaction_count_by_number(&self, block: BlockTag) -> Result { + async fn get_block_transaction_count_by_number(&self, block: BlockTag) -> Result { convert_err(self.node.get_block_transaction_count_by_number(block).await).map(U64::from) } - async fn get_code(&self, address: Address, block: BlockTag) -> Result { + async fn get_code(&self, address: Address, block: BlockTag) -> Result { convert_err(self.node.get_code(address, block).await) } - async fn call(&self, tx: TransactionRequest, block: BlockTag) -> Result { + async fn call(&self, tx: TransactionRequest, block: BlockTag) -> Result { self.node .call(&tx, block) .await .map_err(NodeError::to_json_rpsee_error) } - async fn estimate_gas(&self, tx: TransactionRequest) -> Result { + async fn estimate_gas(&self, tx: TransactionRequest) -> Result { self.node .estimate_gas(&tx) .await @@ -173,19 +174,19 @@ impl EthRpcServer for RpcInner { .map(U64::from) } - async fn chain_id(&self) -> Result { + async fn chain_id(&self) -> Result { Ok(U64::from(self.node.chain_id())) } - async fn gas_price(&self) -> Result { + async fn gas_price(&self) -> Result { convert_err(self.node.get_gas_price().await) } - async fn max_priority_fee_per_gas(&self) -> Result { + async fn max_priority_fee_per_gas(&self) -> Result { convert_err(self.node.get_priority_fee()) } - async fn block_number(&self) -> Result { + async fn block_number(&self) -> Result { convert_err(self.node.get_block_number().await).map(U64::from) } @@ -193,26 +194,26 @@ impl EthRpcServer for RpcInner { &self, block: BlockTag, full_tx: bool, - ) -> Result, Error> { + ) -> Result, ErrorObjectOwned> { convert_err(self.node.get_block_by_number(block, full_tx).await) } - async fn get_block_by_hash(&self, hash: B256, full_tx: bool) -> Result, Error> { + async fn get_block_by_hash(&self, hash: B256, full_tx: bool) -> Result, ErrorObjectOwned> { convert_err(self.node.get_block_by_hash(hash, full_tx).await) } - async fn send_raw_transaction(&self, bytes: Bytes) -> Result { + async fn send_raw_transaction(&self, bytes: Bytes) -> Result { convert_err(self.node.send_raw_transaction(&bytes).await) } async fn get_transaction_receipt( &self, hash: B256, - ) -> Result, Error> { + ) -> Result, ErrorObjectOwned> { convert_err(self.node.get_transaction_receipt(hash).await) } - async fn get_transaction_by_hash(&self, hash: B256) -> Result, Error> { + async fn get_transaction_by_hash(&self, hash: B256) -> Result, ErrorObjectOwned> { Ok(self.node.get_transaction_by_hash(hash).await) } @@ -220,42 +221,42 @@ impl EthRpcServer for RpcInner { &self, hash: B256, index: U64, - ) -> Result, Error> { + ) -> Result, ErrorObjectOwned> { Ok(self .node .get_transaction_by_block_hash_and_index(hash, index.to()) .await) } - async fn coinbase(&self) -> Result { + async fn coinbase(&self) -> Result { convert_err(self.node.get_coinbase().await) } - async fn syncing(&self) -> Result { + async fn syncing(&self) -> Result { convert_err(self.node.syncing().await) } - async fn get_logs(&self, filter: Filter) -> Result, Error> { + async fn get_logs(&self, filter: Filter) -> Result, ErrorObjectOwned> { convert_err(self.node.get_logs(&filter).await) } - async fn get_filter_changes(&self, filter_id: U256) -> Result, Error> { + async fn get_filter_changes(&self, filter_id: U256) -> Result, ErrorObjectOwned> { convert_err(self.node.get_filter_changes(filter_id).await) } - async fn uninstall_filter(&self, filter_id: U256) -> Result { + async fn uninstall_filter(&self, filter_id: U256) -> Result { convert_err(self.node.uninstall_filter(filter_id).await) } - async fn get_new_filter(&self, filter: Filter) -> Result { + async fn get_new_filter(&self, filter: Filter) -> Result { convert_err(self.node.get_new_filter(&filter).await) } - async fn get_new_block_filter(&self) -> Result { + async fn get_new_block_filter(&self) -> Result { convert_err(self.node.get_new_block_filter().await) } - async fn get_new_pending_transaction_filter(&self) -> Result { + async fn get_new_pending_transaction_filter(&self) -> Result { convert_err(self.node.get_new_pending_transaction_filter().await) } @@ -264,14 +265,14 @@ impl EthRpcServer for RpcInner { address: Address, slot: B256, block: BlockTag, - ) -> Result { + ) -> Result { convert_err(self.node.get_storage_at(address, slot, block).await) } } #[async_trait] impl NetRpcServer for RpcInner { - async fn version(&self) -> Result { + async fn version(&self) -> Result { Ok(self.node.chain_id()) } } @@ -287,11 +288,11 @@ async fn start(rpc: RpcInner) -> Result<(ServerHandle, SocketA methods.merge(eth_methods)?; methods.merge(net_methods)?; - let handle = server.start(methods)?; + let handle = server.start(methods); Ok((handle, addr)) } -fn convert_err(res: Result) -> Result { - res.map_err(|err| Error::Custom(err.to_string())) +fn convert_err(res: Result) -> Result { + res.map_err(|err| ErrorObject::owned(1, err.to_string(), None::<()>)) }