Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/ic-certified-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ struct GetArg {
accept_encodings: Vec<String>,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
struct GetChunksInfoArg {
key: Key,
content_encoding: String,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
struct GetChunkArg {
key: Key,
Expand Down Expand Up @@ -203,6 +209,18 @@ struct HttpRequest {
body: ByteBuf,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
struct ChunkInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to have certification of these results and to add certification for the get_chunk call. I don't know if we need to do that in this PR though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jplevyak
yes, most likely it is better to make a separate PR.
I am currently working on my own certified-assets-based chunk certification solution. If I succeed, then I will definitely share them in the PR format in order to at least discuss the solution

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jplevyak done :)
#219

chunk_id: ChunkId,
chunk_length: u64,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
struct ChunksInfoReponse {
total_length: u64,
chunks: Vec<ChunkInfo>,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
struct HttpResponse {
status_code: u16,
Expand Down Expand Up @@ -402,6 +420,33 @@ fn get(arg: GetArg) -> EncodedAsset {
})
}

#[query]
fn get_chunks_info(arg: GetChunksInfoArg) -> ChunksInfoReponse {
STATE.with(|s| {
let assets = s.assets.borrow();
let asset = assets.get(&arg.key).unwrap_or_else(|| {
trap("asset not found");
});

let mut result = ChunksInfoReponse {
total_length: 0,
chunks: vec![],
};

if let Some(asset_enc) = asset.encodings.get(&arg.content_encoding) {
for (i, chunk) in asset_enc.content_chunks.iter().enumerate() {
let chunk_length = chunk.len() as u64;
result.total_length += chunk_length;
result.chunks.push(ChunkInfo {
chunk_id: Nat::from(i),
chunk_length,
});
}
}
result
})
}

#[query]
fn get_chunk(arg: GetChunkArg) -> GetChunkResponse {
STATE.with(|s| {
Expand Down