Skip to content

Commit

Permalink
feat(storage): add total size to bucket state
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Mar 3, 2023
1 parent 467c2da commit ce5d622
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions contracts/cw-storage/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct Bucket {
pub name: String,
/// The limits of the bucket.
pub limits: Limits,
/// The total size of the objects contained in the bucket.
pub size: u128,
}

impl Bucket {
Expand All @@ -23,7 +25,11 @@ impl Bucket {
return Err(EmptyName);
}

Ok(Self { name: n, limits })
Ok(Self {
name: n,
limits,
size: 0u128,
})
}
}

Expand Down Expand Up @@ -61,7 +67,7 @@ pub struct Object {
/// The owner of the object.
pub owner: Addr,
/// The size of the object.
pub size: Uint128,
pub size: u128,
}

pub struct ObjectIndexes<'a> {
Expand Down Expand Up @@ -97,30 +103,17 @@ pub struct PinIndexes<'a> {
}

impl IndexList<Pin> for PinIndexes<'_> {
fn get_indexes(&'_ self) -> Box<dyn Iterator<Item=&'_ dyn Index<Pin>> + '_> {
Box::new(
vec![
&self.object as &dyn Index<Pin>,
&self.address
].into_iter()
)
fn get_indexes(&'_ self) -> Box<dyn Iterator<Item = &'_ dyn Index<Pin>> + '_> {
Box::new(vec![&self.object as &dyn Index<Pin>, &self.address].into_iter())
}
}

pub fn pins<'a>() -> IndexedMap<'a, (String, Addr), Pin, PinIndexes<'a>> {
IndexedMap::new(
"PIN",
PinIndexes {
object: MultiIndex::new(
|_, pin| pin.id.clone(),
"PIN",
"PIN__OBJECT",
),
address: MultiIndex::new(
|_, pin| pin.address.clone(),
"PIN",
"PIN__ADDRESS",
),
}
object: MultiIndex::new(|_, pin| pin.id.clone(), "PIN", "PIN__OBJECT"),
address: MultiIndex::new(|_, pin| pin.address.clone(), "PIN", "PIN__ADDRESS"),
},
)
}

0 comments on commit ce5d622

Please sign in to comment.