diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 5d56faf9..00000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "nightly" diff --git a/server/src/config.rs b/server/src/config.rs index a0ad7323..0aec908c 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -1,17 +1,13 @@ -use axum::http::HeaderValue; -use axum::http::Method; +use crate::{ + database::{cache::CacheManager, DBConnectionManager}, + prelude::*, +}; +use axum::http::{HeaderValue, Method}; use clap::{Parser, ValueEnum}; -use std::collections::HashSet; -use std::fmt; -use std::sync::Arc; -use tower_http::cors::Any; -use tower_http::cors::CorsLayer; +use std::{collections::HashSet, fmt, sync::Arc}; +use tower_http::cors::{Any, CorsLayer}; use tracing_subscriber::EnvFilter; -use crate::database::cache::CacheManager; -use crate::database::DBConnectionManager; -use crate::prelude::*; - #[derive(Clone)] pub(crate) struct Context { pub(crate) cache: Arc, diff --git a/server/src/database/archive.rs b/server/src/database/archive.rs index cd1fba7c..9af67665 100644 --- a/server/src/database/archive.rs +++ b/server/src/database/archive.rs @@ -1,10 +1,14 @@ +use crate::{ + database::DBConnectionManager, + models::vote::{ChainStatusType, MinaBlockStatus}, + prelude::*, +}; use anyhow::Context; -use diesel::sql_types::{BigInt, Text}; -use diesel::{sql_query, QueryableByName, RunQueryDsl}; - -use crate::database::DBConnectionManager; -use crate::models::vote::{ChainStatusType, MinaBlockStatus}; -use crate::prelude::*; +use diesel::{ + sql_query, + sql_types::{BigInt, Text}, + QueryableByName, RunQueryDsl, +}; #[derive(QueryableByName)] pub(crate) struct FetchChainTipResult { diff --git a/server/src/database/cache.rs b/server/src/database/cache.rs index 3f59bfe7..31313ee4 100644 --- a/server/src/database/cache.rs +++ b/server/src/database/cache.rs @@ -1,10 +1,10 @@ +use crate::models::{ + ledger::LedgerAccount, + vote::{MinaVote, MinaVoteWithWeight}, +}; use moka::future::Cache as MokaCache; use std::sync::Arc; -use crate::models::ledger::LedgerAccount; -use crate::models::vote::MinaVote; -use crate::models::vote::MinaVoteWithWeight; - type ArcVotes = Arc>; type ArcVotesWeighted = Arc>; type ArcLedger = Arc>; diff --git a/server/src/database/mod.rs b/server/src/database/mod.rs index 965f1347..b1d60a8e 100644 --- a/server/src/database/mod.rs +++ b/server/src/database/mod.rs @@ -1,12 +1,12 @@ -use diesel::prelude::*; -use diesel::r2d2::ConnectionManager; -use diesel::r2d2::Pool; - -use crate::config::Config; - pub(crate) mod archive; pub(crate) mod cache; +use crate::config::Config; +use diesel::{ + prelude::*, + r2d2::{ConnectionManager, Pool}, +}; + pub(crate) type PgConnectionPool = Pool>; pub(crate) struct DBConnectionManager { diff --git a/server/src/main.rs b/server/src/main.rs index 8c4325d4..df912b7a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,17 +1,3 @@ -use axum::Extension; -use clap::Parser; -use std::net::SocketAddr; -use std::sync::Arc; -use tokio::signal; -use tower::ServiceBuilder; -use tower_http::trace::TraceLayer; - -use crate::config::Config; -use crate::config::Context; -use crate::database::{cache::CacheManager, DBConnectionManager}; -use crate::prelude::*; -use crate::routes::Build; - mod config; mod database; mod error; @@ -20,6 +6,19 @@ mod prelude; mod routes; mod schema; +use crate::{ + config::{Config, Context}, + database::{cache::CacheManager, DBConnectionManager}, + prelude::*, + routes::Build, +}; +use axum::Extension; +use clap::Parser; +use std::{net::SocketAddr, sync::Arc}; +use tokio::signal; +use tower::ServiceBuilder; +use tower_http::trace::TraceLayer; + extern crate tracing; pub(crate) const MINA_GOVERNANCE_SERVER: &str = "mina_governance_server"; diff --git a/server/src/models/ledger.rs b/server/src/models/ledger.rs index 459047ec..a3e608f9 100644 --- a/server/src/models/ledger.rs +++ b/server/src/models/ledger.rs @@ -1,15 +1,12 @@ -use std::collections::HashMap; -use std::io::Read; -use std::path::Path; - +use crate::{ + config::NetworkConfig, + models::{diesel::ProposalVersion, vote::MinaVote}, + prelude::*, +}; use anyhow::anyhow; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; - -use crate::config::NetworkConfig; -use crate::models::diesel::ProposalVersion; -use crate::models::vote::MinaVote; -use crate::prelude::*; +use std::{collections::HashMap, io::Read, path::Path}; const LEDGER_BALANCE_SCALE: u32 = 9; diff --git a/server/src/models/vote.rs b/server/src/models/vote.rs index 14ddb444..cffb338a 100644 --- a/server/src/models/vote.rs +++ b/server/src/models/vote.rs @@ -1,3 +1,8 @@ +use crate::{ + database::archive::FetchTransactionResult, + models::{diesel::MinaProposal, ledger::Ledger}, + prelude::*, +}; use anyhow::Context; use diesel::SqlType; use diesel_derive_enum::DbEnum; @@ -5,11 +10,6 @@ use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use std::collections::{hash_map::Entry, HashMap}; -use crate::database::archive::FetchTransactionResult; -use crate::models::diesel::MinaProposal; -use crate::models::ledger::Ledger; -use crate::prelude::*; - #[derive(SqlType)] #[diesel(postgres_type(name = "chain_status_type"))] pub(crate) struct ChainStatusType; @@ -106,7 +106,7 @@ impl MinaVote { .into_vec() .with_context(|| f!("failed to decode memo {} - bs58", &self.memo))?; - let value = &decoded[3..decoded[2] as usize + 3]; + let value = &decoded[3 .. decoded[2] as usize + 3]; Ok(String::from_utf8(value.to_vec()).with_context(|| f!("failed to decode memo {} - from_utf8", &self.memo))?) } diff --git a/server/src/routes/info.rs b/server/src/routes/info.rs index 2e8e9ae7..16df43a7 100644 --- a/server/src/routes/info.rs +++ b/server/src/routes/info.rs @@ -1,10 +1,10 @@ +use crate::{ + database::archive::{fetch_chain_tip, fetch_latest_slot}, + prelude::*, +}; use axum::{http::StatusCode, response::IntoResponse, routing::get, Extension, Json, Router}; use serde::{Deserialize, Serialize}; -use crate::database::archive::fetch_chain_tip; -use crate::database::archive::fetch_latest_slot; -use crate::prelude::*; - pub(crate) fn router() -> Router { Router::new().route("/api/info", get(get_core_api_info)) } diff --git a/server/src/routes/mod.rs b/server/src/routes/mod.rs index 4096da8d..eb97ec3d 100644 --- a/server/src/routes/mod.rs +++ b/server/src/routes/mod.rs @@ -1,8 +1,8 @@ -use axum::Router; - mod info; mod proposal; +use axum::Router; + pub(crate) trait Build { fn build() -> Router; } diff --git a/server/src/routes/proposal.rs b/server/src/routes/proposal.rs index 7f782b62..5bc524b5 100644 --- a/server/src/routes/proposal.rs +++ b/server/src/routes/proposal.rs @@ -1,22 +1,19 @@ +use crate::{ + database::archive::{fetch_chain_tip, fetch_transactions}, + models::{ + diesel::MinaProposal, + ledger::Ledger, + vote::{MinaVote, MinaVoteWithWeight}, + }, + prelude::*, +}; use anyhow::Context; -use axum::extract::Path; -use axum::http::StatusCode; -use axum::response::IntoResponse; -use axum::routing::get; -use axum::{Extension, Json, Router}; +use axum::{extract::Path, http::StatusCode, response::IntoResponse, routing::get, Extension, Json, Router}; use diesel::prelude::*; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use std::sync::Arc; -use crate::database::archive::fetch_chain_tip; -use crate::database::archive::fetch_transactions; -use crate::models::diesel::MinaProposal; -use crate::models::ledger::Ledger; -use crate::models::vote::MinaVote; -use crate::models::vote::MinaVoteWithWeight; -use crate::prelude::*; - pub(crate) fn router() -> Router { Router::new() .route("/api/proposals", get(get_mina_proposals))