From 4a9a22451d504cdff4d34a7a0187413c1a173df5 Mon Sep 17 00:00:00 2001 From: Eureka <49989931+M2887@users.noreply.github.com> Date: Mon, 9 Dec 2024 19:20:11 +0800 Subject: [PATCH] task2 --- mover/M2887/code/task2/M2887_coin/Move.lock | 34 ++++++++++ mover/M2887/code/task2/M2887_coin/Move.toml | 37 +++++++++++ .../task2/M2887_coin/sources/m2887_coin.move | 64 +++++++++++++++++++ .../M2887_coin/tests/m2887_coin_tests.move | 18 ++++++ .../code/task2/M2887_faucet_coin/Move.lock | 34 ++++++++++ .../code/task2/M2887_faucet_coin/Move.toml | 37 +++++++++++ .../sources/m2887_faucet_coin.move | 50 +++++++++++++++ .../tests/m2887_faucet_coin_tests.move | 18 ++++++ mover/M2887/readme.md | 10 +-- 9 files changed, 297 insertions(+), 5 deletions(-) create mode 100644 mover/M2887/code/task2/M2887_coin/Move.lock create mode 100644 mover/M2887/code/task2/M2887_coin/Move.toml create mode 100644 mover/M2887/code/task2/M2887_coin/sources/m2887_coin.move create mode 100644 mover/M2887/code/task2/M2887_coin/tests/m2887_coin_tests.move create mode 100644 mover/M2887/code/task2/M2887_faucet_coin/Move.lock create mode 100644 mover/M2887/code/task2/M2887_faucet_coin/Move.toml create mode 100644 mover/M2887/code/task2/M2887_faucet_coin/sources/m2887_faucet_coin.move create mode 100644 mover/M2887/code/task2/M2887_faucet_coin/tests/m2887_faucet_coin_tests.move diff --git a/mover/M2887/code/task2/M2887_coin/Move.lock b/mover/M2887/code/task2/M2887_coin/Move.lock new file mode 100644 index 000000000..d38988c7a --- /dev/null +++ b/mover/M2887/code/task2/M2887_coin/Move.lock @@ -0,0 +1,34 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "A3C48AC10A4DA68968B0E13A48727700DF3E5338373844B02767097F9C3C2AEE" +deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.38.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x5a3a556c1b4cb0d9e20595fc0819bef617de4a6b16c258e58f49e7d1c27d4cf9" +latest-published-id = "0x5a3a556c1b4cb0d9e20595fc0819bef617de4a6b16c258e58f49e7d1c27d4cf9" +published-version = "1" diff --git a/mover/M2887/code/task2/M2887_coin/Move.toml b/mover/M2887/code/task2/M2887_coin/Move.toml new file mode 100644 index 000000000..efc3531f0 --- /dev/null +++ b/mover/M2887/code/task2/M2887_coin/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "M2887_coin" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +m2887_coin = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/mover/M2887/code/task2/M2887_coin/sources/m2887_coin.move b/mover/M2887/code/task2/M2887_coin/sources/m2887_coin.move new file mode 100644 index 000000000..f6ae56937 --- /dev/null +++ b/mover/M2887/code/task2/M2887_coin/sources/m2887_coin.move @@ -0,0 +1,64 @@ +/* +/// Module: m2887_coin +module m2887_coin::m2887_coin; +*/ +/* +/// Module: m2887_coin +module m2887_coin::m2887_coin; +*/ + +module m2887_coin::m2887_coin { // 定义模块 M2887_coin + use sui::coin::{Self, Coin, TreasuryCap}; // 引入 Coin 和 TreasuryCap 相关功能 + use sui::url::{Self, Url}; // 引入 URL 相关功能 + + // 定义一种新的货币类型 M2887_COIN,且具有可丢弃的特性 + public struct M2887_COIN has drop {} + + // 初始化函数,用于创建该货币 + fun init( + witness: M2887_COIN, // 货币的见证对象 + ctx: &mut TxContext // 交易上下文 + ) { + // 调用 coin 模块创建货币,并设置相关参数 + let (treasury_cap, metadata) = coin::create_currency( + witness, // 见证对象 + 9, // 小数位数 + b"M2887", // 货币符号 + b"M2887_COIN", // 货币代码 + b"M2887 Coin", // 货币名称 + option::some( // 货币相关的 URL + url::new_unsafe_from_bytes( + b"https://avatars.githubusercontent.com/u/49989931" // 头像链接 + ) + ), + ctx // 交易上下文 + ); + // 冻结元数据对象,确保其在交易过程中不会被修改 + transfer::public_freeze_object(metadata); + // 将国库资本转移到交易的发送者地址 + transfer::public_transfer( + treasury_cap, + tx_context::sender(ctx) // 获取发送者地址 + ) + } + + // 公共入口函数,用于铸造新的 M2887_COIN 货币 + public entry fun mint( + treasury_cap: &mut TreasuryCap, // 货币国库 + amount: u64, // 铸造的数量 + recipient: address, // 接收地址 + ctx: &mut TxContext // 交易上下文 + ) { + // 调用 coin 模块的铸造和转移函数 + coin::mint_and_transfer(treasury_cap, amount, recipient, ctx); + } + + // 公共函数,用于销毁 M2887_COIN 货币 + public fun burn( + treasury_cap: &mut TreasuryCap, // 货币国库 + coin: Coin // 需要销毁的货币 + ) { + // 调用 coin 模块的销毁函数 + coin::burn(treasury_cap, coin); + } +} diff --git a/mover/M2887/code/task2/M2887_coin/tests/m2887_coin_tests.move b/mover/M2887/code/task2/M2887_coin/tests/m2887_coin_tests.move new file mode 100644 index 000000000..83dda0292 --- /dev/null +++ b/mover/M2887/code/task2/M2887_coin/tests/m2887_coin_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module m2887_coin::m2887_coin_tests; +// uncomment this line to import the module +// use m2887_coin::m2887_coin; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_m2887_coin() { + // pass +} + +#[test, expected_failure(abort_code = ::m2887_coin::m2887_coin_tests::ENotImplemented)] +fun test_m2887_coin_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/M2887/code/task2/M2887_faucet_coin/Move.lock b/mover/M2887/code/task2/M2887_faucet_coin/Move.lock new file mode 100644 index 000000000..b265786d2 --- /dev/null +++ b/mover/M2887/code/task2/M2887_faucet_coin/Move.lock @@ -0,0 +1,34 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "3A777708EF0279F6E6ACE0D9041A7E7BDAD519CF18475E902C51FEFD4A64DAAB" +deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.38.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x8526f8f3d7e23ca6e2c68c67855357745f03a9097d93a3dd3274a44290fc3faa" +latest-published-id = "0x8526f8f3d7e23ca6e2c68c67855357745f03a9097d93a3dd3274a44290fc3faa" +published-version = "1" diff --git a/mover/M2887/code/task2/M2887_faucet_coin/Move.toml b/mover/M2887/code/task2/M2887_faucet_coin/Move.toml new file mode 100644 index 000000000..3b642289e --- /dev/null +++ b/mover/M2887/code/task2/M2887_faucet_coin/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "M2887_faucet_coin" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +m2887_faucet_coin = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/mover/M2887/code/task2/M2887_faucet_coin/sources/m2887_faucet_coin.move b/mover/M2887/code/task2/M2887_faucet_coin/sources/m2887_faucet_coin.move new file mode 100644 index 000000000..6bd6b7598 --- /dev/null +++ b/mover/M2887/code/task2/M2887_faucet_coin/sources/m2887_faucet_coin.move @@ -0,0 +1,50 @@ +/* +/// Module: m2887_faucet_coin +module m2887_faucet_coin::m2887_faucet_coin; +*/ +module m2887_faucet_coin::m2887_faucet_coin { + use sui::coin::{Self, Coin, TreasuryCap}; + use sui::url::{Self, Url}; + + public struct M2887_FAUCET_COIN has drop {} + + fun init( + witness: M2887_FAUCET_COIN, + ctx: &mut TxContext + ) { + let (treasury_cap, metadata) = coin::create_currency( + witness, + 9, + b"CRF", + b"M2887_FAUCET_COIN", + b"M2887 Faucet Coin", + option::some( + url::new_unsafe_from_bytes( + b"https://avatars.githubusercontent.com/u/49989931" + ) + ), + ctx + ); + transfer::public_freeze_object(metadata); + transfer::public_share_object(treasury_cap) + } + + public entry fun mint( + treasury_cap: &mut TreasuryCap, + amount: u64, + recipient: address, + ctx: &mut TxContext + ) { + coin::mint_and_transfer(treasury_cap, amount, recipient, ctx); + } + + public fun burn( + treasury_cap: &mut TreasuryCap, + coin: Coin + ) { + coin::burn(treasury_cap, coin); + + } +} + + diff --git a/mover/M2887/code/task2/M2887_faucet_coin/tests/m2887_faucet_coin_tests.move b/mover/M2887/code/task2/M2887_faucet_coin/tests/m2887_faucet_coin_tests.move new file mode 100644 index 000000000..9785c3ce5 --- /dev/null +++ b/mover/M2887/code/task2/M2887_faucet_coin/tests/m2887_faucet_coin_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module m2887_faucet_coin::m2887_faucet_coin_tests; +// uncomment this line to import the module +// use m2887_faucet_coin::m2887_faucet_coin; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_m2887_faucet_coin() { + // pass +} + +#[test, expected_failure(abort_code = ::m2887_faucet_coin::m2887_faucet_coin_tests::ENotImplemented)] +fun test_m2887_faucet_coin_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/M2887/readme.md b/mover/M2887/readme.md index bc9e2d360..dede15804 100755 --- a/mover/M2887/readme.md +++ b/mover/M2887/readme.md @@ -19,11 +19,11 @@ - [] package id 在 scan上的查看截图:![Scan截图](./images/SuiScan.png) ## 02 move coin -- [] My Coin package id : -- [] Faucet package id : -- [] 转账 `My Coin` hash: -- [] `Faucet Coin` address1 mint hash: -- [] `Faucet Coin` address2 mint hash: +- [] My Coin package id : 0x5a3a556c1b4cb0d9e20595fc0819bef617de4a6b16c258e58f49e7d1c27d4cf9 +- [] Faucet package id : 0x8526f8f3d7e23ca6e2c68c67855357745f03a9097d93a3dd3274a44290fc3faa +- [] 转账 `My Coin` hash: E7n184sQfv9zPwZ5MZV2AAQoQPPnafXi1mTMqDwc8Uzp +- [] `Faucet Coin` address1 mint hash: 447AsExCJqbPaYqo1wgZnXvNmDoToua5X33qARR1WHsq +- [] `Faucet Coin` address2 mint hash: 97y7zWpdvJHN1u8bx1rn1QxhdhbM3UB8qfJ1sc2nCgAn ## 03 move NFT - [] nft package id :