Use entry API for HashMap
This commit is contained in:
parent
c58ec93f08
commit
4bb6dfbeff
1 changed files with 10 additions and 5 deletions
|
@ -66,10 +66,10 @@ pub mod execute {
|
|||
|
||||
*state
|
||||
.utilization
|
||||
.get_mut(&creditor)
|
||||
.unwrap()
|
||||
.get_mut(&info.sender)
|
||||
.unwrap() += amount;
|
||||
.entry(creditor)
|
||||
.or_default()
|
||||
.entry(info.sender)
|
||||
.or_default() += amount;
|
||||
Ok(state)
|
||||
})?;
|
||||
|
||||
|
@ -131,13 +131,18 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
|||
|
||||
pub mod query {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::msg::GetObligationsResponse;
|
||||
|
||||
pub fn get_obligations(deps: Deps, creditor: Addr) -> StdResult<GetObligationsResponse> {
|
||||
let state = STATE.load(deps.storage)?;
|
||||
Ok(GetObligationsResponse {
|
||||
obligations: state.utilization[&creditor].clone(),
|
||||
obligations: state
|
||||
.utilization
|
||||
.get(&creditor)
|
||||
.unwrap_or(&HashMap::new())
|
||||
.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue