Remove all unwrap() calls

This commit is contained in:
junderw
2023-06-24 16:41:53 -07:00
committed by Mononaut
parent 4661bea2f0
commit dfe24ed9d7
3 changed files with 20 additions and 9 deletions

View File

@@ -27,7 +27,9 @@ pub fn make(mempool_buffer: Uint8Array, callback: JsFunction) -> Result<()> {
map.insert(tx.uid, tx);
}
let mut global_map = THREAD_TRANSACTIONS.lock().unwrap();
let mut global_map = THREAD_TRANSACTIONS
.lock()
.map_err(|_| napi::Error::from_reason("THREAD_TRANSACTIONS Mutex poisoned"))?;
*global_map = map;
run_in_thread(callback)
@@ -37,7 +39,9 @@ pub fn make(mempool_buffer: Uint8Array, callback: JsFunction) -> Result<()> {
ts_args_type = "newTxs: Uint8Array, removeTxs: Uint8Array, callback: (result: GbtResult) => void"
)]
pub fn update(new_txs: Uint8Array, remove_txs: Uint8Array, callback: JsFunction) -> Result<()> {
let mut map = THREAD_TRANSACTIONS.lock().unwrap();
let mut map = THREAD_TRANSACTIONS
.lock()
.map_err(|_| napi::Error::from_reason("THREAD_TRANSACTIONS Mutex poisoned"))?;
for tx in ThreadTransaction::batch_from_buffer(&new_txs) {
map.insert(tx.uid, tx);
}