Skip to content

Commit

Permalink
update code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
jessiemongeon1 committed Nov 22, 2024
1 parent e023626 commit cb0a39a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 48 deletions.
15 changes: 2 additions & 13 deletions docs/developer-docs/smart-contracts/maintain/history.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,20 @@ actor Info {

<TabItem value="rust" label="Rust">

View the [Rust `canister-info` sample project](https://github.com/dfinity/examples/blob/master/rust/canister-info/src/lib.rs) for a detailed example of how to use `canister_info` in a Rust canister.
```rust file=../../../references/samples/rust/canister-info/src/lib.rs
```

</TabItem>

<AdornedTab value={"typescript"} label="TypeScript" endAdornment={<BetaChip />}>

```typescript

Azle code coming soon.

[Learn more about Azle](https://demergent-labs.github.io/azle/get_started.html).

```
</AdornedTab>

<AdornedTab value={"python"} label="Python" endAdornment={<BetaChip />}>

```typescript

Kybra code coming soon.

[Learn more about Kybra](https://demergent-labs.github.io/kybra/).

```
</AdornedTab>
</AdornedTabs>
2 changes: 1 addition & 1 deletion docs/developer-docs/smart-contracts/maintain/import.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Service providers should use the following deployment process to deploy their `p
- #### Step 1: From within your project's repo, deploy the canister to the mainnet with the command:

```
dfx deploy <canister_name> --network ic
dfx deploy <canister-name> --network ic
```

- #### Step 2: If you're using GitHub, `git tag` and `GitHub release` with the commands:
Expand Down
12 changes: 6 additions & 6 deletions docs/developer-docs/smart-contracts/maintain/logs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The <GlossaryTooltip>canister</GlossaryTooltip> logging feature is designed to p
A canister's controller is able to retrieve the canister's logs, even when executions trap, using [`dfx canister logs`](/docs/current/developer-docs/developer-tools/cli-tools/cli-reference/dfx-canister#dfx-canister-logs):

```
dfx canister logs <CANISTER_NAME>
dfx canister logs <canister-name>
```

:::info
Expand All @@ -38,7 +38,7 @@ Non-replicated calls are not currently supported for logging.
By default, a canister's logs are only visible to the controllers of the canister. A canister's logs can be made public by updating the canister's settings with [`dfx canister update-settings`](/docs/current/developer-docs/developer-tools/cli-tools/cli-reference/dfx-canister#dfx-canister-update-settings) command:

```bash
dfx canister update-settings CANISTER_ID --log-visibility public
dfx canister update-settings <canister-name> --log-visibility public
```

### Log viewer allow lists
Expand All @@ -47,16 +47,16 @@ Canister log allow lists enable principals that are not controllers of the canis

To add a principal to the canister's log allow list, update the canister's settings with the flags:

- `dfx canister update-settings CANISTER_ID --set-log-viewer PRINCIPAL_ID`: Set a single principal as a log viewer.
- `dfx canister update-settings <canister-name> --set-log-viewer PRINCIPAL_ID`: Set a single principal as a log viewer.

- `dfx canister update-settings CANISTER_ID --add-log-viewer PRINCIPAL_ID`: Add a principal to a list of log viewers.
- `dfx canister update-settings <canister-name> --add-log-viewer PRINCIPAL_ID`: Add a principal to a list of log viewers.

- `dfx canister update-settings CANISTER_ID --remove-log-viewer PRINCIPAL_ID`: Remove a principal from the log viewer list.
- `dfx canister update-settings <canister-name> --remove-log-viewer PRINCIPAL_ID`: Remove a principal from the log viewer list.

You can also configure a principal as a log viewer when you create a canister:

```
dfx canister create CANISTER_NAME --log-viewer PRINCIPAL_ID
dfx canister create <canister-name> --log-viewer PRINCIPAL_ID
```

Or, you can set the `canisters[].initialization_values.log_visibility.allowed_viewers` configuration setting in your project's `dfx.json` file.
17 changes: 0 additions & 17 deletions docs/developer-docs/smart-contracts/maintain/recovery.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,3 @@ One method for recovering a canister is to roll the canister back to a snapshot
## Recovering a canister that does not have controllers

If a canister is unable to be upgraded via any of the canister's existing controllers, either due to the canister not having controllers or loss of access to the canister's controllers, there is no supported method to recover that canister.

## Recovering a canister with an NNS proposal

If a canister does not have a snapshot that can be used for recovery, one possible last resort recovery method can be used, however it requires that the canister have the NNS root canister `r7inp-6aaaa-aaaaa-aaabq-cai` configured as a controller of the canister.

To add the NNS root canister as a controller of your canister, use the command:

```sh
dfx canister update-settings CANISTER_NAME --network ic --add-controller r7inp-6aaaa-aaaaa-aaabq-cai
```

:::info
This step cannot be taken after access to a canister's controllers is already lost, since only a current controller of the canister can add additional controllers. If a canister's code has failed and cannot be upgraded, but access to the canister's controllers is possible, then this step can be performed.
:::

Then, when the canister needs to be recovered, it may be recovered by using the System Canister Management NNS proposal used for upgrading all system canisters. When submitting this proposal, include the canister ID of the broken canister and a new Wasm module for the canister. Once this proposal is submitted, the NNS DAO will vote on whether to upgrade the canister using the proposed new Wasm file or not. If the proposal is passed, the canister will be upgraded and potentially recovered.

17 changes: 7 additions & 10 deletions docs/developer-docs/smart-contracts/maintain/settings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Currently, there are seven canister setting fields:

There are two ways to read the settings of a canister:

1. Command line: [`dfx canister status <canister-id>`](/docs/current/developer-docs/developer-tools/cli-tools/cli-reference/dfx-canister#dfx-canister-status). Note that this command returns the canister's settings, along with other canister status information.
1. Command line: [`dfx canister status <canister-name>`](/docs/current/developer-docs/developer-tools/cli-tools/cli-reference/dfx-canister#dfx-canister-status). Note that this command returns the canister's settings, along with other canister status information.
2. Programmatically: Call the [`canister_status`](https://internetcomputer.org/docs/current/references/ic-interface-spec) endpoint of the IC management canister. The canister's settings will be in the `settings` field of the result.

### Command line
Expand Down Expand Up @@ -71,27 +71,24 @@ Log visibility: controllers
<AdornedTabs groupId="language">
<TabItem value="motoko" label="Motoko" default>

For an example of how to use `canister_status` in your Motoko code, view the [sample application](https://github.com/dfinity/examples/blob/master/motoko/query_stats/src/query_stats_backend/main.mo).
```motoko no-repl file=../../../references/samples/motoko/query_stats/src/query_stats_backend/main.mo
```

</TabItem>
<TabItem value="rust" label="Rust">

For an example of how to use `canister_status` in your Rust code, view the [sample application](https://github.com/dfinity/examples/blob/master/rust/query_stats/src/lib.rs).

```rust file=../../../references/samples/rust/query_stats/src/query_stats_backend/src/lib.rs
```
</TabItem>

<AdornedTab value={"typescript"} label="TypeScript" endAdornment={<BetaChip />}>

Azle code coming soon.

[Learn more about Azle](https://demergent-labs.github.io/azle/the_azle_book.html).

</AdornedTab>

<AdornedTab value={"python"} label="Python" endAdornment={<BetaChip />}>

Kybra code coming soon.

[Learn more about Kybra](https://demergent-labs.github.io/kybra/).

</AdornedTab>
Expand All @@ -101,15 +98,15 @@ Kybra code coming soon.

There are two ways to modify the settings of a canister:

1. Command line: `dfx canister update-settings <canister-id> --<field-name> <field-value>`.
1. Command line: `dfx canister update-settings <canister-name> --<field-name> <field-value>`.
1. Programmatically: Call the [`update_settings`](/docs/current/references/ic-interface-spec#ic-update_settings) endpoint of the IC management canister.

Note that only a controller of the canister can modify canister settings.

### Command line

```bash
dfx canister update-settings ajuq4-ruaaa-aaaaa-qaaga-cai --wasm-memory-limit 3000000000
dfx canister update-settings my_canister --wasm-memory-limit 3000000000
```

### Programmatically
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-docs/smart-contracts/maintain/storage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ This garbage collector is still in beta testing and should be used with caution.

### Rust storage handling

To utilize stable memory for canisters written in Rust, the crates [ic-stable-memory](https://github.com/seniorjoinu/ic-stable-memory) and [ic-stable-structures](https://github.com/dfinity/stable-structures) can be used. It is recommended to review the documentation for these crates to learn more, or [review the tutorial on the stable structures crate](https://mmapped.blog/posts/14-stable-structures.html).
To utilize stable memory for canisters written in Rust, the crate [ic-stable-structures](https://github.com/dfinity/stable-structures) can be used. It is recommended to review the documentation for these crates to learn more, or [review the tutorial on the stable structures crate](https://mmapped.blog/posts/14-stable-structures.html).

As good practice, stable memory should be versioned since the stable memory decoding mechanism may need to guess the data's format in situations where the serialization format or stable data layout of a canister drastically changes. This can be as simple as declaring that the first byte of the canister's stable memory will be used to represent the version number.

Expand Down

0 comments on commit cb0a39a

Please sign in to comment.