-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from anoma/tiago/index-tx-blocks
implement block index builder
- Loading branch information
Showing
20 changed files
with
568 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "block-index" | ||
description = "Namada masp indexer block index builder." | ||
resolver = "2" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
readme.workspace = true | ||
version.workspace = true | ||
|
||
[[bin]] | ||
name = "block-index-builder" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
bincode.workspace = true | ||
clap-verbosity-flag.workspace = true | ||
clap.workspace = true | ||
deadpool-diesel.workspace = true | ||
diesel.workspace = true | ||
diesel_migrations.workspace = true | ||
orm.workspace = true | ||
shared.workspace = true | ||
tokio.workspace = true | ||
tracing-appender.workspace = true | ||
tracing-subscriber.workspace = true | ||
tracing.workspace = true | ||
xorf.workspace = true | ||
|
||
[build-dependencies] | ||
vergen = { version = "8.0.0", features = ["build", "git", "gitcl"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use std::error::Error; | ||
|
||
use vergen::EmitBuilder; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
EmitBuilder::builder().all_git().emit()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::env; | ||
|
||
use anyhow::Context; | ||
use deadpool_diesel::postgres::{Object, Pool as DbPool}; | ||
|
||
#[derive(Clone)] | ||
pub struct AppState { | ||
db: DbPool, | ||
} | ||
|
||
impl AppState { | ||
pub fn new(db_url: String) -> anyhow::Result<Self> { | ||
let max_pool_size = env::var("DATABASE_POOL_SIZE") | ||
.unwrap_or_else(|_| 8.to_string()) | ||
.parse::<usize>() | ||
.unwrap_or(8_usize); | ||
let pool_manager = deadpool_diesel::Manager::from_config( | ||
db_url, | ||
deadpool_diesel::Runtime::Tokio1, | ||
deadpool_diesel::ManagerConfig { | ||
recycling_method: deadpool_diesel::RecyclingMethod::Verified, | ||
}, | ||
); | ||
let pool = DbPool::builder(pool_manager) | ||
.max_size(max_pool_size) | ||
.build() | ||
.context("Failed to build Postgres db pool")?; | ||
|
||
Ok(Self { db: pool }) | ||
} | ||
|
||
pub async fn get_db_connection(&self) -> anyhow::Result<Object> { | ||
self.db | ||
.get() | ||
.await | ||
.context("Failed to get db connection handle from deadpool") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::num::NonZeroU64; | ||
|
||
use clap_verbosity_flag::{InfoLevel, LevelFilter, Verbosity}; | ||
use tracing::Level; | ||
use tracing_appender::non_blocking::NonBlocking; | ||
use tracing_subscriber::FmtSubscriber; | ||
|
||
#[derive(clap::Parser)] | ||
pub struct AppConfig { | ||
/// Link to the Postgres database | ||
#[clap(long, env)] | ||
pub database_url: String, | ||
|
||
/// How often (in seconds) a new block index is built | ||
#[clap(long, env)] | ||
pub interval: Option<NonZeroU64>, | ||
|
||
#[command(flatten)] | ||
pub verbosity: Verbosity<InfoLevel>, | ||
} | ||
|
||
pub fn install_tracing_subscriber( | ||
verbosity: Verbosity<InfoLevel>, | ||
non_blocking_logger: NonBlocking, | ||
) { | ||
let log_level = match verbosity.log_level_filter() { | ||
LevelFilter::Off => None, | ||
LevelFilter::Error => Some(Level::ERROR), | ||
LevelFilter::Warn => Some(Level::WARN), | ||
LevelFilter::Info => Some(Level::INFO), | ||
LevelFilter::Debug => Some(Level::DEBUG), | ||
LevelFilter::Trace => Some(Level::TRACE), | ||
}; | ||
if let Some(log_level) = log_level { | ||
let subscriber = FmtSubscriber::builder() | ||
.with_max_level(log_level) | ||
.with_writer(non_blocking_logger) | ||
.finish(); | ||
tracing::subscriber::set_global_default(subscriber).unwrap(); | ||
} | ||
} |
Oops, something went wrong.