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
|
*state
|
||||||
.utilization
|
.utilization
|
||||||
.get_mut(&creditor)
|
.entry(creditor)
|
||||||
.unwrap()
|
.or_default()
|
||||||
.get_mut(&info.sender)
|
.entry(info.sender)
|
||||||
.unwrap() += amount;
|
.or_default() += amount;
|
||||||
Ok(state)
|
Ok(state)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -131,13 +131,18 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
|
||||||
|
|
||||||
pub mod query {
|
pub mod query {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::msg::GetObligationsResponse;
|
use crate::msg::GetObligationsResponse;
|
||||||
|
|
||||||
pub fn get_obligations(deps: Deps, creditor: Addr) -> StdResult<GetObligationsResponse> {
|
pub fn get_obligations(deps: Deps, creditor: Addr) -> StdResult<GetObligationsResponse> {
|
||||||
let state = STATE.load(deps.storage)?;
|
let state = STATE.load(deps.storage)?;
|
||||||
Ok(GetObligationsResponse {
|
Ok(GetObligationsResponse {
|
||||||
obligations: state.utilization[&creditor].clone(),
|
obligations: state
|
||||||
|
.utilization
|
||||||
|
.get(&creditor)
|
||||||
|
.unwrap_or(&HashMap::new())
|
||||||
|
.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue