@@ -39,7 +39,11 @@ struct OrdinalsIndexer {
39
39
40
40
#[ allow( dead_code) ]
41
41
enum IndexerCommand {
42
- Start ,
42
+ StreamBlocks ,
43
+ SyncBlocks ,
44
+ DropBlocks ( Vec < u64 > ) ,
45
+ RewriteBlocks ( Vec < u64 > ) ,
46
+ ReplayBlocks ( Vec < u64 > ) ,
43
47
Stop ,
44
48
}
45
49
@@ -64,7 +68,7 @@ impl OrdinalsIndexer {
64
68
logger : Some ( logger) ,
65
69
tracer : false ,
66
70
} ;
67
-
71
+
68
72
// Initialize service
69
73
// {
70
74
// let _ = initialize_ordhook_db(&ordhook_config.expected_cache_path(), &ctx);
@@ -151,7 +155,7 @@ impl OrdinalsIndexer {
151
155
} ;
152
156
153
157
match cmd {
154
- IndexerCommand :: Start => {
158
+ IndexerCommand :: StreamBlocks => {
155
159
// We start the service as soon as the start() method is being called.
156
160
let future = service. catch_up_with_chain_tip ( false , & observer_config) ;
157
161
let _ = hiro_system_kit:: nestable_block_on ( future)
@@ -163,6 +167,18 @@ impl OrdinalsIndexer {
163
167
let _ = service. start_main_runloop ( & command_tx, event_rx, None ) ;
164
168
break ;
165
169
}
170
+ IndexerCommand :: ReplayBlocks ( blocks) => {
171
+ println ! ( "Will replay blocks {:?}" , blocks) ;
172
+ }
173
+ IndexerCommand :: DropBlocks ( blocks) => {
174
+ println ! ( "Will drop blocks {:?}" , blocks) ;
175
+ }
176
+ IndexerCommand :: RewriteBlocks ( blocks) => {
177
+ println ! ( "Will rewrite blocks {:?}" , blocks) ;
178
+ }
179
+ IndexerCommand :: SyncBlocks => {
180
+ println ! ( "Will sync blocks" ) ;
181
+ }
166
182
IndexerCommand :: Stop => {
167
183
break ;
168
184
}
@@ -177,8 +193,28 @@ impl OrdinalsIndexer {
177
193
}
178
194
}
179
195
180
- fn start ( & self ) -> Result < bool , String > {
181
- let _ = self . command_tx . send ( IndexerCommand :: Start ) ;
196
+ fn stream_blocks ( & self ) -> Result < bool , String > {
197
+ let _ = self . command_tx . send ( IndexerCommand :: StreamBlocks ) ;
198
+ Ok ( true )
199
+ }
200
+
201
+ fn replay_blocks ( & self , blocks : Vec < u64 > ) -> Result < bool , String > {
202
+ let _ = self . command_tx . send ( IndexerCommand :: ReplayBlocks ( blocks) ) ;
203
+ Ok ( true )
204
+ }
205
+
206
+ fn drop_blocks ( & self , blocks : Vec < u64 > ) -> Result < bool , String > {
207
+ let _ = self . command_tx . send ( IndexerCommand :: DropBlocks ( blocks) ) ;
208
+ Ok ( true )
209
+ }
210
+
211
+ fn rewrite_blocks ( & self , blocks : Vec < u64 > ) -> Result < bool , String > {
212
+ let _ = self . command_tx . send ( IndexerCommand :: RewriteBlocks ( blocks) ) ;
213
+ Ok ( true )
214
+ }
215
+
216
+ fn sync_blocks ( & self ) -> Result < bool , String > {
217
+ let _ = self . command_tx . send ( IndexerCommand :: SyncBlocks ) ;
182
218
Ok ( true )
183
219
}
184
220
@@ -249,10 +285,88 @@ impl OrdinalsIndexer {
249
285
Ok ( cx. boxed ( devnet) )
250
286
}
251
287
252
- fn js_start ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
288
+ fn js_stream_blocks ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
289
+ cx. this ( )
290
+ . downcast_or_throw :: < JsBox < OrdinalsIndexer > , _ > ( & mut cx) ?
291
+ . stream_blocks ( )
292
+ . or_else ( |err| cx. throw_error ( err. to_string ( ) ) ) ?;
293
+
294
+ Ok ( cx. undefined ( ) )
295
+ }
296
+
297
+ fn js_replay_blocks ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
298
+ let blocks = {
299
+ let seq = cx
300
+ . argument :: < JsArray > ( 0 ) ?
301
+ . root ( & mut cx)
302
+ . into_inner ( & mut cx)
303
+ . to_vec ( & mut cx) ?;
304
+ let mut blocks = vec ! [ ] ;
305
+ for item in seq. iter ( ) {
306
+ let block = item. downcast :: < JsNumber , _ > ( & mut cx) . unwrap ( ) ;
307
+ blocks. push ( block. value ( & mut cx) as u64 ) ;
308
+ }
309
+ blocks
310
+ } ;
311
+
312
+ cx. this ( )
313
+ . downcast_or_throw :: < JsBox < OrdinalsIndexer > , _ > ( & mut cx) ?
314
+ . replay_blocks ( blocks)
315
+ . or_else ( |err| cx. throw_error ( err. to_string ( ) ) ) ?;
316
+
317
+ Ok ( cx. undefined ( ) )
318
+ }
319
+
320
+ fn js_drop_blocks ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
321
+ let blocks = {
322
+ let seq = cx
323
+ . argument :: < JsArray > ( 0 ) ?
324
+ . root ( & mut cx)
325
+ . into_inner ( & mut cx)
326
+ . to_vec ( & mut cx) ?;
327
+ let mut blocks = vec ! [ ] ;
328
+ for item in seq. iter ( ) {
329
+ let block = item. downcast :: < JsNumber , _ > ( & mut cx) . unwrap ( ) ;
330
+ blocks. push ( block. value ( & mut cx) as u64 ) ;
331
+ }
332
+ blocks
333
+ } ;
334
+
335
+ cx. this ( )
336
+ . downcast_or_throw :: < JsBox < OrdinalsIndexer > , _ > ( & mut cx) ?
337
+ . drop_blocks ( blocks)
338
+ . or_else ( |err| cx. throw_error ( err. to_string ( ) ) ) ?;
339
+
340
+ Ok ( cx. undefined ( ) )
341
+ }
342
+
343
+ fn js_sync_blocks ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
344
+ cx. this ( )
345
+ . downcast_or_throw :: < JsBox < OrdinalsIndexer > , _ > ( & mut cx) ?
346
+ . sync_blocks ( )
347
+ . or_else ( |err| cx. throw_error ( err. to_string ( ) ) ) ?;
348
+
349
+ Ok ( cx. undefined ( ) )
350
+ }
351
+
352
+ fn js_rewrite_blocks ( mut cx : FunctionContext ) -> JsResult < JsUndefined > {
353
+ let blocks = {
354
+ let seq = cx
355
+ . argument :: < JsArray > ( 0 ) ?
356
+ . root ( & mut cx)
357
+ . into_inner ( & mut cx)
358
+ . to_vec ( & mut cx) ?;
359
+ let mut blocks = vec ! [ ] ;
360
+ for item in seq. iter ( ) {
361
+ let block = item. downcast :: < JsNumber , _ > ( & mut cx) . unwrap ( ) ;
362
+ blocks. push ( block. value ( & mut cx) as u64 ) ;
363
+ }
364
+ blocks
365
+ } ;
366
+
253
367
cx. this ( )
254
368
. downcast_or_throw :: < JsBox < OrdinalsIndexer > , _ > ( & mut cx) ?
255
- . start ( )
369
+ . rewrite_blocks ( blocks )
256
370
. or_else ( |err| cx. throw_error ( err. to_string ( ) ) ) ?;
257
371
258
372
Ok ( cx. undefined ( ) )
@@ -288,7 +402,20 @@ impl OrdinalsIndexer {
288
402
#[ neon:: main]
289
403
fn main ( mut cx : ModuleContext ) -> NeonResult < ( ) > {
290
404
cx. export_function ( "ordinalsIndexerNew" , OrdinalsIndexer :: js_new) ?;
291
- cx. export_function ( "ordinalsIndexerStart" , OrdinalsIndexer :: js_start) ?;
405
+ cx. export_function (
406
+ "ordinalsIndexerStreamBlocks" ,
407
+ OrdinalsIndexer :: js_stream_blocks,
408
+ ) ?;
409
+ cx. export_function (
410
+ "ordinalsIndexerReplayBlocks" ,
411
+ OrdinalsIndexer :: js_replay_blocks,
412
+ ) ?;
413
+ cx. export_function ( "ordinalsIndexerDropBlocks" , OrdinalsIndexer :: js_drop_blocks) ?;
414
+ cx. export_function ( "ordinalsIndexerSyncBlocks" , OrdinalsIndexer :: js_sync_blocks) ?;
415
+ cx. export_function (
416
+ "ordinalsIndexerRewriteBlocks" ,
417
+ OrdinalsIndexer :: js_rewrite_blocks,
418
+ ) ?;
292
419
cx. export_function ( "ordinalsIndexerTerminate" , OrdinalsIndexer :: js_terminate) ?;
293
420
cx. export_function (
294
421
"ordinalsIndexerOnBlockApply" ,
0 commit comments