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

refactor: destruct candid service in ic-mgmt #757

Merged
merged 3 commits into from
Nov 20, 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
26 changes: 13 additions & 13 deletions packages/ic-management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Update canister settings
| ---------------- | ------------------------------------------------------------------------------------------- |
| `updateSettings` | `({ canisterId, senderCanisterVersion, settings, }: UpdateSettingsParams) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L99)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L101)

##### :gear: installCode

Expand All @@ -110,7 +110,7 @@ Install code to a canister
| ------------- | ----------------------------------------------------------------------------------------------------- |
| `installCode` | `({ mode, canisterId, wasmModule, arg, senderCanisterVersion, }: InstallCodeParams) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L121)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L126)

##### :gear: uploadChunk

Expand All @@ -125,7 +125,7 @@ Parameters:
- `params.canisterId`: The canister in which the chunks will be stored.
- `params.chunk`: A chunk of Wasm module.

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L146)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L154)

##### :gear: clearChunkStore

Expand All @@ -139,7 +139,7 @@ Parameters:

- `params.canisterId`: The canister in which the chunks are stored.

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L166)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L174)

##### :gear: storedChunks

Expand All @@ -153,7 +153,7 @@ Parameters:

- `params.canisterId`: The canister in which the chunks are stored.

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L185)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L193)

##### :gear: installChunkedCode

Expand All @@ -173,7 +173,7 @@ Parameters:
- `params.storeCanisterId`: Specifies the canister in whose chunk storage the chunks are stored (this parameter defaults to target_canister if not specified).
- `params.wasmModuleHash`: The Wasm module hash as hex string. Used to check that the SHA-256 hash of wasm_module is equal to the wasm_module_hash parameter and can calls install_code with parameters.

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L210)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L218)

##### :gear: uninstallCode

Expand All @@ -183,7 +183,7 @@ Uninstall code from a canister
| --------------- | -------------------------------------------------------------------------------- |
| `uninstallCode` | `({ canisterId, senderCanisterVersion, }: UninstallCodeParams) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L243)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L251)

##### :gear: startCanister

Expand All @@ -193,7 +193,7 @@ Start a canister
| --------------- | ------------------------------------------ |
| `startCanister` | `(canisterId: Principal) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L258)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L269)

##### :gear: stopCanister

Expand All @@ -203,7 +203,7 @@ Stop a canister
| -------------- | ------------------------------------------ |
| `stopCanister` | `(canisterId: Principal) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L267)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L281)

##### :gear: canisterStatus

Expand All @@ -213,7 +213,7 @@ Get canister details (memory size, status, etc.)
| ---------------- | ------------------------------------------------------------ |
| `canisterStatus` | `(canisterId: Principal) => Promise<canister_status_result>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L276)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L292)

##### :gear: deleteCanister

Expand All @@ -223,7 +223,7 @@ Deletes a canister
| ---------------- | ------------------------------------------ |
| `deleteCanister` | `(canisterId: Principal) => Promise<void>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L287)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L306)

##### :gear: provisionalCreateCanisterWithCycles

Expand All @@ -233,7 +233,7 @@ Creates a canister. Only available on development instances.
| ------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `provisionalCreateCanisterWithCycles` | `({ settings, amount, canisterId, }?: ProvisionalCreateCanisterWithCyclesParams) => Promise<Principal>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L299)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L321)

##### :gear: fetchCanisterLogs

Expand All @@ -243,7 +243,7 @@ Given a canister ID as input, this method returns a vector of logs of that canis
| ------------------- | ---------------------------------------------------------------- |
| `fetchCanisterLogs` | `(canisterId: Principal) => Promise<fetch_canister_logs_result>` |

[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L321)
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/ic-management/src/ic-management.canister.ts#L344)

<!-- TSDOC_END -->

