cargo clippy lints

This commit is contained in:
Bryan Stitt 2023-06-07 10:55:07 -07:00
parent f6b2b0deab
commit fb97ef5180
5 changed files with 21 additions and 28 deletions

@ -32,9 +32,9 @@ use hashbrown::HashMap;
use http::StatusCode;
use log::{info, trace};
use serde_json::json;
use std::str::from_utf8_mut;
use std::sync::atomic::AtomicU64;
use std::sync::Arc;
use std::{str::from_utf8_mut, sync::atomic::AtomicUsize};
use tokio::sync::{broadcast, OwnedSemaphorePermit, RwLock};
/// How to select backend servers for a request

@ -1,7 +1,6 @@
//! Handle registration, logins, and managing account data.
use crate::app::Web3ProxyApp;
use crate::errors::Web3ProxyResponse;
use crate::frontend::users::referral;
use crate::referral_code::ReferralCode;
use anyhow::Context;
use axum::{
@ -21,7 +20,6 @@ use migration::sea_orm::ActiveModelTrait;
use migration::sea_orm::ColumnTrait;
use migration::sea_orm::EntityTrait;
use migration::sea_orm::QueryFilter;
use num_traits::one;
use serde::Serialize;
use serde_json::json;
use std::sync::Arc;
@ -102,7 +100,7 @@ pub async fn user_used_referral_stats(
credits_applied_for_referrer: Decimal,
referral_start_date: DateTime,
used_referral_code: String,
};
}
let mut out: Vec<Info> = Vec::new();
for x in referrals.into_iter() {
@ -153,7 +151,7 @@ pub async fn user_shared_referral_stats(
.await?;
// Return early if the user does not have any referred entities
if referrals.len() == 0 {
if referrals.is_empty() {
let response_json = json!({
"referrals": [],
"used_referral_code": None::<()>,
@ -171,7 +169,7 @@ pub async fn user_shared_referral_stats(
credits_applied_for_referrer: Decimal,
referral_start_date: DateTime,
referred_address: Address,
};
}
let mut out: Vec<Info> = Vec::new();
let mut used_referral_code = "".to_owned(); // This is only for safety purposes, because of the condition above we always know that there is at least one record

@ -60,7 +60,7 @@ pub async fn user_revert_logs_get(
struct OutTuple {
id: u64,
role: Role,
};
}
// Also add rpc keys for which this user has access
let shared_rpc_keys = secondary_user::Entity::find()

@ -11,12 +11,11 @@ use axum::{
};
use axum_macros::debug_handler;
use entities::sea_orm_active_enums::Role;
use entities::user::Relation::UserTier;
use entities::{balance, rpc_key, secondary_user, user, user_tier};
use entities::{balance, rpc_key, secondary_user, user};
use ethers::types::Address;
use hashbrown::HashMap;
use http::StatusCode;
use log::{debug, trace, warn};
use log::{trace, warn};
use migration::sea_orm;
use migration::sea_orm::prelude::Decimal;
use migration::sea_orm::ActiveModelTrait;

@ -1,40 +1,37 @@
//! Store "stats" in a database for billing and a different database for graphing
//! TODO: move some of these structs/functions into their own file?
mod stat_buffer;
pub mod db_queries;
pub mod influxdb_queries;
mod stat_buffer;
pub use stat_buffer::{SpawnedStatBuffer, StatBuffer};
use std::borrow::BorrowMut;
use std::cmp;
use self::stat_buffer::BufferedRpcQueryStats;
use crate::app::{RpcSecretKeyCache, UserBalanceCache};
use crate::errors::{Web3ProxyError, Web3ProxyResult};
use crate::frontend::authorization::{Authorization, RequestMetadata, RpcSecretKey};
use crate::frontend::authorization::{Authorization, RequestMetadata};
use crate::rpcs::one::Web3Rpc;
use anyhow::{anyhow, Context};
use axum::headers::Origin;
use chrono::{DateTime, Months, TimeZone, Utc};
use derive_more::From;
use entities::sea_orm_active_enums::TrackingLevel;
use entities::{balance, referee, referrer, rpc_accounting_v2, rpc_key, user};
use ethers::core::k256::elliptic_curve::bigint::NonZero;
use entities::{balance, referee, referrer, rpc_accounting_v2, rpc_key};
use influxdb2::models::DataPoint;
use log::{error, info, trace, warn};
use log::trace;
use migration::sea_orm::prelude::Decimal;
use migration::sea_orm::{
self, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter,
TransactionTrait,
self, ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter, TransactionTrait,
};
use migration::sea_orm::{DatabaseTransaction, QuerySelect};
use migration::{Expr, LockType, OnConflict, Order};
use num_traits::{clamp, clamp_min, ToPrimitive};
use migration::{Expr, LockType, OnConflict};
use num_traits::ToPrimitive;
use parking_lot::Mutex;
use std::num::NonZeroU64;
use std::sync::atomic::{self, Ordering};
use std::sync::Arc;
use tokio::sync::RwLock;
use self::stat_buffer::BufferedRpcQueryStats;
pub use stat_buffer::{SpawnedStatBuffer, StatBuffer};
#[derive(Debug, PartialEq, Eq)]
pub enum StatType {
@ -486,8 +483,7 @@ impl BufferedRpcQueryStats {
.to_owned(),
)
.exec(txn)
.await?
.last_insert_id;
.await?;
let user_balance = balance::ActiveModel {
id: sea_orm::NotSet,
@ -544,9 +540,9 @@ impl BufferedRpcQueryStats {
None => return Ok(()),
};
let mut latest_balance = sender_latest_balance.write().await;
let balance_before = (*latest_balance).clone();
let balance_before = *latest_balance;
// Now modify the balance
*latest_balance = *latest_balance + deltas.sender_available_balance_delta;
*latest_balance += deltas.sender_available_balance_delta;
if *latest_balance < Decimal::from(0) {
*latest_balance = Decimal::from(0);
}
@ -620,7 +616,7 @@ impl BufferedRpcQueryStats {
return Ok(());
}
let rpc_secret_key_id: &NonZeroU64 = match &key.rpc_secret_key_id {
Some(x) => x.into(),
Some(x) => x,
None => return Ok(()),
};