示例指南
这里是所有 Rooch 示例介绍和源代码索引。
关于示例项目命名解释
Rooch 提供自动创建并初始化项目的命令 rooch move new,当我们要编写新的合约项目时,可以利用这个命令简化我们的初始化工作。
我们可以使用任何合法字符来作为项目名,包括 -,但是,当我们使用带有 - 的项目名时,rooch move new 命令会自动将项目名用作这个项目的地址。
例如:
rooch move new hello-world然而,- 不是命名地址(变量)的合法字符,所以当我们使用 rooch move new 创建好项目后,务必检查 Move.toml 文件中的项目地址别名是否存在非法字符。
使用 rooch move new 创建带有 - 的项目(名),我们推荐手动修改 Move.toml 文件,将 - 替换为 _。
另一种方式是,创建项目时,直接使用 _ 作为项目名称单词的连接符号。
例如:
rooch move new hello_world在 Rooch 的 examples 中,我们创建的项目的名字统一使用 _ 连接,至于实际开发中,使用那种风格,请根据您的喜好决定。
我们向 examples 中贡献示例时,使用 rooch move new 初始化项目后,Move.toml 文件的项目地址需要使用 _ 通配符替换外,还需要增加一个 [dev-addresses] 表,填写一个用于单元测试的地址。
未向 examples/quick_start_counter/Move.toml 添加 [dev-addresses] 表:
BUILDING quick_start_counter
Success
    Finished dev [unoptimized + debuginfo] target(s) in 0.53s
     Running `target/debug/rooch move test -p examples/quick_start_counter`
thread 'main' panicked at 'resolve package dep failed: Unresolved addresses found: [
Named address 'quick_start_counter' in package 'quick_start_counter'
]
To fix this, add an entry for each unresolved address to the [addresses] section of examples/quick_start_counter/Move.toml: e.g.,
[addresses]
Std = "0x1"
Alternatively, you can also define [dev-addresses] and call with the -d flag', crates/rooch/src/commands/move_cli/commands/unit_test.rs:64:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: Process completed with exit code 101.Basic object
This example introduces how to use the Rooch object.
Source code
basic_object (opens in a new tab)
Blog
本示例介绍如何使用低代码工具开发博客示例应用程序。
Source code
Coins
Source code
Complex struct
Source code
complex_struct (opens in a new tab)
Counter
Source code
Event
Source code
KV store
Source code
Module init
Source code
module_init (opens in a new tab)
Noop auth validator
Source code
noop_auth_validator (opens in a new tab)
Private generics
Source code
private_generics (opens in a new tab)
References
一文读懂私有泛型函数 (opens in a new tab)
Publish modules
Source code
publish_modules (opens in a new tab)
Simple blog
Source code
simple_blog (opens in a new tab)
Steal split
Source code
steal_split (opens in a new tab)