remove unnecessary enum and try_into
This commit is contained in:
parent
bda666eb6c
commit
94bc6fef8c
@ -15,7 +15,7 @@ pub async fn public_proxy_web3_rpc(
|
|||||||
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
||||||
ClientIp(ip): ClientIp,
|
ClientIp(ip): ClientIp,
|
||||||
) -> FrontendResult {
|
) -> FrontendResult {
|
||||||
let _ip: IpAddr = rate_limit_by_ip(&app, ip).await?.try_into()?;
|
let _ip: IpAddr = rate_limit_by_ip(&app, ip).await?;
|
||||||
|
|
||||||
let protocol = Protocol::HTTP;
|
let protocol = Protocol::HTTP;
|
||||||
let user_id = 0;
|
let user_id = 0;
|
||||||
@ -67,7 +67,7 @@ pub async fn user_proxy_web3_rpc(
|
|||||||
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
Extension(app): Extension<Arc<Web3ProxyApp>>,
|
||||||
Path(user_key): Path<Uuid>,
|
Path(user_key): Path<Uuid>,
|
||||||
) -> FrontendResult {
|
) -> FrontendResult {
|
||||||
let user_id: u64 = rate_limit_by_user_key(&app, user_key).await?.try_into()?;
|
let user_id: u64 = rate_limit_by_user_key(&app, user_key).await?;
|
||||||
|
|
||||||
let protocol = Protocol::HTTP;
|
let protocol = Protocol::HTTP;
|
||||||
|
|
||||||
|
@ -52,11 +52,14 @@ impl TryFrom<RequestFrom> for u64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn rate_limit_by_ip(app: &Web3ProxyApp, ip: IpAddr) -> RateLimitFrontendResult {
|
pub async fn rate_limit_by_ip(
|
||||||
|
app: &Web3ProxyApp,
|
||||||
|
ip: IpAddr,
|
||||||
|
) -> Result<IpAddr, FrontendErrorResponse> {
|
||||||
let rate_limit_result = app.rate_limit_by_ip(ip).await?;
|
let rate_limit_result = app.rate_limit_by_ip(ip).await?;
|
||||||
|
|
||||||
match rate_limit_result {
|
match rate_limit_result {
|
||||||
RateLimitResult::AllowedIp(x) => Ok(x.into()),
|
RateLimitResult::AllowedIp(x) => Ok(x),
|
||||||
RateLimitResult::AllowedUser(_) => panic!("only ips or errors are expected here"),
|
RateLimitResult::AllowedUser(_) => panic!("only ips or errors are expected here"),
|
||||||
rate_limit_result => {
|
rate_limit_result => {
|
||||||
let _: RequestFrom = rate_limit_result.try_into()?;
|
let _: RequestFrom = rate_limit_result.try_into()?;
|
||||||
@ -70,12 +73,12 @@ pub async fn rate_limit_by_user_key(
|
|||||||
app: &Web3ProxyApp,
|
app: &Web3ProxyApp,
|
||||||
// TODO: change this to a Ulid
|
// TODO: change this to a Ulid
|
||||||
user_key: Uuid,
|
user_key: Uuid,
|
||||||
) -> RateLimitFrontendResult {
|
) -> Result<u64, FrontendErrorResponse> {
|
||||||
let rate_limit_result = app.rate_limit_by_key(user_key).await?;
|
let rate_limit_result = app.rate_limit_by_key(user_key).await?;
|
||||||
|
|
||||||
match rate_limit_result {
|
match rate_limit_result {
|
||||||
RateLimitResult::AllowedIp(_) => panic!("only user keys or errors are expected here"),
|
RateLimitResult::AllowedIp(_) => panic!("only user keys or errors are expected here"),
|
||||||
RateLimitResult::AllowedUser(x) => Ok(x.into()),
|
RateLimitResult::AllowedUser(x) => Ok(x),
|
||||||
rate_limit_result => {
|
rate_limit_result => {
|
||||||
let _: RequestFrom = rate_limit_result.try_into()?;
|
let _: RequestFrom = rate_limit_result.try_into()?;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ pub async fn get_login(
|
|||||||
// TODO: allow ENS names here?
|
// TODO: allow ENS names here?
|
||||||
Path(mut params): Path<HashMap<String, String>>,
|
Path(mut params): Path<HashMap<String, String>>,
|
||||||
) -> FrontendResult {
|
) -> FrontendResult {
|
||||||
let _ip: IpAddr = rate_limit_by_ip(&app, ip).await?.try_into()?;
|
let _ip: IpAddr = rate_limit_by_ip(&app, ip).await?;
|
||||||
|
|
||||||
// at first i thought about checking that user_address is in our db
|
// at first i thought about checking that user_address is in our db
|
||||||
// but theres no need to separate the registration and login flows
|
// but theres no need to separate the registration and login flows
|
||||||
@ -134,7 +134,7 @@ pub async fn post_login(
|
|||||||
Json(payload): Json<PostLogin>,
|
Json(payload): Json<PostLogin>,
|
||||||
Query(query): Query<PostLoginQuery>,
|
Query(query): Query<PostLoginQuery>,
|
||||||
) -> FrontendResult {
|
) -> FrontendResult {
|
||||||
let _ip: IpAddr = rate_limit_by_ip(&app, ip).await?.try_into()?;
|
let _ip: IpAddr = rate_limit_by_ip(&app, ip).await?;
|
||||||
|
|
||||||
let mut new_user = true; // TODO: check the database
|
let mut new_user = true; // TODO: check the database
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ pub async fn public_websocket_handler(
|
|||||||
ClientIp(ip): ClientIp,
|
ClientIp(ip): ClientIp,
|
||||||
ws_upgrade: Option<WebSocketUpgrade>,
|
ws_upgrade: Option<WebSocketUpgrade>,
|
||||||
) -> FrontendResult {
|
) -> FrontendResult {
|
||||||
let _ip: IpAddr = rate_limit_by_ip(&app, ip).await?.try_into()?;
|
let _ip: IpAddr = rate_limit_by_ip(&app, ip).await?;
|
||||||
|
|
||||||
let user_id = 0;
|
let user_id = 0;
|
||||||
let protocol = Protocol::Websocket;
|
let protocol = Protocol::Websocket;
|
||||||
@ -57,7 +57,7 @@ pub async fn user_websocket_handler(
|
|||||||
Path(user_key): Path<Uuid>,
|
Path(user_key): Path<Uuid>,
|
||||||
ws_upgrade: Option<WebSocketUpgrade>,
|
ws_upgrade: Option<WebSocketUpgrade>,
|
||||||
) -> FrontendResult {
|
) -> FrontendResult {
|
||||||
let user_id: u64 = rate_limit_by_user_key(&app, user_key).await?.try_into()?;
|
let user_id: u64 = rate_limit_by_user_key(&app, user_key).await?;
|
||||||
|
|
||||||
let protocol = Protocol::Websocket;
|
let protocol = Protocol::Websocket;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user