uploads a wasm chunk to the ICP chunk store
(target_canister: Principal, chunk: Vec<u8>)
| 104 | |
| 105 | // uploads a wasm chunk to the ICP chunk store |
| 106 | async 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 | |
| 127 | pub async fn install_chunked_code( |
| 128 | target_canister: Principal, |
no test coverage detected