mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-06-14 00:22:19 +08:00
fix: safer error handling
This commit is contained in:
@@ -173,7 +173,7 @@ pub async fn scan_bitcoin_chain_with_predicate(
|
||||
&ctx,
|
||||
);
|
||||
|
||||
update_storage_and_augment_bitcoin_block_with_inscription_transfer_data(
|
||||
let _ = update_storage_and_augment_bitcoin_block_with_inscription_transfer_data(
|
||||
&mut block,
|
||||
&mut storage,
|
||||
&ctx,
|
||||
|
||||
@@ -406,13 +406,14 @@ pub struct WatchedSatpoint {
|
||||
pub fn find_inscriptions_at_wached_outpoint(
|
||||
outpoint: &str,
|
||||
hord_db_conn: &Connection,
|
||||
) -> Vec<WatchedSatpoint> {
|
||||
) -> Result<Vec<WatchedSatpoint>, String> {
|
||||
let args: &[&dyn ToSql] = &[&outpoint.to_sql().unwrap()];
|
||||
let mut stmt = hord_db_conn
|
||||
.prepare("SELECT inscription_id, inscription_number, ordinal_number, offset FROM inscriptions WHERE outpoint_to_watch = ? ORDER BY offset ASC")
|
||||
.unwrap();
|
||||
.map_err(|e| format!("unable to query inscriptions table: {}", e.to_string()))?;
|
||||
let mut results = vec![];
|
||||
let mut rows = stmt.query(args).unwrap();
|
||||
let mut rows = stmt.query(args)
|
||||
.map_err(|e| format!("unable to query inscriptions table: {}", e.to_string()))?;
|
||||
while let Ok(Some(row)) = rows.next() {
|
||||
let inscription_id: String = row.get(0).unwrap();
|
||||
let inscription_number: u64 = row.get(1).unwrap();
|
||||
@@ -425,7 +426,7 @@ pub fn find_inscriptions_at_wached_outpoint(
|
||||
offset,
|
||||
});
|
||||
}
|
||||
return results;
|
||||
return Ok(results);
|
||||
}
|
||||
|
||||
pub fn insert_entry_in_blocks(
|
||||
|
||||
@@ -153,7 +153,7 @@ pub fn update_hord_db_and_augment_bitcoin_block(
|
||||
new_block,
|
||||
&mut Storage::Sqlite(rw_hord_db_conn),
|
||||
&ctx,
|
||||
);
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_transfer_data(
|
||||
block: &mut BitcoinBlockData,
|
||||
storage: &mut Storage,
|
||||
ctx: &Context,
|
||||
) {
|
||||
) -> Result<(), String> {
|
||||
let mut cumulated_fees = 0;
|
||||
let first_sat_post_subsidy = Height(block.block_identifier.index).starting_sat().0;
|
||||
let coinbase_txid = &block.transactions[0].transaction_identifier.hash.clone();
|
||||
@@ -291,7 +291,7 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_transfer_data(
|
||||
|
||||
let entries = match storage {
|
||||
Storage::Sqlite(rw_hord_db_conn) => {
|
||||
find_inscriptions_at_wached_outpoint(&outpoint_pre_transfer, &rw_hord_db_conn)
|
||||
find_inscriptions_at_wached_outpoint(&outpoint_pre_transfer, &rw_hord_db_conn)?
|
||||
}
|
||||
Storage::Memory(ref mut map) => match map.remove(&outpoint_pre_transfer) {
|
||||
Some(entries) => entries,
|
||||
@@ -424,4 +424,5 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_transfer_data(
|
||||
}
|
||||
cumulated_fees += new_tx.metadata.fee;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user