Skip to content

Commit 9b45f90

Browse files
author
Ludo Galabru
committed
feat: attempt to support cursed inscriptions
1 parent 96825c3 commit 9b45f90

File tree

4 files changed

+194
-127
lines changed

4 files changed

+194
-127
lines changed

components/chainhook-event-observer/src/hord/db/mod.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ pub fn find_latest_inscription_number_at_block_height(
362362
block_height: &u64,
363363
inscriptions_db_conn: &Connection,
364364
_ctx: &Context,
365-
) -> Result<Option<u64>, String> {
365+
) -> Result<Option<i64>, String> {
366366
let args: &[&dyn ToSql] = &[&block_height.to_sql().unwrap()];
367367
let mut stmt = inscriptions_db_conn
368368
.prepare(
@@ -373,25 +373,28 @@ pub fn find_latest_inscription_number_at_block_height(
373373
.query(args)
374374
.map_err(|e| format!("unable to query inscriptions: {}", e.to_string()))?;
375375
while let Ok(Some(row)) = rows.next() {
376-
let inscription_number: u64 = row.get(0).unwrap();
376+
let inscription_number: i64 = row.get(0).unwrap();
377377
return Ok(Some(inscription_number));
378378
}
379379
Ok(None)
380380
}
381381

382-
pub fn find_latest_inscription_number(
382+
pub fn find_latest_cursed_inscription_number_at_block_height(
383+
block_height: &u64,
383384
inscriptions_db_conn: &Connection,
384385
_ctx: &Context,
385-
) -> Result<Option<u64>, String> {
386-
let args: &[&dyn ToSql] = &[];
386+
) -> Result<Option<i64>, String> {
387+
let args: &[&dyn ToSql] = &[&block_height.to_sql().unwrap()];
387388
let mut stmt = inscriptions_db_conn
388389
.prepare(
389-
"SELECT inscription_number FROM inscriptions ORDER BY inscription_number DESC LIMIT 1",
390+
"SELECT inscription_number FROM inscriptions WHERE block_height < ? ORDER BY inscription_number ASC LIMIT 1",
390391
)
391-
.unwrap();
392-
let mut rows = stmt.query(args).unwrap();
392+
.map_err(|e| format!("unable to query inscriptions: {}", e.to_string()))?;
393+
let mut rows = stmt
394+
.query(args)
395+
.map_err(|e| format!("unable to query inscriptions: {}", e.to_string()))?;
393396
while let Ok(Some(row)) = rows.next() {
394-
let inscription_number: u64 = row.get(0).unwrap();
397+
let inscription_number: i64 = row.get(0).unwrap();
395398
return Ok(Some(inscription_number));
396399
}
397400
Ok(None)
@@ -428,7 +431,7 @@ pub fn find_inscription_with_id(
428431
while let Ok(Some(row)) = rows.next() {
429432
let inscription_block_hash: String = row.get(2).unwrap();
430433
if block_hash.eq(&inscription_block_hash) {
431-
let inscription_number: u64 = row.get(0).unwrap();
434+
let inscription_number: i64 = row.get(0).unwrap();
432435
let ordinal_number: u64 = row.get(1).unwrap();
433436
let traversal = TraversalResult {
434437
inscription_number,
@@ -451,7 +454,7 @@ pub fn find_all_inscriptions(
451454
let mut results: BTreeMap<u64, Vec<(TransactionIdentifier, TraversalResult)>> = BTreeMap::new();
452455
let mut rows = stmt.query(args).unwrap();
453456
while let Ok(Some(row)) = rows.next() {
454-
let inscription_number: u64 = row.get(0).unwrap();
457+
let inscription_number: i64 = row.get(0).unwrap();
455458
let ordinal_number: u64 = row.get(1).unwrap();
456459
let block_height: u64 = row.get(2).unwrap();
457460
let transaction_id = {
@@ -476,7 +479,7 @@ pub fn find_all_inscriptions(
476479
#[derive(Clone, Debug)]
477480
pub struct WatchedSatpoint {
478481
pub inscription_id: String,
479-
pub inscription_number: u64,
482+
pub inscription_number: i64,
480483
pub ordinal_number: u64,
481484
pub offset: u64,
482485
}
@@ -503,7 +506,7 @@ pub fn find_watched_satpoint_for_inscription(
503506
.map_err(|e| format!("unable to query inscriptions table: {}", e.to_string()))?;
504507
while let Ok(Some(row)) = rows.next() {
505508
let inscription_id: String = row.get(0).unwrap();
506-
let inscription_number: u64 = row.get(1).unwrap();
509+
let inscription_number: i64 = row.get(1).unwrap();
507510
let ordinal_number: u64 = row.get(2).unwrap();
508511
let offset: u64 = row.get(3).unwrap();
509512
let block_height: u64 = row.get(4).unwrap();
@@ -537,7 +540,7 @@ pub fn find_inscriptions_at_wached_outpoint(
537540
.map_err(|e| format!("unable to query inscriptions table: {}", e.to_string()))?;
538541
while let Ok(Some(row)) = rows.next() {
539542
let inscription_id: String = row.get(0).unwrap();
540-
let inscription_number: u64 = row.get(1).unwrap();
543+
let inscription_number: i64 = row.get(1).unwrap();
541544
let ordinal_number: u64 = row.get(2).unwrap();
542545
let offset: u64 = row.get(3).unwrap();
543546
results.push(WatchedSatpoint {
@@ -813,7 +816,7 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
813816

814817
#[derive(Clone, Debug)]
815818
pub struct TraversalResult {
816-
pub inscription_number: u64,
819+
pub inscription_number: i64,
817820
pub ordinal_number: u64,
818821
pub transfers: u32,
819822
}
@@ -834,7 +837,7 @@ pub fn retrieve_satoshi_point_using_lazy_storage(
834837
blocks_db: &DB,
835838
block_identifier: &BlockIdentifier,
836839
transaction_identifier: &TransactionIdentifier,
837-
inscription_number: u64,
840+
inscription_number: i64,
838841
traversals_cache: Arc<
839842
DashMap<(u32, [u8; 8]), LazyBlockTransaction, BuildHasherDefault<FxHasher>>,
840843
>,

0 commit comments

Comments
 (0)