mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-01-13 08:40:17 +08:00
fix: address build warnings
This commit is contained in:
@@ -308,6 +308,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
|
||||
ConfigCommand::New(cmd) => {
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
let _config = Config::default(cmd.devnet, cmd.testnet, cmd.mainnet, &None)?;
|
||||
let config_content = generate_config();
|
||||
let mut file_path = PathBuf::new();
|
||||
file_path.push("Chainhook.toml");
|
||||
|
||||
@@ -6,8 +6,7 @@ use chainhook_event_observer::chainhooks::bitcoin::{
|
||||
use chainhook_event_observer::chainhooks::types::{
|
||||
BitcoinPredicateType, ChainhookConfig, ChainhookFullSpecification, OrdinalOperations, Protocols,
|
||||
};
|
||||
use chainhook_event_observer::indexer::ordinals::{self, ord::initialize_ordinal_index};
|
||||
use chainhook_event_observer::indexer::{self, BitcoinChainContext};
|
||||
use chainhook_event_observer::indexer;
|
||||
use chainhook_event_observer::observer::{
|
||||
start_event_observer, ApiKey, EventObserverConfig, ObserverEvent,
|
||||
};
|
||||
@@ -136,13 +135,13 @@ impl Node {
|
||||
"Listening for chainhook predicate registrations on port {}", DEFAULT_CONTROL_PORT
|
||||
);
|
||||
|
||||
let ordinal_index = match initialize_ordinal_index(&event_observer_config, None, &self.ctx)
|
||||
{
|
||||
Ok(index) => index,
|
||||
Err(e) => {
|
||||
panic!()
|
||||
}
|
||||
};
|
||||
// let ordinal_index = match initialize_ordinal_index(&event_observer_config, None, &self.ctx)
|
||||
// {
|
||||
// Ok(index) => index,
|
||||
// Err(e) => {
|
||||
// panic!()
|
||||
// }
|
||||
// };
|
||||
|
||||
let context_cloned = self.ctx.clone();
|
||||
let event_observer_config_moved = event_observer_config.clone();
|
||||
|
||||
@@ -9,6 +9,7 @@ use chainhook_event_observer::chainhooks::types::{
|
||||
BitcoinChainhookFullSpecification, BitcoinPredicateType, HookAction, OrdinalOperations,
|
||||
Protocols,
|
||||
};
|
||||
use chainhook_event_observer::indexer;
|
||||
use chainhook_event_observer::indexer::bitcoin::{
|
||||
retrieve_block_hash, retrieve_full_block_breakdown_with_retry,
|
||||
};
|
||||
@@ -22,9 +23,8 @@ use chainhook_event_observer::indexer::ordinals::ord::indexing::{
|
||||
};
|
||||
use chainhook_event_observer::indexer::ordinals::ord::initialize_ordinal_index;
|
||||
use chainhook_event_observer::indexer::ordinals::ord::inscription_id::InscriptionId;
|
||||
use chainhook_event_observer::indexer::{self, BitcoinChainContext};
|
||||
use chainhook_event_observer::observer::{
|
||||
BitcoinConfig, EventObserverConfig, DEFAULT_CONTROL_PORT, DEFAULT_INGESTION_PORT,
|
||||
EventObserverConfig, DEFAULT_CONTROL_PORT, DEFAULT_INGESTION_PORT,
|
||||
};
|
||||
use chainhook_event_observer::redb::ReadableTable;
|
||||
use chainhook_event_observer::utils::{file_append, send_request, Context};
|
||||
@@ -348,9 +348,9 @@ pub async fn scan_bitcoin_chain_with_predicate(
|
||||
|
||||
if pipeline_started {
|
||||
let _ = retrieve_ordinal_tx.send(None);
|
||||
handle_3.join();
|
||||
handle_1.join();
|
||||
handle_2.join();
|
||||
let _ = handle_3.join();
|
||||
let _ = handle_1.join();
|
||||
let _ = handle_2.join();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
collections::{HashMap, HashSet, VecDeque},
|
||||
collections::{HashMap, VecDeque},
|
||||
process,
|
||||
};
|
||||
|
||||
@@ -12,7 +12,6 @@ use chainhook_event_observer::{
|
||||
chainhooks::stacks::{
|
||||
handle_stacks_hook_action, StacksChainhookOccurrence, StacksTriggerChainhook,
|
||||
},
|
||||
observer::{EventObserverConfig, DEFAULT_CONTROL_PORT, DEFAULT_INGESTION_PORT},
|
||||
utils::{file_append, send_request, AbstractStacksBlock},
|
||||
};
|
||||
use chainhook_event_observer::{
|
||||
@@ -83,26 +82,6 @@ pub async fn scan_stacks_chain_with_predicate(
|
||||
let _ = record_tx.send(None);
|
||||
});
|
||||
|
||||
let event_observer_config = EventObserverConfig {
|
||||
normalization_enabled: true,
|
||||
grpc_server_enabled: false,
|
||||
hooks_enabled: true,
|
||||
bitcoin_rpc_proxy_enabled: true,
|
||||
event_handlers: vec![],
|
||||
chainhook_config: None,
|
||||
ingestion_port: DEFAULT_INGESTION_PORT,
|
||||
control_port: DEFAULT_CONTROL_PORT,
|
||||
bitcoin_node_username: config.network.bitcoin_node_rpc_username.clone(),
|
||||
bitcoin_node_password: config.network.bitcoin_node_rpc_password.clone(),
|
||||
bitcoin_node_rpc_url: config.network.bitcoin_node_rpc_url.clone(),
|
||||
stacks_node_rpc_url: config.network.stacks_node_rpc_url.clone(),
|
||||
operators: HashSet::new(),
|
||||
display_logs: false,
|
||||
cache_path: config.storage.cache_path.clone(),
|
||||
bitcoin_network: config.network.bitcoin_network.clone(),
|
||||
stacks_network: config.network.stacks_network.clone(),
|
||||
};
|
||||
|
||||
let mut indexer = Indexer::new(config.network.clone());
|
||||
|
||||
let mut canonical_fork = {
|
||||
|
||||
@@ -259,7 +259,7 @@ impl BitcoinPredicateType {
|
||||
pub fn evaluate_transaction_predicate(
|
||||
&self,
|
||||
tx: &BitcoinTransactionData,
|
||||
ctx: &Context,
|
||||
_ctx: &Context,
|
||||
) -> bool {
|
||||
// TODO(lgalabru): follow-up on this implementation
|
||||
match &self {
|
||||
|
||||
@@ -265,13 +265,9 @@ pub fn standardize_bitcoin_block(
|
||||
ctx.try_log(|logger| slog::debug!(logger, "Standardizing Bitcoin transaction {txid}"));
|
||||
|
||||
let mut stacks_operations = vec![];
|
||||
if let Some(op) = try_parse_stacks_operation(
|
||||
&tx.vout,
|
||||
&pox_config,
|
||||
&expected_magic_bytes,
|
||||
block_height,
|
||||
ctx,
|
||||
) {
|
||||
if let Some(op) =
|
||||
try_parse_stacks_operation(&tx.vout, &pox_config, &expected_magic_bytes, ctx)
|
||||
{
|
||||
stacks_operations.push(op);
|
||||
}
|
||||
|
||||
@@ -370,7 +366,7 @@ pub fn standardize_bitcoin_block(
|
||||
fn try_parse_ordinal_operation(
|
||||
tx: &BitcoinTransactionFullBreakdown,
|
||||
_block_height: u64,
|
||||
ctx: &Context,
|
||||
_ctx: &Context,
|
||||
) -> Option<OrdinalOperation> {
|
||||
for input in tx.vin.iter() {
|
||||
if let Some(ref witnesses) = input.txinwitness {
|
||||
@@ -433,7 +429,6 @@ fn try_parse_stacks_operation(
|
||||
outputs: &Vec<BitcoinTransactionOutputFullBreakdown>,
|
||||
pox_config: &PoxConfig,
|
||||
expected_magic_bytes: &[u8; 2],
|
||||
block_height: u64,
|
||||
ctx: &Context,
|
||||
) -> Option<StacksBaseChainOperation> {
|
||||
if outputs.is_empty() {
|
||||
|
||||
@@ -287,7 +287,7 @@ pub fn update_transfered_inscription(
|
||||
|
||||
pub fn find_last_inscription_number(
|
||||
storage_conn: &Connection,
|
||||
ctx: &Context,
|
||||
_ctx: &Context,
|
||||
) -> Result<u64, String> {
|
||||
let args: &[&dyn ToSql] = &[];
|
||||
let mut stmt = storage_conn
|
||||
@@ -306,7 +306,7 @@ pub fn find_last_inscription_number(
|
||||
pub fn find_inscription_with_ordinal_number(
|
||||
ordinal_number: &u64,
|
||||
storage_conn: &Connection,
|
||||
ctx: &Context,
|
||||
_ctx: &Context,
|
||||
) -> Option<String> {
|
||||
let args: &[&dyn ToSql] = &[&ordinal_number.to_sql().unwrap()];
|
||||
let mut stmt = storage_conn
|
||||
@@ -375,6 +375,7 @@ pub async fn build_bitcoin_traversal_local_storage(
|
||||
let block_height = block_cursor.clone();
|
||||
let block_hash_tx = block_hash_tx.clone();
|
||||
let config = bitcoin_config.clone();
|
||||
let moved_ctx = ctx.clone();
|
||||
retrieve_block_hash_pool.execute(move || {
|
||||
let mut err_count = 0;
|
||||
let mut rng = rand::thread_rng();
|
||||
@@ -386,6 +387,9 @@ pub async fn build_bitcoin_traversal_local_storage(
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
moved_ctx.try_log(|logger| {
|
||||
slog::error!(logger, "unable to retrieve block_hash: #{}", e)
|
||||
});
|
||||
err_count += 1;
|
||||
let delay = (err_count + (rng.next_u64() % 3)) * 1000;
|
||||
std::thread::sleep(std::time::Duration::from_millis(delay));
|
||||
@@ -398,7 +402,7 @@ pub async fn build_bitcoin_traversal_local_storage(
|
||||
let bitcoin_config = bitcoin_config.clone();
|
||||
let moved_ctx = ctx.clone();
|
||||
let block_data_tx_moved = block_data_tx.clone();
|
||||
let handle_1 = hiro_system_kit::thread_named("Block data retrieval")
|
||||
let _ = hiro_system_kit::thread_named("Block data retrieval")
|
||||
.spawn(move || {
|
||||
while let Ok(Some((block_height, block_hash))) = block_hash_rx.recv() {
|
||||
let moved_bitcoin_config = bitcoin_config.clone();
|
||||
@@ -421,7 +425,7 @@ pub async fn build_bitcoin_traversal_local_storage(
|
||||
})
|
||||
.expect("unable to spawn thread");
|
||||
|
||||
let handle_2 = hiro_system_kit::thread_named("Block data compression")
|
||||
let _ = hiro_system_kit::thread_named("Block data compression")
|
||||
.spawn(move || {
|
||||
while let Ok(Some(block_data)) = block_data_rx.recv() {
|
||||
let block_compressed_tx_moved = block_compressed_tx.clone();
|
||||
@@ -432,7 +436,6 @@ pub async fn build_bitcoin_traversal_local_storage(
|
||||
});
|
||||
|
||||
let res = compress_block_data_pool.join();
|
||||
// let _ = block_compressed_tx.send(None);
|
||||
res
|
||||
}
|
||||
})
|
||||
|
||||
@@ -30,57 +30,10 @@ impl Inscription {
|
||||
InscriptionParser::parse(&tx.input.get(0)?.witness).ok()
|
||||
}
|
||||
|
||||
fn append_reveal_script_to_builder(&self, mut builder: script::Builder) -> script::Builder {
|
||||
builder = builder
|
||||
.push_opcode(opcodes::OP_FALSE)
|
||||
.push_opcode(opcodes::all::OP_IF)
|
||||
.push_slice(PROTOCOL_ID);
|
||||
|
||||
if let Some(content_type) = &self.content_type {
|
||||
builder = builder
|
||||
.push_slice(CONTENT_TYPE_TAG)
|
||||
.push_slice(content_type);
|
||||
}
|
||||
|
||||
if let Some(body) = &self.body {
|
||||
builder = builder.push_slice(BODY_TAG);
|
||||
for chunk in body.chunks(520) {
|
||||
builder = builder.push_slice(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
builder.push_opcode(opcodes::all::OP_ENDIF)
|
||||
}
|
||||
|
||||
pub(crate) fn append_reveal_script(&self, builder: script::Builder) -> Script {
|
||||
self.append_reveal_script_to_builder(builder).into_script()
|
||||
}
|
||||
|
||||
pub(crate) fn media(&self) -> Media {
|
||||
if self.body.is_none() {
|
||||
return Media::Unknown;
|
||||
}
|
||||
|
||||
let content_type = match self.content_type() {
|
||||
Some(content_type) => content_type,
|
||||
None => return Media::Unknown,
|
||||
};
|
||||
|
||||
content_type.parse().unwrap_or(Media::Unknown)
|
||||
}
|
||||
|
||||
pub(crate) fn body(&self) -> Option<&[u8]> {
|
||||
Some(self.body.as_ref()?)
|
||||
}
|
||||
|
||||
pub(crate) fn into_body(self) -> Option<Vec<u8>> {
|
||||
self.body
|
||||
}
|
||||
|
||||
pub(crate) fn content_length(&self) -> Option<usize> {
|
||||
Some(self.body()?.len())
|
||||
}
|
||||
|
||||
pub(crate) fn content_type(&self) -> Option<&str> {
|
||||
str::from_utf8(self.content_type.as_ref()?).ok()
|
||||
}
|
||||
|
||||
@@ -224,9 +224,9 @@ impl OrdinalIndexUpdater {
|
||||
}
|
||||
|
||||
fn get_block_with_retries(
|
||||
client: &Client,
|
||||
height: u64,
|
||||
ctx: &Context,
|
||||
_client: &Client,
|
||||
_height: u64,
|
||||
_ctx: &Context,
|
||||
) -> Result<Option<BlockData>> {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -278,7 +278,7 @@ impl OrdinalIndexUpdater {
|
||||
}
|
||||
let txs = match try_join_all(futs).await {
|
||||
Ok(txs) => txs,
|
||||
Err(e) => {
|
||||
Err(_e) => {
|
||||
// log::error!("Couldn't receive txs {e}");
|
||||
return;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ impl OrdinalIndexUpdater {
|
||||
async fn index_block(
|
||||
&mut self,
|
||||
index: &OrdinalIndex,
|
||||
outpoint_sender: &mut Sender<OutPoint>,
|
||||
_outpoint_sender: &mut Sender<OutPoint>,
|
||||
value_receiver: &mut Receiver<u64>,
|
||||
wtx: &mut WriteTransaction<'_>,
|
||||
block: BlockData,
|
||||
@@ -317,7 +317,7 @@ impl OrdinalIndexUpdater {
|
||||
|
||||
let mut height_to_block_hash = wtx.open_table(HEIGHT_TO_BLOCK_HASH)?;
|
||||
|
||||
let start = Instant::now();
|
||||
let _start = Instant::now();
|
||||
let mut sat_ranges_written = 0;
|
||||
let mut outputs_in_block = 0;
|
||||
|
||||
@@ -382,7 +382,7 @@ impl OrdinalIndexUpdater {
|
||||
self.sat_ranges_since_flush += 1;
|
||||
}
|
||||
|
||||
for (tx_offset, (tx, txid)) in block.txdata.iter().enumerate().skip(1) {
|
||||
for (_tx_offset, (tx, txid)) in block.txdata.iter().enumerate().skip(1) {
|
||||
let mut input_sat_ranges = VecDeque::new();
|
||||
|
||||
for input in &tx.input {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
use hiro_system_kit::slog;
|
||||
use std::{path::PathBuf, time::Duration};
|
||||
|
||||
|
||||
@@ -621,7 +621,10 @@ impl StacksBlockPool {
|
||||
ctx,
|
||||
) {
|
||||
Ok(res) => res,
|
||||
Err(e) => None,
|
||||
Err(e) => {
|
||||
ctx.try_log(|logger| slog::error!(logger, "Unable to detect convergence: {:?}", e));
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
Ok(chain_event)
|
||||
|
||||
@@ -702,23 +702,34 @@ pub async fn start_observer_commands_handler(
|
||||
let offset = 0;
|
||||
let script_pub_key_hex =
|
||||
new_tx.metadata.outputs[index].get_script_pubkey_hex();
|
||||
let updated_address =
|
||||
match Script::from_hex(&script_pub_key_hex) {
|
||||
Ok(script) => match Address::from_script(
|
||||
&script,
|
||||
Network::Bitcoin,
|
||||
) {
|
||||
Ok(address) => Some(address.to_string()),
|
||||
Err(e) => {
|
||||
// todo(lgalabru log error)
|
||||
None
|
||||
}
|
||||
},
|
||||
let updated_address = match Script::from_hex(
|
||||
&script_pub_key_hex,
|
||||
) {
|
||||
Ok(script) => match Address::from_script(
|
||||
&script,
|
||||
Network::Bitcoin,
|
||||
) {
|
||||
Ok(address) => Some(address.to_string()),
|
||||
Err(e) => {
|
||||
// todo(lgalabru log error)
|
||||
ctx.try_log(|logger| {
|
||||
slog::warn!(
|
||||
logger,
|
||||
"unable to retrieve address from {script_pub_key_hex}: {}", e.to_string()
|
||||
)
|
||||
});
|
||||
None
|
||||
}
|
||||
};
|
||||
},
|
||||
Err(e) => {
|
||||
ctx.try_log(|logger| {
|
||||
slog::warn!(
|
||||
logger,
|
||||
"unable to retrieve address from {script_pub_key_hex}: {}", e.to_string()
|
||||
)
|
||||
});
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// let vout = new_tx.metadata.outputs[index];
|
||||
(outpoint, offset, updated_address)
|
||||
@@ -789,9 +800,6 @@ pub async fn start_observer_commands_handler(
|
||||
bitcoin_block_store.insert(new_block.block_identifier.clone(), new_block);
|
||||
}
|
||||
ObserverCommand::PropagateBitcoinChainEvent(blockchain_event) => {
|
||||
let ordinals_db_conn =
|
||||
open_readonly_ordinals_db_conn(&config.get_cache_path_buf(), &ctx)?;
|
||||
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(logger, "Handling PropagateBitcoinChainEvent command")
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user