web3-proxy/web3-proxy/src/frontend/http_proxy.rs

16 lines
531 B
Rust
Raw Normal View History

2022-06-05 22:58:47 +03:00
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
use std::sync::Arc;
2022-06-16 05:53:37 +03:00
use super::errors::handle_anyhow_error;
use crate::{app::Web3ProxyApp, jsonrpc::JsonRpcRequestEnum};
2022-06-05 22:58:47 +03:00
pub async fn proxy_web3_rpc(
payload: Json<JsonRpcRequestEnum>,
app: Extension<Arc<Web3ProxyApp>>,
) -> impl IntoResponse {
match app.proxy_web3_rpc(payload.0).await {
2022-06-05 22:58:47 +03:00
Ok(response) => (StatusCode::OK, Json(&response)).into_response(),
Err(err) => handle_anyhow_error(err, None).await.into_response(),
}
}