|
| 1 | +//! Signet RPC methods and related code. |
| 2 | +pub(crate) mod error; |
| 3 | + |
| 4 | +use crate::util::await_jh_option; |
| 5 | +use crate::{ctx::RpcCtx, Pnt}; |
| 6 | +use ajj::HandlerCtx; |
| 7 | +use error::SignetError; |
| 8 | +use reth_node_api::FullNodeComponents; |
| 9 | +use signet_bundle::SignetEthBundle; |
| 10 | +use signet_zenith::SignedOrder; |
| 11 | + |
| 12 | +/// Instantiate a `signet` API router. |
| 13 | +pub fn signet<Host, Signet>() -> ajj::Router<RpcCtx<Host, Signet>> |
| 14 | +where |
| 15 | + Host: FullNodeComponents, |
| 16 | + Signet: Pnt, |
| 17 | +{ |
| 18 | + ajj::Router::new().route("sendBundle", send_bundle).route("sendOrder", send_order) |
| 19 | +} |
| 20 | + |
| 21 | +pub(super) async fn send_bundle<Host, Signet>( |
| 22 | + hctx: HandlerCtx, |
| 23 | + bundle: SignetEthBundle, |
| 24 | + ctx: RpcCtx<Host, Signet>, |
| 25 | +) -> Result<(), String> |
| 26 | +where |
| 27 | + Host: FullNodeComponents, |
| 28 | + Signet: Pnt, |
| 29 | +{ |
| 30 | + let task = |hctx: HandlerCtx| async move { |
| 31 | + let Some(forwarder) = ctx.signet().forwarder() else { |
| 32 | + return Err(SignetError::TxCacheUrlNotProvided.into_string()); |
| 33 | + }; |
| 34 | + |
| 35 | + hctx.spawn(async move { |
| 36 | + forwarder |
| 37 | + .forward_bundle(bundle) |
| 38 | + .await |
| 39 | + .map_err(|e| SignetError::EthApiError(e).into_string()) |
| 40 | + }); |
| 41 | + |
| 42 | + Ok(()) |
| 43 | + }; |
| 44 | + |
| 45 | + await_jh_option!(hctx.spawn_blocking_with_ctx(task)) |
| 46 | +} |
| 47 | + |
| 48 | +pub(super) async fn send_order<Host, Signet>( |
| 49 | + hctx: HandlerCtx, |
| 50 | + order: SignedOrder, |
| 51 | + ctx: RpcCtx<Host, Signet>, |
| 52 | +) -> Result<(), String> |
| 53 | +where |
| 54 | + Host: FullNodeComponents, |
| 55 | + Signet: Pnt, |
| 56 | +{ |
| 57 | + let task = |hctx: HandlerCtx| async move { |
| 58 | + let Some(forwarder) = ctx.signet().forwarder() else { |
| 59 | + return Err(SignetError::TxCacheUrlNotProvided.into_string()); |
| 60 | + }; |
| 61 | + |
| 62 | + hctx.spawn(async move { |
| 63 | + forwarder |
| 64 | + .forward_order(order) |
| 65 | + .await |
| 66 | + .map_err(|e| SignetError::EthApiError(e).into_string()) |
| 67 | + }); |
| 68 | + |
| 69 | + Ok(()) |
| 70 | + }; |
| 71 | + |
| 72 | + await_jh_option!(hctx.spawn_blocking_with_ctx(task)) |
| 73 | +} |
0 commit comments