Skip to content

Commit

Permalink
feat(objectarium): include bucket statistics in bucket information query
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Jun 11, 2024
1 parent a9be78d commit 8728049
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions contracts/axone-objectarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ pub mod query {
config: bucket.config.into(),
limits: bucket.limits.into(),
pagination: bucket.pagination.into(),
stat: bucket.stat.into(),
})
}

Expand Down
16 changes: 16 additions & 0 deletions contracts/axone-objectarium/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ pub struct BucketResponse {
pub limits: BucketLimits,
/// The configuration for paginated query.
pub pagination: PaginationConfig,
/// The statistics of the bucket.
pub stat: BucketStat,
}

/// CompressionAlgorithm is an enumeration that defines the different compression algorithms
Expand Down Expand Up @@ -351,6 +353,20 @@ impl Default for PaginationConfig {
}
}

/// # BucketStat
///
/// BucketStat is the type of the statistics of a bucket.
#[cw_serde]
#[derive(Default, Builder)]
pub struct BucketStat {
/// The total size of the objects contained in the bucket.
pub size: Uint128,
/// The total size of the objects contained in the bucket after compression.
pub compressed_size: Uint128,
/// The number of objects in the bucket.
pub object_count: Uint128,
}

/// # ObjectResponse
/// ObjectResponse is the response of the Object query.
#[cw_serde]
Expand Down
10 changes: 9 additions & 1 deletion contracts/axone-objectarium/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ impl From<BucketLimits> for msg::BucketLimits {
}
}

impl From<BucketStat> for msg::BucketStat {
fn from(stat: BucketStat) -> Self {
msg::BucketStat {
size: stat.size,
compressed_size: stat.compressed_size,
object_count: stat.object_count,
}
}
}
impl BucketLimits {
fn try_new(
max_total_size: Option<Uint128>,
Expand Down Expand Up @@ -262,7 +271,6 @@ impl TryFrom<msg::BucketLimits> for BucketLimits {
)
}
}

/// Pagination is the type carrying configuration for paginated queries.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct Pagination {
Expand Down

0 comments on commit 8728049

Please sign in to comment.