Skip to content

Commit

Permalink
fix rpc query_utxos (#1001)
Browse files Browse the repository at this point in the history
Co-authored-by: Your Name <[email protected]>
  • Loading branch information
shaorongqiang and Your Name authored Jul 31, 2023
1 parent 0c89713 commit 8852e77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
13 changes: 8 additions & 5 deletions src/ledger/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,16 +730,19 @@ impl LedgerState {
}

#[allow(missing_docs)]
pub fn get_utxos(&self, sid_list: &[TxoSID]) -> Vec<Option<AuthenticatedUtxo>> {
pub fn get_utxos(
&self,
sid_list: &[TxoSID],
) -> Result<Vec<Option<AuthenticatedUtxo>>> {
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,
Expand All @@ -754,7 +757,7 @@ impl LedgerState {
}
}

utxos
Ok(utxos)
}

#[allow(missing_docs)]
Expand Down

0 comments on commit 8852e77

Please sign in to comment.