Skip to content

Commit c0a31b4

Browse files
authored
chore: migrate rust/qrcode to icp-cli (#1401)
1 parent 9da5d94 commit c0a31b4

29 files changed

Lines changed: 419 additions & 631 deletions

‎.github/workflows/qrcode.yml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: qrcode
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
paths:
9+
- rust/qrcode/**
10+
- .github/workflows/qrcode.yml
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
rust-qrcode:
18+
runs-on: ubuntu-24.04
19+
container: ghcr.io/dfinity/icp-dev-env-rust:1.0.1
20+
env:
21+
ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
steps:
23+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
24+
- name: Deploy and test
25+
working-directory: rust/qrcode
26+
run: |
27+
icp network start -d
28+
icp deploy
29+
bash test.sh

‎rust/qrcode/.devcontainer/devcontainer.json‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎rust/qrcode/.gitignore‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77
.DS_Store
88
**/.DS_Store
99

10-
# dfx temporary files
11-
.dfx/
12-
13-
# generated files
14-
src/declarations/
10+
# generated bindings
11+
**/src/bindings/
1512

1613
# rust
1714
target/
1815

1916
# frontend code
2017
node_modules/
2118
dist/
22-
23-
# environment variables
24-
.env

‎rust/qrcode/BUILD.md‎

Lines changed: 0 additions & 113 deletions
This file was deleted.

‎rust/qrcode/Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/qrcode/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[workspace]
2-
members = ["src/qrcode_backend"]
2+
members = ["backend"]
33
resolver = "2"

‎rust/qrcode/Makefile‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎rust/qrcode/README.md‎

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,55 @@ This example shows that an Internet Computer dapp can perform a long-running com
44
This is possible due to a unique feature called Deterministic Time Slicing (DTS), which automatically divides long computations into smaller slices executed across multiple blocks.
55
Developers can write long-running code as usual and don't require anything special to take advantage of DTS, as demonstrated in this example.
66

7-
You try the live version of the dapp running on the mainnet here: [https://khpe2-4qaaa-aaaao-a2fnq-cai.icp0.io/](https://khpe2-4qaaa-aaaao-a2fnq-cai.icp0.io/).
7+
You can try the live version of the dapp running on the mainnet here: [https://khpe2-4qaaa-aaaao-a2fnq-cai.icp.net/](https://khpe2-4qaaa-aaaao-a2fnq-cai.icp.net/).
88

9-
## Deploying from ICP Ninja
9+
## How it works
10+
11+
The frontend consists of an HTML page with a form where users can enter text for the QR code and choose various options.
12+
When the user clicks the "Generate!" button, a JavaScript handler initiates a call to the backend canister.
1013

11-
When viewing this project in ICP Ninja, you can deploy it directly to the mainnet for free by clicking "Run" in the upper right corner. Open this project in ICP Ninja:
14+
The backend, written in Rust, uses the `qrcode-generator` and `image` crates to create a QR code from user text.
15+
It also performs some image processing to add the Internet Computer logo and a color gradient to the final result.
16+
Note that the amount of computational work may be significant for large images.
1217

13-
[![](https://icp.ninja/assets/open.svg)](https://icp.ninja/i?g=https://github.com/dfinity/examples/rust/qrcode)
18+
For educational purposes, the backend offers two public endpoints for QR code generation: one for updates and another for queries.
19+
Currently, DTS is supported for updates, but not for queries.
20+
As a result, the update endpoint has a larger instruction limit compared to the query endpoint and thus can handle larger images.
1421

15-
## Build and deploy from the command-line
16-
This example requires an installation of:
22+
## Build and deploy from the command line
1723

18-
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
19-
- [x] Make sure your Rust version is up-to-date (e.g., run `rustup update`).
20-
- [x] Add the `wasm32` target to your rust installation (by running `rustup target add wasm32-unknown-unknown`).
21-
- [x] Install `node.js` dependencies by running `npm install`.
22-
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
24+
### Prerequisites
2325

24-
## Running locally
26+
- Node.js
27+
- icp-cli: `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm`
28+
- Rust with the `wasm32-unknown-unknown` target: `rustup target add wasm32-unknown-unknown`
2529

26-
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
30+
### Install
2731

28-
```sh
32+
```bash
33+
git clone https://github.com/dfinity/examples
2934
cd examples/rust/qrcode
30-
dfx start --clean --background
3135
```
3236

33-
You can omit the `--background` argument if you want to see log messages of the dapp.
34-
35-
Now you can build and deploy the dapp with a single command:
37+
### Deploy and test
3638

3739
```bash
38-
dfx deploy
40+
icp network start -d
41+
icp deploy
42+
bash test.sh
43+
icp network stop
3944
```
4045

41-
If you see any error, it might be worthwhile to consult the [developer forum](https://forum.dfinity.org/).
42-
In case of successful deployment, you will see an output with local URLs:
46+
If you want to interact with the frontend during development, run the Vite dev server for hot reload:
4347

4448
```bash
45-
Deployed canisters.
46-
URLs:
47-
Frontend canister via browser
48-
qrcode_frontend: ...
49-
Backend canister via Candid interface:
50-
qrcode_backend: ...
49+
npm run dev --prefix frontend
5150
```
5251

5352
Navigate to the frontend URL in your browser and you'll be able to interact with the dapp.
5453

5554
![Screenshot of the frontend UI](screenshot.png)
5655

57-
58-
## How it works
59-
60-
The initial code of the dapp was autogenerated by `dfx` using the standard frontend/backend template.
61-
62-
The frontend consists of an HTML page with a form where users can enter text for the QR code and choose various options.
63-
When the user clicks the "Generate!" button, a JavaScript handler initiates a call to the backend canister.
64-
The heavy lifting of this call is managed by `candid`, `js-agent`, and `dfx`, which automatically generates a JavaScript object from the backend's Candid interface.
65-
That object contains `async` functions for each of the backend's endpoints, and the button handler uses them to make the calls.
66-
67-
The backend, written in Rust, uses the `qrcode-generator` and `image` crates to create a QR code from user text.
68-
It also performs some image processing, to add the Internet Computer logo and a color gradient to the final result.
69-
Note the amount of computational work may be significant for large images.
70-
71-
For educational purposes, the backend offers two public endpoints for QR code generation: one for updates and another for queries.
72-
Currently, DTS is supported for updates, but not for queries.
73-
As a result, the update endpoint has a larger instruction limit compared to the query endpoint and thus can handle larger images.
74-
7556
## Security considerations and best practices
7657

77-
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices.
58+
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for developing on ICP. This example may not implement all the best practices.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
2+
name = "backend"
3+
version = "0.1.0"
24
edition = "2021"
3-
name = "qrcode_backend"
4-
version = "1.1.0"
55

66
[lib]
77
crate-type = ["cdylib"]
File renamed without changes.

0 commit comments

Comments
 (0)