mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-06-13 16:19:01 +08:00
fix: include proof on scan commands
This commit is contained in:
@@ -20,6 +20,7 @@ use chainhook_event_observer::indexer;
|
||||
use chainhook_event_observer::indexer::bitcoin::{
|
||||
retrieve_block_hash_with_retry, retrieve_full_block_breakdown_with_retry,
|
||||
};
|
||||
use chainhook_event_observer::observer::{gather_proofs, EventObserverConfig};
|
||||
use chainhook_event_observer::utils::{file_append, send_request, Context};
|
||||
use chainhook_types::{BitcoinChainEvent, BitcoinChainUpdatedWithBlocksData};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
@@ -189,7 +190,8 @@ pub async fn scan_bitcoin_chain_with_predicate(
|
||||
ctx,
|
||||
);
|
||||
|
||||
actions_triggered += execute_predicates_action(hits, &ctx).await;
|
||||
actions_triggered +=
|
||||
execute_predicates_action(hits, &event_observer_config, &ctx).await;
|
||||
}
|
||||
} else {
|
||||
let use_scan_to_seed_hord_db = true;
|
||||
@@ -209,15 +211,6 @@ pub async fn scan_bitcoin_chain_with_predicate(
|
||||
ctx,
|
||||
)?;
|
||||
|
||||
if use_scan_to_seed_hord_db {
|
||||
// Inject new block in ingestion pipeline
|
||||
//
|
||||
// let _ = cache_block_tx.send(Some((
|
||||
// block_breakdown.height as u32,
|
||||
// CompactedBlock::from_full_block(&block_breakdown),
|
||||
// )));
|
||||
}
|
||||
|
||||
let chain_event =
|
||||
BitcoinChainEvent::ChainUpdatedWithBlocks(BitcoinChainUpdatedWithBlocksData {
|
||||
new_blocks: vec![block],
|
||||
@@ -230,7 +223,8 @@ pub async fn scan_bitcoin_chain_with_predicate(
|
||||
ctx,
|
||||
);
|
||||
|
||||
actions_triggered += execute_predicates_action(hits, &ctx).await;
|
||||
actions_triggered +=
|
||||
execute_predicates_action(hits, &event_observer_config, &ctx).await;
|
||||
}
|
||||
}
|
||||
info!(
|
||||
@@ -243,12 +237,12 @@ pub async fn scan_bitcoin_chain_with_predicate(
|
||||
|
||||
pub async fn execute_predicates_action<'a>(
|
||||
hits: Vec<BitcoinTriggerChainhook<'a>>,
|
||||
config: &EventObserverConfig,
|
||||
ctx: &Context,
|
||||
) -> u32 {
|
||||
let mut actions_triggered = 0;
|
||||
|
||||
let proofs = gather_proofs(&hits, &config, &ctx);
|
||||
for hit in hits.into_iter() {
|
||||
let proofs = HashMap::new();
|
||||
match handle_bitcoin_hook_action(hit, &proofs) {
|
||||
Err(e) => {
|
||||
error!(ctx.expect_logger(), "unable to handle action {}", e);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::chainhooks::bitcoin::{
|
||||
evaluate_bitcoin_chainhooks_on_chain_event, handle_bitcoin_hook_action,
|
||||
BitcoinChainhookOccurrence, BitcoinChainhookOccurrencePayload,
|
||||
BitcoinChainhookOccurrence, BitcoinChainhookOccurrencePayload, BitcoinTriggerChainhook,
|
||||
};
|
||||
use crate::chainhooks::stacks::{
|
||||
evaluate_stacks_chainhooks_on_chain_event, handle_stacks_hook_action,
|
||||
@@ -446,6 +446,51 @@ pub fn apply_bitcoin_block() {}
|
||||
|
||||
pub fn rollback_bitcoin_block() {}
|
||||
|
||||
pub fn gather_proofs<'a>(
|
||||
chainhooks_to_trigger: &Vec<BitcoinTriggerChainhook<'a>>,
|
||||
config: &EventObserverConfig,
|
||||
ctx: &Context,
|
||||
) -> HashMap<&'a TransactionIdentifier, String> {
|
||||
let bitcoin_client_rpc = Client::new(
|
||||
&config.bitcoin_node_rpc_url,
|
||||
Auth::UserPass(
|
||||
config.bitcoin_node_username.to_string(),
|
||||
config.bitcoin_node_password.to_string(),
|
||||
),
|
||||
)
|
||||
.expect("unable to build http client");
|
||||
|
||||
let mut proofs = HashMap::new();
|
||||
for hook_to_trigger in chainhooks_to_trigger.iter() {
|
||||
for (transactions, block) in hook_to_trigger.apply.iter() {
|
||||
for transaction in transactions.iter() {
|
||||
if !proofs.contains_key(&transaction.transaction_identifier) {
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
"collecting proof for transaction {}",
|
||||
transaction.transaction_identifier.hash
|
||||
)
|
||||
});
|
||||
match get_bitcoin_proof(
|
||||
&bitcoin_client_rpc,
|
||||
&transaction.transaction_identifier,
|
||||
&block.block_identifier,
|
||||
) {
|
||||
Ok(proof) => {
|
||||
proofs.insert(&transaction.transaction_identifier, proof);
|
||||
}
|
||||
Err(e) => {
|
||||
ctx.try_log(|logger| slog::error!(logger, "{e}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
proofs
|
||||
}
|
||||
|
||||
pub async fn start_observer_commands_handler(
|
||||
config: EventObserverConfig,
|
||||
chainhook_store: Arc<RwLock<ChainhookStore>>,
|
||||
@@ -753,49 +798,7 @@ pub async fn start_observer_commands_handler(
|
||||
}
|
||||
}
|
||||
|
||||
let bitcoin_client_rpc = Client::new(
|
||||
&config.bitcoin_node_rpc_url,
|
||||
Auth::UserPass(
|
||||
config.bitcoin_node_username.to_string(),
|
||||
config.bitcoin_node_password.to_string(),
|
||||
),
|
||||
)
|
||||
.expect("unable to build http client");
|
||||
|
||||
let mut proofs = HashMap::new();
|
||||
for hook_to_trigger in chainhooks_to_trigger.iter() {
|
||||
for (transactions, block) in hook_to_trigger.apply.iter() {
|
||||
for transaction in transactions.iter() {
|
||||
if !proofs.contains_key(&transaction.transaction_identifier)
|
||||
{
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
"collecting proof for transaction {}",
|
||||
transaction.transaction_identifier.hash
|
||||
)
|
||||
});
|
||||
match get_bitcoin_proof(
|
||||
&bitcoin_client_rpc,
|
||||
&transaction.transaction_identifier,
|
||||
&block.block_identifier,
|
||||
) {
|
||||
Ok(proof) => {
|
||||
proofs.insert(
|
||||
&transaction.transaction_identifier,
|
||||
proof,
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
ctx.try_log(|logger| {
|
||||
slog::error!(logger, "{e}")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let proofs = gather_proofs(&chainhooks_to_trigger, &config, &ctx);
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
|
||||
Reference in New Issue
Block a user