Expand Down
74 changes: 50 additions & 24 deletions packages/ic-management/src/ic-management.canister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export class ICManagementCanister {
settings,
senderCanisterVersion,
}: CreateCanisterParams = {}): Promise<Principal> => {
const { canister_id } = await this.service.create_canister({
const { create_canister } = this.service;
peterpeterparker marked this conversation as resolved.
Show resolved Hide resolved

const { canister_id } = await create_canister({
settings: toNullable(toCanisterSettings(settings)),
sender_canister_version: toNullable(senderCanisterVersion),
});
Expand All @@ -100,12 +102,15 @@ export class ICManagementCanister {
canisterId,
senderCanisterVersion,
settings,
}: UpdateSettingsParams): Promise<void> =>
this.service.update_settings({
}: UpdateSettingsParams): Promise<void> => {
const { update_settings } = this.service;

return update_settings({
canister_id: canisterId,
sender_canister_version: toNullable(senderCanisterVersion),
settings: toCanisterSettings(settings),
});
};

/**
* Install code to a canister
Expand All @@ -124,14 +129,17 @@ export class ICManagementCanister {
wasmModule,
arg,
senderCanisterVersion,
}: InstallCodeParams): Promise<void> =>
this.service.install_code({
}: InstallCodeParams): Promise<void> => {
const { install_code } = this.service;

return install_code({
mode: toInstallMode(mode),
canister_id: canisterId,
wasm_module: wasmModule,
arg,
sender_canister_version: toNullable(senderCanisterVersion),
});
};

/**
* Upload chunks of Wasm modules that are too large to fit in a single message for installation purposes.
Expand Down Expand Up @@ -243,49 +251,63 @@ export class ICManagementCanister {
uninstallCode = ({
canisterId,
senderCanisterVersion,
}: UninstallCodeParams): Promise<void> =>
this.service.uninstall_code({
}: UninstallCodeParams): Promise<void> => {
const { uninstall_code } = this.service;

return uninstall_code({
canister_id: canisterId,
sender_canister_version: toNullable(senderCanisterVersion),
});
};

/**
* Start a canister
*
* @param {Principal} canisterId
* @returns {Promise<void>}
*/
startCanister = (canisterId: Principal): Promise<void> =>
this.service.start_canister({ canister_id: canisterId });
startCanister = (canisterId: Principal): Promise<void> => {
const { start_canister } = this.service;

return start_canister({ canister_id: canisterId });
};

/**
* Stop a canister
*
* @param {Principal} canisterId
* @returns {Promise<void>}
*/
stopCanister = (canisterId: Principal): Promise<void> =>
this.service.stop_canister({ canister_id: canisterId });
stopCanister = (canisterId: Principal): Promise<void> => {
const { stop_canister } = this.service;
return stop_canister({ canister_id: canisterId });
};

/**
* Get canister details (memory size, status, etc.)
*
* @param {Principal} canisterId
* @returns {Promise<CanisterStatusResponse>}
*/
canisterStatus = (canisterId: Principal): Promise<CanisterStatusResponse> =>
this.service.canister_status({
canisterStatus = (canisterId: Principal): Promise<CanisterStatusResponse> => {
const { canister_status } = this.service;

return canister_status({
canister_id: canisterId,
});
};

/**
* Deletes a canister
*
* @param {Principal} canisterId
* @returns {Promise<void>}
*/
deleteCanister = (canisterId: Principal): Promise<void> =>
this.service.delete_canister({ canister_id: canisterId });
deleteCanister = (canisterId: Principal): Promise<void> => {
const { delete_canister } = this.service;

return delete_canister({ canister_id: canisterId });
};

/**
* Creates a canister. Only available on development instances.
Expand All @@ -301,13 +323,14 @@ export class ICManagementCanister {
amount,
canisterId,
}: ProvisionalCreateCanisterWithCyclesParams = {}): Promise<Principal> => {
const { canister_id } =
await this.service.provisional_create_canister_with_cycles({
settings: toNullable(toCanisterSettings(settings)),
amount: toNullable(amount),
specified_id: toNullable(canisterId),
sender_canister_version: [],
});
const { provisional_create_canister_with_cycles } = this.service;

const { canister_id } = await provisional_create_canister_with_cycles({
settings: toNullable(toCanisterSettings(settings)),
amount: toNullable(amount),
specified_id: toNullable(canisterId),
sender_canister_version: [],
});

return canister_id;
};
Expand All @@ -320,8 +343,11 @@ export class ICManagementCanister {
*/
fetchCanisterLogs = (
canisterId: Principal,
): Promise<FetchCanisterLogsResponse> =>
this.service.fetch_canister_logs({
): Promise<FetchCanisterLogsResponse> => {
const { fetch_canister_logs } = this.service;

return fetch_canister_logs({
canister_id: canisterId,
});
};
}
Loading