Skip to content

Commit 323c768

Browse files
Update rust readmes
1 parent 80ea550 commit 323c768

File tree

27 files changed

+293
-617
lines changed

27 files changed

+293
-617
lines changed

rust/basic_bitcoin/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Basic Bitcoin
1+
# Basic Bitcoin
22

33
This tutorial will walk you through how to deploy a sample [canister smart contract](https://internetcomputer.org/docs/current/developer-docs/multi-chain/bitcoin/overview) **that can send and receive Bitcoin** on the Internet Computer.
44

@@ -14,7 +14,7 @@ of the Internet Computer.
1414

1515
For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin integration documentation](https://wiki.internetcomputer.org/wiki/Bitcoin_Integration).
1616

17-
### Prerequisites
17+
## Prerequisites
1818

1919
* [x] Install the [IC
2020
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
@@ -111,7 +111,7 @@ from three types of addresses:
111111
key. This precaution is to prevent attacks that can occur when creating
112112
taproot multisigner addresses using specific multisignature schemes. However,
113113
the Schnorr API of the internet computer does not support Schnorr
114-
multisignatures.
114+
multisignatures.
115115
3. A [P2TR
116116
address](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki)
117117
where the funds can be spent using the provided public key with the script
@@ -209,7 +209,7 @@ reflected in your current balance.
209209

210210
## Step 6: Retrieving block headers
211211

212-
You can also get a range of Bitcoin block headers by using the `get_block_headers`
212+
You can also get a range of Bitcoin block headers by using the `get_block_headers`
213213
endpoint on your canister.
214214

215215
In the Candid UI, write the desired start height and optionally end height, and click on "Call":
@@ -233,7 +233,7 @@ In this tutorial, you were able to:
233233
* Connect the canister to the Bitcoin testnet.
234234
* Send the canister some testnet BTC.
235235
* Check the testnet BTC balance of the canister.
236-
* Use the canister to send testnet BTC to another testnet BTC address.
236+
* Use the canister to send testnet BTC to another testnet BTC address.
237237

238238
This example is extensively documented in the following tutorials:
239239

rust/basic_dao/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Certain system parameters, like the number of `Yes` votes needed to pass a propo
1010

1111
View the [canister service definition](https://github.com/dfinity/examples/blob/master/rust/basic_dao/src/basic_dao/src/basic_dao.did) for more details.
1212

13-
### Prerequisites
13+
## Prerequisites
1414
This example requires an installation of:
1515

1616
- [x] The Rust toolchain (e.g. cargo).

rust/basic_ethereum/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ features of the Internet Computer.
1414
For a deeper understanding of the ICP < > ETH integration, see
1515
the [Ethereum integration overview](https://internetcomputer.org/docs/current/developer-docs/multi-chain/ethereum/overview).
1616

17-
### Prerequisites
17+
## Prerequisites
1818

1919
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
2020

rust/canister-snapshots/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The `remove_spam` canister method intentionally includes a bug to simulate data
66
The example outlines the steps to install the canister, create a snapshot,
77
and subsequently restore the data after the simulated data loss.
88

9-
### Prerequisites
9+
## Prerequisites
1010

1111
This example requires an installation of:
1212

rust/canister_logs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Canister logs
22

3-
### Prerequisites
3+
## Prerequisites
44

55
- [x] Install the [IC
66
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.

rust/composite_query/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Composite queries
22

3-
### Prerequisites
3+
## Prerequisites
44
This example requires an installation of:
55

66
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx).

rust/counter/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This example demonstrates a counter application.
44

5-
### Prerequisites
5+
## Prerequisites
66
This example requires an installation of:
77

88
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/).

rust/dip721-nft-container/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ A running instance of the Rust canister for demonstration purposes is available
8686
The interface is meant to be programmatic, but the Rust version additionally contains HTTP functionality so you can view a metadata file at `<canister URL>/<NFT ID>/<file ID>`.
8787
It contains six NFTs, so you can look at items from `<canister URL>/0/0` to `<canister URL>/5/0`.
8888

89-
### Prerequisites
89+
## Prerequisites
9090

9191
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
9292
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`

rust/face-recognition/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ torch.onnx.export(resnet, input, "face-recognition.onnx", verbose=False, opset_v
4949

5050
- #### Step 4: This should produce `face-recognition.onnx`. Copy the file to the root of this repository.
5151

52-
### Prerequisites
52+
## Prerequisites
5353

5454
- [x] Install the [IC
5555
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.

rust/hello/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This example is based on the default project created by running `dfx new hello`.
3636

3737
This example is based on the default project created by running `dfx new --type=rust hello`.
3838

39-
### Prerequisites
39+
## Prerequisites
4040

4141
This example requires an installation of:
4242
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx).

rust/icp_transfer/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The sample code revolves around one core transfer function which takes as input
1313

1414
This sample will use the Rust variant.
1515

16-
### Prerequisites
16+
## Prerequisites
1717

1818
- [x] Install the [IC
1919
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.

rust/nft-wallet/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is an NFT wallet example dapp that utilizes minted NFTs from the Rust dip721-nft-container. Among some of its essential features, the wallet can register NFTs, transfer out NFTs, and check how many NFTs it contains. This dapp includes a frontend UI for interaction.
44

5-
### Prerequisites
5+
## Prerequisites
66

77
- [x] Install the [IC
88
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.

rust/parallel_calls/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The sample code revolves around two simple canisters, `caller` and `callee`. `Ca
1010

1111
The callee exposes a simple `ping` endpoint that takes no parameters and returns nothing.
1212

13-
### Prerequisites
13+
## Prerequisites
1414

1515
- [x] Install the [IC
1616
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.

rust/performance_counters/README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ In the future, ICP might expose more performance counters.
3131

3232
## Prerequisites
3333

34-
## Prerequisites
35-
36-
- [x] Install the [IC
37-
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.
34+
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). For local testing, `dfx >= 0.22.0` is required.
3835
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
3936

4037
## Step 1: Setup project environment

rust/periodic_tasks/README.md

+38-37
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,17 @@ The example consists of two canisters named `heartbeat` and `timer`, both implem
1414
## Prerequisites
1515
This example requires an installation of:
1616

17-
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx).
17+
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
1818
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
1919

20-
### Example 1:
20+
## Example 1: heartbeats and timers
2121

22-
- #### Step 1: Begin by opening a terminal window and navigating into the project's directory.
22+
- ### Step 1: Setup project environment
2323

24-
```sh
25-
cd examples/rust/periodic_tasks
26-
```
27-
28-
- #### Step 2: Start a clean local Internet Computer replica and a web server:
24+
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
2925

3026
```sh
31-
dfx stop
27+
cd examples/rust/periodic_tasks
3228
dfx start --clean
3329
```
3430

@@ -37,18 +33,18 @@ This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pr
3733
Example output:
3834

3935
```sh
40-
% dfx stop && dfx start --clean
36+
dfx start --clean
4137
[...]
4238
Dashboard: http://localhost:63387/_/dashboard
4339
```
4440

45-
- #### Step 3: Open another terminal window in the same directory:
41+
- #### Step 2: Open another terminal window in the same directory:
4642

4743
```sh
4844
cd examples/rust/periodic_tasks
4945
```
5046

51-
- #### Step 4: Compile and deploy `heartbeat` and `timer` canisters, setting the interval for periodic tasks to 10s:
47+
- #### Step 3: Compile and deploy the `heartbeat` and `timer` canisters, setting the interval for periodic tasks to 10s:
5248

5349
```sh
5450
dfx deploy heartbeat --argument 10
@@ -77,25 +73,25 @@ URLs:
7773
timer: http://127.0.0.1/...
7874
```
7975

80-
- #### Step 5: After 10s, observe similar non-zero counters in both canisters:
76+
- #### Step 4: After 10s, observe similar non-zero counters in both canisters:
8177

8278
```sh
8379
dfx canister call heartbeat counter
8480
dfx canister call timer counter
8581
```
8682

87-
Note, as the canisters deployed one by one, there might be a minor discrepancy in the counters.
83+
Note: As the canisters deployed one by one, there might be a minor discrepancy in the counters.
8884

8985
Example output:
9086

9187
```sh
92-
% dfx canister call heartbeat counter
88+
% dfx canister call heartbeat counter
9389
(8 : nat32)
94-
% dfx canister call timer counter
90+
% dfx canister call timer counter
9591
(7 : nat32)
9692
```
9793

98-
- #### Step 6: Compare the amount of cycles used to schedule the periodic task with 10s interval:
94+
- #### Step 5: Compare the amount of cycles used to schedule the periodic task with 10s interval:
9995

10096
```sh
10197
dfx canister call heartbeat cycles_used
@@ -115,36 +111,40 @@ For periodic tasks with 10 sec intervals, the `heartbeat` canister uses *more* c
115111

116112
Not only do timers use fewer cycles, but they are also more composable. As there is no global state or methods to export, different libraries with timers could be easily used in the same project.
117113

118-
Also, timers provide isolation between the scheduling logic and the periodic task. If the periodic task fails, all the changes made by this task will be reverted, but the timers library state will be updated, i.e. the failed task will be removed from the list of timers to execute.
114+
Also, timers provide isolation between the scheduling logic and the periodic task. If the periodic task fails, all the changes made by this task will be reverted, but the timers library state will be updated, i.e., the failed task will be removed from the list of timers to execute.
119115

120116
For such isolation of execution and scheduling contexts, the internal timers library uses self-canister calls:
121117

122-
```rust
123-
# This is a pseudo-code of a self call:
124-
ic_cdk::call(ic_cdk::id(), "periodic_task", ());
125-
```
118+
```rust
119+
# This is a pseudo-code of a self call:
120+
ic_cdk::call(ic_cdk::id(), "periodic_task", ());
121+
```
122+
123+
Despite the [costs](https://internetcomputer.org/docs/current/developer-docs/gas-cost) associated with such self-canister calls, the timers library still uses fewer cycles than the heartbeats.
126124

127-
Despite the [costs](https://internetcomputer.org/docs/current/developer-docs/production/computation-and-storage-costs) associated with such self-canister calls, the timers library still uses fewer cycles than the heartbeats.
125+
## Example 2: Cycles usage for tasks with 1s interval
128126

129-
### Example 2: Cycles usage for tasks with 1s interval
130127

128+
- ### Step 1: Setup project environment
131129

132-
- #### Step 1: Open a new terminal window in the example root directory:
130+
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
133131

134132
```sh
135133
cd examples/rust/periodic_tasks
134+
dfx start --clean
136135
```
137136

138-
- #### Step 2: Start a clean local Internet Computer replica and a web server:
137+
This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pressed or `dfx stop` command is run.
138+
139+
Example output:
139140

140141
```sh
141-
dfx stop
142142
dfx start --clean
143+
[...]
144+
Dashboard: http://localhost:63387/_/dashboard
143145
```
144146

145-
This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pressed or `dfx stop` command is run.
146-
147-
- #### Step 3: Open another terminal window in the same directory:
147+
- #### Step 2: Open another terminal window in the same directory:
148148

149149
```sh
150150
cd examples/rust/periodic_tasks
@@ -153,12 +153,12 @@ cd examples/rust/periodic_tasks
153153
Example output:
154154

155155
```sh
156-
% dfx stop && dfx start --clean
156+
dfx start --clean
157157
[...]
158158
Dashboard: http://localhost:63387/_/dashboard
159159
```
160160

161-
- #### Step 4:. Compile and deploy `heartbeat` and `timer` canisters, setting the interval for periodic tasks to 1s:
161+
- #### Step 3:. Compile and deploy `heartbeat` and `timer` canisters, setting the interval for periodic tasks to 1s:
162162

163163
```sh
164164
dfx deploy --argument 1 heartbeat
@@ -187,25 +187,25 @@ URLs:
187187
timer: http://127.0.0.1/...
188188
```
189189

190-
- #### Step 5: After a few seconds, observe similar non-zero counters in both canisters:
190+
- #### Step 4: After a few seconds, observe similar non-zero counters in both canisters:
191191

192192
```sh
193193
dfx canister call heartbeat counter
194194
dfx canister call timer counter
195195
```
196196

197-
Note, as the canisters deployed one by one, there might be a minor discrepancy in the counters.
197+
Note: As the canisters deployed one by one, there might be a minor discrepancy in the counters.
198198

199199
Example output:
200200

201201
```sh
202-
% dfx canister call heartbeat counter
202+
% dfx canister call heartbeat counter
203203
(8 : nat32)
204-
% dfx canister call timer counter
204+
% dfx canister call timer counter
205205
(9 : nat32)
206206
```
207207

208-
- #### Step 6: Compare the number of cycles used to schedule the periodic task with 1s interval:
208+
- #### Step 5: Compare the number of cycles used to schedule the periodic task with 1s interval:
209209

210210
```sh
211211
dfx canister call heartbeat cycles_used
@@ -230,6 +230,7 @@ Also, there is no isolation between the scheduling logic and the periodic task.
230230
For such isolation of execution and scheduling contexts, the timers library uses internal self-canister calls as described in `Demo 1`. Due to the [costs](https://internetcomputer.org/docs/current/developer-docs/production/computation-and-storage-costs) associated with such self-canister calls, `timer` canister uses more cycles for very frequent periodic tasks.
231231

232232
## Further learning
233+
233234
1. Have a look at the locally running dashboard. The URL is at the end of the `dfx start` command: `Dashboard: http://localhost/...`
234235
2. Check out `heartbeat` and `timer` canisters Candid user interface. The URLs are at the end of the `dfx deploy` command: `heartbeat: http://127.0.0.1/...`
235236
3. Find which interval makes even the costs of running periodic tasks in the `timer` and `heartbeat` canisters: `dfx deploy heartbeat --argument 5 && dfx deploy timer --argument 5`

0 commit comments

Comments
 (0)