From 5e5e42f6ab283f62820ec650a8fb1ea752fe2bbc Mon Sep 17 00:00:00 2001 From: Leonardo Arias Fonseca Date: Thu, 12 Sep 2024 21:04:06 +0000 Subject: [PATCH 1/2] Update jsonrpsee to 0.18.0 --- Cargo.lock | 36 ++++++++++++++++++------------------ client/Cargo.toml | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8211b330..50afb70e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3097,9 +3097,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b971ce0f6cd1521ede485afc564b95b2c8e7079b9da41d4273bd9b55140a55d" +checksum = "1822d18e4384a5e79d94dc9e4d1239cfa9fad24e55b44d2efeff5b394c9fece4" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -3114,9 +3114,9 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca00d975eda834826b04ad57d4e690c67439bb51b02eb0f8b7e4c30fcef8ab9" +checksum = "11aa5766d5c430b89cb26a99b88f3245eb91534be8126102cea9e45ee3891b22" dependencies = [ "futures-channel", "futures-util", @@ -3136,9 +3136,9 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b83cca7a5a7899eed8b2935d5f755c8c4052ad66ab5b328bd34ac2b3ffd3515f" +checksum = "64c6832a55f662b5a6ecc844db24b8b9c387453f923de863062c60ce33d62b81" dependencies = [ "anyhow", "async-lock", @@ -3164,9 +3164,9 @@ dependencies = [ [[package]] name = "jsonrpsee-http-client" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6483fea826f62260a88a132fa750a47b40d4218d41e3391936579533c6c67509" +checksum = "1705c65069729e3dccff6fd91ee431d5d31cabcf00ce68a62a2c6435ac713af9" dependencies = [ "async-trait", "hyper 0.14.30", @@ -3183,9 +3183,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d814a21d9a819f8de1a41b819a263ffd68e4bb5f043d936db1c49b54684bde0a" +checksum = "c6027ac0b197ce9543097d02a290f550ce1d9432bf301524b013053c0b75cc94" dependencies = [ "heck 0.4.1", "proc-macro-crate 1.3.1", @@ -3196,9 +3196,9 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cf8b28bb9b0248d1ece5923c97355a4defc81c06b4b7a0097c61e412c716ca1" +checksum = "4f06661d1a6b6e5b85469dc9c29acfbb9b3bb613797a6fd10a3ebb8a70754057" dependencies = [ "futures-util", "hyper 0.14.30", @@ -3216,9 +3216,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd301ccc3e08718393432d1961539d78c4580dcca86014dfe6769c308b2c08b2" +checksum = "6e5bf6c75ce2a4217421154adfc65a24d2b46e77286e59bba5d9fa6544ccc8f4" dependencies = [ "anyhow", "beef", @@ -3230,9 +3230,9 @@ dependencies = [ [[package]] name = "jsonrpsee-wasm-client" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85dc3aea8bbb844dacc45cd98d01f624e4485184149a045761888c2e5fa5a0c6" +checksum = "34e6ea7c6d862e60f8baebd946c037b70c6808a4e4e31e792a4029184e3ce13a" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -3241,9 +3241,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.17.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89a69852133d549b07cb37ff2d0ec540eae0d20abb75ae923f5d39bc7536d987" +checksum = "a64b2589680ba1ad7863f279cd2d5083c1dc0a7c0ea959d22924553050f8ab9f" dependencies = [ "http 0.2.12", "jsonrpsee-client-transport", diff --git a/client/Cargo.toml b/client/Cargo.toml index 9e069380..f1d885ea 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.18.0", features = ["full"] } [target.'cfg(target_arch = "wasm32")'.dependencies] gloo-timers = "0.3.0" From fa814378713f512da48c38bcfb25e6239fd5578c Mon Sep 17 00:00:00 2001 From: Leonardo Arias Fonseca Date: Thu, 12 Sep 2024 18:06:42 +0000 Subject: [PATCH 2/2] Update jsonrpsee ErrorObject After v0.18.0, jsonrpsee::core::Error was removed. These are just naive changes to get it to compile. See: https://github.com/paritytech/jsonrpsee/releases/tag/v0.18.0 --- client/src/errors.rs | 18 +++---- client/src/rpc.rs | 115 ++++++++++++++++++++++--------------------- 2 files changed, 66 insertions(+), 67 deletions(-) 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..e2b45877 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()) } } @@ -292,6 +293,6 @@ async fn start(rpc: RpcInner) -> Result<(ServerHandle, SocketA 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::<()>)) }