global: small fixes

This commit is contained in:
nym21
2024-12-17 10:39:28 +01:00
parent e0a378cb81
commit 8fabbde13b
23 changed files with 179 additions and 170 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ use super::{
AnyDateMap, AnyHeightMap, AnyMap, Date, DateMap, Height, HeightMap, MapKind, MapPath, MapValue,
};
#[derive(Allocative)]
#[derive(Allocative, Debug)]
pub struct BiMap<Value>
where
Value: MapValue,
+32 -29
View File
@@ -1,5 +1,6 @@
use std::{
fs::{self},
mem,
path::{Path, PathBuf},
};
@@ -46,28 +47,30 @@ pub struct Config {
#[arg(long, value_name = "SECONDS")]
delay: Option<u64>,
// Maximum ram you want the program to use in GB, default: 50% of total, not saved
// #[arg(long, value_name = "GB")]
// pub max_ram: Option<f64>,
/// Enable or disable the parser, default: true, not saved
#[arg(long, value_name = "BOOL")]
parser: Option<bool>,
/// Disable the parser, not saved
#[serde(default)]
#[arg(long, default_value_t = false)]
no_parser: bool,
/// Enable or disable the server, default: true, not saved
#[arg(long, value_name = "BOOL")]
server: Option<bool>,
/// Disable the server, not saved
#[serde(default)]
#[arg(long, default_value_t = false)]
no_server: bool,
/// Start a dry run, default: true, not saved
#[arg(long, value_name = "BOOL")]
dry_run: Option<bool>,
/// Run without saving, not saved
#[serde(default)]
#[arg(long, default_value_t = false)]
dry_run: bool,
/// Record ram usage, default: false, not saved
#[arg(long, value_name = "BOOL")]
record_ram_usage: Option<bool>,
/// Record ram usage, not saved
#[serde(default)]
#[arg(long, default_value_t = false)]
record_ram_usage: bool,
/// Recompute all computed datasets, default: false, not saved
#[arg(long, value_name = "BOOL")]
recompute_computed: Option<bool>,
/// Recompute all computed datasets, not saved
#[serde(default)]
#[arg(long, default_value_t = false)]
recompute_computed: bool,
}
impl Config {
@@ -125,11 +128,11 @@ impl Config {
config.write(&path)?;
config.parser = config_args.parser.take();
config.server = config_args.server.take();
config.dry_run = config_args.dry_run.take();
config.record_ram_usage = config_args.record_ram_usage.take();
config.recompute_computed = config_args.recompute_computed.take();
config.no_parser = mem::take(&mut config_args.no_parser);
config.no_server = mem::take(&mut config_args.no_server);
config.dry_run = mem::take(&mut config_args.dry_run);
config.record_ram_usage = mem::take(&mut config_args.record_ram_usage);
config.recompute_computed = mem::take(&mut config_args.recompute_computed);
info!("Configuration {{");
info!(" bitcoindir: {:?}", config.bitcoindir);
@@ -233,22 +236,22 @@ impl Config {
}
pub fn dry_run(&self) -> bool {
self.dry_run.is_some_and(|b| b)
self.dry_run
}
pub fn record_ram_usage(&self) -> bool {
self.record_ram_usage.is_some_and(|b| b)
self.record_ram_usage
}
pub fn recompute_computed(&self) -> bool {
self.recompute_computed.is_some_and(|b| b)
self.recompute_computed
}
pub fn path_bitcoindir(&self) -> PathBuf {
Self::fix_user_path(self.bitcoindir.as_ref().unwrap().as_ref())
}
fn path_kibodir(&self) -> PathBuf {
pub fn path_kibodir(&self) -> PathBuf {
Self::fix_user_path(self.kibodir.as_ref().unwrap().as_ref())
}
@@ -311,10 +314,10 @@ impl Config {
}
pub fn parser(&self) -> bool {
self.parser.is_none_or(|b| b)
!self.no_parser
}
pub fn server(&self) -> bool {
self.server.is_none_or(|b| b)
!self.no_server
}
}
+2 -2
View File
@@ -74,8 +74,8 @@ impl Date {
self.month() == 1
}
pub fn is_june(&self) -> bool {
self.month() == 6
pub fn is_july(&self) -> bool {
self.month() == 7
}
pub fn is_first_of_month(&self) -> bool {
+15
View File
@@ -0,0 +1,15 @@
use std::time::Instant;
use color_eyre::owo_colors::OwoColorize;
pub trait DisplayInstant {
fn display(&self) -> String;
}
impl DisplayInstant for Instant {
fn display(&self) -> String {
format!("{:.2}s", self.elapsed().as_secs_f32())
.bright_black()
.to_string()
}
}
+4
View File
@@ -24,12 +24,14 @@ mod generic_map;
mod height;
mod height_map;
mod height_map_chunk_id;
mod instant;
mod liquidity;
mod map_path;
mod map_value;
mod ohlc;
mod partial_txout_data;
mod price;
mod rpc;
mod sent_data;
mod serialized_btreemap;
mod serialized_vec;
@@ -63,12 +65,14 @@ pub use generic_map::*;
pub use height::*;
pub use height_map::*;
pub use height_map_chunk_id::*;
pub use instant::*;
pub use liquidity::*;
pub use map_path::*;
pub use map_value::*;
pub use ohlc::*;
pub use partial_txout_data::*;
pub use price::*;
pub use rpc::*;
pub use sent_data::*;
pub use serialized_btreemap::*;
pub use serialized_vec::*;
+17
View File
@@ -0,0 +1,17 @@
use biter::bitcoincore_rpc::Client;
use crate::structs::Config;
impl From<&Config> for Client {
fn from(config: &Config) -> Self {
Client::new(
&format!(
"http://{}:{}",
config.rpcconnect().unwrap_or(&"localhost".to_owned()),
config.rpcport().unwrap_or(8332)
),
config.to_rpc_auth().unwrap(),
)
.unwrap()
}
}