diff --git a/mover/JianhaWang/code/task2/Move.toml b/mover/JianhaWang/code/task2/Move.toml new file mode 100644 index 000000000..6a6098d99 --- /dev/null +++ b/mover/JianhaWang/code/task2/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "task2" +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://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] +task2 = "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/JianhaWang/code/task2/sources/coin.move b/mover/JianhaWang/code/task2/sources/coin.move new file mode 100644 index 000000000..dc7319c49 --- /dev/null +++ b/mover/JianhaWang/code/task2/sources/coin.move @@ -0,0 +1,26 @@ +module task2::jianhawang_coin { + use sui::coin; + use sui::coin::{TreasuryCap}; + use sui::transfer::{public_transfer, public_freeze_object}; + + public struct JIANHAWANG_COIN has drop{} + fun init(witness: JIANHAWANG_COIN, ctx: &mut TxContext){ + let (treasuryCap, denyCap ,metadata) = coin::create_regulated_currency( + witness, + 8, + b"JIANHAWANG", + b"JIANHAWANG Coin", + b"move coin", + option::none(), + ctx + ); + public_transfer(treasuryCap, tx_context::sender(ctx)); + public_transfer(denyCap, tx_context::sender(ctx)); + public_freeze_object(metadata); + } + + public entry fun mint(cap: &mut TreasuryCap, amount: u64, recipient: address, ctx: &mut TxContext){ + let coin = coin::mint(cap, amount, ctx); + public_transfer(coin, recipient); + } +} \ No newline at end of file diff --git a/mover/JianhaWang/code/task2/sources/faucet.move b/mover/JianhaWang/code/task2/sources/faucet.move new file mode 100644 index 000000000..0f23bac89 --- /dev/null +++ b/mover/JianhaWang/code/task2/sources/faucet.move @@ -0,0 +1,24 @@ +module task2::jianhawang_faucet_coin { + use sui::coin; + use sui::coin::TreasuryCap; + use sui::transfer::{ public_share_object, public_freeze_object}; + + public struct JIANHAWANG_FAUCET_COIN has drop{} + fun init(witness: JIANHAWANG_FAUCET_COIN, ctx: &mut TxContext){ + let (treasury, metadata) = coin::create_currency( + witness, + 8, + b"JIANHAWANG_PUBLIC", + b"jianhawang Faucet coin", + b"test faucet coin", + option::none(), + ctx + ); + public_share_object(treasury); + public_freeze_object(metadata); + } + + public entry fun mint(cap: &mut TreasuryCap, value: u64, recipient: address, ctx: &mut TxContext){ + coin::mint_and_transfer(cap, value, recipient, ctx); + } +} \ No newline at end of file diff --git a/mover/JianhaWang/code/task3/Move.toml b/mover/JianhaWang/code/task3/Move.toml new file mode 100644 index 000000000..480be1592 --- /dev/null +++ b/mover/JianhaWang/code/task3/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "task3" +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://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] +task3 = "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/JianhaWang/code/task3/sources/task3.move b/mover/JianhaWang/code/task3/sources/task3.move new file mode 100644 index 000000000..c9e097291 --- /dev/null +++ b/mover/JianhaWang/code/task3/sources/task3.move @@ -0,0 +1,47 @@ +module task3::jianhawang_nft { + use std::ascii::String; + use std::string::utf8; + use sui::display; + use sui::object; + use sui::object::{UID}; + use sui::package; + use sui::transfer; + use sui::transfer::public_transfer; + use sui::tx_context; + use sui::tx_context::{TxContext}; + + public struct JIANHAWANG_NFT has drop {} + + public struct NFT has key,store { + id: UID, + name: String, + } + + fun init(otw: JIANHAWANG_NFT, ctx: &mut sui::tx_context::TxContext) { + let keys = vector[ + utf8(b"name"), + utf8(b"image_url"), + ]; + + let values = vector[ + utf8(b"{name}"), + utf8(b"https://avatars.githubusercontent.com/u/168746492"), + ]; + + let publisher = package::claim(otw, ctx); + let mut display = display::new_with_fields(&publisher, keys, values,ctx); + + display::update_version(&mut display); + + transfer::public_transfer(publisher, tx_context::sender(ctx)); + transfer::public_transfer(display, tx_context::sender(ctx)); + } + + public entry fun mint_to(name: String, recipient: address,ctx: &mut TxContext) { + let nft = NFT{ + id: object::new(ctx), + name, + }; + public_transfer(nft, recipient) + } +} \ No newline at end of file diff --git a/mover/JianhaWang/code/task4/Move.toml b/mover/JianhaWang/code/task4/Move.toml new file mode 100644 index 000000000..86e124a47 --- /dev/null +++ b/mover/JianhaWang/code/task4/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "task4" +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://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] +task4 = "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/JianhaWang/code/task4/sources/task4.move b/mover/JianhaWang/code/task4/sources/task4.move new file mode 100644 index 000000000..009f7f5d5 --- /dev/null +++ b/mover/JianhaWang/code/task4/sources/task4.move @@ -0,0 +1,162 @@ +module task4::jianhawang_game { + use std::string::{Self, String}; + use sui::event; + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin}; + use sui::tx_context::sender; + use std::hash; + use sui::bcs; + + const EPoolNotEnough: u64 = 1; + const EInputNotEnough: u64 = 2; + const ERR_HIGH_ARG_GREATER_THAN_LOW_ARG: u64 = 101; + + public struct GameResult has copy, drop { + result: String, + is_winner: bool, + } + + public struct Game has key { + id: UID, + pool: Balance, + ticket: u64, + reward: u64, + } + + public fun game_pool(game: &Game): u64 { + balance::value(&game.pool) + } + + public fun game_ticket(game: &Game): u64 { + game.ticket + } + + public fun game_reward(game: &Game): u64 { + game.reward + } + + public struct AdminCap has key { + id: UID, + } + + fun init(_ctx: &mut TxContext) { + } + + entry fun creat_game(ctx: &mut TxContext) { + let game = Game { + id: object::new(ctx), + pool: balance::zero(), + ticket: 1000, + reward: 2000, + }; + transfer::share_object(game); + + let admin_cap = AdminCap { id: object::new(ctx) }; + transfer::transfer(admin_cap, sender(ctx)); + } + + fun get_spin_result(ctx: &mut TxContext) : u8 { + let spin = (rand_u64_range(0, 5, ctx) as u8); + spin + } + + public entry fun play(game: &mut Game, input: Coin, ctx: &mut TxContext) { + assert!(balance::value(&game.pool) >= game.reward - game.ticket, EPoolNotEnough); + + let player_spin = get_spin_result(ctx); + let winning_combination = 2; + + let input_value = coin::value(&input); + assert!(input_value >= game.ticket, EInputNotEnough); + + let mut input_balance = coin::into_balance(input); + if (input_value > game.ticket) { + balance::join( + &mut game.pool, + balance::split(&mut input_balance, game.ticket) + ); + let change = coin::from_balance(input_balance, ctx); + transfer::public_transfer(change, sender(ctx)); + } else { + balance::join(&mut game.pool, input_balance); + }; + + let (result, is_winner) = if (player_spin == winning_combination) { + ( string::utf8(b"Congratulations, you hit the jackpot! Collect your coins"), true) + } else { + ( string::utf8(b"Try again, better luck next time!"), false) + }; + + if (is_winner) { + let reward_balance = balance::split(&mut game.pool, game.reward); + let reward = coin::from_balance(reward_balance, ctx); + transfer::public_transfer(reward, sender(ctx)); + }; + + event::emit(GameResult { + result, + is_winner, + }); + } + + public entry fun deposit(game: &mut Game, input: Coin, amount: u64, ctx: &mut TxContext) { + let input_value = coin::value(&input); + assert!(input_value >= amount, EInputNotEnough); + + let mut input_balance = coin::into_balance(input); + if (input_value > amount) { + balance::join( + &mut game.pool, + balance::split(&mut input_balance, amount) + ); + let change = coin::from_balance(input_balance, ctx); + transfer::public_transfer(change, sender(ctx)); + } else { + balance::join(&mut game.pool, input_balance); + } + } + + public entry fun withdraw(_: &AdminCap, game: &mut Game, amount: u64, ctx: &mut TxContext) { + let output_balance = balance::split(&mut game.pool, amount); + let output = coin::from_balance(output_balance, ctx); + transfer::public_transfer(output, sender(ctx)); + } + + fun seed(ctx: &mut TxContext): vector { + let ctx_bytes = bcs::to_bytes(ctx); + let uid = object::new(ctx); + let uid_bytes: vector = object::uid_to_bytes(&uid); + object::delete(uid); + + let mut info: vector = vector::empty(); + vector::append(&mut info, ctx_bytes); + vector::append(&mut info, uid_bytes); + + let hash: vector = hash::sha3_256(info); + hash + } + + fun bytes_to_u64(bytes: vector): u64 { + let mut value = 0u64; + let mut i = 0u64; + while (i < 8) { + value = value | ((*vector::borrow(&bytes, i) as u64) << ((8 * (7 - i)) as u8)); + i = i + 1; + }; + return value + } + + fun rand_u64_with_seed(_seed: vector): u64 { + bytes_to_u64(_seed) + } + + fun rand_u64_range_with_seed(_seed: vector, low: u64, high: u64): u64 { + assert!(high > low, ERR_HIGH_ARG_GREATER_THAN_LOW_ARG); + let value = rand_u64_with_seed(_seed); + (value % (high - low)) + low + } + + public fun rand_u64_range(low: u64, high: u64, ctx: &mut TxContext): u64 { + rand_u64_range_with_seed(seed(ctx), low, high) + } +} \ No newline at end of file diff --git a/mover/JianhaWang/notes/3.png b/mover/JianhaWang/notes/3.png new file mode 100644 index 000000000..596814c75 Binary files /dev/null and b/mover/JianhaWang/notes/3.png differ diff --git a/mover/JianhaWang/readme.md b/mover/JianhaWang/readme.md index 3696a1573..d60a51b79 100644 --- a/mover/JianhaWang/readme.md +++ b/mover/JianhaWang/readme.md @@ -19,23 +19,24 @@ - [x] package id 在 scan上的查看截图:![Scan截图](./notes/2.png) ## 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 : [0x3532789c2976cbc05868dba979423c5f6376da1de5ef1257d55d296b99e3c15a](https://suivision.xyz/package/0x3532789c2976cbc05868dba979423c5f6376da1de5ef1257d55d296b99e3c15a) +- [x] Faucet package id : [0x3532789c2976cbc05868dba979423c5f6376da1de5ef1257d55d296b99e3c15a](https://suivision.xyz/package/0x3532789c2976cbc05868dba979423c5f6376da1de5ef1257d55d296b99e3c15a) +- [x] 转账 `My Coin` hash: [3XE4YWCtdPH9MBwycNqjjrucV1mgDFMXhTVb7JKkUtba](https://suivision.xyz/txblock/3XE4YWCtdPH9MBwycNqjjrucV1mgDFMXhTVb7JKkUtba) +- [x] `Faucet Coin` address1 mint hash: [3dEEoFLdgs9NZcKsK6LbGcCwYjuYa5SouvZapXUrTMvR](https://suivision.xyz/txblock/3dEEoFLdgs9NZcKsK6LbGcCwYjuYa5SouvZapXUrTMvR) +- [x] `Faucet Coin` address2 mint hash: [Gmbh2iabzHSqeyjrru9uATzxw3DE7tJhwVH2QYnnBVsT](https://suivision.xyz/txblock/Gmbh2iabzHSqeyjrru9uATzxw3DE7tJhwVH2QYnnBVsT) ## 03 move NFT -- [] nft package id : -- [] nft object id : -- [] 转账 nft hash: -- [] scan上的NFT截图:![Scan截图](./images/你的图片地址) +- [x] nft package id : [0xe17f33b07c9a91b35632386f436a45ee78a66a9a8cdad9973f8a6dde5f770d40](https://suivision.xyz/package/0xe17f33b07c9a91b35632386f436a45ee78a66a9a8cdad9973f8a6dde5f770d40) +- [x] nft object id : [0x7ec425ed0c6ef9af1c00b8a8b792a815b00e5f5887cc24131fb31383522bf3e0](https://suivision.xyz/object/0x7ec425ed0c6ef9af1c00b8a8b792a815b00e5f5887cc24131fb31383522bf3e0) +- [x] 转账 nft hash : [HsojqjGBSq7vTg7LViex9mu6De4fWHgBEgmtqxARhoDc](https://suivision.xyz/txblock/HsojqjGBSq7vTg7LViex9mu6De4fWHgBEgmtqxARhoDc) +- [x] scan上的NFT截图:![Scan截图](./notes/3.png) ## 04 Move Game -- [] game package id : -- [] deposit Coin hash: -- [] withdraw `Coin` hash: -- [] play game hash: +- [x] game package id : [0xd22aa04dc7b3c5ec7586d35f9ccd6b449a08dbb4c7dbbe71ebe216d82514e6cb](https://suivision.xyz/package/0xd22aa04dc7b3c5ec7586d35f9ccd6b449a08dbb4c7dbbe71ebe216d82514e6cb) +- [x] deposit Coin hash: [9873ZiH6RoMEGqrmm26RrsCzpkJGtQ1DL2xPF8ZBtgmy](https://suivision.xyz/txblock/9873ZiH6RoMEGqrmm26RrsCzpkJGtQ1DL2xPF8ZBtgmy) +- [x] withdraw `Coin` hash: [DLZ1zvT3CoBZxcKzFpNMbnT2e3CkzY4pEzRoSTPACttR](https://suivision.xyz/txblock/DLZ1zvT3CoBZxcKzFpNMbnT2e3CkzY4pEzRoSTPACttR) +- [x] play game hash: [FafWkF8u5bXCprHMbQmkm8tR9PZq3zCcqaY9BYz673dV](https://suivision.xyz/txblock/FafWkF8u5bXCprHMbQmkm8tR9PZq3zCcqaY9BYz673dV) + ## 05 Move Swap - [] swap package id :