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

Update Rust project READMEs #1073

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 6 additions & 15 deletions rust/basic_bitcoin/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
---
keywords: [advanced, rust, bitcoin, btc, integration, bitcoin integration]
---
# Basic Bitcoin

# Basic Bitcoin

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_bitcoin)

## Overview
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.

## Architecture
Expand All @@ -24,15 +17,13 @@ For a deeper understanding of the ICP < > BTC integration, see the [Bitcoin inte
## Prerequisites

* [x] Install the [IC
SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx).
SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
For local testing, `dfx >= 0.22.0-beta.0` is required.
* [x] On macOS, `llvm` with the `wasm32-unknown-unknown` target (which is not included in the XCode installation by default) is required.
To install, run `brew install llvm`.

## Step 1: Building and deploying sample code

### Clone the smart contract

This tutorial has the same smart contract written in
[Motoko](https://internetcomputer.org/docs/current/developer-docs/backend/motoko/index.md)
using ECDSA, Schnorr, and Bitcoin API.
Expand Down Expand Up @@ -120,7 +111,7 @@ from three types of addresses:
key. This precaution is to prevent attacks that can occur when creating
taproot multisigner addresses using specific multisignature schemes. However,
the Schnorr API of the internet computer does not support Schnorr
multisignatures.
multisignatures.
3. A [P2TR
address](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki)
where the funds can be spent using the provided public key with the script
Expand All @@ -130,7 +121,7 @@ from three types of addresses:
Note that P2TR *key path* spending with a tweaked key is currently not available
on the IC because the threshold Schnorr signing interface does not allow
applying BIP341 tweaks to the private key. In contrast, the
tweaked public key is used to spend in the script path, which is availble on the
tweaked public key is used to spend in the script path, which is available on the
IC. For a technical comparison of different ways of how single-signer P2TR
addresses can be constructed and used, you may want to take a look at [this
post](https://bitcoin.stackexchange.com/a/111100) by Pieter Wuille.
Expand Down Expand Up @@ -218,7 +209,7 @@ reflected in your current balance.

## Step 6: Retrieving block headers

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

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

This example is extensively documented in the following tutorials:

Expand Down
40 changes: 18 additions & 22 deletions rust/basic_dao/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
---
keywords: [advanced, rust, dao, decentralized organization, decentralized org]
---

# Basic DAO

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_dao)

This sample project demonstrates a basic [decentralized autonomous organization](https://en.wikipedia.org/wiki/Decentralized_autonomous_organization) (DAO) that can be deployed to the [Internet Computer](https://github.com/dfinity/ic). The basic DAO sample code is available in [Motoko](https://github.com/dfinity/examples/tree/master/motoko/basic_dao) and [Rust](https://github.com/dfinity/examples/tree/master/rust/basic_dao). You can see a quick introduction on [YouTube](https://youtu.be/3IcYlieA-EE).

## Overview

A `basic_dao` can be initialized with a set of accounts: mappings from principal IDs to a number of tokens. Account owners can query their account balance by calling `account_balance` and transfer tokens to other accounts by calling `transfer`. Anyone can call `list_accounts` to view all accounts.

Account owners can submit proposals by calling `submit_proposal`. A proposal specifies a canister, method, and arguments for this method. Account owners can cast votes (either `Yes` or `No`) on a proposal by calling `vote`. The amount of votes cast is equal to the amount of tokens the account owner has. If enough `Yes` votes are cast, `basic_dao` will execute the proposal by calling the proposal’s given method with the given args against the given canister. If enough `No` votes are cast, the proposal is not executed, and is instead marked as `Rejected`.
Expand All @@ -23,32 +15,34 @@ This example requires an installation of:

- [x] The Rust toolchain (e.g. cargo).
- [x] [didc.](https://github.com/dfinity/candid/tree/master/tools/didc)
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/).
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`

Begin by opening a terminal window.

### Step 1: Build the `basic_dao` canister:
## Step 1: Build the `basic_dao` canister

```bash
make clean; make
```

### Step 2: Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the command:
## Step 2: Setup the dev environment

Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the command:

```bash
cd basic_dao
dfx start --background
```

### Step 3: Create test identities with the commands:
## Step 3: Create test identities with the commands

```bash
dfx identity new --disable-encryption Alice; dfx identity use Alice; export ALICE=$(dfx identity get-principal);
dfx identity new --disable-encryption Bob; dfx identity use Bob; export BOB=$(dfx identity get-principal);
```

### Step 4: Deploy basic_dao with the initial test accounts:
## Step 4: Deploy basic_dao with the initial test accounts

```bash
dfx deploy --argument "(record {
Expand All @@ -63,7 +57,7 @@ dfx deploy --argument "(record {
})"
```

### Step 5: List accounts and confirm you see the two test accounts:
## Step 5: List accounts and confirm you see the two test accounts

```bash
dfx canister call basic_dao list_accounts '()'
Expand All @@ -86,7 +80,7 @@ Output:
)
```

### Step 6: Call `account_balance` as Bob:
## Step 6: Call `account_balance` as Bob

```bash
dfx canister call basic_dao account_balance '()'
Expand All @@ -98,7 +92,7 @@ You should see the output:
(record { amount_e8s = 100_000_000 : nat64 })
```

### Step 7: Transfer tokens to Alice:
## Step 7: Transfer tokens to Alice

```bash
dfx canister call basic_dao transfer "(record { to = principal \"$ALICE\"; amount = record { amount_e8s = 90_000_000:nat;};})";
Expand All @@ -110,7 +104,7 @@ Output:
(variant { Ok })
```

### Step 8: List accounts and see that the transfer was made:
## Step 8: List accounts and see that the transfer was made

```bash
dfx canister call basic_dao list_accounts '()'
Expand All @@ -137,7 +131,9 @@ Output:
Note that the transfer fee was deducted from Bob's account.
:::

