Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

fix: sequencer tx forwarding #113

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jsonrpsee.workspace = true
http = "0.2.8"
http-body = "0.4.5"
hyper = "0.14.24"
reqwest = "0.11.20"
jsonwebtoken = "8"

# async
Expand Down
32 changes: 15 additions & 17 deletions crates/rpc/rpc/src/eth/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ use revm_primitives::{utilities::create_address, Env, ResultAndState, SpecId};
#[cfg(feature = "optimism")]
use bytes::BytesMut;
#[cfg(feature = "optimism")]
use http::{header::CONTENT_TYPE, HeaderValue};
#[cfg(feature = "optimism")]
use hyper::{Body, Client, Method, Request};
use http::header::CONTENT_TYPE;
#[cfg(feature = "optimism")]
use reth_revm::{executor, optimism::L1BlockInfo};
#[cfg(feature = "optimism")]
Expand Down Expand Up @@ -430,26 +428,26 @@ where
async fn send_raw_transaction(&self, tx: Bytes) -> EthResult<H256> {
#[cfg(feature = "optimism")]
if let Some(endpoint) = self.network().sequencer_endpoint() {
let client = Client::new();

let body = serde_json::json!({
let body = serde_json::to_string(&serde_json::json!({
"jsonrpc": "2.0",
"method": "eth_sendRawTransaction",
"params": [hex::encode(tx.clone())],
"params": [format!("0x{}", hex::encode(tx.clone()))],
"id": self.network().chain_id()
});

let req = Request::builder()
.method(Method::POST)
.uri(endpoint)
.header(CONTENT_TYPE, HeaderValue::from_static("application/json"))
.body(Body::from(serde_json::to_string(&body).unwrap()))?;

client.request(req).await?;
}))
.map_err(|_| EthApiError::InternalEthError)?;

let client = reqwest::Client::new();

client
.post(endpoint)
.header(CONTENT_TYPE, "application/json")
.body(body)
.send()
.await
.map_err(|_| EthApiError::InternalEthError)?;
}

let recovered = recover_raw_transaction(tx)?;

let pool_transaction = <Pool::Transaction>::from_recovered_transaction(recovered);

// submit the transaction to the pool with a `Local` origin
Expand Down
Loading