mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-01-12 16:52:57 +08:00
feat: add logs
This commit is contained in:
@@ -379,7 +379,7 @@ fn load_predicates_from_redis(
|
||||
|
||||
let mut predicates = vec![];
|
||||
for key in chainhooks_to_load.iter() {
|
||||
let mut chainhook = match redis_con.hget::<_, _, String>(key, "specification") {
|
||||
let chainhook = match redis_con.hget::<_, _, String>(key, "specification") {
|
||||
Ok(spec) => match ChainhookSpecification::deserialize_specification(&spec, key) {
|
||||
Ok(spec) => spec,
|
||||
Err(e) => {
|
||||
|
||||
@@ -89,15 +89,19 @@ impl ChainhookConfig {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn register_specification(&mut self, spec: ChainhookSpecification, enabled: bool) -> Result<(), String> {
|
||||
pub fn register_specification(
|
||||
&mut self,
|
||||
spec: ChainhookSpecification,
|
||||
enabled: bool,
|
||||
) -> Result<(), String> {
|
||||
match spec {
|
||||
ChainhookSpecification::Stacks(spec) => {
|
||||
let mut spec = spec.clone();
|
||||
let mut spec = spec.clone();
|
||||
spec.enabled = enabled;
|
||||
self.stacks_chainhooks.push(spec);
|
||||
}
|
||||
ChainhookSpecification::Bitcoin(spec) => {
|
||||
let mut spec = spec.clone();
|
||||
let mut spec = spec.clone();
|
||||
spec.enabled = enabled;
|
||||
self.bitcoin_chainhooks.push(spec);
|
||||
}
|
||||
|
||||
@@ -927,16 +927,14 @@ pub fn retrieve_satoshi_point_using_local_storage(
|
||||
let coinbase_txid = &res.0 .0 .0;
|
||||
let txid = tx_cursor.0;
|
||||
|
||||
// ctx.try_log(|logger| {
|
||||
// slog::info!(
|
||||
// logger,
|
||||
// "{ordinal_block_number}:{:?}:{:?}",
|
||||
// hex::encode(&coinbase_txid),
|
||||
// hex::encode(&txid)
|
||||
// )
|
||||
// });
|
||||
|
||||
// to remove
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
"{ordinal_block_number}:{:?}:{:?}",
|
||||
hex::encode(&coinbase_txid),
|
||||
hex::encode(&txid)
|
||||
)
|
||||
});
|
||||
|
||||
// evaluate exit condition: did we reach the **final** coinbase transaction
|
||||
if coinbase_txid.eq(&txid) {
|
||||
@@ -985,44 +983,44 @@ pub fn retrieve_satoshi_point_using_local_storage(
|
||||
continue;
|
||||
}
|
||||
|
||||
// ctx.try_log(|logger| {
|
||||
// slog::debug!(logger, "Evaluating {}: {:?}", hex::encode(&txid_n), outputs)
|
||||
// });
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(logger, "Evaluating {}: {:?}", hex::encode(&txid_n), outputs)
|
||||
});
|
||||
|
||||
let mut sats_out = 0;
|
||||
for (index, output_value) in outputs.iter().enumerate() {
|
||||
if index == tx_cursor.1 {
|
||||
break;
|
||||
}
|
||||
// ctx.try_log(|logger| {
|
||||
// slog::debug!(logger, "Adding {} from output #{}", output_value, index)
|
||||
// });
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(logger, "Adding {} from output #{}", output_value, index)
|
||||
});
|
||||
sats_out += output_value;
|
||||
}
|
||||
sats_out += ordinal_offset;
|
||||
// ctx.try_log(|logger| {
|
||||
// slog::debug!(
|
||||
// logger,
|
||||
// "Adding offset {ordinal_offset} to sats_out {sats_out}"
|
||||
// )
|
||||
// });
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
"Adding offset {ordinal_offset} to sats_out {sats_out}"
|
||||
)
|
||||
});
|
||||
|
||||
let mut sats_in = 0;
|
||||
for (txin, block_height, vout, txin_value) in inputs.into_iter() {
|
||||
sats_in += txin_value;
|
||||
// ctx.try_log(|logger| {
|
||||
// slog::debug!(
|
||||
// logger,
|
||||
// "Adding txin_value {txin_value} to sats_in {sats_in} (txin: {})",
|
||||
// hex::encode(&txin)
|
||||
// )
|
||||
// });
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
"Adding txin_value {txin_value} to sats_in {sats_in} (txin: {})",
|
||||
hex::encode(&txin)
|
||||
)
|
||||
});
|
||||
|
||||
if sats_out < sats_in {
|
||||
ordinal_offset = sats_out - (sats_in - txin_value);
|
||||
ordinal_block_number = block_height;
|
||||
|
||||
ctx.try_log(|logger| slog::debug!(logger, "Block {ordinal_block_number} / Tx {} / [in:{sats_in}, out:{sats_out}]: {block_height} -> {ordinal_block_number}:{ordinal_offset} -> {}:{vout}",
|
||||
ctx.try_log(|logger| slog::info!(logger, "Block {ordinal_block_number} / Tx {} / [in:{sats_in}, out:{sats_out}]: {block_height} -> {ordinal_block_number}:{ordinal_offset} -> {}:{vout}",
|
||||
hex::encode(&txid_n),
|
||||
hex::encode(&txin)));
|
||||
tx_cursor = (txin, vout as usize);
|
||||
|
||||
@@ -228,7 +228,6 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data(
|
||||
{
|
||||
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 => {
|
||||
@@ -250,56 +249,58 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data(
|
||||
inscription.transfers_pre_inscription = traversal.transfers;
|
||||
inscription.inscription_fee = new_tx.metadata.fee;
|
||||
|
||||
match storage {
|
||||
Storage::Sqlite(rw_hord_db_conn) => {
|
||||
if let Some(_entry) = find_inscription_with_ordinal_number(
|
||||
&traversal.ordinal_number,
|
||||
&inscription_db_conn,
|
||||
&ctx,
|
||||
) {
|
||||
ctx.try_log(|logger| {
|
||||
slog::warn!(
|
||||
if let Some(_entry) = find_inscription_with_ordinal_number(
|
||||
&traversal.ordinal_number,
|
||||
&inscription_db_conn,
|
||||
&ctx,
|
||||
) {
|
||||
ctx.try_log(|logger| {
|
||||
slog::warn!(
|
||||
logger,
|
||||
"Transaction {} in block {} is overriding an existing inscription {}",
|
||||
new_tx.transaction_identifier.hash,
|
||||
block.block_identifier.index,
|
||||
traversal.ordinal_number
|
||||
);
|
||||
});
|
||||
ordinals_events_indexes_to_discard.push_front(ordinal_event_index);
|
||||
} else {
|
||||
});
|
||||
ordinals_events_indexes_to_discard.push_front(ordinal_event_index);
|
||||
} else {
|
||||
match storage {
|
||||
Storage::Sqlite(rw_hord_db_conn) => {
|
||||
latest_inscription_number += 1;
|
||||
inscription.inscription_number = inscription_number;
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
"Transaction {} in block {} inscribed some content ({}) on Satoshi #{}",
|
||||
new_tx.transaction_identifier.hash,
|
||||
block.block_identifier.index,
|
||||
inscription.content_type,
|
||||
traversal.ordinal_number
|
||||
);
|
||||
});
|
||||
slog::info!(
|
||||
logger,
|
||||
"Transaction {} in block {} inscribed some content ({}) on Satoshi #{}",
|
||||
new_tx.transaction_identifier.hash,
|
||||
block.block_identifier.index,
|
||||
inscription.content_type,
|
||||
traversal.ordinal_number
|
||||
);
|
||||
});
|
||||
store_new_inscription(
|
||||
&inscription,
|
||||
&block.block_identifier,
|
||||
&rw_hord_db_conn,
|
||||
&ctx,
|
||||
);
|
||||
);
|
||||
}
|
||||
Storage::Memory(map) => {
|
||||
// Do something!
|
||||
let outpoint = inscription.satpoint_post_inscription
|
||||
[0..inscription.satpoint_post_inscription.len() - 2]
|
||||
.to_string();
|
||||
map.insert(
|
||||
outpoint,
|
||||
vec![WatchedSatpoint {
|
||||
inscription_id: inscription.inscription_id.clone(),
|
||||
inscription_number: inscription.inscription_number,
|
||||
ordinal_number: inscription.ordinal_number,
|
||||
offset: 0,
|
||||
}],
|
||||
);
|
||||
}
|
||||
}
|
||||
Storage::Memory(map) => {
|
||||
let outpoint = inscription.satpoint_post_inscription
|
||||
[0..inscription.satpoint_post_inscription.len() - 2]
|
||||
.to_string();
|
||||
map.insert(
|
||||
outpoint,
|
||||
vec![WatchedSatpoint {
|
||||
inscription_id: inscription.inscription_id.clone(),
|
||||
inscription_number: inscription.inscription_number,
|
||||
ordinal_number: inscription.ordinal_number,
|
||||
offset: 0,
|
||||
}],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user