@@ -20,7 +20,10 @@ use crate::{
20
20
utils:: Context ,
21
21
} ;
22
22
23
- use super :: { ord:: height:: Height , update_hord_db_and_augment_bitcoin_block} ;
23
+ use super :: {
24
+ ord:: { height:: Height , sat:: Sat } ,
25
+ update_hord_db_and_augment_bitcoin_block,
26
+ } ;
24
27
25
28
fn get_default_hord_db_file_path ( base_dir : & PathBuf ) -> PathBuf {
26
29
let mut destination_path = base_dir. clone ( ) ;
@@ -350,30 +353,50 @@ pub fn find_inscription_with_ordinal_number(
350
353
return None ;
351
354
}
352
355
353
- pub fn find_all_inscriptions ( hord_db_conn : & Connection ) -> BTreeMap < u64 , Vec < ( String , u64 , u64 ) > > {
356
+ pub fn find_all_inscriptions (
357
+ hord_db_conn : & Connection ,
358
+ ) -> BTreeMap < u64 , Vec < ( TransactionIdentifier , TraversalResult ) > > {
354
359
let args: & [ & dyn ToSql ] = & [ ] ;
355
360
let mut stmt = hord_db_conn
356
- . prepare ( "SELECT inscription_id, inscription_number, ordinal_number, block_height FROM inscriptions ORDER BY inscription_number ASC" )
361
+ . prepare ( "SELECT inscription_number, ordinal_number, block_height, inscription_id FROM inscriptions ORDER BY inscription_number ASC" )
357
362
. unwrap ( ) ;
358
- let mut results: BTreeMap < u64 , Vec < ( String , u64 , u64 ) > > = BTreeMap :: new ( ) ;
363
+ let mut results: BTreeMap < u64 , Vec < ( TransactionIdentifier , TraversalResult ) > > = BTreeMap :: new ( ) ;
359
364
let mut rows = stmt. query ( args) . unwrap ( ) ;
360
365
while let Ok ( Some ( row) ) = rows. next ( ) {
361
- let inscription_id: String = row. get ( 0 ) . unwrap ( ) ;
362
- let inscription_number: u64 = row. get ( 1 ) . unwrap ( ) ;
363
- let ordinal_number: u64 = row. get ( 2 ) . unwrap ( ) ;
364
- let block_height: u64 = row. get ( 3 ) . unwrap ( ) ;
366
+ let inscription_number: u64 = row. get ( 0 ) . unwrap ( ) ;
367
+ let ordinal_number: u64 = row. get ( 1 ) . unwrap ( ) ;
368
+ let block_height: u64 = row. get ( 2 ) . unwrap ( ) ;
369
+ let transaction_id = {
370
+ let inscription_id: String = row. get ( 3 ) . unwrap ( ) ;
371
+ TransactionIdentifier {
372
+ hash : format ! ( "0x{}" , & inscription_id[ 0 ..inscription_id. len( ) - 2 ] ) ,
373
+ }
374
+ } ;
375
+ let traversal = TraversalResult {
376
+ inscription_number,
377
+ ordinal_number,
378
+ transfers : 0 ,
379
+ } ;
365
380
results
366
381
. entry ( block_height)
367
- . and_modify ( |v| v. push ( ( inscription_id . clone ( ) , inscription_number , ordinal_number ) ) )
368
- . or_insert ( vec ! [ ( inscription_id , inscription_number , ordinal_number ) ] ) ;
382
+ . and_modify ( |v| v. push ( ( transaction_id . clone ( ) , traversal . clone ( ) ) ) )
383
+ . or_insert ( vec ! [ ( transaction_id , traversal ) ] ) ;
369
384
}
370
385
return results;
371
386
}
372
387
388
+ #[ derive( Clone , Debug ) ]
389
+ pub struct WatchedSatpoint {
390
+ pub inscription_id : String ,
391
+ pub inscription_number : u64 ,
392
+ pub ordinal_number : u64 ,
393
+ pub offset : u64 ,
394
+ }
395
+
373
396
pub fn find_inscriptions_at_wached_outpoint (
374
397
outpoint : & str ,
375
398
hord_db_conn : & Connection ,
376
- ) -> Vec < ( String , u64 , u64 , u64 ) > {
399
+ ) -> Vec < WatchedSatpoint > {
377
400
let args: & [ & dyn ToSql ] = & [ & outpoint. to_sql ( ) . unwrap ( ) ] ;
378
401
let mut stmt = hord_db_conn
379
402
. prepare ( "SELECT inscription_id, inscription_number, ordinal_number, offset FROM inscriptions WHERE outpoint_to_watch = ? ORDER BY offset ASC" )
@@ -385,7 +408,12 @@ pub fn find_inscriptions_at_wached_outpoint(
385
408
let inscription_number: u64 = row. get ( 1 ) . unwrap ( ) ;
386
409
let ordinal_number: u64 = row. get ( 2 ) . unwrap ( ) ;
387
410
let offset: u64 = row. get ( 3 ) . unwrap ( ) ;
388
- results. push ( ( inscription_id, inscription_number, ordinal_number, offset) ) ;
411
+ results. push ( WatchedSatpoint {
412
+ inscription_id,
413
+ inscription_number,
414
+ ordinal_number,
415
+ offset,
416
+ } ) ;
389
417
}
390
418
return results;
391
419
}
@@ -456,88 +484,6 @@ pub fn remove_entry_from_inscriptions(
456
484
}
457
485
}
458
486
459
- // pub async fn update_hord_db(
460
- // bitcoin_config: &BitcoinConfig,
461
- // hord_db_path: &PathBuf,
462
- // start_block: u64,
463
- // end_block: u64,
464
- // _ctx: &Context,
465
- // network_thread: usize,
466
- // ) -> Result<(), String> {
467
- // let (block_tx, block_rx) = channel::<BitcoinBlockFullBreakdown>();
468
- // let first_inscription_block_height = 767430;
469
- // let ctx = _ctx.clone();
470
- // let network = bitcoin_config.network.clone();
471
- // let hord_db_path = hord_db_path.clone();
472
- // let handle = hiro_system_kit::thread_named("Inscriptions indexing")
473
- // .spawn(move || {
474
- // let mut cursor = first_inscription_block_height;
475
- // let mut inbox = HashMap::new();
476
-
477
- // while let Ok(raw_block) = block_rx.recv() {
478
- // // Early return, only considering blocks after 1st inscription
479
- // if raw_block.height < first_inscription_block_height {
480
- // continue;
481
- // }
482
- // let block_height = raw_block.height;
483
- // inbox.insert(raw_block.height, raw_block);
484
-
485
- // // In the context of ordinals, we're constrained to process blocks sequentially
486
- // // Blocks are processed by a threadpool and could be coming out of order.
487
- // // Inbox block for later if the current block is not the one we should be
488
- // // processing.
489
- // if block_height != cursor {
490
- // continue;
491
- // }
492
-
493
- // // Is the action of processing a block allows us
494
- // // to process more blocks present in the inbox?
495
- // while let Some(next_block) = inbox.remove(&cursor) {
496
- // let mut new_block = match standardize_bitcoin_block(next_block, &network, &ctx)
497
- // {
498
- // Ok(block) => block,
499
- // Err(e) => {
500
- // ctx.try_log(|logger| {
501
- // slog::error!(logger, "Unable to standardize bitcoin block: {e}",)
502
- // });
503
- // return;
504
- // }
505
- // };
506
-
507
- // if let Err(e) = update_hord_db_and_augment_bitcoin_block(
508
- // &mut new_block,
509
- // &hord_db_path,
510
- // &ctx,
511
- // ) {
512
- // ctx.try_log(|logger| {
513
- // slog::error!(
514
- // logger,
515
- // "Unable to augment bitcoin block with hord_db: {e}",
516
- // )
517
- // });
518
- // return;
519
- // }
520
- // cursor += 1;
521
- // }
522
- // }
523
- // })
524
- // .expect("unable to detach thread");
525
-
526
- // fetch_and_cache_blocks_in_hord_db(
527
- // bitcoin_config,
528
- // hord_db_conn,
529
- // start_block,
530
- // end_block,
531
- // &_ctx,
532
- // network_thread,
533
- // )
534
- // .await?;
535
-
536
- // let _ = handle.join();
537
-
538
- // Ok(())
539
- // }
540
-
541
487
pub fn delete_data_in_hord_db (
542
488
start_block : u64 ,
543
489
end_block : u64 ,
@@ -698,17 +644,30 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
698
644
Ok ( ( ) )
699
645
}
700
646
647
+ #[ derive( Clone ) ]
701
648
pub struct TraversalResult {
702
- pub ordinal_block_number : u64 ,
703
- pub ordinal_offset : u64 ,
649
+ pub inscription_number : u64 ,
704
650
pub ordinal_number : u64 ,
705
651
pub transfers : u32 ,
706
652
}
707
653
654
+ impl TraversalResult {
655
+ pub fn get_ordinal_coinbase_height ( & self ) -> u64 {
656
+ let sat = Sat ( self . ordinal_number ) ;
657
+ sat. height ( ) . n ( )
658
+ }
659
+
660
+ pub fn get_ordinal_coinbase_offset ( & self ) -> u64 {
661
+ let sat = Sat ( self . ordinal_number ) ;
662
+ self . ordinal_number - sat. height ( ) . starting_sat ( ) . n ( )
663
+ }
664
+ }
665
+
708
666
pub fn retrieve_satoshi_point_using_local_storage (
709
667
hord_db_conn : & Connection ,
710
668
block_identifier : & BlockIdentifier ,
711
669
transaction_identifier : & TransactionIdentifier ,
670
+ inscription_number : u64 ,
712
671
ctx : & Context ,
713
672
) -> Result < TraversalResult , String > {
714
673
ctx. try_log ( |logger| {
@@ -851,8 +810,7 @@ pub fn retrieve_satoshi_point_using_local_storage(
851
810
let ordinal_number = height. starting_sat ( ) . 0 + ordinal_offset;
852
811
853
812
Ok ( TraversalResult {
854
- ordinal_block_number : ordinal_block_number. into ( ) ,
855
- ordinal_offset,
813
+ inscription_number,
856
814
ordinal_number,
857
815
transfers : hops,
858
816
} )
0 commit comments