global: utxos part 2

This commit is contained in:
nym21
2025-05-17 19:51:52 +02:00
parent 7b38355cd4
commit c8a25934a6
15 changed files with 435 additions and 60 deletions

View File

@@ -3,7 +3,7 @@
#![doc = include_str!("../examples/main.rs")]
#![doc = "```"]
use std::{collections::BTreeMap, fs, path::Path};
use std::{collections::BTreeMap, fs, path::Path, thread::sleep, time::Duration};
use brk_core::{Cents, Close, Date, Dollars, Height, High, Low, OHLCCents, Open, Timestamp};
use color_eyre::eyre::Error;
@@ -50,6 +50,16 @@ impl Fetcher {
height: Height,
timestamp: Timestamp,
previous_timestamp: Option<Timestamp>,
) -> color_eyre::Result<OHLCCents> {
self.get_height_(height, timestamp, previous_timestamp, 0)
}
fn get_height_(
&mut self,
height: Height,
timestamp: Timestamp,
previous_timestamp: Option<Timestamp>,
tries: usize,
) -> color_eyre::Result<OHLCCents> {
let timestamp = timestamp.floor_seconds();
@@ -69,6 +79,14 @@ impl Fetcher {
.unwrap_or_else(|e| {
eprintln!("{e}");
self.kibo.get_from_height(height).unwrap_or_else(|e| {
sleep(Duration::from_secs(30));
if tries < 8 * 60 * 2 {
return self
.get_height_(height, timestamp, previous_timestamp, tries + 1)
.unwrap();
}
let date = Date::from(timestamp);
eprintln!("{e}");
panic!(