1
1
use crate :: config:: Config ;
2
- use crate :: node:: ordinals:: inscription_id:: InscriptionId ;
3
- use chainhook_event_observer:: bitcoincore_rpc:: bitcoin:: BlockHash ;
4
2
use chainhook_event_observer:: bitcoincore_rpc:: jsonrpc;
5
3
use chainhook_event_observer:: chainhooks:: bitcoin:: {
6
4
handle_bitcoin_hook_action, BitcoinChainhookOccurrence , BitcoinTriggerChainhook ,
7
5
} ;
8
6
use chainhook_event_observer:: chainhooks:: types:: {
9
- BitcoinPredicateType , ChainhookConfig , OrdinalOperations , Protocols ,
7
+ BitcoinPredicateType , ChainhookConfig , ChainhookFullSpecification , OrdinalOperations , Protocols ,
10
8
} ;
11
- use chainhook_event_observer:: indexer:: ordinals:: indexing:: entry:: Entry ;
12
- use chainhook_event_observer:: indexer:: ordinals:: indexing:: {
13
- HEIGHT_TO_BLOCK_HASH , INSCRIPTION_NUMBER_TO_INSCRIPTION_ID ,
14
- } ;
15
- use chainhook_event_observer:: indexer:: ordinals:: { self , initialize_ordinal_index} ;
9
+ use chainhook_event_observer:: indexer:: ordinals:: { self , ord:: initialize_ordinal_index} ;
16
10
use chainhook_event_observer:: indexer:: { self , BitcoinChainContext } ;
17
11
use chainhook_event_observer:: observer:: {
18
- start_event_observer, EventObserverConfig , ObserverEvent ,
12
+ start_event_observer, ApiKey , EventObserverConfig , ObserverEvent ,
19
13
} ;
20
- use chainhook_event_observer:: redb:: ReadableTable ;
21
14
use chainhook_event_observer:: utils:: { file_append, send_request, Context } ;
22
15
use chainhook_event_observer:: {
23
16
chainhooks:: stacks:: {
@@ -71,7 +64,7 @@ impl Node {
71
64
for key in chainhooks_to_load. iter ( ) {
72
65
let chainhook = match redis_con. hget :: < _ , _ , String > ( key, "specification" ) {
73
66
Ok ( spec) => {
74
- ChainhookSpecification :: deserialize_specification ( & spec, key) . unwrap ( )
67
+ ChainhookFullSpecification :: deserialize_specification ( & spec, key) . unwrap ( )
75
68
// todo
76
69
}
77
70
Err ( e) => {
@@ -84,8 +77,30 @@ impl Node {
84
77
continue ;
85
78
}
86
79
} ;
87
- // TODO
88
- // chainhook_config.register_hook(chainhook);
80
+
81
+ match chainhook_config. register_hook (
82
+ (
83
+ & self . config . network . bitcoin_network ,
84
+ & self . config . network . stacks_network ,
85
+ ) ,
86
+ chainhook,
87
+ & ApiKey ( None ) ,
88
+ ) {
89
+ Ok ( spec) => {
90
+ info ! (
91
+ self . ctx. expect_logger( ) ,
92
+ "Predicate {} retrieved from storage and loaded" ,
93
+ spec. uuid( ) ,
94
+ ) ;
95
+ }
96
+ Err ( e) => {
97
+ error ! (
98
+ self . ctx. expect_logger( ) ,
99
+ "Failed loading predicate from storage: {}" ,
100
+ e. to_string( )
101
+ ) ;
102
+ }
103
+ }
89
104
}
90
105
}
91
106
@@ -128,7 +143,6 @@ impl Node {
128
143
panic ! ( )
129
144
}
130
145
} ;
131
- let mut bitcoin_context = BitcoinChainContext :: new ( Some ( ordinal_index) ) ;
132
146
133
147
let context_cloned = self . ctx . clone ( ) ;
134
148
let _ = std:: thread:: spawn ( move || {
@@ -311,50 +325,51 @@ impl Node {
311
325
}
312
326
ChainhookSpecification :: Bitcoin ( predicate_spec) => {
313
327
let mut inscriptions_hints = BTreeMap :: new ( ) ;
314
- let mut use_hinting = false ;
328
+ let use_hinting = false ;
315
329
if let BitcoinPredicateType :: Protocol ( Protocols :: Ordinal (
316
330
OrdinalOperations :: InscriptionRevealed ,
317
331
) ) = & predicate_spec. predicate
318
332
{
319
- if let Some ( ref ordinal_index) = bitcoin_context. ordinal_index {
320
- for ( inscription_number, inscription_id) in ordinal_index
321
- . database
322
- . begin_read ( )
323
- . unwrap ( )
324
- . open_table ( INSCRIPTION_NUMBER_TO_INSCRIPTION_ID )
325
- . unwrap ( )
326
- . iter ( )
327
- . unwrap ( )
328
- {
329
- let inscription =
330
- InscriptionId :: load ( * inscription_id. value ( ) ) ;
331
- println ! (
332
- "{} -> {}" ,
333
- inscription_number. value( ) ,
334
- inscription
335
- ) ;
336
-
337
- let entry = ordinal_index
338
- . get_inscription_entry ( inscription)
339
- . unwrap ( )
340
- . unwrap ( ) ;
341
- println ! ( "{:?}" , entry) ;
342
-
343
- let blockhash = ordinal_index
344
- . database
345
- . begin_read ( )
346
- . unwrap ( )
347
- . open_table ( HEIGHT_TO_BLOCK_HASH )
348
- . unwrap ( )
349
- . get ( & entry. height )
350
- . unwrap ( )
351
- . map ( |k| BlockHash :: load ( * k. value ( ) ) )
352
- . unwrap ( ) ;
353
-
354
- inscriptions_hints. insert ( entry. height , blockhash) ;
355
- use_hinting = true ;
356
- }
357
- }
333
+ inscriptions_hints. insert ( 1 , 1 ) ;
334
+ // if let Some(ref ordinal_index) = bitcoin_context.ordinal_index {
335
+ // for (inscription_number, inscription_id) in ordinal_index
336
+ // .database
337
+ // .begin_read()
338
+ // .unwrap()
339
+ // .open_table(INSCRIPTION_NUMBER_TO_INSCRIPTION_ID)
340
+ // .unwrap()
341
+ // .iter()
342
+ // .unwrap()
343
+ // {
344
+ // let inscription =
345
+ // InscriptionId::load(*inscription_id.value());
346
+ // println!(
347
+ // "{} -> {}",
348
+ // inscription_number.value(),
349
+ // inscription
350
+ // );
351
+
352
+ // let entry = ordinal_index
353
+ // .get_inscription_entry(inscription)
354
+ // .unwrap()
355
+ // .unwrap();
356
+ // println!("{:?}", entry);
357
+
358
+ // let blockhash = ordinal_index
359
+ // .database
360
+ // .begin_read()
361
+ // .unwrap()
362
+ // .open_table(HEIGHT_TO_BLOCK_HASH)
363
+ // .unwrap()
364
+ // .get(&entry.height)
365
+ // .unwrap()
366
+ // .map(|k| BlockHash::load(*k.value()))
367
+ // .unwrap();
368
+
369
+ // inscriptions_hints.insert(entry.height, blockhash);
370
+ // use_hinting = true;
371
+ // }
372
+ // }
358
373
}
359
374
360
375
let start_block = match predicate_spec. start_block {
@@ -469,7 +484,6 @@ impl Node {
469
484
let block = indexer:: bitcoin:: standardize_bitcoin_block (
470
485
& self . config . network ,
471
486
raw_block,
472
- & mut bitcoin_context,
473
487
& self . ctx ,
474
488
) ?;
475
489
0 commit comments