MCPcopy Create free account
hub / github.com/dfinity/orbit / upload_chunk

Function upload_chunk

libs/orbit-essentials/src/install_chunked_code.rs:106–125  ·  view source on GitHub ↗

uploads a wasm chunk to the ICP chunk store

(target_canister: Principal, chunk: Vec<u8>)

Source from the content-addressed store, hash-verified

104
105// uploads a wasm chunk to the ICP chunk store
106async fn upload_chunk(target_canister: Principal, chunk: Vec<u8>) -> Result<Vec<u8>, String> {
107 let mut hasher = Sha256::new();
108 hasher.update(chunk.clone());
109 let chunk_hash = hasher.finalize().to_vec();
110 let actual_hash = mgmt::upload_chunk(UploadChunkArgument {
111 canister_id: target_canister,
112 chunk,
113 })
114 .await
115 .map_err(|(_, err)| format!("failed to upload chunk: {err}"))?
116 .0;
117 if actual_hash.hash != chunk_hash {
118 return Err(format!(
119 "chunk hash mismatch (expected hash: {}, actual hash: {})",
120 hex::encode(chunk_hash),
121 hex::encode(&actual_hash.hash)
122 ));
123 }
124 Ok(chunk_hash)
125}
126
127pub async fn install_chunked_code(
128 target_canister: Principal,

Callers 1

install_chunked_codeFunction · 0.85

Calls 2

updateMethod · 0.80
to_vecMethod · 0.80

Tested by

no test coverage detected