mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-06-15 08:58:29 +08:00
feat: introduce terminate function
This commit is contained in:
@@ -9,6 +9,7 @@ const {
|
||||
ordinalsIndexerRewriteBlocks,
|
||||
ordinalsIndexerOnBlockApply,
|
||||
ordinalsIndexerOnBlockUndo,
|
||||
ordinalsIndexerTerminate,
|
||||
} = require("../native/index.node");
|
||||
|
||||
// import {
|
||||
@@ -97,11 +98,11 @@ export class OrdinalsIndexer {
|
||||
return ordinalsIndexerOnBlockUndo.call(this.handle, callback);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @summary Terminates the containers
|
||||
// * @memberof DevnetNetworkOrchestrator
|
||||
// */
|
||||
// terminate(): boolean {
|
||||
// return stacksDevnetTerminate.call(this.handle);
|
||||
// }
|
||||
/**
|
||||
* @summary Terminates indexer
|
||||
* @memberof DevnetNetworkOrchestrator
|
||||
*/
|
||||
terminate() {
|
||||
return ordinalsIndexerTerminate.call(this.handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,3 +26,5 @@ indexer.rewriteBlocks([32103, 32104]);
|
||||
indexer.syncBlocks();
|
||||
|
||||
indexer.replayBlocks([32103, 32104]);
|
||||
|
||||
indexer.terminate();
|
||||
@@ -44,12 +44,14 @@ enum IndexerCommand {
|
||||
DropBlocks(Vec<u64>),
|
||||
RewriteBlocks(Vec<u64>),
|
||||
ReplayBlocks(Vec<u64>),
|
||||
Stop,
|
||||
Terminate,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
enum CustomIndexerCommand {
|
||||
UpdateApplyCallback(Root<JsFunction>),
|
||||
UpdateUndoCallback(Root<JsFunction>),
|
||||
Terminate,
|
||||
}
|
||||
|
||||
impl Finalize for OrdinalsIndexer {}
|
||||
@@ -136,6 +138,9 @@ impl OrdinalsIndexer {
|
||||
Ok(CustomIndexerCommand::UpdateUndoCallback(callback)) => {
|
||||
undo_callback = Some(callback);
|
||||
}
|
||||
Ok(CustomIndexerCommand::Terminate) => {
|
||||
return Ok(())
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -179,8 +184,8 @@ impl OrdinalsIndexer {
|
||||
IndexerCommand::SyncBlocks => {
|
||||
println!("Will sync blocks");
|
||||
}
|
||||
IndexerCommand::Stop => {
|
||||
break;
|
||||
IndexerCommand::Terminate => {
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,6 +203,11 @@ impl OrdinalsIndexer {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn terminate(&self) -> Result<bool, String> {
|
||||
let _ = self.command_tx.send(IndexerCommand::Terminate);
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn replay_blocks(&self, blocks: Vec<u64>) -> Result<bool, String> {
|
||||
let _ = self.command_tx.send(IndexerCommand::ReplayBlocks(blocks));
|
||||
Ok(true)
|
||||
@@ -372,8 +382,13 @@ impl OrdinalsIndexer {
|
||||
Ok(cx.undefined())
|
||||
}
|
||||
|
||||
fn js_terminate(mut _cx: FunctionContext) -> JsResult<JsBoolean> {
|
||||
unimplemented!();
|
||||
fn js_terminate(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||
cx.this()
|
||||
.downcast_or_throw::<JsBox<OrdinalsIndexer>, _>(&mut cx)?
|
||||
.terminate()
|
||||
.or_else(|err| cx.throw_error(err.to_string()))?;
|
||||
|
||||
Ok(cx.undefined())
|
||||
}
|
||||
|
||||
fn js_on_block_apply(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
||||
|
||||
Reference in New Issue
Block a user