### Step 9: Let's make a proposal to change the transfer fee. You can call `get_system_params` to learn the current transfer fee:
## Step 9: Let's make a proposal to change the transfer fee

You can call `get_system_params` to learn the current transfer fee:

```bash
dfx canister call basic_dao get_system_params '()';
Expand Down Expand Up @@ -177,7 +173,7 @@ Output:
blob "DIDL\03l\01\f2\c7\94\ae\03\01n\02l\01\b9\ef\93\80\08x\01\00\01 N\00\00\00\00\00\00"
```

### Step 10: We can then submit the proposal:
## Step 10: We can then submit the proposal

```bash
dfx canister call basic_dao submit_proposal '(record { canister_id = principal "rrkah-fqaaa-aaaaa-aaaaq-cai";
Expand All @@ -191,15 +187,15 @@ Note the output proposal ID:
(variant { Ok = 0 : nat64 })
```

### Step 11: Confirm the proposal was created:
## Step 11: Confirm the proposal was created

```bash
dfx canister call basic_dao get_proposal '(0:nat64)'
```

You should see `state = variant { Open };` in the output.

### Step 12: Vote on the proposal:
## Step 12: Vote on the proposal

```bash
dfx canister call basic_dao vote '(record { proposal_id = 0:nat64; vote = variant { Yes };})'
Expand Down Expand Up @@ -253,7 +249,7 @@ Output:
)
```

