workspace: reorg

This commit is contained in:
nym21
2025-01-28 17:45:36 +01:00
parent f7f3e3cc03
commit 8c610f8a83
66 changed files with 268 additions and 389 deletions

36
computer/src/lib.rs Normal file
View File

@@ -0,0 +1,36 @@
use std::path::Path;
use bindex::Indexer;
use biter::rpc;
use exit::Exit;
mod structs;
use structs::*;
pub struct Bomputer;
impl Bomputer {
pub fn compute() {}
}
pub fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
let data_dir = Path::new("../../bitcoin");
let rpc = rpc::Client::new(
"http://localhost:8332",
rpc::Auth::CookieFile(Path::new(data_dir).join(".cookie")),
)?;
let exit = Exit::new();
let i = std::time::Instant::now();
let mut indexer = Indexer::import(Path::new("indexes"))?;
indexer.index(data_dir, rpc, &exit)?;
dbg!(i.elapsed());
Ok(())
}

13
computer/src/main.rs Normal file
View File

@@ -0,0 +1,13 @@
use structs::Date;
mod structs;
pub fn main() -> color_eyre::Result<()> {
let date1 = Date::from(jiff::civil::Date::constant(2009, 1, 9));
let date2 = Date::from(jiff::civil::Date::constant(2009, 1, 31));
let date3 = Date::from(jiff::civil::Date::constant(2019, 1, 9));
dbg!(usize::try_from(date1))?;
dbg!(usize::try_from(date2))?;
dbg!(usize::try_from(date3))?;
Ok(())
}

View File

@@ -0,0 +1,41 @@
use bindex::Timestamp;
use color_eyre::eyre::eyre;
use derive_deref::Deref;
use jiff::{civil::Date as _Date, tz::TimeZone};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Deref)]
pub struct Date(_Date);
impl Date {
const INDEX_ZERO: Self = Self(_Date::constant(2009, 1, 3));
const INDEX_ONE: Self = Self(_Date::constant(2009, 1, 9));
}
impl From<_Date> for Date {
fn from(value: _Date) -> Self {
Self(value)
}
}
impl From<&Timestamp> for Date {
fn from(value: &Timestamp) -> Self {
Self(_Date::from(value.to_zoned(TimeZone::UTC)))
}
}
impl TryFrom<Date> for usize {
type Error = color_eyre::Report;
fn try_from(value: Date) -> Result<Self, Self::Error> {
if value < Date::INDEX_ZERO {
Err(eyre!("Date is too early"))
} else if value == Date::INDEX_ZERO {
Ok(0)
} else if value < Date::INDEX_ONE {
Err(eyre!("Date is between first and second"))
} else if value == Date::INDEX_ONE {
Ok(1)
} else {
Ok(Date::INDEX_ONE.until(*value)?.get_days() as usize + 1)
}
}
}

View File

@@ -0,0 +1,4 @@
use derive_deref::Deref;
#[derive(Debug, Deref, Clone, Copy)]
pub struct Feerate(f32);

View File

@@ -0,0 +1,5 @@
mod date;
mod feerate;
pub use date::*;
pub use feerate::*;