Skip to content

Commit

Permalink
Merge pull request #2092 from Helen2022a/main
Browse files Browse the repository at this point in the history
task2 and task3 by Helen2022a
  • Loading branch information
Sifotd authored Dec 4, 2024
2 parents fe5b7b9 + c5840d2 commit 84f879f
Show file tree
Hide file tree
Showing 14 changed files with 408 additions and 9 deletions.
34 changes: 34 additions & 0 deletions mover/Helen2022a/code/task2/faucet_coin/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @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.mainnet]
chain-id = "35834a8a"
original-published-id = "0x5d2aad9075f6d13961d0d08545eaf9e3194b466f9775bc45492e87395ba3059b"
latest-published-id = "0x5d2aad9075f6d13961d0d08545eaf9e3194b466f9775bc45492e87395ba3059b"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/Helen2022a/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"

26 changes: 26 additions & 0 deletions mover/Helen2022a/code/task2/faucet_coin/sources/faucet_coin.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module faucet_coin::faucet_coin{
use std::option;
use sui::coin;
use sui::coin::{mint_and_transfer,TreasuryCap};
use sui::transfer::{public_share_object,public_freeze_object};
use sui::tx_context::TxContext;

//一次性见证者的名字是模块名的大写,如模块名为faucet_coin,则一次性见证者的名字则为FAUCET_COIN。一次性见证者只拥有drop能力
public struct FAUCET_COIN has drop{}

fun init (witness:FAUCET_COIN,ctx:&mut TxContext){
//treasury_cap,faucet_coin分别是指代币的铸币权和代币信息
//从左往右输入的参数依次是一次性见证者,代币的精度(例如微信最低是分),代币符号,代币名称,代币描述,代币图标的链接,特殊参数(不需要指定)
let (treasury_cap,faucet_coin) = coin::create_currency(witness,8,b"Helen2022a_faucet",b"Helen2022a_faucet_coin",b"First faucet coin created by Helen2022a", option::none(),ctx);

//使用冻结函数确保faucet_coin的信息不更改
public_freeze_object(faucet_coin);
//权限转移,faucet_coin的铸造权通过 public_share_object函数共享给每个人
public_share_object(treasury_cap);
}

public entry fun mint_and_send(treasury_cap:&mut TreasuryCap<FAUCET_COIN>,amount:u64,recipient:address,ctx:&mut TxContext){
//先铸造再发送
mint_and_transfer(treasury_cap,amount,recipient,ctx);
}
}
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
}
*/
34 changes: 34 additions & 0 deletions mover/Helen2022a/code/task2/my_coin/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "0A4652D38CF3C3FDB79EC6C1C98FCFF7B2E933E12B84A1DA267DB28F66AFECE3"
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.mainnet]
chain-id = "35834a8a"
original-published-id = "0x5c3a6b4a55686eb982ce65be5cb4b0d7935765c8be1dc1902de031efd945866e"
latest-published-id = "0x5c3a6b4a55686eb982ce65be5cb4b0d7935765c8be1dc1902de031efd945866e"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/Helen2022a/code/task2/my_coin/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "my_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]
my_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 mover/Helen2022a/code/task2/my_coin/sources/my_coin.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module my_coin::my_coin{
use std::option;
use sui::coin;
use sui::coin::{mint_and_transfer,TreasuryCap};
use sui::transfer::{public_transfer,public_freeze_object};
use sui::tx_context::TxContext;

//一次性见证者的名字是模块名的大写,如模块名为my_coin,则一次性见证者的名字则为MY_COIN。一次性见证者只拥有drop能力
public struct MY_COIN has drop{}

fun init (witness:MY_COIN,ctx:&mut TxContext){
//treasury_cap,my_coin分别是指代币的铸币权和代币信息
//从左往右输入的参数依次是一次性见证者,代币的精度(例如微信最低是分),代币符号,代币名称,代币描述,代币图标的链接,特殊参数(不需要指定)
let (treasury_cap,my_coin) = coin::create_currency(witness,8,b"Helen2022a",b"Helen2022a_coin",b"First coin created by Helen2022a", option::none(),ctx);
//使用冻结函数确保my_coin的信息不更改
public_freeze_object(my_coin);
//权限转移,my_coin的铸造权通过 public_share_object函数共享给每个人
public_transfer(treasury_cap, tx_context::sender(ctx));
}

public entry fun mint_and_send(treasury_cap:&mut TreasuryCap<MY_COIN>,amount:u64,recipient:address,ctx:&mut TxContext){
//先铸造再发送
mint_and_transfer(treasury_cap,amount,recipient,ctx);
}
}
18 changes: 18 additions & 0 deletions mover/Helen2022a/code/task2/my_coin/tests/my_coin_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module my_coin::my_coin_tests;
// uncomment this line to import the module
// use my_coin::my_coin;
const ENotImplemented: u64 = 0;
#[test]
fun test_my_coin() {
// pass
}
#[test, expected_failure(abort_code = ::my_coin::my_coin_tests::ENotImplemented)]
fun test_my_coin_fail() {
abort ENotImplemented
}
*/
34 changes: 34 additions & 0 deletions mover/Helen2022a/code/task3/my_nft/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "4C9B47E7441289AA0D50D87EEB9836BD01CE3604E3B249490E7F2046EAEE3400"
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.mainnet]
chain-id = "35834a8a"
original-published-id = "0x4c0422d8d35d3bb908d90b4bd3bcd1c784529508ee441e5e4e512b0a4e29fe97"
latest-published-id = "0x4c0422d8d35d3bb908d90b4bd3bcd1c784529508ee441e5e4e512b0a4e29fe97"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/Helen2022a/code/task3/my_nft/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "my_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]
my_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"

73 changes: 73 additions & 0 deletions mover/Helen2022a/code/task3/my_nft/sources/my_nft.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module my_nft::my_nft;

use std::string::String;

// The creator bundle: these two packages often go together.
use sui::package;
use sui::display;

/// The MyNft - an outstanding collection of digital art.
public struct MyNft has key, store {
id: UID,
name: String,
image_url: String,
}

/// One-Time-Witness for the module.
public struct MY_NFT has drop {}

/// Claim the `Publisher` object in the module initializer
/// to then create a `Display`. The `Display` is initialized with
/// a set of fields (but can be modified later) and published via
/// the `update_version` call.
///
/// Keys and values are set in the initializer but could also be
/// set after publishing if a `Publisher` object was created.
fun init(otw: MY_NFT, ctx: &mut TxContext) {
let keys = vector[
b"name".to_string(),
b"link".to_string(),
b"image_url".to_string(),
b"description".to_string(),
b"project_url".to_string(),
b"creator".to_string(),
];

let values = vector[
// For `name` one can use the `MyNft.name` property
b"{name}".to_string(),
// For `link` one can build a URL using an `id` property
b"https://github.com/{name}".to_string(),
// For `image_url` use an IPFS template + `image_url` property.
b"{image_url}".to_string(),
// Description is static for all `MyNft` objects.
b"First NFT from Helen2022a !".to_string(),
// Project URL is usually static
b"https://github.com/{name}/letsmove".to_string(),
// Creator field can be any
b"Helen2022a".to_string(),
];

// Claim the `Publisher` for the package!
let publisher = package::claim(otw, ctx);

// Get a new `Display` object for the `MyNft` type.
let mut display = display::new_with_fields<MyNft>(
&publisher, keys, values, ctx
);

// Commit first version of `Display` to apply changes.
display.update_version();

transfer::public_transfer(publisher, ctx.sender());
transfer::public_transfer(display, ctx.sender());
}

public entry fun mint_and_send(name: String, image_url: String, recipient:address, ctx: &mut TxContext) {
let myNFT = MyNft {
id: object::new(ctx),
name,
image_url
};
transfer::transfer(myNFT,recipient);
}
Loading

0 comments on commit 84f879f

Please sign in to comment.