Skip to content

Commit

Permalink
fix: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
eugypalu committed Sep 20, 2024
1 parent 9512f61 commit c4683e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 3 additions & 7 deletions src/eth_rpc/servers/eth_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde_json::Value;
use starknet::providers::Provider;
#[cfg(feature = "rpc_forwarding")]
use {
crate::providers::eth_provider::{constant::MAIN_RPC_URL, error::EthereumDataFormatError},
crate::providers::eth_provider::constant::MAIN_RPC_URL,
alloy_provider::{Provider as provider_alloy, ProviderBuilder},
url::Url,
};
Expand Down Expand Up @@ -247,12 +247,8 @@ where
tracing::info!("Serving eth_sendRawTransaction");
#[cfg(feature = "rpc_forwarding")]
{
let provider_builded = ProviderBuilder::new().on_http(Url::parse(&MAIN_RPC_URL).expect("invalid rpc url"));

let tx_hash = provider_builded
.send_raw_transaction(&bytes)
.await
.map_err(|_| EthApiError::EthereumDataFormat(EthereumDataFormatError::TransactionConversion))?;
let provider = ProviderBuilder::new().on_http(Url::parse(MAIN_RPC_URL.as_ref()).unwrap());
let tx_hash = provider.send_raw_transaction(&bytes).await.expect("failed to send transaction");

return Ok(*tx_hash.tx_hash());
}
Expand Down
7 changes: 5 additions & 2 deletions src/providers/eth_provider/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
str::FromStr,
sync::{LazyLock, OnceLock},
};
use url::Url;

/// Maximum priority fee per gas
pub static MAX_PRIORITY_FEE_PER_GAS: LazyLock<u64> = LazyLock::new(|| 0);
Expand Down Expand Up @@ -79,5 +80,7 @@ pub mod hive {
pub static DEPLOY_WALLET_NONCE: LazyLock<Arc<Mutex<Felt>>> = LazyLock::new(|| Arc::new(Mutex::new(Felt::ZERO)));
}

pub static MAIN_RPC_URL: LazyLock<String> =
LazyLock::new(|| std::env::var("MAIN_RPC_URL").expect("Missing MAIN_RPC_URL environment variable"));
pub static MAIN_RPC_URL: LazyLock<Url> = LazyLock::new(|| {
Url::parse(&std::env::var("MAIN_RPC_URL").expect("Missing MAIN_RPC_URL environment variable"))
.expect("Invalid MAIN_RPC_URL environment variable")
});
4 changes: 2 additions & 2 deletions tests/tests/kakarot_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use reth_primitives::{sign_message, Address, Bytes, Transaction, TransactionSign
use rstest::*;
use serde_json::Value;
use std::str::FromStr;
#[cfg(feature = "rpc_forwarding")]
use {mockito::Server, std::env};

#[cfg(feature = "rpc_forwarding")]
#[rstest]
#[awt]
#[tokio::test(flavor = "multi_thread")]
async fn test_send_raw_transaction_rpc_forwarding(#[future] katana: Katana, _setup: ()) {
use mockito::Server;
use std::env;
let mut server = Server::new();
let mock_server = server
.mock("POST", "/")
Expand Down

0 comments on commit c4683e1

Please sign in to comment.