### Resources
## Resources
- [ic-cdk](https://docs.rs/ic-cdk/latest/ic_cdk/)
- [ic-cdk-macros](https://docs.rs/ic-cdk-macros)
- [JavaScript API reference](https://erxue-5aaaa-aaaab-qaagq-cai.ic0.app/)
Expand Down
10 changes: 1 addition & 9 deletions rust/basic_ethereum/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
---
keywords: [ advanced, rust, ethereum, eth, integration, ethereum integration ]
---

# Basic Ethereum

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/basic_ethereum)

## Overview

This tutorial will walk you through how to deploy a
sample [canister smart contract](https://internetcomputer.org/docs/current/developer-docs/multi-chain/ethereum/overview)
**that can send and receive Ether (ETH)** on the Internet Computer.
Expand All @@ -24,7 +16,7 @@ the [Ethereum integration overview](https://internetcomputer.org/docs/current/de

## Prerequisites

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

## Step 1: Building and deploying sample code

Expand Down
6 changes: 0 additions & 6 deletions rust/canister-info/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
---
keywords: [beginner, rust, canister info]
---

# Canister info

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/canister-info)

The purpose of this dapp is to give developers a small (backend) dapp that uses the IC's `canister_info` management call to retrieve information about canisters including canister history.

You can find a detailed description of its methods in the form of doc comments in the source code.
Expand Down
40 changes: 15 additions & 25 deletions rust/canister-snapshots/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
---
keywords: [advanced, rust, backup, restore, snapshots]
---

# Canister Snapshots Example

[View this sample's code on GitHub](https://github.com/dfinity/examples/tree/master/rust/canister-snapshots)

## Overview
# Canister snapshots

This example demonstrates the process of taking and loading canister snapshots.
It features a canister named `chat`, which functions as a miniature database.
Expand All @@ -18,40 +10,38 @@ and subsequently restore the data after the simulated data loss.

This example requires an installation of:

- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/setup/install/index.mdx). Note: the Canister Snapshots feature requires `dfx` version `0.23.0-beta.3` or later.
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install). Note: the Canister Snapshots feature requires `dfx` version `0.23.0-beta.3` or later.
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`

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

```sh
cd examples/rust/canister-snapshots
```
## Step 1: Setup the project environment

- ### Step 2: Start a clean local Internet Computer replica and a web server
Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the commands:

```sh
dfx stop
dfx start --clean

```bash
cd examples/rust/canister-snapshots
dfx start
```

This terminal will stay blocked, printing log messages, until the `Ctrl+C` is pressed or `dfx stop` command is run.

Example output:

```sh
% dfx stop && dfx start --clean
Running dfx start for version 0.23.0-beta.3
[...]
Replica API running on 127.0.0.1:4943
```

- ### Step 3: Open another terminal window in the same directory
## Step 2: Open another terminal window in the same directory

```sh
cd examples/rust/canister-snapshots
```

- ### Step 4: Compile and deploy `chat` canister
## Step 3: Compile and deploy `chat` canister

```sh
dfx deploy
Expand All @@ -69,7 +59,7 @@ URLs:
chat: http://127.0.0.1:4943/?canisterId=...
```

- ### Step 5: Populate the database with data
## Step 4: Populate the database with data

```sh
dfx canister call chat append 'Hi there!'
Expand All @@ -85,7 +75,7 @@ Example output:
(vec { "Hi there!" })
```

- ### Step 6: Take canister snapshot
## Step 5: Take canister snapshot

Canister `chat` is currently running, and snapshots should not be taken of active canisters.
Therefore, the canister should be stopped before taking a snapshot and then restarted.
Expand All @@ -107,7 +97,7 @@ Created a new snapshot of canister chat. Snapshot ID: 00000000000000008000000000
Starting code for canister chat, with canister_id bkyz2-fmaaa-aaaaa-qaaaq-cai
```

- ### Step 7: Simulate data loss
## Step 6: Simulate data loss

The `remove_spam` canister method intentionally includes a bug to simulate data loss.

Expand All @@ -127,7 +117,7 @@ Example output:

There is no more data in the database.

- ### Step 8: Restore the canister state from the snapshot
## Step 7: Restore the canister state from the snapshot

Canister `chat` is currently running, and snapshots should not be applied to active canisters.
Therefore, the canister must be stopped before applying the snapshot and then restarted.
Expand Down
Loading
Loading