diff --git a/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs b/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs index 4a80483e2..f40706e47 100644 --- a/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs +++ b/src/components/abciapp/src/api/query_server/query_api/ledger_api.rs @@ -121,8 +121,10 @@ pub async fn query_utxos( if sid_list.len() > 10 || sid_list.is_empty() { return Err(actix_web::error::ErrorBadRequest("Invalid Query List")); } - - Ok(web::Json(ledger.get_utxos(sid_list.as_slice()))) + match ledger.get_utxos(sid_list.as_slice()) { + Ok(v) => Ok(web::Json(v)), + Err(e) => Err(actix_web::error::ErrorBadRequest(format!("{:?}", e))), + } } /// query asset according to `AssetType` diff --git a/src/ledger/src/store/mod.rs b/src/ledger/src/store/mod.rs index 1975d7d59..df4ffae74 100644 --- a/src/ledger/src/store/mod.rs +++ b/src/ledger/src/store/mod.rs @@ -730,16 +730,19 @@ impl LedgerState { } #[allow(missing_docs)] - pub fn get_utxos(&self, sid_list: &[TxoSID]) -> Vec> { + pub fn get_utxos( + &self, + sid_list: &[TxoSID], + ) -> Result>> { let mut utxos = vec![]; for sid in sid_list.iter() { let utxo = self.status.get_utxo(*sid); if let Some(utxo) = utxo { - let txn_location = self.status.txo_to_txn_location.get(sid).unwrap(); - let authenticated_txn = self.get_transaction(txn_location.0).unwrap(); + let txn_location = self.status.txo_to_txn_location.get(sid).c(d!())?; + let authenticated_txn = self.get_transaction(txn_location.0)?; let authenticated_spent_status = self.get_utxo_status(*sid); let state_commitment_data = - self.status.state_commitment_data.as_ref().unwrap().clone(); + self.status.state_commitment_data.clone().c(d!())?; let utxo_location = txn_location.1; let auth_utxo = AuthenticatedUtxo { utxo, @@ -754,7 +757,7 @@ impl LedgerState { } } - utxos + Ok(utxos) } #[allow(missing_docs)]