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 new file mode 100644 index 000000000..a6121ea4b --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/03-hello-blockchain.md @@ -0,0 +1,71 @@ +# 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):用于与节点进行连接。 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager):用于打包 Move 模块。 + +假设 Starcoin 二进制文件已编译成功,执行以下命令连接到 Starcoin 控制台并打包工程: + +```shell +# 连接到 Starcoin 控制台, 为网络名称(如 dev、barnard 等) +starcoin -n console + +# 查看节点的同步进度,确保本地节点同步完成后再提交测试交易 +starcoin% node sync progress +``` + +## 测试指令集 + +首先,使用 `mpm2` 构建 Blob 二进制包。请注意,在打包前需将 `Move.toml` 中的模块目标地址修改为发布地址,例如 `0x143e9f2175f92f51d9adaeee2b3d8bf0`。 + +```shell +# 切换到工程目录 +cd /starcoin/vm2/move-examples/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 +``` + +在 Starcoin 控制台中部署并测试合约: + +```shell +# 部署合约,若结果显示 "Executed" 则表示部署成功 +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", + } + ... + } +} + +# 设置消息 +starcoin% account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::set_message --arg b"abcdefg" -b + +# 查看消息,结果为 "abcdefg" 的 BCS 编码 +starcoin% dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::message::get_message --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + { + "bytes": "0x61626364656667" + } + ] +} +``` \ 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 new file mode 100644 index 000000000..1d7effa87 --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/04-resource-groups.md @@ -0,0 +1,103 @@ +# 资源组 (Resource Groups) + +本章节介绍如何在 Starcoin 区块链上测试和部署 `resource-groups` 示例工程,用以测试 VM2 下的资源组功能。该合约分为两部分:`primary` 模块用于测试资源组的基本功能,`secondary` 模块用于测试跨模块的资源组引用。 + +## 前提条件 + +该工程位于 [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):用于与节点连接。 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager):用于打包 Move 模块。 + +假设 Starcoin 二进制文件已编译成功,执行以下命令连接到 Starcoin 控制台并打包工程: + +```shell +# 连接到 Starcoin 控制台, 为网络名称(如 dev、barnard 等) +starcoin -n console + +# 查看节点的同步进度,确保本地节点同步完成后再提交测试交易 +starcoin% node sync progress +There are no running sync tasks. +``` + +## 测试指令集 + +### 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 + +# 检查值,预期返回 10000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 10000 + ] +} + +# 设置值为 20000 +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::primary::set_value --arg 20000u64 -b + +# 检查值,预期返回 20000 +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 +{ + "ok": [ + false + ] +} +``` + +### Secondary 模块 + +```shell +# 部署 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 + +# 检查值,预期返回 10000 +dev call --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::read --arg 0x143e9f2175f92f51d9adaeee2b3d8bf0 +{ + "ok": [ + 10000 + ] +} + +# 设置值为 20000 +account execute-function -s 0x143e9f2175f92f51d9adaeee2b3d8bf0 --function 0x143e9f2175f92f51d9adaeee2b3d8bf0::secondary::set_value --arg 20000u32 -b + +# 检查值,预期返回 20000 +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 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..6d57f172b --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/03-move/98-move-examples/05-shared-account.md @@ -0,0 +1,53 @@ +# 共享账户 (Shared Account) + +本章节介绍如何在 Starcoin 区块链上测试和部署 `shared-account` 示例工程。该工程旨在模拟 NFT 佣金分发的场景:从主账户创建一个派生账户,将部分代币存入派生账户,并添加参与佣金分发的账户。在需要分发时,直接从派生账户中进行分发。 + +## 前提条件 + +该工程位于 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):用于与节点连接。 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager):用于打包 Move 模块。 + +假设 Starcoin 二进制文件已编译成功,执行以下命令连接到 Starcoin 控制台并打包工程: + +```shell +# 连接到 Starcoin 控制台, 为网络名称(如 dev、barnard 等) +starcoin -n console + +# 查看节点的同步进度,确保本地节点同步完成后再提交测试交易 +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 + +# 查询派生账户的地址 +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::initialize_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 +``` \ 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 new file mode 100644 index 000000000..6c4cc6550 --- /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)授权给接收者(Recipient,简称 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):用于与节点连接。 +2. [move-package-manager2](https://github.com/starcoinorg/starcoin/tree/dual-verse-dag/vm2/move-package-manager):用于打包 Move 模块。 + +假设 Starcoin 二进制文件已编译成功,并导入以下账户信息: + +- 发起者(S)账户:`0x82cbfefb8076f2da3339b782fb074438` +- 接收者(R1)账户:`0x95cb8c2ef522014bd03f633bd6c8dee6` +- 接收者(R2)账户:`0x7111c56355d63f3434aa7de8b3c94aff` + +账户导入数据(JSON 格式): + +```json +[ + { + "ok": { + "account": "0x82cbfefb8076f2da3339b782fb074438", + "private_key": "0x01f747e8476fe3727ca29ae87fd44dd8d222609b42517274908c9ef24023169a" + } + }, + { + "ok": { + "account": "0x95cb8c2ef522014bd03f633bd6c8dee6", + "private_key": "0x37528fbbace04e2b3609de312bdcfeb4704cd83a3488b9fc836118d02835c36e" + } + }, + { + "ok": { + "account": "0x7111c56355d63f3434aa7de8b3c94aff", + "private_key": "0xb1a0d666adaae36d103631a182f8742717c7a650f374912804a1f5e740f4b1b7" + } + } +] +``` + +执行以下命令连接到 Starcoin 控制台并打包工程: + +```shell +# 连接到 Starcoin 控制台, 为网络名称(如 dev、barnard 等) +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 账户发起授权,将 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),锁仓时间 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 的锁仓总数 +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::total_locks -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 + +# 查看 S 为 R1 锁仓的额度 +dev call --function 0x82cbfefb8076f2da3339b782fb074438::locked_coins::locked_amount -t 0x1::starcoin_coin::STC --arg 0x82cbfefb8076f2da3339b782fb074438 --arg 0x95cb8c2ef522014bd03f633bd6c8dee6 + +# 查看 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 秒内提取会报错) +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,锁仓时间 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 + +# 取消锁仓 +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/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"