diff --git a/mover/sahab328/coLearn2411/images/week3_learning.png b/mover/sahab328/coLearn2411/images/week3_learning.png new file mode 100644 index 000000000..fff05b924 Binary files /dev/null and b/mover/sahab328/coLearn2411/images/week3_learning.png differ diff --git a/mover/sahab328/coLearn2411/readme.md b/mover/sahab328/coLearn2411/readme.md index e5983660e..5b2bcdf96 100644 --- a/mover/sahab328/coLearn2411/readme.md +++ b/mover/sahab328/coLearn2411/readme.md @@ -13,7 +13,7 @@ - [] 第一周:![学习记录截图](./images/你的图片地址) - [] 第二周:![学习记录截图](./images/你的图片地址) -- [] 第三周:![学习记录截图](./images/你的图片地址) +- [x] 第三周:![学习记录截图](./images/week3_learning.png) - [] 第四周:![学习记录截图](./images/你的图片地址) ## 参加直播答疑 diff --git a/mover/sahab328/code/task2/my_coin/Move.lock b/mover/sahab328/code/task2/my_coin/Move.lock new file mode 100644 index 000000000..34b84de97 --- /dev/null +++ b/mover/sahab328/code/task2/my_coin/Move.lock @@ -0,0 +1,40 @@ +# @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.36.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0xa87eaab797fcf55cf3a8798f5bc66528aa838a506021b7eaa4a077c6391b8c85" +latest-published-id = "0xa87eaab797fcf55cf3a8798f5bc66528aa838a506021b7eaa4a077c6391b8c85" +published-version = "1" + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x6fad4e0f5f68ed70e322aca3dc36f9d09da758bdcdb8e06661aa18bd8da5ed6a" +latest-published-id = "0x6fad4e0f5f68ed70e322aca3dc36f9d09da758bdcdb8e06661aa18bd8da5ed6a" +published-version = "1" diff --git a/mover/sahab328/code/task2/my_coin/Move.toml b/mover/sahab328/code/task2/my_coin/Move.toml new file mode 100644 index 000000000..b9ca003f8 --- /dev/null +++ b/mover/sahab328/code/task2/my_coin/Move.toml @@ -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 (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] +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" + diff --git a/mover/sahab328/code/task2/my_coin/sources/meme.move b/mover/sahab328/code/task2/my_coin/sources/meme.move new file mode 100644 index 000000000..ac3df9a44 --- /dev/null +++ b/mover/sahab328/code/task2/my_coin/sources/meme.move @@ -0,0 +1,20 @@ +module my_coin::meme; + +use sui::url::{Self, Url}; +use sui::coin::{create_currency}; +use std::option::{some}; + +use sui::transfer::{public_freeze_object, public_share_object}; + +public struct MEME has drop {} + +fun init(witness: MEME, ctx: &mut TxContext) { + // let no = none(); + let url = url::new_unsafe_from_bytes(b"https://avatars.githubusercontent.com/u/162699534"); + let icon_url = some(url); + let (treasury, coin_meta) = create_currency(witness, 18, b"MEME", b"MEME", b"sahab's meme token", icon_url, ctx); + + public_freeze_object(coin_meta); + + public_share_object(treasury); +} \ No newline at end of file diff --git a/mover/sahab328/code/task2/my_coin/sources/sa.move b/mover/sahab328/code/task2/my_coin/sources/sa.move new file mode 100644 index 000000000..0afbb4872 --- /dev/null +++ b/mover/sahab328/code/task2/my_coin/sources/sa.move @@ -0,0 +1,20 @@ +module my_coin::sa; + +use sui::url::{Self, Url}; +use sui::coin::{create_currency}; +use std::option::{some}; + +use sui::transfer::{public_freeze_object, public_transfer}; + +public struct SA has drop {} + +fun init(sa: SA, ctx: &mut TxContext) { + // let no = none(); + let url = url::new_unsafe_from_bytes(b"https://avatars.githubusercontent.com/u/162699534"); + let icon_url = some(url); + let (treasury, coin_meta) = create_currency(sa, 18, b"SA", b"SA", b"sahab's token", icon_url, ctx); + + public_freeze_object(coin_meta); + + public_transfer(treasury, ctx.sender()); +} \ No newline at end of file diff --git a/mover/sahab328/code/task2/my_coin/tests/my_coin_tests.move b/mover/sahab328/code/task2/my_coin/tests/my_coin_tests.move new file mode 100644 index 000000000..cd5b36060 --- /dev/null +++ b/mover/sahab328/code/task2/my_coin/tests/my_coin_tests.move @@ -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 +} +*/ diff --git a/mover/sahab328/code/task3/nft/Move.lock b/mover/sahab328/code/task3/nft/Move.lock new file mode 100644 index 000000000..8d22939e9 --- /dev/null +++ b/mover/sahab328/code/task3/nft/Move.lock @@ -0,0 +1,40 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "9D4FCF5807A34E3110DFBA44AD92FEFEC55EE3DE8CF58F3D302F55D3004E70D1" +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 = "0x1d47e2d3ad1a2b9ef6c292f03ab8ee4674a8ac25ba8e9506e38d25822d1e150f" +latest-published-id = "0x1d47e2d3ad1a2b9ef6c292f03ab8ee4674a8ac25ba8e9506e38d25822d1e150f" +published-version = "1" + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x3adb69d9749acdec6662209d9be6300cc0c79988622e6532447b52f4c53b6df1" +latest-published-id = "0x3adb69d9749acdec6662209d9be6300cc0c79988622e6532447b52f4c53b6df1" +published-version = "1" diff --git a/mover/sahab328/code/task3/nft/Move.toml b/mover/sahab328/code/task3/nft/Move.toml new file mode 100644 index 000000000..504c662e4 --- /dev/null +++ b/mover/sahab328/code/task3/nft/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "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 (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] +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" + diff --git a/mover/sahab328/code/task3/nft/sources/nft.move b/mover/sahab328/code/task3/nft/sources/nft.move new file mode 100644 index 000000000..a17bbc006 --- /dev/null +++ b/mover/sahab328/code/task3/nft/sources/nft.move @@ -0,0 +1,32 @@ + +module nft::nft; + +use std::string::{Self, String}; +use sui::url::{Self, Url}; +use sui::transfer::transfer; + +public struct NFT has key { + id: UID, + name: String, + url: Url +} + +fun init(ctx: &mut TxContext) { + let nft = NFT { + id: object::new(ctx), + name: string::utf8(b"sahab NFT"), + url: url::new_unsafe(b"https://avatars.githubusercontent.com/u/162699534".to_ascii_string()) + }; + + transfer(nft, ctx.sender()); +} + +public entry fun mint_to(receiver: address, ctx: &mut TxContext) { + let nft = NFT { + id: object::new(ctx), + name: string::utf8(b"sahab NFT"), + url: url::new_unsafe(b"https://avatars.githubusercontent.com/u/162699534".to_ascii_string()) + }; + + transfer(nft, receiver); +} \ No newline at end of file diff --git a/mover/sahab328/code/task3/nft/tests/nft_tests.move b/mover/sahab328/code/task3/nft/tests/nft_tests.move new file mode 100644 index 000000000..3c9c56a93 --- /dev/null +++ b/mover/sahab328/code/task3/nft/tests/nft_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module nft::nft_tests; +// uncomment this line to import the module +// use nft::nft; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_nft() { + // pass +} + +#[test, expected_failure(abort_code = ::nft::nft_tests::ENotImplemented)] +fun test_nft_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/sahab328/code/task4/game/Move.lock b/mover/sahab328/code/task4/game/Move.lock new file mode 100644 index 000000000..ad26c3914 --- /dev/null +++ b/mover/sahab328/code/task4/game/Move.lock @@ -0,0 +1,49 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "86203A0985C424653C576953C170EEEDC2F4B20DCF61ED64DEDCEB710F8D735F" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "my_coin", name = "my_coin" }, +] + +[[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.package]] +id = "my_coin" +source = { local = "../../task2/my_coin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.36.2" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0xc29de30c4951b1e8d8b80b532a62fe3736b5411d031680411a47db917852ab47" +latest-published-id = "0xc29de30c4951b1e8d8b80b532a62fe3736b5411d031680411a47db917852ab47" +published-version = "1" + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x90c9955a7f6bf5eadabe0df7d3d029c6a59fe84f0d0ddf05724d8568814e9b57" +latest-published-id = "0x90c9955a7f6bf5eadabe0df7d3d029c6a59fe84f0d0ddf05724d8568814e9b57" +published-version = "1" diff --git a/mover/sahab328/code/task4/game/Move.toml b/mover/sahab328/code/task4/game/Move.toml new file mode 100644 index 000000000..25ca6e4ba --- /dev/null +++ b/mover/sahab328/code/task4/game/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "game" +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" } +my_coin = { local = "../../task2/my_coin" } + +# 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] +game = "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/sahab328/code/task4/game/sources/flip_coin.move b/mover/sahab328/code/task4/game/sources/flip_coin.move new file mode 100644 index 000000000..ed787621f --- /dev/null +++ b/mover/sahab328/code/task4/game/sources/flip_coin.move @@ -0,0 +1,66 @@ +module game::flip_coin; + +use sui::balance::{Self, Balance}; +use sui::coin::{Self, Coin}; +use sui::transfer::{transfer, share_object, public_transfer}; +use sui::random::{Self, new_generator, Random}; +use std::string::String; + +use my_coin::meme::MEME; + +public struct Game has key { + id: UID, + balance: Balance, + desc: String, +} + +public struct AdminCap has key { + id: UID, +} + +const ETooMuchMoney: u64 = 0; +const ENotEnoughBalance: u64 = 1; + +fun init(ctx: &mut TxContext) { + let game = Game { + id: object::new(ctx), + balance: balance::zero(), + desc: b"sahab328's flip coin game".to_string(), + }; + + share_object(game); + + let cap = AdminCap { + id: object::new(ctx), + }; + transfer(cap, ctx.sender()); +} + +entry fun play(game: &mut Game, rand: &Random, guess: bool, in_coin: Coin, ctx: &mut TxContext) { + let in_value = in_coin.value(); + let game_value = game.balance.value(); + // 最多玩池子的1/10 + assert!(game_value >= in_value * 10, ETooMuchMoney); + + let mut rand_gen = new_generator(rand, ctx); + let result: bool = random::generate_bool(&mut rand_gen); + + if (guess == result) { // win + let out_coin = coin::from_balance(game.balance.split(in_value), ctx); + public_transfer(out_coin, ctx.sender()); + public_transfer(in_coin, ctx.sender()); + } else { // loss + game.balance.join(coin::into_balance(in_coin)); + } +} + +public entry fun add_balance(game: &mut Game, in_coin: Coin, _ctx: &mut TxContext) { + game.balance.join(coin::into_balance(in_coin)); +} + +public entry fun remove_balance(_:&AdminCap, game: &mut Game, out_value: u64, ctx: &mut TxContext) { + let game_value = game.balance.value(); + assert!(game_value >= out_value, ENotEnoughBalance); + let out_coin = coin::from_balance(game.balance.split(out_value), ctx); + public_transfer(out_coin, ctx.sender()); +} diff --git a/mover/sahab328/code/task4/game/tests/flip_coin_tests.move b/mover/sahab328/code/task4/game/tests/flip_coin_tests.move new file mode 100644 index 000000000..d05a3ca31 --- /dev/null +++ b/mover/sahab328/code/task4/game/tests/flip_coin_tests.move @@ -0,0 +1,18 @@ +/* +#[test_only] +module flip_coin::flip_coin_tests; +// uncomment this line to import the module +// use flip_coin::flip_coin; + +const ENotImplemented: u64 = 0; + +#[test] +fun test_flip_coin() { + // pass +} + +#[test, expected_failure(abort_code = ::flip_coin::flip_coin_tests::ENotImplemented)] +fun test_flip_coin_fail() { + abort ENotImplemented +} +*/ diff --git a/mover/sahab328/images/nft-scan.png b/mover/sahab328/images/nft-scan.png new file mode 100644 index 000000000..b3bbb0b56 Binary files /dev/null and b/mover/sahab328/images/nft-scan.png differ diff --git a/mover/sahab328/readme.md b/mover/sahab328/readme.md index 95b2f761c..abb6fa3d0 100644 --- a/mover/sahab328/readme.md +++ b/mover/sahab328/readme.md @@ -19,23 +19,23 @@ - [x] package id 在 scan上的查看截图:![Scan截图](./images/package-scan.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 : 0x6fad4e0f5f68ed70e322aca3dc36f9d09da758bdcdb8e06661aa18bd8da5ed6a +- [x] Faucet package id : 0x6fad4e0f5f68ed70e322aca3dc36f9d09da758bdcdb8e06661aa18bd8da5ed6a +- [x] 转账 `My Coin` hash: ZcV7yM6YVHLHLmHGQiKWsSuVnNgYCrRvssvVjRudJvD +- [x] `Faucet Coin` address1 mint hash: Bw1nfWS7yS676DbTcd8FBsM7smog3dvyXEXmLTBY9uaq +- [x] `Faucet Coin` address2 mint hash: 9YwG3XNQdMvECpUGTCeHPwYr1dDU45E2YvnoGeenCTmP ## 03 move NFT -- [] nft package id : -- [] nft object id : -- [] 转账 nft hash: -- [] scan上的NFT截图:![Scan截图](./images/你的图片地址) +- [x] nft package id : 0x3adb69d9749acdec6662209d9be6300cc0c79988622e6532447b52f4c53b6df1 +- [x] nft object id : 0x256a4a7e580d0db4613ea2440ac12dbbbe7fda165aab054164bf23c48f3d9cd9 +- [x] 转账 nft hash: 5AJXFajzDP8ji3qmEyJjeB6nMQpFn6oc2KPxNngaiScW +- [x] scan上的NFT截图:![Scan截图](./images/nft-scan.png) ## 04 Move Game -- [] game package id : -- [] deposit Coin hash: -- [] withdraw `Coin` hash: -- [] play game hash: +- [x] game package id : 0x90c9955a7f6bf5eadabe0df7d3d029c6a59fe84f0d0ddf05724d8568814e9b57 +- [x] deposit Coin hash: GMNxbvHA7aLAPrSBEdhtuvUB8N9hAWfTKUKms8R2TTgW +- [x] withdraw `Coin` hash: EEiQdohPFJZj9RWjRYqdcN7j2ybJ5WhTpJZ4MSxiUTAV +- [x] play game hash: BuwnM2J7hQu4GWXsxkeevfoWVcT2Pfxhjz8BTZzyaWPK ## 05 Move Swap - [] swap package id :