Skip to content

Commit

Permalink
feat(storage): load buckect only if object exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Mar 9, 2023
1 parent 4bb1af0 commit 57327db
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions contracts/cw-storage/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ pub mod execute {
info: MessageInfo,
object_id: ObjectId,
) -> Result<Response, ContractError> {
let res = Response::new()
.add_attribute("action", "pin_object")
.add_attribute("id", object_id.clone());

if pins().has(deps.storage, (object_id.clone(), info.sender.clone())) {
return Ok(Response::new()
.add_attribute("action", "pin_object")
.add_attribute("id", object_id));
return Ok(res);
}

let bucket = BUCKET.load(deps.storage)?;

let o = objects().update(
deps.storage,
object_id.clone(),
Expand All @@ -146,6 +146,8 @@ pub mod execute {
},
)?;

let bucket = BUCKET.load(deps.storage)?;

match bucket.limits {
Limits {
max_object_pins: Some(max),
Expand All @@ -158,13 +160,11 @@ pub mod execute {
deps.storage,
(object_id.clone(), info.sender.clone()),
&Pin {
id: object_id.clone(),
id: object_id,
address: info.sender,
},
)?;
Ok(Response::new()
.add_attribute("action", "pin_object")
.add_attribute("id", object_id))
Ok(res)
}
}
}
Expand Down

0 comments on commit 57327db

Please sign in to comment.