Skip to content

Commit

Permalink
Idiomatic filter / maps
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Jun 17, 2023
1 parent 1647f6b commit 7198e05
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions contracts/provider/vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,24 @@ impl VaultContract<'_> {
account
.as_ref()
.map(|(_, account_lock)| {
match account_lock.read() {
Ok(account) => !with_collateral || !account.collateral.is_zero(), // Skip zero collateral
Err(_) => false, // Skip write-locked accounts
}
account_lock
.read()
.map(|account| !with_collateral || !account.collateral.is_zero()) // Skip zero collateral
.unwrap_or(false) // Skip write-locked accounts
})
.unwrap_or(false)
.unwrap_or(false) // Skip other errors
})
.map(|account| {
let (addr, account_lock) = account?;
let account = account_lock.read()?;
Ok::<AllAccountsResponseItem, ContractError>(AllAccountsResponseItem {
account: addr.into(),
denom: denom.clone(),
bonded: account.collateral,
free: account.free_collateral(),
})
account.map(|(addr, account_lock)| {
account_lock.read().map(|account| {
Ok(AllAccountsResponseItem {
account: addr.into(),
denom: denom.clone(),
bonded: account.collateral,
free: account.free_collateral(),
})
})?
})?
})
.take(limit)
.collect::<Result<_, ContractError>>()?;
Expand Down

0 comments on commit 7198e05

Please sign in to comment.