mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-01-12 16:52:57 +08:00
fix: enable specs on reboot
This commit is contained in:
@@ -170,7 +170,9 @@ pub async fn scan_stacks_chainstate_via_csv_using_predicate(
|
||||
Ok(action) => {
|
||||
actions_triggered += 1;
|
||||
let res = match action {
|
||||
StacksChainhookOccurrence::Http(request) => send_request(request, 3, 1, &ctx).await,
|
||||
StacksChainhookOccurrence::Http(request) => {
|
||||
send_request(request, 3, 1, &ctx).await
|
||||
}
|
||||
StacksChainhookOccurrence::File(path, bytes) => file_append(path, bytes, &ctx),
|
||||
StacksChainhookOccurrence::Data(_payload) => unreachable!(),
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ impl Service {
|
||||
let registered_predicates = load_predicates_from_redis(&self.config, &self.ctx)?;
|
||||
for predicate in registered_predicates.into_iter() {
|
||||
let predicate_uuid = predicate.uuid().to_string();
|
||||
match chainhook_config.register_specification(predicate) {
|
||||
match chainhook_config.register_specification(predicate, true) {
|
||||
Ok(_) => {
|
||||
info!(
|
||||
self.ctx.expect_logger(),
|
||||
@@ -379,7 +379,7 @@ fn load_predicates_from_redis(
|
||||
|
||||
let mut predicates = vec![];
|
||||
for key in chainhooks_to_load.iter() {
|
||||
let chainhook = match redis_con.hget::<_, _, String>(key, "specification") {
|
||||
let mut chainhook = match redis_con.hget::<_, _, String>(key, "specification") {
|
||||
Ok(spec) => match ChainhookSpecification::deserialize_specification(&spec, key) {
|
||||
Ok(spec) => spec,
|
||||
Err(e) => {
|
||||
|
||||
@@ -89,13 +89,17 @@ impl ChainhookConfig {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn register_specification(&mut self, spec: ChainhookSpecification) -> Result<(), String> {
|
||||
pub fn register_specification(&mut self, spec: ChainhookSpecification, enabled: bool) -> Result<(), String> {
|
||||
match spec {
|
||||
ChainhookSpecification::Stacks(spec) => {
|
||||
self.stacks_chainhooks.push(spec.clone());
|
||||
let mut spec = spec.clone();
|
||||
spec.enabled = enabled;
|
||||
self.stacks_chainhooks.push(spec);
|
||||
}
|
||||
ChainhookSpecification::Bitcoin(spec) => {
|
||||
self.bitcoin_chainhooks.push(spec.clone());
|
||||
let mut spec = spec.clone();
|
||||
spec.enabled = enabled;
|
||||
self.bitcoin_chainhooks.push(spec);
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
||||
@@ -81,7 +81,6 @@ pub fn initialize_hord_db(path: &PathBuf, ctx: &Context) -> Connection {
|
||||
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
|
||||
}
|
||||
|
||||
|
||||
conn
|
||||
}
|
||||
|
||||
@@ -827,7 +826,11 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
|
||||
&ctx,
|
||||
) {
|
||||
ctx.try_log(|logger| {
|
||||
slog::error!(logger, "Unable to augment bitcoin block {} with hord_db: {e}", new_block.block_identifier.index)
|
||||
slog::error!(
|
||||
logger,
|
||||
"Unable to augment bitcoin block {} with hord_db: {e}",
|
||||
new_block.block_identifier.index
|
||||
)
|
||||
});
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
@@ -20,9 +20,8 @@ use crate::{
|
||||
hord::{
|
||||
db::{
|
||||
find_inscription_with_ordinal_number, find_inscriptions_at_wached_outpoint,
|
||||
insert_entry_in_blocks,
|
||||
retrieve_satoshi_point_using_local_storage, store_new_inscription,
|
||||
update_transfered_inscription, CompactedBlock,
|
||||
insert_entry_in_blocks, retrieve_satoshi_point_using_local_storage,
|
||||
store_new_inscription, update_transfered_inscription, CompactedBlock,
|
||||
},
|
||||
ord::height::Height,
|
||||
},
|
||||
@@ -30,8 +29,9 @@ use crate::{
|
||||
};
|
||||
|
||||
use self::db::{
|
||||
find_inscription_with_id, open_readonly_hord_db_conn_rocks_db, remove_entry_from_blocks,
|
||||
remove_entry_from_inscriptions, TraversalResult, WatchedSatpoint, find_latest_inscription_number_at_block_height,
|
||||
find_inscription_with_id, find_latest_inscription_number_at_block_height,
|
||||
open_readonly_hord_db_conn_rocks_db, remove_entry_from_blocks, remove_entry_from_inscriptions,
|
||||
TraversalResult, WatchedSatpoint,
|
||||
};
|
||||
|
||||
pub fn get_inscriptions_revealed_in_block(
|
||||
@@ -202,6 +202,24 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data(
|
||||
inscription_db_conn: &Connection,
|
||||
ctx: &Context,
|
||||
) {
|
||||
let mut latest_inscription_number = match find_latest_inscription_number_at_block_height(
|
||||
&block.block_identifier.index,
|
||||
&inscription_db_conn,
|
||||
&ctx,
|
||||
) {
|
||||
Ok(None) => 0,
|
||||
Ok(Some(inscription_number)) => inscription_number + 1,
|
||||
Err(e) => {
|
||||
ctx.try_log(|logger| {
|
||||
slog::error!(
|
||||
logger,
|
||||
"unable to retrieve inscription number: {}",
|
||||
e.to_string()
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
for new_tx in block.transactions.iter_mut().skip(1) {
|
||||
let mut ordinals_events_indexes_to_discard = VecDeque::new();
|
||||
// Have a new inscription been revealed, if so, are looking at a re-inscription
|
||||
@@ -209,6 +227,8 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data(
|
||||
new_tx.metadata.ordinal_operations.iter_mut().enumerate()
|
||||
{
|
||||
if let OrdinalOperation::InscriptionRevealed(inscription) = ordinal_event {
|
||||
let inscription_number = latest_inscription_number;
|
||||
latest_inscription_number += 1;
|
||||
let traversal = match traversals.get(&new_tx.transaction_identifier) {
|
||||
Some(traversal) => traversal,
|
||||
None => {
|
||||
@@ -248,21 +268,7 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data(
|
||||
});
|
||||
ordinals_events_indexes_to_discard.push_front(ordinal_event_index);
|
||||
} else {
|
||||
inscription.inscription_number =
|
||||
match find_latest_inscription_number_at_block_height(&block.block_identifier.index, &inscription_db_conn, &ctx) {
|
||||
Ok(None) => 0,
|
||||
Ok(Some(inscription_number)) => inscription_number + 1,
|
||||
Err(e) => {
|
||||
ctx.try_log(|logger| {
|
||||
slog::error!(
|
||||
logger,
|
||||
"unable to retrieve satoshi number: {}",
|
||||
e.to_string()
|
||||
);
|
||||
});
|
||||
continue;
|
||||
}
|
||||
};
|
||||
inscription.inscription_number = inscription_number;
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
@@ -273,13 +279,13 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data(
|
||||
traversal.ordinal_number
|
||||
);
|
||||
});
|
||||
store_new_inscription(
|
||||
&inscription,
|
||||
&block.block_identifier,
|
||||
&rw_hord_db_conn,
|
||||
&ctx,
|
||||
);
|
||||
}
|
||||
store_new_inscription(
|
||||
&inscription,
|
||||
&block.block_identifier,
|
||||
&rw_hord_db_conn,
|
||||
&ctx,
|
||||
);
|
||||
}
|
||||
Storage::Memory(map) => {
|
||||
let outpoint = inscription.satpoint_post_inscription
|
||||
|
||||
@@ -699,7 +699,8 @@ pub async fn start_observer_commands_handler(
|
||||
ctx.try_log(|logger| {
|
||||
slog::error!(
|
||||
logger,
|
||||
"Unable to insert bitcoin block {} in hord_db: {e}", block.block_identifier.index
|
||||
"Unable to insert bitcoin block {} in hord_db: {e}",
|
||||
block.block_identifier.index
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user