Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rpc query_utxos #1001

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading