From ee976e6a4844c34fa3422c9904026e4e4d8dd253 Mon Sep 17 00:00:00 2001 From: BobOng <2261238+welbon@users.noreply.github.com> Date: Sat, 20 Sep 2025 17:52:59 +0800 Subject: [PATCH 1/6] hello blockchain project --- .../98-move-examples/03-hello-blockchain.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md new file mode 100644 index 000000000..20b5269a2 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md @@ -0,0 +1,68 @@ +# Hello blockchain + +这一章节主要介绍开发者如何在 Starcoin 区块链上测试部署一个测试工程,用以测试区块链的可用性 + +## 前提 + +该工程在 [hello-blockchain](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/hello_blockchain) 处, +需要预先将starcoin仓库下载到本地,编译以下工程 +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager),该二进制负责进行打包 +3. 执行以下执行令进行编译连接(假设starcoin二进制已经编译成功),并且打包工程 +```shell + +# 连接到starcoin控制台 +➜ starcoin -n console + +# 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 +➜ starcoin% node sync progress + +``` + +## 测试指令集 + +使用 mpm 先构建 blob 二进制包 +```shell +➜ cd /starcoin/vm2/move-example/hello-blockchain +➜ mpm2 release + +INCLUDING DEPENDENCY MoveStdlib +INCLUDING DEPENDENCY StarcoinFramework +INCLUDING DEPENDENCY StarcoinStdlib +BUILDING hello-blockchain + +Packaging Modules: + 0x143e9f2175f92f51d9adaeee2b3d8bf0::message +Release done: release/hello-blockchain.v0.0.1.blob, package hash: 0x4c3ba39b4e716aa4d80b3697721107e39e8d6d9244a5ece3de4670335749b030 +``` + +在控制台中部署并测试 +```shell + +# 部署合约,若结果输出状态为Executed说明部署成功 +startoin% dev -s /starcoin/vm2/move-example/hello-blockchain/release/hello-blockchain.v0.0.1.blob +txn 0x12481f66a05a56d93cb51d34e05c1815919ba6cea40ee073621f1d05a66341ac submitted. +{ + "ok": { + ... + "dry_run_output": { + "explained_status": "Executed", + "status": "Executed", + } + ... + } +} + +# 设置 message +starcoin% account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::set_message --arg b"abcdefg" -b + +# 查看 message,该结果表示输出的为`abcdefg` 的BCS编码 +starcoin% dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::get_message --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + { + "bytes": "0x61626364656667" + } + ] +} +``` From 936e90b2a54236459779b2f303389294451a67df Mon Sep 17 00:00:00 2001 From: BobOng <2261238+welbon@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:23:05 +0800 Subject: [PATCH 2/6] resource-group project --- .../98-move-examples/04-resource-groups.md | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md new file mode 100644 index 000000000..3249af5fe --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md @@ -0,0 +1,51 @@ +# resource-groups + +这一章节主要介绍开发者如何在 Starcoin +区块链上测试部署resource-groups测试工程,用以测试vm2下面的资源组,该合约有两部分,其主要测试资源组,secondary主要负责测试跨模块的资源组引用 + +## 前提 + +该工程在 [hello-blockchain](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/hello_blockchain) +处, +需要预先将starcoin仓库下载到本地,编译以下工程 + +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager) + ,该二进制负责进行打包 +3. 执行以下执行令进行编译连接(假设starcoin二进制已经编译成功),并且打包工程 + +```shell + +# 连接到starcoin控制台 +➜ starcoin -n console + +# 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 +➜ starcoin% node sync progress + +``` + +## 测试指令集 + +### primary 部分 + +```shell +# 代码部署 +dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /home/bob/starcoin/vm2/move-examples/resource_groups/primary/release/ResourceGroupsPrimary.v0.0.1.blob + + +# 初始化 +account execute-function --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::init -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --arg 10000u64 -b + +# 检查值,预期1000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 + +# 设置值 +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::set_value --arg 20000u64 -b + +# 移除值 +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::remove -b + +# 检查存在性, 预期 false +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::exists_at --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 + +``` \ No newline at end of file From 262e0974f041985059468914eac401c233d1bb2d Mon Sep 17 00:00:00 2001 From: BobOng <2261238+welbon@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:23:05 +0800 Subject: [PATCH 3/6] resource-group project --- .../98-move-examples/04-resource-groups.md | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md index 3249af5fe..74a217ef6 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md @@ -5,9 +5,8 @@ ## 前提 -该工程在 [hello-blockchain](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/hello_blockchain) -处, -需要预先将starcoin仓库下载到本地,编译以下工程 +该工程在 [resource-group](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/resource_groups) +处, 需要预先将starcoin仓库下载到本地,编译以下工程 1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager) @@ -21,6 +20,7 @@ # 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 ➜ starcoin% node sync progress +There are no running sync tasks. ``` @@ -30,7 +30,7 @@ ```shell # 代码部署 -dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /home/bob/starcoin/vm2/move-examples/resource_groups/primary/release/ResourceGroupsPrimary.v0.0.1.blob +dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /starcoin/vm2/move-examples/resource_groups/primary/release/ResourceGroupsPrimary.v0.0.1.blob # 初始化 @@ -38,14 +38,69 @@ account execute-function --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary: # 检查值,预期1000 dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 10000 + ] +} # 设置值 account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::set_value --arg 20000u64 -b +# 检查值,预期2000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 20000 + ] +} + + # 移除值 account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::remove -b # 检查存在性, 预期 false dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::exists_at --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +``` + + +### Secondary 部分 + +```shell +# 部署 +dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /starcoin/vm2/move-examples/resource_groups/secondary/release/ResourceGroupsSecondary.v0.0.1.blob + +# 初始化 +account execute-function --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::init -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --arg 10000u32 -b + +# 检查值,预期1000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 10000 + ] +} + +# 设置值 +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::set_value --arg 20000u32 -b + +# 检查值,预期2000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 20000 + ] +} + +# 移除值 +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::remove -b + +# 检查存在性, 预期 false +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::exists_at --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + false + ] +} ``` \ No newline at end of file From 78a070fa7e31b9858cfde9e2b2669dd6401f6d16 Mon Sep 17 00:00:00 2001 From: BobOng <2261238+welbon@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:46:58 +0800 Subject: [PATCH 4/6] shared account project --- .../98-move-examples/05-shared-account.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md new file mode 100644 index 000000000..fafc56f22 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md @@ -0,0 +1,58 @@ +# shared_account + +这一章节主要介绍开发者如何在 Starcoin +区块链上测试部署shared-account测试工程,该工程用以测试模拟NFT佣金的派发场景,即从主账户创建一个派生账户,将一部分Token放在并且在其中添加一些参与佣金派发的账户,当需要派发时,直接从派生账户中派发 + +## 前提 + +该工程在 [resource-group](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/resource_groups) +处, 需要预先将starcoin仓库下载到本地,编译以下工程 + +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager) + ,该二进制负责进行打包 +3. 执行以下执行令进行编译连接(假设starcoin二进制已经编译成功),并且打包工程 + +```shell + +# 连接到starcoin控制台 +➜ starcoin -n console + +# 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 +➜ starcoin% node sync progress +There are no running sync tasks. + +``` + +## 测试指令集 + +```shell +# 部署合约 +dev deploy -s 0x82cbfefb8076f2da3339b782fb074438 /home/bob/starcoin/vm2/move-examples/shared_account/release/shared_account.v0.0.1.blob + +# 查询派生账户的地址 +dev call --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::get_derive_account --arg 0x82cbfefb8076f2da3339b782fb074438 --arg b"1" +{ + "ok": [ + "0x711f9777700a13eaf73b173aa2664216" + ] +} + +# 给派生地址转账,否则在分发的时候报派生地址余额不足 +account transfer -r 0x711f9777700a13eaf73b173aa2664216 -v 10000000000 + +# 初始化 +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::initliaze_with_resource_account --arg b"1" -b + + +# 添加R1 +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::add_address --arg b"1" --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100u64 -b + +# 添加R2 +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::add_address --arg b"1" --arg 0x7111c56355d63f3434aa7de8b3c94aff --arg 100u64 -b + +# 执行分发 +account execute-function --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::disperse -t 0x1::starcoin_coin::STC --arg 0x711f9777700a13eaf73b173aa2664216 -b + +``` + From 1db53e16fd63ba97a0ca3d86d14bcbbd456012ee Mon Sep 17 00:00:00 2001 From: BobOng <2261238+welbon@users.noreply.github.com> Date: Sat, 20 Sep 2025 18:57:36 +0800 Subject: [PATCH 5/6] 1. add defi project; 2. fixed hello project --- .../98-move-examples/03-hello-blockchain.md | 2 +- .../03-move/98-move-examples/06-defi.md | 108 ++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/06-defi.md diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md index 20b5269a2..084457a32 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md @@ -21,7 +21,7 @@ ## 测试指令集 -使用 mpm 先构建 blob 二进制包 +使用 mpm 先构建 blob 二进制包,需要注意先将`Move.toml`中的模块目标地址改成发布地址,此处为`0x143e9f2175f92f51d9adaeee2b3d8bf0` ```shell ➜ cd /starcoin/vm2/move-example/hello-blockchain ➜ mpm2 release diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/06-defi.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/06-defi.md new file mode 100644 index 000000000..2cb52326d --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/06-defi.md @@ -0,0 +1,108 @@ +# defi + +这一章节主要介绍开发者如何在 Starcoin 区块链上测试部署测试defi工程, +该工程的主要功能是用来测试sponsor(下称S)授权Coin给recipient(下称R)一些锁仓的Token,R可以在指定的锁仓时间之后来领取解锁的代币 + +## 前提 + +该工程在 [defi](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/defi) +处, 需要预先将starcoin仓库下载到本地,编译以下工程 + +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager) + ,该二进制负责进行打包 +3. 执行以下执行令进行编译连接(假设starcoin二进制已经编译成功),并且打包工程 +4. 假设S为`0x82cbfefb8076f2da3339b782fb074438` ,R1为 `0x95cb8c2ef522014bd03f633bd6c8dee6` + ,R2账户为:`0x7111c56355d63f3434aa7de8b3c94aff`, 需要执行导入操作 + +```json lines +[ + // S账户 + { + "ok": { + "account": "0x82cbfefb8076f2da3339b782fb074438", + "private_key": "0x01f747e8476fe3727ca29ae87fd44dd8d222609b42517274908c9ef24023169a" + } + }, + // R1账户 + { + "ok": { + "account": "0x95cb8c2ef522014bd03f633bd6c8dee6", + "private_key": "0x37528fbbace04e2b3609de312bdcfeb4704cd83a3488b9fc836118d02835c36e" + } + }, + // R2账户 + { + "ok": { + "account": "0x7111c56355d63f3434aa7de8b3c94aff", + "private_key": "0xb1a0d666adaae36d103631a182f8742717c7a650f374912804a1f5e740f4b1b7" + } + } +] +``` + +```shell + +# 连接到starcoin控制台 +➜ starcoin -n console + +# 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 +➜ starcoin% node sync progress +There are no running sync tasks. + +``` + +## 测试指令集 + +### 正常基本流程 + +S授权R1,100个STC 锁仓60秒, R1在60秒后取到100个STC + +```shell +# 初始化:需要要求S账户有STC余额,使用S账户发起初始授权,将R作为initialize_sponsor的接收地址参数 +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::initialize_sponsor -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -b + +# 添加锁仓,假设为100个STC(STC精度为9,则传入100*1e9) +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::add_locked_coins -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100000000000u64 --arg 60u64 -b + +# 查看S的锁仓数量 +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::total_locks -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 + +# 查看S锁仓的额度 +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::locked_amount -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 + +# 查看S锁仓的时间 +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim_time_secs -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 + +# 查看锁仓可取账户的地址 +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::withdrawal_address -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 + +# R1声明取出S的锁仓 (在60秒内claim会报错) +account execute-function -s 0x95cb8c2ef522014bd03f633bd6c8dee6 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 -b +``` + +### 错误取出流程 + +```shell +account execute-function -s 0x95cb8c2ef522014bd03f633bd6c8dee6 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -b +``` + +### 更新锁仓 + +```shell +# 更新锁仓 +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::update_lockup -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 600u64 -b + +# 查看锁仓时间是否有变化 +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim_time_secs -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 +``` + +### 取消锁仓 + +```shell +# 重新添加锁仓,假设为100个STC(STC精度为9,则传入100*1e9) +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::add_locked_coins -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100000000000u64 --arg 60u64 -b + +# 取消锁仓 +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::cancel_lockup -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -b +``` \ No newline at end of file From 6215f41378c8bf83292745e11abfd454e48af8b4 Mon Sep 17 00:00:00 2001 From: BobOng <2261238+welbon@users.noreply.github.com> Date: Sat, 20 Sep 2025 22:43:36 +0800 Subject: [PATCH 6/6] fixed english version --- .../98-move-examples/03-hello-blockchain.md | 79 ++++++++++++ .../98-move-examples/04-resource-groups.md | 110 +++++++++++++++++ .../98-move-examples/05-shared-account.md | 61 ++++++++++ docs/03-move/98-move-examples/06-defi.md | 114 ++++++++++++++++++ .../98-move-examples/03-hello-blockchain.md | 49 ++++---- .../98-move-examples/04-resource-groups.md | 67 +++++----- .../98-move-examples/05-shared-account.md | 47 ++++---- .../03-move/98-move-examples/06-defi.md | 70 +++++------ .../03-move/98-move-examples/README.md | 2 + yarn.lock | 13 +- 10 files changed, 484 insertions(+), 128 deletions(-) create mode 100644 docs/03-move/98-move-examples/03-hello-blockchain.md create mode 100644 docs/03-move/98-move-examples/04-resource-groups.md create mode 100644 docs/03-move/98-move-examples/05-shared-account.md create mode 100644 docs/03-move/98-move-examples/06-defi.md diff --git a/docs/03-move/98-move-examples/03-hello-blockchain.md b/docs/03-move/98-move-examples/03-hello-blockchain.md new file mode 100644 index 000000000..5a55a985e --- /dev/null +++ b/docs/03-move/98-move-examples/03-hello-blockchain.md @@ -0,0 +1,79 @@ +# Hello Blockchain + +This section mainly introduces how developers can test and deploy a sample project on the Starcoin blockchain to verify +the blockchain's availability. + +## Prerequisites + +The sample project is located in +the [hello-blockchain](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/hello_blockchain) +repository. Please clone the Starcoin repository to your local machine and compile the following tools: + +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin): Used for connecting to + nodes. +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager): Used + for packaging Move modules. + +Assuming the Starcoin binary has been compiled successfully, execute the following commands to connect to the Starcoin +console and package the project: + +```shell +# Connect to the Starcoin console, where is the network name (e.g., dev, barnard, etc.) +starcoin -n console + +# View the node's sync progress; ensure the local node is fully synced before submitting test transactions +starcoin% node sync progress +``` + +## Test Command Set + +First, use `mpm2` to build the Blob binary package. Note that before packaging, you need to modify the module target +address in `Move.toml` to the deployment address, for example, `0x143e9f2175f92f51d9adaeee2b3d8bf0`. + +```shell +# Switch to the project directory +cd /starcoin/vm2/move-examples/hello-blockchain + +# Execute the packaging command +mpm2 release + +INCLUDING DEPENDENCY MoveStdlib +INCLUDING DEPENDENCY StarcoinFramework +INCLUDING DEPENDENCY StarcoinStdlib +BUILDING hello-blockchain + +Packaging Modules: + 0x143e9f2175f92f51d9adaeee2b3d8bf0::message +Release done: release/hello-blockchain.v0.0.1.blob, package hash: 0x4c3ba39b4e716aa4d80b3697721107e39e8d6d9244a5ece3de4670335749b030 +``` + +Deploy and test the contract in the Starcoin console: + +```shell +# Deploy the contract; if the result shows "Executed", it indicates successful deployment +starcoin% dev deploy -s /starcoin/vm2/move-examples/hello-blockchain/release/hello-blockchain.v0.0.1.blob +txn 0x12481f66a05a56d93cb51d34e05c1815919ba6cea40ee073621f1d05a66341ac submitted. +{ + "ok": { + ... + "dry_run_output": { + "explained_status": "Executed", + "status": "Executed", + } + ... + } +} + +# Set the message +starcoin% account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::set_message --arg b"abcdefg" -b + +# View the message; the result is the BCS encoding of "abcdefg" +starcoin% dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::get_message --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + { + "bytes": "0x61626364656667" + } + ] +} +``` \ No newline at end of file diff --git a/docs/03-move/98-move-examples/04-resource-groups.md b/docs/03-move/98-move-examples/04-resource-groups.md new file mode 100644 index 000000000..d757bc861 --- /dev/null +++ b/docs/03-move/98-move-examples/04-resource-groups.md @@ -0,0 +1,110 @@ +# Resource Groups + +This section explains how to test and deploy the `resource-groups` sample project on the Starcoin blockchain to test the +resource group functionality under VM2. The contract consists of two parts: the `primary` module tests the basic +functionality of resource groups, while the `secondary` module tests cross-module resource group references. + +## Prerequisites + +The project is located in +the [resource-groups](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/resource_groups) +repository. Please clone the Starcoin repository to your local machine and compile the following tools: + +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin): Used for connecting to + nodes. +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager): Used + for packaging Move modules. + +Assuming the Starcoin binary has been compiled successfully, execute the following commands to connect to the Starcoin +console and package the project: + +```shell +# Connect to the Starcoin console, where is the network name (e.g., dev, barnard, etc.) +starcoin -n console + +# View the node's sync progress; ensure the local node is fully synced before submitting test transactions +starcoin% node sync progress +There are no running sync tasks. +``` + +## Test Command Set + +### Primary Module + +```shell +# Deploy the Primary module +dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /starcoin/vm2/move-examples/resource_groups/primary/release/ResourceGroupsPrimary.v0.0.1.blob + +# Initialize the resource group with an initial value of 10000 +account execute-function --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::init -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --arg 10000u64 -b + +# Check the value, expected to return 10000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 10000 + ] +} + +# Set the value to 20000 +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::set_value --arg 20000u64 -b + +# Check the value, expected to return 20000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 20000 + ] +} + +# Remove the value +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::remove -b + +# Check if the resource exists, expected to return false +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::exists_at --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + false + ] +} +``` + +### Secondary Module + +```shell +# Deploy the Secondary module +dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /starcoin/vm2/move-examples/resource_groups/secondary/release/ResourceGroupsSecondary.v0.0.1.blob + +# Initialize the resource group with an initial value of 10000 +account execute-function --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::init -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --arg 10000u32 -b + +# Check the value, expected to return 10000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 10000 + ] +} + +# Set the value to 20000 +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::set_value --arg 20000u32 -b + +# Check the value, expected to return 20000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 20000 + ] +} + +# Remove the value +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::remove -b + +# Check if the resource exists, expected to return false +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::exists_at --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + false + ] +} +``` \ No newline at end of file diff --git a/docs/03-move/98-move-examples/05-shared-account.md b/docs/03-move/98-move-examples/05-shared-account.md new file mode 100644 index 000000000..9caa3df82 --- /dev/null +++ b/docs/03-move/98-move-examples/05-shared-account.md @@ -0,0 +1,61 @@ +# Shared Account + +This section explains how to test and deploy the `shared-account` sample project on the Starcoin blockchain. The project +simulates an NFT commission distribution scenario: a derived account is created from a main account, a portion of tokens +is deposited into the derived account, and accounts participating in commission distribution are added. When +distribution is required, tokens are disbursed directly from the derived account. + +## Prerequisites + +The project is located in +the [shared-account](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/shared_account) +repository. Please clone the Starcoin repository to your local machine and compile the following tools: + +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin): Used for connecting to + nodes. +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager): Used + for packaging Move modules. + +Assuming the Starcoin binary has been compiled successfully, execute the following commands to connect to the Starcoin +console and package the project: + +```shell +# Connect to the Starcoin console, where is the network name (e.g., dev, barnard, etc.) +starcoin -n console + +# View the node's sync progress; ensure the local node is fully synced before submitting test transactions +starcoin% node sync progress +There are no running sync tasks. +``` + +## Test Command Set + +The following steps demonstrate how to deploy and test the `shared-account` contract in the Starcoin console: + +```shell +# Deploy the contract +dev deploy -s 0x82cbfefb8076f2da3339b782fb074438 /home/bob/starcoin/vm2/move-examples/shared_account/release/shared_account.v0.0.1.blob + +# Query the derived account address +dev call --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::get_derive_account --arg 0x82cbfefb8076f2da3339b782fb074438 --arg b"1" +{ + "ok": [ + "0x711f9777700a13eaf73b173aa2664216" + ] +} + +# Transfer tokens to the derived account to ensure sufficient balance for distribution +account transfer -r 0x711f9777700a13eaf73b173aa2664216 -v 10000000000 + +# Initialize the derived account +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::initialize_with_resource_account --arg b"1" -b + +# Add participant account R1 for distribution +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::add_address --arg b"1" --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100u64 -b + +# Add participant account R2 for distribution +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::add_address --arg b"1" --arg 0x7111c56355d63f3434aa7de8b3c94aff --arg 100u64 -b + +# Execute commission distribution +account execute-function --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::disperse -t 0x1::starcoin_coin::STC --arg 0x711f9777700a13eaf73b173aa2664216 -b +``` \ No newline at end of file diff --git a/docs/03-move/98-move-examples/06-defi.md b/docs/03-move/98-move-examples/06-defi.md new file mode 100644 index 000000000..b33aa4adb --- /dev/null +++ b/docs/03-move/98-move-examples/06-defi.md @@ -0,0 +1,114 @@ +# Decentralized Finance (DeFi) + +This section explains how to test and deploy the `defi` sample project on the Starcoin blockchain. The project’s main +functionality is to test a scenario where a sponsor (S) authorizes a recipient (R) to receive a certain amount of locked +tokens, which the recipient can claim after a specified lockup period. + +## Prerequisites + +The project is located in the [defi](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/defi) +repository. Please clone the Starcoin repository to your local machine and compile the following tools: + +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin): Used for connecting to + nodes. +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager): Used + for packaging Move modules. + +Assuming the Starcoin binary has been compiled successfully, import the following account information: + +- Sponsor (S) account: `0x82cbfefb8076f2da3339b782fb074438` +- Recipient (R1) account: `0x95cb8c2ef522014bd03f633bd6c8dee6` +- Recipient (R2) account: `0x7111c56355d63f3434aa7de8b3c94aff` + +Account import data (JSON format): + +```json +[ + { + "ok": { + "account": "0x82cbfefb8076f2da3339b782fb074438", + "private_key": "0x01f747e8476fe3727ca29ae87fd44dd8d222609b42517274908c9ef24023169a" + } + }, + { + "ok": { + "account": "0x95cb8c2ef522014bd03f633bd6c8dee6", + "private_key": "0x37528fbbace04e2b3609de312bdcfeb4704cd83a3488b9fc836118d02835c36e" + } + }, + { + "ok": { + "account": "0x7111c56355d63f3434aa7de8b3c94aff", + "private_key": "0xb1a0d666adaae36d103631a182f8742717c7a650f374912804a1f5e740f4b1b7" + } + } +] +``` + +Execute the following commands to connect to the Starcoin console and package the project: + +```shell +# Connect to the Starcoin console, where is the network name (e.g., dev, barnard, etc.) +starcoin -n console + +# View the node's sync progress; ensure the local node is fully synced before submitting test transactions +starcoin% node sync progress +There are no running sync tasks. +``` + +## Test Command Set + +### Standard Workflow + +Sponsor S authorizes Recipient R1 with 100 STC, locked for 60 seconds. R1 can claim the 100 STC after the 60-second +lockup period. + +```shell +# Initialize: Ensure the S account has an STC balance, and use S to authorize R1 as the recipient +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::initialize_sponsor -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -b + +# Add locked coins: Authorize 100 STC (STC has 9 decimals, so pass 100 * 1e9), locked for 60 seconds +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::add_locked_coins -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100000000000u64 --arg 60u64 -b + +# View the total number of locks for S +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::total_locks -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 + +# View the locked amount for R1 by S +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::locked_amount -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 + +# View the lockup time for R1 by S +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim_time_secs -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 + +# View the withdrawal address for the lock +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::withdrawal_address -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 + +# R1 claims the locked tokens from S (claiming within 60 seconds will result in an error) +account execute-function -s 0x95cb8c2ef522014bd03f633bd6c8dee6 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 -b +``` + +### Error Claim Workflow + +```shell +# Error claim: R1 attempts to claim locked tokens from an incorrect account +account execute-function -s 0x95cb8c2ef522014bd03f633bd6c8dee6 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -b +``` + +### Update Lockup + +```shell +# Update the lockup time to 600 seconds +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::update_lockup -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 600u64 -b + +# Verify if the lockup time has been updated +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim_time_secs -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 +``` + +### Cancel Lockup + +```shell +# Re-add locked coins: Authorize 100 STC, locked for 60 seconds +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::add_locked_coins -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100000000000u64 --arg 60u64 -b + +# Cancel the lockup +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::cancel_lockup -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -b +``` \ No newline at end of file diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md index 084457a32..a6121ea4b 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md @@ -1,30 +1,33 @@ -# Hello blockchain +# Hello Blockchain -这一章节主要介绍开发者如何在 Starcoin 区块链上测试部署一个测试工程,用以测试区块链的可用性 +本章节主要介绍开发者如何在 Starcoin 区块链上测试并部署一个示例工程,用于验证区块链的可用性。 -## 前提 +## 前提条件 -该工程在 [hello-blockchain](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/hello_blockchain) 处, -需要预先将starcoin仓库下载到本地,编译以下工程 -1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 -2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager),该二进制负责进行打包 -3. 执行以下执行令进行编译连接(假设starcoin二进制已经编译成功),并且打包工程 -```shell +该示例工程位于 [hello-blockchain](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/hello_blockchain) 仓库中。请先将 Starcoin 仓库克隆到本地,并编译以下工具: +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin):用于与节点进行连接。 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager):用于打包 Move 模块。 -# 连接到starcoin控制台 -➜ starcoin -n console +假设 Starcoin 二进制文件已编译成功,执行以下命令连接到 Starcoin 控制台并打包工程: -# 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 -➜ starcoin% node sync progress +```shell +# 连接到 Starcoin 控制台, 为网络名称(如 dev、barnard 等) +starcoin -n console +# 查看节点的同步进度,确保本地节点同步完成后再提交测试交易 +starcoin% node sync progress ``` ## 测试指令集 -使用 mpm 先构建 blob 二进制包,需要注意先将`Move.toml`中的模块目标地址改成发布地址,此处为`0x143e9f2175f92f51d9adaeee2b3d8bf0` +首先,使用 `mpm2` 构建 Blob 二进制包。请注意,在打包前需将 `Move.toml` 中的模块目标地址修改为发布地址,例如 `0x143e9f2175f92f51d9adaeee2b3d8bf0`。 + ```shell -➜ cd /starcoin/vm2/move-example/hello-blockchain -➜ mpm2 release +# 切换到工程目录 +cd /starcoin/vm2/move-examples/hello-blockchain + +# 执行打包命令 +mpm2 release INCLUDING DEPENDENCY MoveStdlib INCLUDING DEPENDENCY StarcoinFramework @@ -36,11 +39,11 @@ Packaging Modules: Release done: release/hello-blockchain.v0.0.1.blob, package hash: 0x4c3ba39b4e716aa4d80b3697721107e39e8d6d9244a5ece3de4670335749b030 ``` -在控制台中部署并测试 -```shell +在 Starcoin 控制台中部署并测试合约: -# 部署合约,若结果输出状态为Executed说明部署成功 -startoin% dev -s /starcoin/vm2/move-example/hello-blockchain/release/hello-blockchain.v0.0.1.blob +```shell +# 部署合约,若结果显示 "Executed" 则表示部署成功 +starcoin% dev deploy -s /starcoin/vm2/move-examples/hello-blockchain/release/hello-blockchain.v0.0.1.blob txn 0x12481f66a05a56d93cb51d34e05c1815919ba6cea40ee073621f1d05a66341ac submitted. { "ok": { @@ -53,10 +56,10 @@ txn 0x12481f66a05a56d93cb51d34e05c1815919ba6cea40ee073621f1d05a66341ac submitted } } -# 设置 message +# 设置消息 starcoin% account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::set_message --arg b"abcdefg" -b -# 查看 message,该结果表示输出的为`abcdefg` 的BCS编码 +# 查看消息,结果为 "abcdefg" 的 BCS 编码 starcoin% dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::get_message --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 { "ok": [ @@ -65,4 +68,4 @@ starcoin% dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::get_m } ] } -``` +``` \ No newline at end of file diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md index 74a217ef6..1d7effa87 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md @@ -1,42 +1,37 @@ -# resource-groups +# 资源组 (Resource Groups) -这一章节主要介绍开发者如何在 Starcoin -区块链上测试部署resource-groups测试工程,用以测试vm2下面的资源组,该合约有两部分,其主要测试资源组,secondary主要负责测试跨模块的资源组引用 +本章节介绍如何在 Starcoin 区块链上测试和部署 `resource-groups` 示例工程,用以测试 VM2 下的资源组功能。该合约分为两部分:`primary` 模块用于测试资源组的基本功能,`secondary` 模块用于测试跨模块的资源组引用。 -## 前提 +## 前提条件 -该工程在 [resource-group](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/resource_groups) -处, 需要预先将starcoin仓库下载到本地,编译以下工程 +该工程位于 [resource-group](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/resource_groups) 仓库中。请先将 Starcoin 仓库克隆到本地,并编译以下工具: -1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 -2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager) - ,该二进制负责进行打包 -3. 执行以下执行令进行编译连接(假设starcoin二进制已经编译成功),并且打包工程 +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin):用于与节点连接。 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager):用于打包 Move 模块。 -```shell +假设 Starcoin 二进制文件已编译成功,执行以下命令连接到 Starcoin 控制台并打包工程: -# 连接到starcoin控制台 -➜ starcoin -n console +```shell +# 连接到 Starcoin 控制台, 为网络名称(如 dev、barnard 等) +starcoin -n console -# 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 -➜ starcoin% node sync progress +# 查看节点的同步进度,确保本地节点同步完成后再提交测试交易 +starcoin% node sync progress There are no running sync tasks. - ``` ## 测试指令集 -### primary 部分 +### Primary 模块 ```shell -# 代码部署 +# 部署 Primary 模块 dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /starcoin/vm2/move-examples/resource_groups/primary/release/ResourceGroupsPrimary.v0.0.1.blob - -# 初始化 +# 初始化资源组,设置初始值 10000 account execute-function --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::init -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --arg 10000u64 -b -# 检查值,预期1000 +# 检查值,预期返回 10000 dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 { "ok": [ @@ -44,10 +39,10 @@ dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x14 ] } -# 设置值 +# 设置值为 20000 account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::set_value --arg 20000u64 -b -# 检查值,预期2000 +# 检查值,预期返回 20000 dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 { "ok": [ @@ -55,26 +50,28 @@ dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x14 ] } - # 移除值 account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::remove -b -# 检查存在性, 预期 false +# 检查资源是否存在,预期返回 false dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::exists_at --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 - +{ + "ok": [ + false + ] +} ``` - -### Secondary 部分 +### Secondary 模块 ```shell -# 部署 -dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /starcoin/vm2/move-examples/resource_groups/secondary/release/ResourceGroupsSecondary.v0.0.1.blob +# 部署 Secondary 模块 +dev deploy -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 /starcoin/vm2/move-examples/resource_groups/secondary/release/ResourceGroupsSecondary.v0.0.1.blob -# 初始化 +# 初始化资源组,设置初始值 10000 account execute-function --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::init -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --arg 10000u32 -b -# 检查值,预期1000 +# 检查值,预期返回 10000 dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 { "ok": [ @@ -82,10 +79,10 @@ dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x ] } -# 设置值 +# 设置值为 20000 account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::set_value --arg 20000u32 -b -# 检查值,预期2000 +# 检查值,预期返回 20000 dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 { "ok": [ @@ -96,7 +93,7 @@ dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x # 移除值 account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::remove -b -# 检查存在性, 预期 false +# 检查资源是否存在,预期返回 false dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::exists_at --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 { "ok": [ diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md index fafc56f22..6d57f172b 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md @@ -1,31 +1,29 @@ -# shared_account +# 共享账户 (Shared Account) -这一章节主要介绍开发者如何在 Starcoin -区块链上测试部署shared-account测试工程,该工程用以测试模拟NFT佣金的派发场景,即从主账户创建一个派生账户,将一部分Token放在并且在其中添加一些参与佣金派发的账户,当需要派发时,直接从派生账户中派发 +本章节介绍如何在 Starcoin 区块链上测试和部署 `shared-account` 示例工程。该工程旨在模拟 NFT 佣金分发的场景:从主账户创建一个派生账户,将部分代币存入派生账户,并添加参与佣金分发的账户。在需要分发时,直接从派生账户中进行分发。 -## 前提 +## 前提条件 -该工程在 [resource-group](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/resource_groups) -处, 需要预先将starcoin仓库下载到本地,编译以下工程 +该工程位于 starcoin的 [shared-account](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/shared_account) 仓库中。请先将 Starcoin 仓库克隆到本地,并编译以下工具: -1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 -2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager) - ,该二进制负责进行打包 -3. 执行以下执行令进行编译连接(假设starcoin二进制已经编译成功),并且打包工程 +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin):用于与节点连接。 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager):用于打包 Move 模块。 -```shell +假设 Starcoin 二进制文件已编译成功,执行以下命令连接到 Starcoin 控制台并打包工程: -# 连接到starcoin控制台 -➜ starcoin -n console +```shell +# 连接到 Starcoin 控制台, 为网络名称(如 dev、barnard 等) +starcoin -n console -# 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 -➜ starcoin% node sync progress +# 查看节点的同步进度,确保本地节点同步完成后再提交测试交易 +starcoin% node sync progress There are no running sync tasks. - ``` ## 测试指令集 +以下是在 Starcoin 控制台中部署和测试 `shared-account` 合约的步骤: + ```shell # 部署合约 dev deploy -s 0x82cbfefb8076f2da3339b782fb074438 /home/bob/starcoin/vm2/move-examples/shared_account/release/shared_account.v0.0.1.blob @@ -38,21 +36,18 @@ dev call --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::get_deriv ] } -# 给派生地址转账,否则在分发的时候报派生地址余额不足 +# 向派生账户转账,以确保分发时余额充足 account transfer -r 0x711f9777700a13eaf73b173aa2664216 -v 10000000000 -# 初始化 -account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::initliaze_with_resource_account --arg b"1" -b +# 初始化派生账户 +account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::initialize_with_resource_account --arg b"1" -b - -# 添加R1 +# 添加参与分发的账户 R1 account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::add_address --arg b"1" --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100u64 -b -# 添加R2 +# 添加参与分发的账户 R2 account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::add_address --arg b"1" --arg 0x7111c56355d63f3434aa7de8b3c94aff --arg 100u64 -b -# 执行分发 +# 执行佣金分发 account execute-function --function 0x82cbfefb8076f2da3339b782fb074438::SharedAccount::disperse -t 0x1::starcoin_coin::STC --arg 0x711f9777700a13eaf73b173aa2664216 -b - -``` - +``` \ No newline at end of file diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/06-defi.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/06-defi.md index 2cb52326d..6c4cc6550 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/06-defi.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/06-defi.md @@ -1,37 +1,36 @@ -# defi +# 去中心化金融 (defi) -这一章节主要介绍开发者如何在 Starcoin 区块链上测试部署测试defi工程, -该工程的主要功能是用来测试sponsor(下称S)授权Coin给recipient(下称R)一些锁仓的Token,R可以在指定的锁仓时间之后来领取解锁的代币 +本章节介绍如何在 Starcoin 区块链上测试和部署 `defi` 示例工程。该工程的主要功能是测试由发起者(Sponsor,简称 S)授权给接收者(Recipient,简称 R)一定数量的锁仓代币,接收者可在指定的锁仓时间后领取解锁的代币。 -## 前提 +## 前提条件 -该工程在 [defi](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/defi) -处, 需要预先将starcoin仓库下载到本地,编译以下工程 +该工程位于 [defi](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-examples/defi) 仓库中。请先将 Starcoin 仓库克隆到本地,并编译以下工具: -1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin),该二进制负责与peer进行连接 -2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager) - ,该二进制负责进行打包 -3. 执行以下执行令进行编译连接(假设starcoin二进制已经编译成功),并且打包工程 -4. 假设S为`0x82cbfefb8076f2da3339b782fb074438` ,R1为 `0x95cb8c2ef522014bd03f633bd6c8dee6` - ,R2账户为:`0x7111c56355d63f3434aa7de8b3c94aff`, 需要执行导入操作 +1. [starcoin-cmd](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/cmd/starcoin):用于与节点连接。 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager):用于打包 Move 模块。 -```json lines +假设 Starcoin 二进制文件已编译成功,并导入以下账户信息: + +- 发起者(S)账户:`0x82cbfefb8076f2da3339b782fb074438` +- 接收者(R1)账户:`0x95cb8c2ef522014bd03f633bd6c8dee6` +- 接收者(R2)账户:`0x7111c56355d63f3434aa7de8b3c94aff` + +账户导入数据(JSON 格式): + +```json [ - // S账户 { "ok": { "account": "0x82cbfefb8076f2da3339b782fb074438", "private_key": "0x01f747e8476fe3727ca29ae87fd44dd8d222609b42517274908c9ef24023169a" } }, - // R1账户 { "ok": { "account": "0x95cb8c2ef522014bd03f633bd6c8dee6", "private_key": "0x37528fbbace04e2b3609de312bdcfeb4704cd83a3488b9fc836118d02835c36e" } }, - // R2账户 { "ok": { "account": "0x7111c56355d63f3434aa7de8b3c94aff", @@ -41,66 +40,67 @@ ] ``` -```shell +执行以下命令连接到 Starcoin 控制台并打包工程: -# 连接到starcoin控制台 -➜ starcoin -n console +```shell +# 连接到 Starcoin 控制台, 为网络名称(如 dev、barnard 等) +starcoin -n console -# 查看节点的同步进度,需要等待本地节点同步完成才能提交下面的测试交易 -➜ starcoin% node sync progress +# 查看节点的同步进度,确保本地节点同步完成后再提交测试交易 +starcoin% node sync progress There are no running sync tasks. - ``` ## 测试指令集 -### 正常基本流程 +### 正常流程 -S授权R1,100个STC 锁仓60秒, R1在60秒后取到100个STC +发起者 S 授权接收者 R1 100 个 STC,锁仓 60 秒,R1 在 60 秒后可领取 100 个 STC。 ```shell -# 初始化:需要要求S账户有STC余额,使用S账户发起初始授权,将R作为initialize_sponsor的接收地址参数 +# 初始化:确保 S 账户有 STC 余额,使用 S 账户发起授权,将 R1 作为接收者地址 account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::initialize_sponsor -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -b -# 添加锁仓,假设为100个STC(STC精度为9,则传入100*1e9) +# 添加锁仓:授权 100 个 STC(STC 精度为 9,实际传入 100 * 1e9),锁仓时间 60 秒 account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::add_locked_coins -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100000000000u64 --arg 60u64 -b -# 查看S的锁仓数量 +# 查看 S 的锁仓总数 dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::total_locks -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 -# 查看S锁仓的额度 +# 查看 S 为 R1 锁仓的额度 dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::locked_amount -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -# 查看S锁仓的时间 +# 查看 S 为 R1 锁仓的时间 dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim_time_secs -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -# 查看锁仓可取账户的地址 +# 查看锁仓可提取的账户地址 dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::withdrawal_address -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 -# R1声明取出S的锁仓 (在60秒内claim会报错) +# R1 提取 S 的锁仓代币(若在 60 秒内提取会报错) account execute-function -s 0x95cb8c2ef522014bd03f633bd6c8dee6 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 -b ``` -### 错误取出流程 +### 错误提取流程 ```shell +# 错误提取:R1 尝试从错误的账户提取锁仓代币 account execute-function -s 0x95cb8c2ef522014bd03f633bd6c8dee6 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 -b ``` ### 更新锁仓 ```shell -# 更新锁仓 +# 更新锁仓时间为 600 秒 account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::update_lockup -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 600u64 -b -# 查看锁仓时间是否有变化 +# 检查锁仓时间是否更新 dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::claim_time_secs -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 ``` ### 取消锁仓 ```shell -# 重新添加锁仓,假设为100个STC(STC精度为9,则传入100*1e9) +# 重新添加锁仓:授权 100 个 STC,锁仓时间 60 秒 account execute-function -s 0x82cbfefb8076f2da3339b782fb074438 --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::add_locked_coins -t 0x1::starcoin_coin::STC --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 --arg 100000000000u64 --arg 60u64 -b # 取消锁仓 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/README.md b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/README.md index b93f3a39d..388a98cb1 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/README.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/README.md @@ -1 +1,3 @@ # Move examples + +本章节共介绍 \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f9a9aebf4..46ca1fcd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3701,15 +3701,10 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001297, caniuse-lite@^1.0.30001313: - version "1.0.30001316" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001316.tgz" - integrity sha512-JgUdNoZKxPZFzbzJwy4hDSyGuH/gXz2rN51QmoR8cBQsVo58llD3A0vlRKKRt8FGf5u69P9eQyIH8/z9vN/S0Q== - -caniuse-lite@^1.0.30001335, caniuse-lite@^1.0.30001359: - version "1.0.30001365" - resolved "https://registry.npmmirror.com/caniuse-lite/-/caniuse-lite-1.0.30001365.tgz#72c2c3863b1a545cfd3d9953535bd2ee17568158" - integrity sha512-VDQZ8OtpuIPMBA4YYvZXECtXbddMCUFJk1qu8Mqxfm/SZJNSr1cy4IuLCOL7RJ/YASrvJcYg1Zh+UEUQ5m6z8Q== +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001297, caniuse-lite@^1.0.30001313, caniuse-lite@^1.0.30001335, caniuse-lite@^1.0.30001359: + version "1.0.30001743" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001743.tgz" + integrity sha512-e6Ojr7RV14Un7dz6ASD0aZDmQPT/A+eZU+nuTNfjqmRrmkmQlnTNWH0SKmqagx9PeW87UVqapSurtAXifmtdmw== ccount@^1.0.0: version "1.1.0"