-
Notifications
You must be signed in to change notification settings - Fork 891
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1839 from Tornoto/main
完成 task 1 2
- Loading branch information
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ([email protected])", "John Snow ([email protected])"] | ||
|
||
[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" | ||
|
25 changes: 25 additions & 0 deletions
25
mover/Tornoto/code/task2/custom_coin/sources/faucet_coin.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MY_COIN>, | ||
} | ||
|
||
public entry | ||
fun create_faucet(treasury_cap: TreasuryCap<MY_COIN>, 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MY_COIN>, | ||
amount: u64, | ||
recipient: address, | ||
ctx: &mut TxContext) { | ||
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters