@@ -19,7 +19,10 @@ use std::hash::BuildHasherDefault;
19
19
20
20
use crate :: {
21
21
core:: {
22
- meta_protocols:: brc20:: { cache:: Brc20MemoryCache , db:: open_readwrite_brc20_db_conn} ,
22
+ meta_protocols:: brc20:: {
23
+ cache:: { brc20_new_cache, Brc20MemoryCache } ,
24
+ db:: brc20_new_rw_db_conn,
25
+ } ,
23
26
pipeline:: processors:: block_archiving:: store_compacted_blocks,
24
27
protocol:: {
25
28
inscription_parsing:: {
@@ -79,6 +82,9 @@ pub fn start_inscription_indexing_processor(
79
82
open_readonly_ordhook_db_conn ( & config. expected_cache_path ( ) , & ctx) . unwrap ( ) ;
80
83
let mut sequence_cursor = SequenceCursor :: new ( & inscriptions_db_conn) ;
81
84
85
+ let mut brc20_cache = brc20_new_cache ( & config) ;
86
+ let mut brc20_db_conn_rw = brc20_new_rw_db_conn ( & config, & ctx) ;
87
+
82
88
loop {
83
89
let ( compacted_blocks, mut blocks) = match commands_rx. try_recv ( ) {
84
90
Ok ( PostProcessorCommand :: ProcessBlocks ( compacted_blocks, blocks) ) => {
@@ -133,6 +139,8 @@ pub fn start_inscription_indexing_processor(
133
139
& mut sequence_cursor,
134
140
& cache_l2,
135
141
& mut inscriptions_db_conn_rw,
142
+ & mut brc20_cache,
143
+ & mut brc20_db_conn_rw,
136
144
& ordhook_config,
137
145
& post_processor,
138
146
& ctx,
@@ -169,26 +177,18 @@ pub fn process_blocks(
169
177
sequence_cursor : & mut SequenceCursor ,
170
178
cache_l2 : & Arc < DashMap < ( u32 , [ u8 ; 8 ] ) , TransactionBytesCursor , BuildHasherDefault < FxHasher > > > ,
171
179
inscriptions_db_conn_rw : & mut Connection ,
180
+ brc20_cache : & mut Option < Brc20MemoryCache > ,
181
+ brc20_db_conn_rw : & mut Option < Connection > ,
172
182
ordhook_config : & OrdhookConfig ,
173
183
post_processor : & Option < Sender < BitcoinBlockData > > ,
174
184
ctx : & Context ,
175
185
) -> Vec < BitcoinBlockData > {
176
186
let mut cache_l1 = BTreeMap :: new ( ) ;
177
-
178
187
let mut updated_blocks = vec ! [ ] ;
179
188
180
- let mut brc20_db_conn_rw = match open_readwrite_brc20_db_conn ( & ordhook_config. db_path , & ctx) {
181
- Ok ( dbs) => dbs,
182
- Err ( e) => {
183
- panic ! ( "Unable to open readwrite connection: {e}" ) ;
184
- }
185
- } ;
186
- let mut brc20_cache = Brc20MemoryCache :: new ( ordhook_config. resources . brc20_lru_cache_size ) ;
187
-
188
189
for _cursor in 0 ..next_blocks. len ( ) {
189
- let inscriptions_db_tx: rusqlite:: Transaction < ' _ > =
190
- inscriptions_db_conn_rw. transaction ( ) . unwrap ( ) ;
191
- let brc20_db_tx = brc20_db_conn_rw. transaction ( ) . unwrap ( ) ;
190
+ let inscriptions_db_tx = inscriptions_db_conn_rw. transaction ( ) . unwrap ( ) ;
191
+ let brc20_db_tx = brc20_db_conn_rw. as_mut ( ) . map ( |c| c. transaction ( ) . unwrap ( ) ) ;
192
192
193
193
let mut block = next_blocks. remove ( 0 ) ;
194
194
@@ -214,8 +214,8 @@ pub fn process_blocks(
214
214
& mut cache_l1,
215
215
cache_l2,
216
216
& inscriptions_db_tx,
217
- Some ( & brc20_db_tx) ,
218
- & mut brc20_cache,
217
+ brc20_db_tx. as_ref ( ) ,
218
+ brc20_cache. as_mut ( ) ,
219
219
ordhook_config,
220
220
ctx,
221
221
) ;
@@ -242,21 +242,20 @@ pub fn process_blocks(
242
242
block. block_identifier. index,
243
243
) ;
244
244
let _ = inscriptions_db_tx. rollback ( ) ;
245
- let _ = brc20_db_tx. rollback ( ) ;
245
+ let _ = brc20_db_tx. map ( |t| t . rollback ( ) ) ;
246
246
} else {
247
247
match inscriptions_db_tx. commit ( ) {
248
- Ok ( _) => match brc20_db_tx. commit ( ) {
249
- Ok ( _) => { }
250
- Err ( _) => {
251
- // delete_data_in_ordhook_db(
252
- // block.block_identifier.index,
253
- // block.block_identifier.index,
254
- // ordhook_config,
255
- // ctx,
256
- // );
257
- todo ! ( )
248
+ Ok ( _) => {
249
+ if let Some ( brc20_db_tx) = brc20_db_tx {
250
+ match brc20_db_tx. commit ( ) {
251
+ Ok ( _) => { }
252
+ Err ( _) => {
253
+ // TODO: Synchronize rollbacks and commits between BRC-20 and inscription DBs.
254
+ todo ! ( )
255
+ }
256
+ }
258
257
}
259
- } ,
258
+ }
260
259
Err ( e) => {
261
260
try_error ! (
262
261
ctx,
@@ -284,7 +283,7 @@ pub fn process_block(
284
283
cache_l2 : & Arc < DashMap < ( u32 , [ u8 ; 8 ] ) , TransactionBytesCursor , BuildHasherDefault < FxHasher > > > ,
285
284
inscriptions_db_tx : & Transaction ,
286
285
brc20_db_tx : Option < & Transaction > ,
287
- brc20_cache : & mut Brc20MemoryCache ,
286
+ brc20_cache : Option < & mut Brc20MemoryCache > ,
288
287
ordhook_config : & OrdhookConfig ,
289
288
ctx : & Context ,
290
289
) -> Result < ( ) , String > {
@@ -322,14 +321,15 @@ pub fn process_block(
322
321
// Handle transfers
323
322
let _ = augment_block_with_ordinals_transfer_data ( block, inscriptions_db_tx, true , & inner_ctx) ;
324
323
325
- if let Some ( brc20_db_tx) = brc20_db_tx {
326
- write_brc20_block_operations (
324
+ match ( brc20_db_tx, brc20_cache ) {
325
+ ( Some ( brc20_db_tx ) , Some ( brc20_cache ) ) => write_brc20_block_operations (
327
326
block,
328
327
& mut brc20_operation_map,
329
328
brc20_cache,
330
- & brc20_db_tx,
329
+ brc20_db_tx,
331
330
& ctx,
332
- ) ;
331
+ ) ,
332
+ _ => { }
333
333
}
334
334
335
335
Ok ( ( ) )
0 commit comments