fix: safer error handling

This commit is contained in:
Ludo Galabru
2023-04-04 12:39:11 -04:00
parent 741ac8473b
commit 11509e4435
3 changed files with 10 additions and 8 deletions

View File

@@ -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,

View File

@@ -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(

View File

@@ -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(())
}