From d85cbcdacd300b8187633b56d9d14a45b2d860c7 Mon Sep 17 00:00:00 2001 From: tornoto Date: Thu, 14 Nov 2024 21:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20task=201=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tornoto/code/task2/custom_coin/Move.toml | 37 +++++++++++++++++++ .../custom_coin/sources/faucet_coin.move | 25 +++++++++++++ .../task2/custom_coin/sources/my_coin.move | 28 ++++++++++++++ mover/Tornoto/readme.md | 10 ++--- 4 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 mover/Tornoto/code/task2/custom_coin/Move.toml create mode 100644 mover/Tornoto/code/task2/custom_coin/sources/faucet_coin.move create mode 100644 mover/Tornoto/code/task2/custom_coin/sources/my_coin.move diff --git a/mover/Tornoto/code/task2/custom_coin/Move.toml b/mover/Tornoto/code/task2/custom_coin/Move.toml new file mode 100644 index 000000000..487e08c81 --- /dev/null +++ b/mover/Tornoto/code/task2/custom_coin/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "custom_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] +custom_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/Tornoto/code/task2/custom_coin/sources/faucet_coin.move b/mover/Tornoto/code/task2/custom_coin/sources/faucet_coin.move new file mode 100644 index 000000000..54165c261 --- /dev/null +++ b/mover/Tornoto/code/task2/custom_coin/sources/faucet_coin.move @@ -0,0 +1,25 @@ +module custom_coin::faucet_coin; +use custom_coin::MY_COIN::MY_COIN; +use sui::coin::TreasuryCap; + +// MY_COIN 的 decimal 是 6,每次给 1 个 +const FAUCET_AMOUNT: u64 = 1_000_000; + +public struct Faucet has key { + id: UID, + treasury_cap: TreasuryCap, +} + +public entry +fun create_faucet(treasury_cap: TreasuryCap, ctx: &mut TxContext) { + let faucet = Faucet { + id: object::new(ctx), + treasury_cap, + }; + transfer::share_object(faucet); +} + +public entry +fun request_coin(faucet: &mut Faucet, recipient: address, ctx: &mut TxContext) { + custom_coin::MY_COIN::mint(&mut faucet.treasury_cap, FAUCET_AMOUNT, recipient, ctx); +} \ No newline at end of file diff --git a/mover/Tornoto/code/task2/custom_coin/sources/my_coin.move b/mover/Tornoto/code/task2/custom_coin/sources/my_coin.move new file mode 100644 index 000000000..63e1457ef --- /dev/null +++ b/mover/Tornoto/code/task2/custom_coin/sources/my_coin.move @@ -0,0 +1,28 @@ +/// Module: custom_coin +module custom_coin::MY_COIN; +use sui::coin; +use sui::coin::TreasuryCap; + +public struct MY_COIN has drop {} + +fun init(witness: MY_COIN, ctx: &mut TxContext) { + let (treasury_cap, coin_metadata) = coin::create_currency( + witness, + 6, + b"Fc", + b"fish_coin", + b"you fish, your fish", + option::none(), + ctx + ); + transfer::public_transfer(treasury_cap, tx_context::sender(ctx)); + transfer::public_freeze_object(coin_metadata); +} + +public +fun mint(treasury_cap: &mut TreasuryCap, + amount: u64, + recipient: address, + ctx: &mut TxContext) { + coin::mint_and_transfer(treasury_cap, amount, recipient, ctx); +} diff --git a/mover/Tornoto/readme.md b/mover/Tornoto/readme.md index f68898188..bf65de0cc 100644 --- a/mover/Tornoto/readme.md +++ b/mover/Tornoto/readme.md @@ -23,11 +23,11 @@ ## 02 move coin -- [] My Coin package id : -- [] Faucet package id : -- [] 转账 `My Coin` hash: -- [] `Faucet Coin` address1 mint hash: -- [] `Faucet Coin` address2 mint hash: +- [x] My Coin package id :0xfcae7534403e4e6c0899c1a85864af7a3016e1c55fa681e223a74f5d23ee2fbc +- [x] Faucet package id :0xfcae7534403e4e6c0899c1a85864af7a3016e1c55fa681e223a74f5d23ee2fbc +- [x] 转账 `My Coin` hash:2VTNQ2ZWsgsnQid5ks7DBEorkxJoaGBZFcdeoHRTgsX8 +- [x] `Faucet Coin` address1 mint hash:841BygAzkEFTGyHAiWq1dLH8gCGYbCcqWhnQgduDwMBx +- [x] `Faucet Coin` address2 mint hash:4YJ3xjdBHwGUFNLqANU6A7JGS7HyThfftm7wxfrcZSBf ## 03 move NFT