-
Notifications
You must be signed in to change notification settings - Fork 897
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 #1915 from looikaizhi/main
task2&3
- Loading branch information
Showing
11 changed files
with
342 additions
and
9 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,40 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 3 | ||
manifest_digest = "A236805D79A413A3B07C3DCC6F251FE22E504BD8453FE8F1D79388B523090A81" | ||
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.36.2" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.testnet] | ||
chain-id = "4c78adac" | ||
original-published-id = "0x798d058dd7a4ad2668f579bae7ae99729cf8c800c3de8a29d446fc683197f500" | ||
latest-published-id = "0x798d058dd7a4ad2668f579bae7ae99729cf8c800c3de8a29d446fc683197f500" | ||
published-version = "1" | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0x8865d5e7cedd69aa766fb758b2436b54439546e6e6956050e2c146dc228738ff" | ||
latest-published-id = "0x8865d5e7cedd69aa766fb758b2436b54439546e6e6956050e2c146dc228738ff" | ||
published-version = "1" |
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 = "generate_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] | ||
generate_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" | ||
|
39 changes: 39 additions & 0 deletions
39
mover/looikaizhi/code/task2/generate_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,39 @@ | ||
module generate_coin::faucet_coin{ | ||
use sui::coin::{Self, TreasuryCap}; | ||
use sui::tx_context::TxContext; | ||
|
||
public struct FAUCET_COIN has drop{} | ||
|
||
public struct TreasuryCaoHolder has key, store{ | ||
id: UID, | ||
treasury_cap: TreasuryCap<FAUCET_COIN>, | ||
} | ||
|
||
// otw = One-time witness,确保只能在init初始化调用一次,同时1结构体只有drop能力 | ||
fun init(otw:FAUCET_COIN, ctx: &mut TxContext){ | ||
let (treasury_cap, metadata) = coin::create_currency( | ||
otw, | ||
6, | ||
b"looikaizhi_Faucet", | ||
b"LKZF", | ||
b"Who can let me become a memecoin!!(This is faucet)", | ||
option::none(), | ||
ctx | ||
); | ||
transfer::public_freeze_object(metadata); | ||
|
||
let treasury_cap_holder = TreasuryCaoHolder{ | ||
id: object::new(ctx), | ||
treasury_cap, | ||
}; | ||
transfer::share_object(treasury_cap_holder); | ||
|
||
} | ||
|
||
public entry fun mint(treasury: &mut TreasuryCaoHolder, ctx: &mut TxContext){ | ||
let sender = tx_context::sender(ctx); | ||
let treasury_cap = &mut treasury.treasury_cap; | ||
let coin = coin::mint(treasury_cap, 10, ctx); // mint代币 | ||
transfer::public_transfer(coin, sender); // 转移至指定地址 | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
mover/looikaizhi/code/task2/generate_coin/sources/my_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,49 @@ | ||
module generate_coin::my_coin { | ||
use sui::coin::{Self, TreasuryCap}; | ||
use sui::tx_context::TxContext; | ||
|
||
public struct MY_COIN has drop{} | ||
|
||
public struct TreasuryCaoHolder has key, store{ | ||
id: UID, | ||
treasury_cap: TreasuryCap<MY_COIN>, | ||
} | ||
|
||
const Minter:address = @0x7b8e0864967427679b4e129f79dc332a885c6087ec9e187b53451a9006ee15f2; | ||
const MAX_SUPPLY: u64 = 1_000_000_000; | ||
|
||
|
||
fun init(otw: MY_COIN, ctx: &mut TxContext){ | ||
let (treasury_cap, metadata) = coin::create_currency( | ||
otw, | ||
6, | ||
b"looikaizhi", | ||
b"LKZ", | ||
b"Who can let me become a memecoin!!", | ||
option::none(), | ||
ctx | ||
); | ||
|
||
transfer::public_freeze_object(metadata); // 冻结 metadata,以确保其内容不可更改 | ||
|
||
let treasury_cap_holder = TreasuryCaoHolder{ | ||
id: object::new(ctx), | ||
treasury_cap, | ||
}; | ||
transfer::public_transfer(treasury_cap_holder, tx_context::sender(ctx)); //将 TreasuryCap 赋予Minter地址 | ||
|
||
} | ||
|
||
public entry fun mint(treasury: &mut TreasuryCaoHolder, minter: address, amount: u64, ctx: &mut TxContext){ | ||
assert!(minter == Minter, 0); // 确保是指定地址 | ||
|
||
let treasury_cap = &mut treasury.treasury_cap; | ||
let current_supply:u64 = coin::total_supply<MY_COIN>(treasury_cap); // 当前代币的总量 | ||
assert!((current_supply + amount) <= MAX_SUPPLY, 0); // 确保不会超出最大供应量 | ||
|
||
let coin = coin::mint(treasury_cap, amount, ctx); // mint代币 | ||
transfer::public_transfer(coin, minter); // 转移至指定地址 | ||
} | ||
|
||
} | ||
|
18 changes: 18 additions & 0 deletions
18
mover/looikaizhi/code/task2/generate_coin/tests/generate_coin_tests.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,18 @@ | ||
/* | ||
#[test_only] | ||
module generate_coin::generate_coin_tests; | ||
// uncomment this line to import the module | ||
// use generate_coin::generate_coin; | ||
const ENotImplemented: u64 = 0; | ||
#[test] | ||
fun test_generate_coin() { | ||
// pass | ||
} | ||
#[test, expected_failure(abort_code = ::generate_coin::generate_coin_tests::ENotImplemented)] | ||
fun test_generate_coin_fail() { | ||
abort ENotImplemented | ||
} | ||
*/ |
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,40 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 3 | ||
manifest_digest = "DC3595091D0FF8B4EA079E2AC5459C03D25A297D44F2480119C7700E4FB53CA0" | ||
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.36.2" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.testnet] | ||
chain-id = "4c78adac" | ||
original-published-id = "0x8cdbb3bd9c005ed5d59eb1cbc1da523d30aea54a214658dd3785d83e5bcc86a2" | ||
latest-published-id = "0x8cdbb3bd9c005ed5d59eb1cbc1da523d30aea54a214658dd3785d83e5bcc86a2" | ||
published-version = "1" | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0xd1f718046bdc4071742938fb13b2976eec402bd793db9aaf0ea6c0e2221637fe" | ||
latest-published-id = "0xd1f718046bdc4071742938fb13b2976eec402bd793db9aaf0ea6c0e2221637fe" | ||
published-version = "1" |
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 = "generate_NFT" | ||
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] | ||
generate_nft = "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" | ||
|
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,55 @@ | ||
module generate_nft::nft{ | ||
use std::string::{utf8, String}; | ||
use sui::package; | ||
use sui::display; | ||
use sui::transfer; | ||
|
||
public struct MyNFT has key, store{ | ||
id: UID, | ||
name: String | ||
} | ||
|
||
public struct NFT has drop{} | ||
|
||
fun init(otw: NFT, ctx: &mut TxContext){ | ||
let keys = vector[ | ||
utf8(b"name"), | ||
utf8(b"link"), | ||
utf8(b"image_url"), | ||
utf8(b"description"), | ||
utf8(b"project_url"), | ||
utf8(b"creator"), | ||
]; | ||
|
||
let values = vector[ | ||
utf8(b"{name}"), | ||
utf8(b"https://sui-heroes.io/hero/{id}"), | ||
utf8(b"https://pbs.twimg.com/profile_images/1809913909513699328/6IF8so7d_400x400.jpg"), | ||
utf8(b"A Meme NFT of the Sui ecosystem!"), | ||
utf8(b"https://docs.sui.io/standards/display"), | ||
utf8(b"looikaizhi"), | ||
]; | ||
|
||
let publisher = package::claim(otw, ctx); | ||
|
||
let mut display = display::new_with_fields<MyNFT>( | ||
&publisher, keys, values, ctx | ||
); | ||
|
||
display.update_version(); | ||
|
||
transfer::public_transfer(publisher, ctx.sender()); | ||
transfer::public_transfer(display, ctx.sender()); | ||
} | ||
|
||
public entry fun mint(name: String, minter:address, ctx: &mut TxContext){ | ||
let nft = MyNFT{ | ||
id: object::new(ctx), | ||
name | ||
}; | ||
|
||
transfer::public_transfer(nft, minter); | ||
} | ||
|
||
} | ||
|
18 changes: 18 additions & 0 deletions
18
mover/looikaizhi/code/task3/generate_NFT/tests/generate_nft_tests.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,18 @@ | ||
/* | ||
#[test_only] | ||
module generate_nft::generate_nft_tests; | ||
// uncomment this line to import the module | ||
// use generate_nft::generate_nft; | ||
const ENotImplemented: u64 = 0; | ||
#[test] | ||
fun test_generate_nft() { | ||
// pass | ||
} | ||
#[test, expected_failure(abort_code = ::generate_nft::generate_nft_tests::ENotImplemented)] | ||
fun test_generate_nft_fail() { | ||
abort ENotImplemented | ||
} | ||
*/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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