|
| 1 | +use alloy_primitives::{B256, Bytes}; |
| 2 | +use alloy_provider::{Provider, RootProvider}; |
| 3 | +use alloy_rpc_types_mev::{EthBundleHash, EthCancelBundle, EthSendBundle}; |
| 4 | +use jsonrpsee::{ |
| 5 | + core::{RpcResult, async_trait}, |
| 6 | + proc_macros::rpc, |
| 7 | + types::ErrorObjectOwned, |
| 8 | +}; |
| 9 | +use tracing::warn; |
| 10 | + |
| 11 | +#[rpc(server, namespace = "eth")] |
| 12 | +pub trait IngressApi { |
| 13 | + /// `eth_sendBundle` can be used to send your bundles to the builder. |
| 14 | + #[method(name = "sendBundle")] |
| 15 | + async fn send_bundle(&self, bundle: EthSendBundle) -> RpcResult<EthBundleHash>; |
| 16 | + |
| 17 | + /// `eth_cancelBundle` is used to prevent a submitted bundle from being included on-chain. |
| 18 | + #[method(name = "cancelBundle")] |
| 19 | + async fn cancel_bundle(&self, request: EthCancelBundle) -> RpcResult<()>; |
| 20 | + |
| 21 | + /// Handler for: `eth_sendRawTransaction` |
| 22 | + #[method(name = "sendRawTransaction")] |
| 23 | + async fn send_raw_transaction(&self, tx: Bytes) -> RpcResult<B256>; |
| 24 | +} |
| 25 | + |
| 26 | +pub struct IngressService { |
| 27 | + provider: RootProvider, |
| 28 | +} |
| 29 | + |
| 30 | +impl IngressService { |
| 31 | + pub fn new(provider: RootProvider) -> Self { |
| 32 | + Self { provider } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +#[async_trait] |
| 37 | +impl IngressApiServer for IngressService { |
| 38 | + async fn send_bundle(&self, _bundle: EthSendBundle) -> RpcResult<EthBundleHash> { |
| 39 | + warn!( |
| 40 | + message = "TODO: implement send_bundle", |
| 41 | + method = "send_bundle" |
| 42 | + ); |
| 43 | + todo!("implement send_bundle") |
| 44 | + } |
| 45 | + |
| 46 | + async fn cancel_bundle(&self, _request: EthCancelBundle) -> RpcResult<()> { |
| 47 | + warn!( |
| 48 | + message = "TODO: implement cancel_bundle", |
| 49 | + method = "cancel_bundle" |
| 50 | + ); |
| 51 | + todo!("implement cancel_bundle") |
| 52 | + } |
| 53 | + |
| 54 | + async fn send_raw_transaction(&self, tx: Bytes) -> RpcResult<B256> { |
| 55 | + let response = self |
| 56 | + .provider |
| 57 | + .send_raw_transaction(tx.iter().as_slice()) |
| 58 | + .await; |
| 59 | + |
| 60 | + match response { |
| 61 | + Ok(r) => Ok(*r.tx_hash()), |
| 62 | + Err(e) => { |
| 63 | + warn!( |
| 64 | + message = "Failed to send raw transaction to mempool", |
| 65 | + method = "send_raw_transaction", |
| 66 | + error = %e |
| 67 | + ); |
| 68 | + Err(ErrorObjectOwned::owned( |
| 69 | + -32000, |
| 70 | + format!("Failed to send transaction: {}", e), |
| 71 | + None::<()>, |
| 72 | + )) |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments