Skip to content

Commit

Permalink
task2和task3
Browse files Browse the repository at this point in the history
  • Loading branch information
wenchao13547 committed Dec 1, 2024
1 parent f435b79 commit 5ed1206
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
40 changes: 40 additions & 0 deletions mover/wenchao13547/code/task2/faucet_coin/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "F8CFCF256E2F1BB7CD401C27799A09C40777C5C100F0DFA253E86DD7F0D4ED1B"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ id = "Sui", name = "Sui" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" }

[[move.package]]
id = "Sui"
source = { git = "https://github.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.37.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0xd59f33fa57cd8e72329ba5abf885907ba7f18d736ebe6d70e2ba76e780285605"
latest-published-id = "0xd59f33fa57cd8e72329ba5abf885907ba7f18d736ebe6d70e2ba76e780285605"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xdcf3749d51e66858ee2443fcc0b92b33482986580aa2db686e5a0d1e5a07ffac"
latest-published-id = "0xdcf3749d51e66858ee2443fcc0b92b33482986580aa2db686e5a0d1e5a07ffac"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/wenchao13547/code/task2/faucet_coin/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "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 ([email protected])", "John Snow ([email protected])"]

[dependencies]
Sui = { git = "https://github.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]
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"

60 changes: 60 additions & 0 deletions mover/wenchao13547/code/task2/faucet_coin/sources/rr.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
/// Module: uu
module my_coin::my_coin;
*/
module faucet_coin::rr {
use std::option;
use sui::coin::{Self, Coin, TreasuryCap};
use sui::transfer;
use sui::tx_context::{Self, TxContext};
/// Struct: Coin
public struct RR has drop {}


fun init(rr: RR, ctx: &mut TxContext) {
let (treasury_cap, metadata) = coin::create_currency<RR>(
rr,
0,
b"RR",
b"RR",
b"this id my faucet coin",
option::none(),
ctx
);
// 共享但不可修改
transfer::public_freeze_object(metadata);
// 共享所有权,每人人都可铸币
transfer::public_share_object(treasury_cap)
}


// `mint` 函数是一个公开的入口函数,用于增加特定数量的货币到区块链的流通中。
// 这个函数接受四个参数:
// - `treasury_cap`: 一个指向 `TreasuryCap<UU>` 类型的可变引用,用于控制货币的铸造上限。
// - `amount`: 一个 `u64` 类型的无符号整数,表示要铸造的货币数量。
// - `recipient`: 一个 `address` 类型的值,表示接收新铸造货币的地址。
// - `ctx`: 一个指向 `TxContext` 类型的可变引用,包含了当前交易的上下文信息。
public entry fun mint(
treasury_cap: &mut TreasuryCap<RR>,
amount: u64,
recipient: address,
ctx: &mut TxContext
) {
// 调用 `coin` 模块中的 `mint_and_transfer` 函数,将新铸造的货币转移到指定的接收者地址。
// 这个函数会处理货币的铸造和转账逻辑,确保不超过 `treasury_cap` 指定的铸造上限。
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx)
}

// `burn` 函数是一个公开的入口函数,用于从区块链的流通中移除特定数量的货币。
// 这个函数接受两个参数:
// - `treasury_cap`: 一个指向 `TreasuryCap<UU>` 类型的可变引用,用于控制货币的销毁上限。
// - `coin`: 一个 `Coin<UU>` 类型的值,表示要销毁的货币。
public entry fun burn(
treasury_cap: &mut TreasuryCap<RR>,
coin: Coin<RR>
) {
// 调用 `coin` 模块中的 `burn` 函数,销毁指定的货币。
// 这个函数会处理货币的销毁逻辑,确保操作符合 `treasury_cap` 指定的销毁上限。
coin::burn(treasury_cap, coin);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module faucet_coin::faucet_coin_tests;
// uncomment this line to import the module
// use faucet_coin::faucet_coin;
const ENotImplemented: u64 = 0;
#[test]
fun test_faucet_coin() {
// pass
}
#[test, expected_failure(abort_code = ::faucet_coin::faucet_coin_tests::ENotImplemented)]
fun test_faucet_coin_fail() {
abort ENotImplemented
}
*/

0 comments on commit 5ed1206

Please sign in to comment.