Skip to content

Commit

Permalink
Apply Crate Import Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Sep 12, 2024
1 parent d0bc3ef commit ff17398
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 77 deletions.
2 changes: 0 additions & 2 deletions rust-toolchain.toml

This file was deleted.

18 changes: 7 additions & 11 deletions server/src/config.rs
Original file line number Diff line number Diff line change
@@ -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<CacheManager>,
Expand Down
16 changes: 10 additions & 6 deletions server/src/database/archive.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions server/src/database/cache.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<MinaVote>>;
type ArcVotesWeighted = Arc<Vec<MinaVoteWithWeight>>;
type ArcLedger = Arc<Vec<LedgerAccount>>;
Expand Down
12 changes: 6 additions & 6 deletions server/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -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<ConnectionManager<PgConnection>>;

pub(crate) struct DBConnectionManager {
Expand Down
27 changes: 13 additions & 14 deletions server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down
15 changes: 6 additions & 9 deletions server/src/models/ledger.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
12 changes: 6 additions & 6 deletions server/src/models/vote.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::{
database::archive::FetchTransactionResult,
models::{diesel::MinaProposal, ledger::Ledger},
prelude::*,
};
use anyhow::Context;
use diesel::SqlType;
use diesel_derive_enum::DbEnum;
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;
Expand Down Expand Up @@ -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))?)
}
Expand Down
8 changes: 4 additions & 4 deletions server/src/routes/info.rs
Original file line number Diff line number Diff line change
@@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use axum::Router;

mod info;
mod proposal;

use axum::Router;

pub(crate) trait Build {
fn build() -> Router;
}
Expand Down
23 changes: 10 additions & 13 deletions server/src/routes/proposal.rs
Original file line number Diff line number Diff line change
@@ -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))
Expand Down

0 comments on commit ff17398

Please sign in to comment.