Skip to content

Commit 6c7eaa3

Browse files
author
Ludo Galabru
committed
feat: ability to resume
1 parent 20d9df6 commit 6c7eaa3

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

components/hord-cli/src/db/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,22 @@ pub fn find_latest_inscription_transfer_data(
528528
Ok(None)
529529
}
530530

531+
pub fn find_latest_transfers_block_height(
532+
inscriptions_db_conn: &Connection,
533+
_ctx: &Context,
534+
) -> Option<u64> {
535+
let args: &[&dyn ToSql] = &[];
536+
let mut stmt = inscriptions_db_conn
537+
.prepare("SELECT block_height FROM locations ORDER BY block_height DESC LIMIT 1")
538+
.unwrap();
539+
let mut rows = stmt.query(args).unwrap();
540+
while let Ok(Some(row)) = rows.next() {
541+
let block_height: u64 = row.get(0).unwrap();
542+
return Some(block_height)
543+
}
544+
None
545+
}
546+
531547
#[derive(Debug, Clone)]
532548
pub struct TransferData {
533549
pub inscription_offset_intra_output: u64,

components/hord-cli/src/service/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::core::{
1212
};
1313
use crate::db::{
1414
find_latest_inscription_block_height, initialize_hord_db, insert_entry_in_blocks,
15-
open_readonly_hord_db_conn, open_readwrite_hord_dbs, InscriptionHeigthHint, LazyBlock,
15+
open_readonly_hord_db_conn, open_readwrite_hord_dbs, InscriptionHeigthHint, LazyBlock, find_latest_transfers_block_height,
1616
};
1717
use crate::scan::bitcoin::process_block_with_predicates;
1818
use crate::service::http_api::{load_predicates_from_redis, start_predicate_api_server};
@@ -59,7 +59,6 @@ impl Service {
5959
// std::thread::sleep(std::time::Duration::from_secs(1200));
6060

6161
let _ = initialize_hord_db(&self.config.expected_cache_path(), &self.ctx);
62-
6362
// Force rebuild
6463
// {
6564
// let blocks_db = open_readwrite_hord_db_conn_rocks_db(
@@ -107,16 +106,17 @@ impl Service {
107106
})
108107
.expect("unable to spawn thread");
109108

110-
let tip = {
109+
110+
let (cursor, tip) = {
111111
let inscriptions_db_conn =
112112
open_readonly_hord_db_conn(&self.config.expected_cache_path(), &self.ctx)?;
113+
let cursor = find_latest_transfers_block_height(&inscriptions_db_conn, &self.ctx).unwrap_or(1);
113114
match find_latest_inscription_block_height(&inscriptions_db_conn, &self.ctx)? {
114-
Some(height) => height,
115+
Some(height) => (cursor, height),
115116
None => panic!(),
116117
}
117118
};
118-
119-
self.replay_transfers(775808, tip, Some(tx_replayer.clone()))
119+
self.replay_transfers(cursor, tip, Some(tx_replayer.clone()))
120120
.await?;
121121
self.update_state(Some(tx_replayer.clone())).await?;
122122

0 commit comments

Comments
 (0)