diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/error.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/error.rs deleted file mode 100644 index 30f39fbefd8b..000000000000 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/error.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::fmt; - -use jsonrpc_core::{Error, ErrorCode}; -use zksync_web3_decl::error::Web3Error; - -use crate::api_server::web3::metrics::API_METRICS; - -pub fn into_jsrpc_error(err: Web3Error) -> Error { - Error { - code: match err { - Web3Error::InternalError | Web3Error::NotImplemented => ErrorCode::InternalError, - Web3Error::NoBlock - | Web3Error::NoSuchFunction - | Web3Error::RLPError(_) - | Web3Error::InvalidTransactionData(_) - | Web3Error::TooManyTopics - | Web3Error::FilterNotFound - | Web3Error::InvalidFeeParams(_) - | Web3Error::LogsLimitExceeded(_, _, _) - | Web3Error::InvalidFilterBlockHash => ErrorCode::InvalidParams, - Web3Error::SubmitTransactionError(_, _) | Web3Error::SerializationError(_) => 3.into(), - Web3Error::PubSubTimeout => 4.into(), - Web3Error::RequestTimeout => 5.into(), - Web3Error::TreeApiUnavailable => 6.into(), - }, - message: match err { - Web3Error::SubmitTransactionError(_, _) => err.to_string(), - _ => err.to_string(), - }, - data: match err { - Web3Error::SubmitTransactionError(_, data) => { - Some(format!("0x{}", hex::encode(data)).into()) - } - _ => None, - }, - } -} - -pub fn internal_error(method_name: &'static str, error: impl fmt::Display) -> Web3Error { - tracing::error!("Internal error in method {method_name}: {error}"); - API_METRICS.web3_internal_errors[&method_name].inc(); - Web3Error::InternalError -} diff --git a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs b/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs deleted file mode 100644 index b305abc91515..000000000000 --- a/core/lib/zksync_core/src/api_server/web3/backend_jsonrpc/namespaces/zks.rs +++ /dev/null @@ -1,318 +0,0 @@ -use std::collections::HashMap; - -use bigdecimal::BigDecimal; -use jsonrpc_core::{BoxFuture, Result}; -use jsonrpc_derive::rpc; -use zksync_types::{ - api::{ - BlockDetails, BridgeAddresses, L1BatchDetails, L2ToL1LogProof, Proof, ProtocolVersion, - TransactionDetails, - }, - fee::Fee, - transaction_request::CallRequest, - Address, L1BatchNumber, MiniblockNumber, H256, U256, U64, -}; -use zksync_web3_decl::types::Token; - -use crate::{ - l1_gas_price::L1GasPriceProvider, - web3::{backend_jsonrpc::error::into_jsrpc_error, namespaces::ZksNamespace}, -}; - -#[rpc] -pub trait ZksNamespaceT { - #[rpc(name = "zks_estimateFee")] - fn estimate_fee(&self, req: CallRequest) -> BoxFuture>; - - #[rpc(name = "zks_estimateGasL1ToL2")] - fn estimate_gas_l1_to_l2(&self, req: CallRequest) -> BoxFuture>; - - #[rpc(name = "zks_getMainContract")] - fn get_main_contract(&self) -> BoxFuture>; - - #[rpc(name = "zks_getTestnetPaymaster")] - fn get_testnet_paymaster(&self) -> BoxFuture>>; - - #[rpc(name = "zks_getBridgeContracts")] - fn get_bridge_contracts(&self) -> BoxFuture>; - - #[rpc(name = "zks_L1ChainId")] - fn l1_chain_id(&self) -> BoxFuture>; - - #[rpc(name = "zks_getConfirmedTokens")] - fn get_confirmed_tokens(&self, from: u32, limit: u8) -> BoxFuture>>; - - #[rpc(name = "zks_getTokenPrice")] - fn get_token_price(&self, token_address: Address) -> BoxFuture>; - - #[rpc(name = "zks_getAllAccountBalances")] - fn get_all_account_balances( - &self, - address: Address, - ) -> BoxFuture>>; - - #[rpc(name = "zks_getL2ToL1MsgProof")] - fn get_l2_to_l1_msg_proof( - &self, - block: MiniblockNumber, - sender: Address, - msg: H256, - l2_log_position: Option, - ) -> BoxFuture>>; - - #[rpc(name = "zks_getL2ToL1LogProof")] - fn get_l2_to_l1_log_proof( - &self, - tx_hash: H256, - index: Option, - ) -> BoxFuture>>; - - #[rpc(name = "zks_L1BatchNumber")] - fn get_l1_batch_number(&self) -> BoxFuture>; - - #[rpc(name = "zks_getBlockDetails")] - fn get_block_details( - &self, - block_number: MiniblockNumber, - ) -> BoxFuture>>; - - #[rpc(name = "zks_getL1BatchBlockRange")] - fn get_miniblock_range(&self, batch: L1BatchNumber) -> BoxFuture>>; - - #[rpc(name = "zks_getTransactionDetails")] - fn get_transaction_details(&self, hash: H256) -> BoxFuture>>; - - #[rpc(name = "zks_getRawBlockTransactions")] - fn get_raw_block_transactions( - &self, - block_number: MiniblockNumber, - ) -> BoxFuture>>; - - #[rpc(name = "zks_getL1BatchDetails")] - fn get_l1_batch_details( - &self, - batch: L1BatchNumber, - ) -> BoxFuture>>; - - #[rpc(name = "zks_getBytecodeByHash")] - fn get_bytecode_by_hash(&self, hash: H256) -> BoxFuture>>>; - - #[rpc(name = "zks_getL1GasPrice")] - fn get_l1_gas_price(&self) -> BoxFuture>; - - #[rpc(name = "zks_getProtocolVersion")] - fn get_protocol_version( - &self, - version_id: Option, - ) -> BoxFuture>>; - - #[rpc(name = "zks_getProof")] - fn get_proof( - &self, - address: Address, - keys: Vec, - l1_batch_number: L1BatchNumber, - ) -> BoxFuture>; -} - -impl ZksNamespaceT for ZksNamespace { - fn estimate_fee(&self, req: CallRequest) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { self_.estimate_fee_impl(req).await.map_err(into_jsrpc_error) }) - } - - fn estimate_gas_l1_to_l2(&self, req: CallRequest) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .estimate_l1_to_l2_gas_impl(req) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_main_contract(&self) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { Ok(self_.get_main_contract_impl()) }) - } - - fn get_miniblock_range(&self, batch: L1BatchNumber) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_miniblock_range_impl(batch) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_testnet_paymaster(&self) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { Ok(self_.get_testnet_paymaster_impl()) }) - } - - fn get_bridge_contracts(&self) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { Ok(self_.get_bridge_contracts_impl()) }) - } - - fn l1_chain_id(&self) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { Ok(self_.l1_chain_id_impl()) }) - } - - fn get_confirmed_tokens(&self, from: u32, limit: u8) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_confirmed_tokens_impl(from, limit) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_token_price(&self, token_address: Address) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_token_price_impl(token_address) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_all_account_balances( - &self, - address: Address, - ) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_all_account_balances_impl(address) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_l2_to_l1_msg_proof( - &self, - block: MiniblockNumber, - sender: Address, - msg: H256, - l2_log_position: Option, - ) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_l2_to_l1_msg_proof_impl(block, sender, msg, l2_log_position) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_l2_to_l1_log_proof( - &self, - tx_hash: H256, - index: Option, - ) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_l2_to_l1_log_proof_impl(tx_hash, index) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_l1_batch_number(&self) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_l1_batch_number_impl() - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_block_details( - &self, - block_number: MiniblockNumber, - ) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_block_details_impl(block_number) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_transaction_details(&self, hash: H256) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_transaction_details_impl(hash) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_raw_block_transactions( - &self, - block_number: MiniblockNumber, - ) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_raw_block_transactions_impl(block_number) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_l1_batch_details( - &self, - batch: L1BatchNumber, - ) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_l1_batch_details_impl(batch) - .await - .map_err(into_jsrpc_error) - }) - } - - fn get_bytecode_by_hash(&self, hash: H256) -> BoxFuture>>> { - let self_ = self.clone(); - Box::pin(async move { Ok(self_.get_bytecode_by_hash_impl(hash).await) }) - } - - fn get_l1_gas_price(&self) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { Ok(self_.get_l1_gas_price_impl()) }) - } - - fn get_protocol_version( - &self, - version_id: Option, - ) -> BoxFuture>> { - let self_ = self.clone(); - Box::pin(async move { Ok(self_.get_protocol_version_impl(version_id).await) }) - } - - fn get_proof( - &self, - address: Address, - keys: Vec, - l1_batch_number: L1BatchNumber, - ) -> BoxFuture> { - let self_ = self.clone(); - Box::pin(async move { - self_ - .get_proofs_impl(address, keys.clone(), l1_batch_number) - .await - .map_err(into_jsrpc_error) - }) - } -}