with_state instead of Extension
This commit is contained in:
parent
753cbb1b60
commit
429cfe04d0
@ -10,10 +10,10 @@ use crate::globals::{global_db_conn, global_db_replica_conn};
|
|||||||
use crate::premium::{get_user_and_tier_from_address, grant_premium_tier};
|
use crate::premium::{get_user_and_tier_from_address, grant_premium_tier};
|
||||||
use crate::user_token::UserBearerToken;
|
use crate::user_token::UserBearerToken;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, Query},
|
extract::{Path, Query, State},
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension, Json, TypedHeader,
|
Json, TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
@ -52,7 +52,7 @@ pub struct AdminIncreaseBalancePost {
|
|||||||
/// - user_role_tier that is supposed to be adapted
|
/// - user_role_tier that is supposed to be adapted
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn admin_increase_balance(
|
pub async fn admin_increase_balance(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Json(payload): Json<AdminIncreaseBalancePost>,
|
Json(payload): Json<AdminIncreaseBalancePost>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -115,7 +115,7 @@ pub async fn admin_increase_balance(
|
|||||||
/// TODO: JSON post data instead of query params
|
/// TODO: JSON post data instead of query params
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn admin_change_user_roles(
|
pub async fn admin_change_user_roles(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
||||||
Query(params): Query<HashMap<String, String>>,
|
Query(params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -130,7 +130,7 @@ pub async fn admin_change_user_roles(
|
|||||||
/// We assume that the admin has already logged in, and has a bearer token ...
|
/// We assume that the admin has already logged in, and has a bearer token ...
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn admin_imitate_login_get(
|
pub async fn admin_imitate_login_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
Path(mut params): Path<HashMap<String, String>>,
|
Path(mut params): Path<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -287,7 +287,7 @@ pub async fn admin_imitate_login_get(
|
|||||||
/// The bearer token can be used to authenticate other admin requests
|
/// The bearer token can be used to authenticate other admin requests
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn admin_imitate_login_post(
|
pub async fn admin_imitate_login_post(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
Json(payload): Json<PostLogin>,
|
Json(payload): Json<PostLogin>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
//! `frontend` contains HTTP and websocket endpoints for use by a website or web3 wallet.
|
//! `frontend` contains HTTP and websocket endpoints for use by a website or web3 wallet.
|
||||||
//!
|
//!
|
||||||
//! Important reading about axum extractors: <https://docs.rs/axum/latest/axum/extract/index.html#the-order-of-extractors>
|
//! Important reading about axum extractors: <https://docs.rs/axum/latest/axum/extract/index.html#the-order-of-extractors>
|
||||||
|
//!
|
||||||
|
//! There are a lot of things in tower/axum that i should have used instead of implementing here.
|
||||||
// TODO: these are only public so docs are generated. What's a better way to do this?
|
// TODO: these are only public so docs are generated. What's a better way to do this?
|
||||||
pub mod admin;
|
pub mod admin;
|
||||||
pub mod authorization;
|
pub mod authorization;
|
||||||
@ -43,12 +45,8 @@ pub enum ResponseCacheKey {
|
|||||||
|
|
||||||
pub type ResponseCache = Cache<ResponseCacheKey, (StatusCode, &'static str, axum::body::Bytes)>;
|
pub type ResponseCache = Cache<ResponseCacheKey, (StatusCode, &'static str, axum::body::Bytes)>;
|
||||||
|
|
||||||
/// Start the frontend server.
|
/// build our axum Router
|
||||||
pub async fn serve(
|
pub fn make_router(app: Arc<App>) -> Router<()> {
|
||||||
app: Arc<App>,
|
|
||||||
mut shutdown_receiver: broadcast::Receiver<()>,
|
|
||||||
shutdown_complete_sender: broadcast::Sender<()>,
|
|
||||||
) -> Web3ProxyResult<()> {
|
|
||||||
// setup caches for whatever the frontend needs
|
// setup caches for whatever the frontend needs
|
||||||
// no need for max items since it is limited by the enum key
|
// no need for max items since it is limited by the enum key
|
||||||
// TODO: latest moka allows for different ttls for different
|
// TODO: latest moka allows for different ttls for different
|
||||||
@ -59,9 +57,8 @@ pub async fn serve(
|
|||||||
.time_to_live(Duration::from_millis(200))
|
.time_to_live(Duration::from_millis(200))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// TODO: read config for if fastest/versus should be available publicly. default off
|
let response_cache = Arc::new(response_cache);
|
||||||
|
|
||||||
// build our axum Router
|
|
||||||
let mut router = Router::new()
|
let mut router = Router::new()
|
||||||
// TODO: i think these routes could be done a lot better
|
// TODO: i think these routes could be done a lot better
|
||||||
//
|
//
|
||||||
@ -142,10 +139,23 @@ pub async fn serve(
|
|||||||
//
|
//
|
||||||
// System things
|
// System things
|
||||||
//
|
//
|
||||||
.route("/health", get(status::health))
|
// TODO: response_cache should probably be inside State
|
||||||
.route("/status", get(status::status))
|
.route(
|
||||||
.route("/status/backups_needed", get(status::backups_needed))
|
"/health",
|
||||||
.route("/status/debug_request", get(status::debug_request))
|
get(status::health).route_layer(Extension(response_cache.clone())),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/status",
|
||||||
|
get(status::status).route_layer(Extension(response_cache.clone())),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/status/backups_needed",
|
||||||
|
get(status::backups_needed).route_layer(Extension(response_cache.clone())),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/status/debug_request",
|
||||||
|
get(status::debug_request).route_layer(Extension(response_cache.clone())),
|
||||||
|
)
|
||||||
//
|
//
|
||||||
// User stuff
|
// User stuff
|
||||||
//
|
//
|
||||||
@ -256,22 +266,17 @@ pub async fn serve(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
router = router
|
// Axum layers
|
||||||
//
|
// layers are ordered bottom up
|
||||||
// Axum layers
|
// the last layer is first for requests and last for responses
|
||||||
// layers are ordered bottom up
|
let router = router
|
||||||
// the last layer is first for requests and last for responses
|
|
||||||
//
|
|
||||||
// Remove trailing slashes
|
// Remove trailing slashes
|
||||||
|
// TODO: this isn't working for me. why?
|
||||||
.layer(NormalizePathLayer::trim_trailing_slash())
|
.layer(NormalizePathLayer::trim_trailing_slash())
|
||||||
// Mark the `Authorization` request header as sensitive so it doesn't show in logs
|
// Mark the `Authorization` request header as sensitive so it doesn't show in logs
|
||||||
.layer(SetSensitiveRequestHeadersLayer::new(once(AUTHORIZATION)))
|
.layer(SetSensitiveRequestHeadersLayer::new(once(AUTHORIZATION)))
|
||||||
// handle cors. we expect queries from all sorts of places
|
// handle cors. we expect queries from all sorts of places
|
||||||
.layer(CorsLayer::very_permissive())
|
.layer(CorsLayer::very_permissive())
|
||||||
// application state
|
|
||||||
.layer(Extension(app.clone()))
|
|
||||||
// frontend caches
|
|
||||||
.layer(Extension(Arc::new(response_cache)))
|
|
||||||
// request id
|
// request id
|
||||||
.layer(
|
.layer(
|
||||||
TraceLayer::new_for_http().make_span_with(|request: &Request<Body>| {
|
TraceLayer::new_for_http().make_span_with(|request: &Request<Body>| {
|
||||||
@ -306,7 +311,20 @@ pub async fn serve(
|
|||||||
}), // .on_failure(|| todo!("on failure that has the request and response body so we can debug more easily")),
|
}), // .on_failure(|| todo!("on failure that has the request and response body so we can debug more easily")),
|
||||||
)
|
)
|
||||||
// 404 for any unknown routes
|
// 404 for any unknown routes
|
||||||
.fallback(errors::handler_404);
|
.fallback(errors::handler_404)
|
||||||
|
.with_state(app);
|
||||||
|
|
||||||
|
router
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start the frontend server.
|
||||||
|
pub async fn serve(
|
||||||
|
app: Arc<App>,
|
||||||
|
mut shutdown_receiver: broadcast::Receiver<()>,
|
||||||
|
shutdown_complete_sender: broadcast::Sender<()>,
|
||||||
|
) -> Web3ProxyResult<()> {
|
||||||
|
// TODO: read config for if fastest/versus should be available publicly. default off
|
||||||
|
let router = make_router(app.clone());
|
||||||
|
|
||||||
// TODO: https://docs.rs/tower-http/latest/tower_http/propagate_header/index.html
|
// TODO: https://docs.rs/tower-http/latest/tower_http/propagate_header/index.html
|
||||||
|
|
||||||
|
@ -5,11 +5,11 @@ use super::rpc_proxy_ws::ProxyMode;
|
|||||||
use crate::errors::Web3ProxyError;
|
use crate::errors::Web3ProxyError;
|
||||||
use crate::{app::App, jsonrpc::JsonRpcRequestEnum};
|
use crate::{app::App, jsonrpc::JsonRpcRequestEnum};
|
||||||
use axum::extract::rejection::JsonRejection;
|
use axum::extract::rejection::JsonRejection;
|
||||||
use axum::extract::Path;
|
use axum::extract::{Path, State};
|
||||||
use axum::headers::{Origin, Referer, UserAgent};
|
use axum::headers::{Origin, Referer, UserAgent};
|
||||||
use axum::response::Response;
|
use axum::response::Response;
|
||||||
use axum::TypedHeader;
|
use axum::TypedHeader;
|
||||||
use axum::{response::IntoResponse, Extension, Json};
|
use axum::{response::IntoResponse, Json};
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
@ -23,7 +23,7 @@ use std::time::Duration;
|
|||||||
/// If possible, please use a WebSocket instead.
|
/// If possible, please use a WebSocket instead.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn proxy_web3_rpc(
|
pub async fn proxy_web3_rpc(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
payload: Result<Json<JsonRpcRequestEnum>, JsonRejection>,
|
payload: Result<Json<JsonRpcRequestEnum>, JsonRejection>,
|
||||||
@ -33,7 +33,7 @@ pub async fn proxy_web3_rpc(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn fastest_proxy_web3_rpc(
|
pub async fn fastest_proxy_web3_rpc(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
payload: Result<Json<JsonRpcRequestEnum>, JsonRejection>,
|
payload: Result<Json<JsonRpcRequestEnum>, JsonRejection>,
|
||||||
@ -45,7 +45,7 @@ pub async fn fastest_proxy_web3_rpc(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn versus_proxy_web3_rpc(
|
pub async fn versus_proxy_web3_rpc(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
payload: Result<Json<JsonRpcRequestEnum>, JsonRejection>,
|
payload: Result<Json<JsonRpcRequestEnum>, JsonRejection>,
|
||||||
@ -126,7 +126,7 @@ async fn _proxy_web3_rpc(
|
|||||||
/// If possible, please use a WebSocket instead.
|
/// If possible, please use a WebSocket instead.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn proxy_web3_rpc_with_key(
|
pub async fn proxy_web3_rpc_with_key(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
referer: Option<TypedHeader<Referer>>,
|
referer: Option<TypedHeader<Referer>>,
|
||||||
@ -151,7 +151,7 @@ pub async fn proxy_web3_rpc_with_key(
|
|||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn debug_proxy_web3_rpc_with_key(
|
pub async fn debug_proxy_web3_rpc_with_key(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
referer: Option<TypedHeader<Referer>>,
|
referer: Option<TypedHeader<Referer>>,
|
||||||
@ -195,7 +195,7 @@ pub async fn debug_proxy_web3_rpc_with_key(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn fastest_proxy_web3_rpc_with_key(
|
pub async fn fastest_proxy_web3_rpc_with_key(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
referer: Option<TypedHeader<Referer>>,
|
referer: Option<TypedHeader<Referer>>,
|
||||||
@ -218,7 +218,7 @@ pub async fn fastest_proxy_web3_rpc_with_key(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn versus_proxy_web3_rpc_with_key(
|
pub async fn versus_proxy_web3_rpc_with_key(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
referer: Option<TypedHeader<Referer>>,
|
referer: Option<TypedHeader<Referer>>,
|
||||||
|
@ -9,9 +9,9 @@ use crate::{app::App, errors::Web3ProxyResult, jsonrpc::SingleRequest};
|
|||||||
use axum::headers::{Origin, Referer, UserAgent};
|
use axum::headers::{Origin, Referer, UserAgent};
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::ws::{Message, WebSocket, WebSocketUpgrade},
|
extract::ws::{Message, WebSocket, WebSocketUpgrade},
|
||||||
extract::Path,
|
extract::{Path, State},
|
||||||
response::{IntoResponse, Redirect},
|
response::{IntoResponse, Redirect},
|
||||||
Extension, TypedHeader,
|
TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
@ -54,7 +54,7 @@ pub enum ProxyMode {
|
|||||||
/// Queries a single server at a time
|
/// Queries a single server at a time
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn websocket_handler(
|
pub async fn websocket_handler(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
ws_upgrade: Option<WebSocketUpgrade>,
|
ws_upgrade: Option<WebSocketUpgrade>,
|
||||||
@ -66,7 +66,7 @@ pub async fn websocket_handler(
|
|||||||
/// Queries all synced backends with every request! This might get expensive!
|
/// Queries all synced backends with every request! This might get expensive!
|
||||||
// #[debug_handler]
|
// #[debug_handler]
|
||||||
pub async fn fastest_websocket_handler(
|
pub async fn fastest_websocket_handler(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
ws_upgrade: Option<WebSocketUpgrade>,
|
ws_upgrade: Option<WebSocketUpgrade>,
|
||||||
@ -87,7 +87,7 @@ pub async fn fastest_websocket_handler(
|
|||||||
/// Queries **all** backends with every request! This might get expensive!
|
/// Queries **all** backends with every request! This might get expensive!
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn versus_websocket_handler(
|
pub async fn versus_websocket_handler(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
ws_upgrade: Option<WebSocketUpgrade>,
|
ws_upgrade: Option<WebSocketUpgrade>,
|
||||||
@ -127,7 +127,7 @@ async fn _websocket_handler(
|
|||||||
/// Can optionally authorized based on origin, referer, or user agent.
|
/// Can optionally authorized based on origin, referer, or user agent.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn websocket_handler_with_key(
|
pub async fn websocket_handler_with_key(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
Path(rpc_key): Path<String>,
|
Path(rpc_key): Path<String>,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
@ -151,7 +151,7 @@ pub async fn websocket_handler_with_key(
|
|||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn debug_websocket_handler_with_key(
|
pub async fn debug_websocket_handler_with_key(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
Path(rpc_key): Path<String>,
|
Path(rpc_key): Path<String>,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
@ -190,7 +190,7 @@ pub async fn debug_websocket_handler_with_key(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn fastest_websocket_handler_with_key(
|
pub async fn fastest_websocket_handler_with_key(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
Path(rpc_key): Path<String>,
|
Path(rpc_key): Path<String>,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
@ -214,7 +214,7 @@ pub async fn fastest_websocket_handler_with_key(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn versus_websocket_handler_with_key(
|
pub async fn versus_websocket_handler_with_key(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
Path(rpc_key): Path<String>,
|
Path(rpc_key): Path<String>,
|
||||||
origin: Option<TypedHeader<Origin>>,
|
origin: Option<TypedHeader<Origin>>,
|
||||||
|
@ -10,6 +10,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
body::{Bytes, Full},
|
body::{Bytes, Full},
|
||||||
|
extract::State,
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
Extension, Json,
|
Extension, Json,
|
||||||
@ -37,7 +38,7 @@ static CONTENT_TYPE_PLAIN: &str = "text/plain";
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn debug_request(
|
pub async fn debug_request(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
ip: InsecureClientIp,
|
ip: InsecureClientIp,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
@ -76,7 +77,7 @@ pub async fn debug_request(
|
|||||||
/// Health check page for load balancers to use.
|
/// Health check page for load balancers to use.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn health(
|
pub async fn health(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
Extension(cache): Extension<Arc<ResponseCache>>,
|
Extension(cache): Extension<Arc<ResponseCache>>,
|
||||||
) -> Result<impl IntoResponse, Web3ProxyError> {
|
) -> Result<impl IntoResponse, Web3ProxyError> {
|
||||||
let (code, content_type, body) = timeout(
|
let (code, content_type, body) = timeout(
|
||||||
@ -113,7 +114,7 @@ async fn _health(app: Arc<App>) -> (StatusCode, &'static str, Bytes) {
|
|||||||
/// Easy alerting if backup servers are in use.
|
/// Easy alerting if backup servers are in use.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn backups_needed(
|
pub async fn backups_needed(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
Extension(cache): Extension<Arc<ResponseCache>>,
|
Extension(cache): Extension<Arc<ResponseCache>>,
|
||||||
) -> Result<impl IntoResponse, Web3ProxyError> {
|
) -> Result<impl IntoResponse, Web3ProxyError> {
|
||||||
let (code, content_type, body) = timeout(
|
let (code, content_type, body) = timeout(
|
||||||
@ -164,7 +165,7 @@ async fn _backups_needed(app: Arc<App>) -> (StatusCode, &'static str, Bytes) {
|
|||||||
/// TODO: replace this with proper stats and monitoring. frontend uses it for their public dashboards though
|
/// TODO: replace this with proper stats and monitoring. frontend uses it for their public dashboards though
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn status(
|
pub async fn status(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
Extension(cache): Extension<Arc<ResponseCache>>,
|
Extension(cache): Extension<Arc<ResponseCache>>,
|
||||||
) -> Result<impl IntoResponse, Web3ProxyError> {
|
) -> Result<impl IntoResponse, Web3ProxyError> {
|
||||||
let (code, content_type, body) = timeout(
|
let (code, content_type, body) = timeout(
|
||||||
|
@ -6,10 +6,10 @@ use crate::globals::{global_db_conn, global_db_replica_conn};
|
|||||||
use crate::secrets::RpcSecretKey;
|
use crate::secrets::RpcSecretKey;
|
||||||
use crate::user_token::UserBearerToken;
|
use crate::user_token::UserBearerToken;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, Query},
|
extract::{Path, Query, State},
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension, Json, TypedHeader,
|
Json, TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
@ -76,7 +76,7 @@ pub struct LoginPostResponse {
|
|||||||
/// We can prompt for an email and and payment after they log in.
|
/// We can prompt for an email and and payment after they log in.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_login_get(
|
pub async fn user_login_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
// TODO: what does axum's error handling look like if the path fails to parse?
|
// TODO: what does axum's error handling look like if the path fails to parse?
|
||||||
Path(mut params): Path<HashMap<String, String>>,
|
Path(mut params): Path<HashMap<String, String>>,
|
||||||
@ -224,7 +224,7 @@ pub async fn register_new_user(
|
|||||||
/// The bearer token can be used to authenticate other requests, such as getting the user's stats or modifying the user's profile.
|
/// The bearer token can be used to authenticate other requests, such as getting the user's stats or modifying the user's profile.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_login_post(
|
pub async fn user_login_post(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
InsecureClientIp(ip): InsecureClientIp,
|
InsecureClientIp(ip): InsecureClientIp,
|
||||||
Query(query): Query<PostLoginQuery>,
|
Query(query): Query<PostLoginQuery>,
|
||||||
Json(payload): Json<PostLogin>,
|
Json(payload): Json<PostLogin>,
|
||||||
|
@ -13,9 +13,10 @@ use crate::app::App;
|
|||||||
use crate::errors::{Web3ProxyError, Web3ProxyErrorContext, Web3ProxyResponse};
|
use crate::errors::{Web3ProxyError, Web3ProxyErrorContext, Web3ProxyResponse};
|
||||||
use crate::globals::global_db_transaction;
|
use crate::globals::global_db_transaction;
|
||||||
use axum::{
|
use axum::{
|
||||||
|
extract::State,
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension, Json, TypedHeader,
|
Json, TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use entities::{self, referee, referrer, user};
|
use entities::{self, referee, referrer, user};
|
||||||
@ -32,7 +33,7 @@ use std::sync::Arc;
|
|||||||
/// TODO: this will change as we add better support for secondary users.
|
/// TODO: this will change as we add better support for secondary users.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_get(
|
pub async fn user_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer_token)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer_token)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
let user = app.bearer_is_authorized(bearer_token).await?;
|
let user = app.bearer_is_authorized(bearer_token).await?;
|
||||||
@ -51,7 +52,7 @@ pub struct UserPost {
|
|||||||
/// `POST /user` -- modify the account connected to the bearer token in the `Authentication` header.
|
/// `POST /user` -- modify the account connected to the bearer token in the `Authentication` header.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_post(
|
pub async fn user_post(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer_token)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer_token)): TypedHeader<Authorization<Bearer>>,
|
||||||
Json(payload): Json<UserPost>,
|
Json(payload): Json<UserPost>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
|
@ -7,10 +7,10 @@ use crate::globals::{global_db_conn, global_db_replica_conn};
|
|||||||
use crate::premium::{get_user_and_tier_from_address, grant_premium_tier};
|
use crate::premium::{get_user_and_tier_from_address, grant_premium_tier};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::Path,
|
extract::{Path, State},
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension, Json, TypedHeader,
|
Json, TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_client_ip::InsecureClientIp;
|
use axum_client_ip::InsecureClientIp;
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
@ -41,7 +41,7 @@ use tracing::{debug, error, info, trace, warn};
|
|||||||
/// - show deposits history (currency, amounts, transaction id)
|
/// - show deposits history (currency, amounts, transaction id)
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_balance_get(
|
pub async fn user_balance_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
let user = app.bearer_is_authorized(bearer).await?;
|
let user = app.bearer_is_authorized(bearer).await?;
|
||||||
@ -61,7 +61,7 @@ pub async fn user_balance_get(
|
|||||||
/// - shows a list of all deposits, including their chain-id, amount and tx-hash
|
/// - shows a list of all deposits, including their chain-id, amount and tx-hash
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_chain_deposits_get(
|
pub async fn user_chain_deposits_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
let user = app.bearer_is_authorized(bearer).await?;
|
let user = app.bearer_is_authorized(bearer).await?;
|
||||||
@ -100,7 +100,7 @@ pub async fn user_chain_deposits_get(
|
|||||||
/// - shows a list of all deposits done through stripe
|
/// - shows a list of all deposits done through stripe
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_stripe_deposits_get(
|
pub async fn user_stripe_deposits_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
let user = app.bearer_is_authorized(bearer).await?;
|
let user = app.bearer_is_authorized(bearer).await?;
|
||||||
@ -143,7 +143,7 @@ pub async fn user_stripe_deposits_get(
|
|||||||
/// - shows a list of all deposits done by admins
|
/// - shows a list of all deposits done by admins
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_admin_deposits_get(
|
pub async fn user_admin_deposits_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
let user = app.bearer_is_authorized(bearer).await?;
|
let user = app.bearer_is_authorized(bearer).await?;
|
||||||
@ -181,7 +181,7 @@ pub async fn user_admin_deposits_get(
|
|||||||
/// `POST /user/balance/:tx_hash` -- Process a confirmed txid to update a user's balance.
|
/// `POST /user/balance/:tx_hash` -- Process a confirmed txid to update a user's balance.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_balance_post(
|
pub async fn user_balance_post(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
ip: Option<InsecureClientIp>,
|
ip: Option<InsecureClientIp>,
|
||||||
Path(mut params): Path<HashMap<String, String>>,
|
Path(mut params): Path<HashMap<String, String>>,
|
||||||
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
||||||
@ -441,7 +441,7 @@ pub async fn user_balance_post(
|
|||||||
/// `POST /user/balance_uncle/:uncle_hash` -- Process an uncle block to potentially update a user's balance.
|
/// `POST /user/balance_uncle/:uncle_hash` -- Process an uncle block to potentially update a user's balance.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_balance_uncle_post(
|
pub async fn user_balance_uncle_post(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
ip: Option<InsecureClientIp>,
|
ip: Option<InsecureClientIp>,
|
||||||
Path(mut params): Path<HashMap<String, String>>,
|
Path(mut params): Path<HashMap<String, String>>,
|
||||||
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
||||||
|
@ -19,7 +19,7 @@ use tracing::{debug, error, warn};
|
|||||||
/// this endpoint is called from the webhook with the user_id parameter in the request
|
/// this endpoint is called from the webhook with the user_id parameter in the request
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_balance_stripe_post(
|
pub async fn user_balance_stripe_post(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
// InsecureClientIp(ip): InsecureClientIp,
|
// InsecureClientIp(ip): InsecureClientIp,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
payload: String,
|
payload: String,
|
||||||
|
@ -5,10 +5,10 @@ use crate::referral_code::ReferralCode;
|
|||||||
use crate::{app::App, globals::global_db_replica_conn};
|
use crate::{app::App, globals::global_db_replica_conn};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::Query,
|
extract::{Query, State},
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension, Json, TypedHeader,
|
Json, TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use entities::{referee, referrer, user};
|
use entities::{referee, referrer, user};
|
||||||
@ -29,7 +29,7 @@ use std::sync::Arc;
|
|||||||
/// This is the link that the user can share to third parties, and get credits.
|
/// This is the link that the user can share to third parties, and get credits.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_referral_link_get(
|
pub async fn user_referral_link_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Query(_params): Query<HashMap<String, String>>,
|
Query(_params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -74,7 +74,7 @@ pub async fn user_referral_link_get(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_used_referral_stats(
|
pub async fn user_used_referral_stats(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Query(_params): Query<HashMap<String, String>>,
|
Query(_params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -132,7 +132,7 @@ pub async fn user_used_referral_stats(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_shared_referral_stats(
|
pub async fn user_shared_referral_stats(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Query(_params): Query<HashMap<String, String>>,
|
Query(_params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
|
@ -5,9 +5,10 @@ use crate::globals::{global_db_conn, global_db_replica_conn};
|
|||||||
use crate::secrets::RpcSecretKey;
|
use crate::secrets::RpcSecretKey;
|
||||||
use axum::headers::{Header, Origin, Referer, UserAgent};
|
use axum::headers::{Header, Origin, Referer, UserAgent};
|
||||||
use axum::{
|
use axum::{
|
||||||
|
extract::State,
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension, Json, TypedHeader,
|
Json, TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use entities;
|
use entities;
|
||||||
@ -27,7 +28,7 @@ use std::sync::Arc;
|
|||||||
/// `GET /user/keys` -- Use a bearer token to get the user's api keys and their settings.
|
/// `GET /user/keys` -- Use a bearer token to get the user's api keys and their settings.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn rpc_keys_get(
|
pub async fn rpc_keys_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
let user = app.bearer_is_authorized(bearer).await?;
|
let user = app.bearer_is_authorized(bearer).await?;
|
||||||
@ -123,7 +124,7 @@ pub async fn rpc_keys_get(
|
|||||||
/// `DELETE /user/keys` -- Use a bearer token to delete an existing key.
|
/// `DELETE /user/keys` -- Use a bearer token to delete an existing key.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn rpc_keys_delete(
|
pub async fn rpc_keys_delete(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
let _user = app.bearer_is_authorized(bearer).await?;
|
let _user = app.bearer_is_authorized(bearer).await?;
|
||||||
@ -153,7 +154,7 @@ pub struct UserKeyManagement {
|
|||||||
/// `POST /user/keys` or `PUT /user/keys` -- Use a bearer token to create or update an existing key.
|
/// `POST /user/keys` or `PUT /user/keys` -- Use a bearer token to create or update an existing key.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn rpc_keys_management(
|
pub async fn rpc_keys_management(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Json(payload): Json<UserKeyManagement>,
|
Json(payload): Json<UserKeyManagement>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
|
@ -8,10 +8,10 @@ use crate::http_params::{
|
|||||||
use crate::stats::influxdb_queries::query_user_influx_stats;
|
use crate::stats::influxdb_queries::query_user_influx_stats;
|
||||||
use crate::stats::StatType;
|
use crate::stats::StatType;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::Query,
|
extract::{Query, State},
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension, Json, TypedHeader,
|
Json, TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use entities;
|
use entities;
|
||||||
@ -28,7 +28,7 @@ use tracing::info;
|
|||||||
/// `GET /user/revert_logs` -- Use a bearer token to get the user's revert logs.
|
/// `GET /user/revert_logs` -- Use a bearer token to get the user's revert logs.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_revert_logs_get(
|
pub async fn user_revert_logs_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Query(params): Query<HashMap<String, String>>,
|
Query(params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -125,7 +125,7 @@ pub async fn user_revert_logs_get(
|
|||||||
/// `GET /user/stats/aggregate` -- Public endpoint for aggregate stats such as bandwidth used and methods requested.
|
/// `GET /user/stats/aggregate` -- Public endpoint for aggregate stats such as bandwidth used and methods requested.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_influx_stats_aggregated_get(
|
pub async fn user_influx_stats_aggregated_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
||||||
Query(params): Query<HashMap<String, String>>,
|
Query(params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -137,7 +137,7 @@ pub async fn user_influx_stats_aggregated_get(
|
|||||||
/// `GET /user/stats/accounting` -- Use a bearer token to get the user's revert logs.
|
/// `GET /user/stats/accounting` -- Use a bearer token to get the user's revert logs.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_mysql_stats_get(
|
pub async fn user_mysql_stats_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
let user = app.bearer_is_authorized(bearer).await?;
|
let user = app.bearer_is_authorized(bearer).await?;
|
||||||
@ -171,7 +171,7 @@ pub async fn user_mysql_stats_get(
|
|||||||
/// TODO: this will change as we add better support for secondary users.
|
/// TODO: this will change as we add better support for secondary users.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn user_influx_stats_detailed_get(
|
pub async fn user_influx_stats_detailed_get(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
bearer: Option<TypedHeader<Authorization<Bearer>>>,
|
||||||
Query(params): Query<HashMap<String, String>>,
|
Query(params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
|
@ -5,10 +5,10 @@ use crate::globals::{global_db_conn, global_db_replica_conn};
|
|||||||
use crate::secrets::RpcSecretKey;
|
use crate::secrets::RpcSecretKey;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::Query,
|
extract::{Query, State},
|
||||||
headers::{authorization::Bearer, Authorization},
|
headers::{authorization::Bearer, Authorization},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Extension, Json, TypedHeader,
|
Json, TypedHeader,
|
||||||
};
|
};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use entities::sea_orm_active_enums::Role;
|
use entities::sea_orm_active_enums::Role;
|
||||||
@ -29,7 +29,7 @@ use tracing::trace;
|
|||||||
use ulid::{self, Ulid};
|
use ulid::{self, Ulid};
|
||||||
|
|
||||||
pub async fn get_keys_as_subuser(
|
pub async fn get_keys_as_subuser(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Query(_params): Query<HashMap<String, String>>,
|
Query(_params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -94,7 +94,7 @@ pub async fn get_keys_as_subuser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_subusers(
|
pub async fn get_subusers(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Query(mut params): Query<HashMap<String, String>>,
|
Query(mut params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
@ -166,7 +166,7 @@ pub async fn get_subusers(
|
|||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn modify_subuser(
|
pub async fn modify_subuser(
|
||||||
Extension(app): Extension<Arc<App>>,
|
State(app): State<Arc<App>>,
|
||||||
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
TypedHeader(Authorization(bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
Query(mut params): Query<HashMap<String, String>>,
|
Query(mut params): Query<HashMap<String, String>>,
|
||||||
) -> Web3ProxyResponse {
|
) -> Web3ProxyResponse {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
use axum::extract::State;
|
||||||
use axum::headers::HeaderName;
|
use axum::headers::HeaderName;
|
||||||
use axum::http::HeaderValue;
|
use axum::http::HeaderValue;
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
use axum::{routing::get, Extension, Router};
|
use axum::{routing::get, Router};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -17,9 +18,7 @@ pub async fn serve(
|
|||||||
mut shutdown_receiver: broadcast::Receiver<()>,
|
mut shutdown_receiver: broadcast::Receiver<()>,
|
||||||
) -> Web3ProxyResult<()> {
|
) -> Web3ProxyResult<()> {
|
||||||
// routes should be ordered most to least common
|
// routes should be ordered most to least common
|
||||||
let router = Router::new()
|
let router = Router::new().route("/", get(root)).with_state(app.clone());
|
||||||
.route("/", get(root))
|
|
||||||
.layer(Extension(app.clone()));
|
|
||||||
|
|
||||||
// note: the port here might be 0
|
// note: the port here might be 0
|
||||||
let port = app.prometheus_port.load(Ordering::SeqCst);
|
let port = app.prometheus_port.load(Ordering::SeqCst);
|
||||||
@ -44,7 +43,7 @@ pub async fn serve(
|
|||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn root(Extension(app): Extension<Arc<App>>) -> Response {
|
async fn root(State(app): State<Arc<App>>) -> Response {
|
||||||
let serialized = app.prometheus_metrics().await;
|
let serialized = app.prometheus_metrics().await;
|
||||||
|
|
||||||
let mut r = serialized.into_response();
|
let mut r = serialized.into_response();
|
||||||
|
Loading…
Reference in New Issue
Block a user