Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose upgrade module #219

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/admin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './errors/upgrade.errors';
export * from './services/mission-control.controllers.services';
export * from './services/mission-control.upgrade.services';
export * from './services/mission-control.version.services';
export * from './services/module.upgrade.services';
export * from './services/orbiter.controllers.services';
export * from './services/orbiter.memory.services';
export * from './services/orbiter.upgrade.services';
Expand Down
28 changes: 28 additions & 0 deletions packages/admin/src/services/module.upgrade.services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {upgrade} from '../handlers/upgrade.handlers';
import type {ActorParameters} from '../types/actor.types';
import type {UpgradeCodeParams} from '../types/upgrade.types';

/**
* Upgrades a module with the provided WASM code and arguments. This generic is notably useful for Juno Docker.
*
* @param {Object} params - Parameters for upgrading the module.
* @param {ActorParameters} params.actor - The actor parameters associated with the module.
* @param {Principal} params.canisterId - The ID of the canister being upgraded.
* @param {Principal} [params.missionControlId] - Optional. An ID to store and reuse WASM chunks across installations.
* @param {Uint8Array} params.wasmModule - The WASM code to be installed during the upgrade.
* @param {Uint8Array} params.arg - The initialization argument for the module upgrade.
* @param {canister_install_mode} params.mode - The installation mode, e.g., `upgrade` or `reinstall`.
* @param {boolean} [params.preClearChunks] - Optional. Forces clearing existing chunks before uploading a chunked WASM module. Recommended for WASM modules larger than 2MB.
* @param {function} [params.onProgress] - Optional. Callback function to track progress during the upgrade process.
* @param {boolean} [params.reset=false] - Optional. Specifies whether to reset the module (reinstall) instead of performing an upgrade. Defaults to `false`.
* @throws {Error} Will throw an error if the parameters are invalid or if the upgrade process fails.
* @returns {Promise<void>} Resolves when the upgrade process is complete.
*/
export const upgradeModule = async (
params: {
actor: ActorParameters;
reset?: boolean;
} & UpgradeCodeParams
): Promise<void> => {
await upgrade(params);
};