From 95a5cda59998ae083c8e7b36599c4134cc176f0e Mon Sep 17 00:00:00 2001 From: earthchen Date: Sat, 16 Nov 2024 16:17:25 +0800 Subject: [PATCH 1/3] task4 --- .../code/task4/earthchen_game/Move.lock | 43 +++++++ .../code/task4/earthchen_game/Move.toml | 38 ++++++ .../task4/earthchen_game/sources/Move.toml | 38 ++++++ .../sources/earthchen_game.move | 113 ++++++++++++++++++ 4 files changed, 232 insertions(+) create mode 100644 mover/EarthChen/code/task4/earthchen_game/Move.lock create mode 100644 mover/EarthChen/code/task4/earthchen_game/Move.toml create mode 100644 mover/EarthChen/code/task4/earthchen_game/sources/Move.toml create mode 100644 mover/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move diff --git a/mover/EarthChen/code/task4/earthchen_game/Move.lock b/mover/EarthChen/code/task4/earthchen_game/Move.lock new file mode 100644 index 000000000..68b065eec --- /dev/null +++ b/mover/EarthChen/code/task4/earthchen_game/Move.lock @@ -0,0 +1,43 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "3E7C99C33A2E20F63FB3D0534558440BAC3F2A5097CA4C5801FAED92F94005EE" +deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" +dependencies = [ + { id = "Sui", name = "Sui" }, + { id = "faucetcoin", name = "faucetcoin" }, +] + +[[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 = "faucetcoin" +source = { local = "../../task2/faucetcoin" } + +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.37.3" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.testnet] +chain-id = "4c78adac" +original-published-id = "0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd" +latest-published-id = "0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd" +published-version = "1" diff --git a/mover/EarthChen/code/task4/earthchen_game/Move.toml b/mover/EarthChen/code/task4/earthchen_game/Move.toml new file mode 100644 index 000000000..d22f36f90 --- /dev/null +++ b/mover/EarthChen/code/task4/earthchen_game/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "guess_number" +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" } +faucetcoin = { local = "../../task2/faucetcoin" } + +# 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] +guess_number = "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/EarthChen/code/task4/earthchen_game/sources/Move.toml b/mover/EarthChen/code/task4/earthchen_game/sources/Move.toml new file mode 100644 index 000000000..4ad983435 --- /dev/null +++ b/mover/EarthChen/code/task4/earthchen_game/sources/Move.toml @@ -0,0 +1,38 @@ +[package] +name = "guess_number" +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/mainnet" } +faucetcoin = { local = "../faucetcoin" } + +# 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] +guess_number = "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/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move b/mover/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move new file mode 100644 index 000000000..7c539bc8e --- /dev/null +++ b/mover/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move @@ -0,0 +1,113 @@ +/// Module: guess_number +module guess_number::guess_number { + use sui::object::{Self, UID}; + use sui::balance::{Self, Balance}; + use sui::coin::{Self, Coin}; + use sui::transfer::{transfer, share_object, public_transfer}; + use sui::tx_context::{Self, sender}; + use sui::bcs; + use faucetcoin::faucetcoin::FAUCETCOIN; + use std::debug::print; + use std::string::utf8; + + const ENotAllow: u64 = 0; + const EInvalidStake: u64 = 1; + const Rate: u64 = 2; + const MaxStake: u64 = 1000; + const MinStake: u64 = 10; + + // otw + public struct GUESS_NUMBER has drop {} + + // 奖金池,管理员为earthchen + public struct PrizePool has key { + id: UID, + prize: Balance, + earthchen: address // my github id + } + + // 用于创建、初始化奖金池,之后删除 + public struct PrizePoolCap has key { + id: UID + } + + // 创建Cap,并发送给earthchen + fun init(_otw: GUESS_NUMBER, ctx: &mut TxContext) { + let prize_pool_cap = PrizePoolCap { + id: object::new(ctx) + }; + transfer(prize_pool_cap, tx_context::sender(ctx)); + } + + // earthchen用于创建奖金池,并注入初始奖金 + public entry fun initialize_pool(cap: PrizePoolCap, coin: Coin, ctx: &mut TxContext) { + let prize_pool = PrizePool { + id: object::new(ctx), + prize: coin.into_balance(), + earthchen: sender(ctx) + }; + share_object(prize_pool); + let PrizePoolCap { id } = cap; + object::delete(id); + } + + + + // 给奖金池注入更多奖金,任何人都有权限 + public entry fun top_up(pool: &mut PrizePool, coin: Coin) { + coin::put(&mut pool.prize, coin) + } + + // 在奖金池取出指定数量金额 + public entry fun withdraw(pool: &mut PrizePool, amount: u64, ctx: &mut TxContext) { + assert!(pool.earthchen == sender(ctx), ENotAllow); + let balance = pool.prize.split(amount); + let coin = coin::from_balance(balance, ctx); + public_transfer(coin, sender(ctx)); + } + + // 在奖金池取出所有奖金 + public fun withdraw_all(pool: &mut PrizePool, ctx: &mut TxContext) { + assert!(pool.earthchen == sender(ctx), ENotAllow); + let balance = pool.prize.withdraw_all(); + let coin = coin::from_balance(balance, ctx); + public_transfer(coin, sender(ctx)); + } + + // 查询奖金池中剩余的金额 + public fun query_prize(pool: &mut PrizePool):u64 { + pool.prize.value() + } + + // 通过交易hash的方式获取随机数 + fun get_random_num(ctx: &mut TxContext): u8 { + let tx_digest = tx_context::digest(ctx); + let tx_digest_u64= bcs::peel_u8(&mut bcs::new(*tx_digest)); + let random_index: u8 = tx_digest_u64 % 3; + random_index + } + + // 开始游戏 + public entry fun start_game(pool: &mut PrizePool, geuss_number: u8, stake: Coin, ctx: &mut TxContext): bool { + let balance = stake.into_balance(); + let value = balance.value(); + let mut res = false; + assert!(value < MaxStake && value > MinStake, EInvalidStake); + pool.prize.join(balance); + let the_number = get_random_num(ctx); + print(&utf8(b"The right number is:")); + print(&the_number); + if (geuss_number == the_number) { + let prize_value = pool.prize.split(Rate * value); + let prize_coin = coin::from_balance(prize_value, ctx); + public_transfer(prize_coin, sender(ctx)); + res = true; + }; + res + } + + #[test_only] + public fun init_for_testing(ctx: &mut TxContext) { + init(GUESS_NUMBER {}, ctx); + } +} From 85a0a5ff5a172c336e5554c7f400386fb17d6705 Mon Sep 17 00:00:00 2001 From: earthchen Date: Sat, 16 Nov 2024 16:18:46 +0800 Subject: [PATCH 2/3] task4 --- mover/EarthChen/code/readme.md | 7 +++++++ mover/EarthChen/code/task2/faucetcoin/Move.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mover/EarthChen/code/readme.md b/mover/EarthChen/code/readme.md index e69de29bb..c174e843b 100644 --- a/mover/EarthChen/code/readme.md +++ b/mover/EarthChen/code/readme.md @@ -0,0 +1,7 @@ +# 猜数游戏信息 + +## testnet + +* packageId: 0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd +* UpgradeCapID:0x3eea017ced2d484f0593b9b7a4bd7fd9da5504177cebccb7581ec18f39b99271 +* guess_number::PrizePoolCap: 0xc362a9db9ecfbe3fa4043dd00be11c1c0e52158554ff457c83d472ae6d49acd6 diff --git a/mover/EarthChen/code/task2/faucetcoin/Move.toml b/mover/EarthChen/code/task2/faucetcoin/Move.toml index e91d0de23..380370c8a 100644 --- a/mover/EarthChen/code/task2/faucetcoin/Move.toml +++ b/mover/EarthChen/code/task2/faucetcoin/Move.toml @@ -5,7 +5,7 @@ edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move # 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/mainnet" } +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. From 2a590e6e4cf77ae8c8590cb0caf5907d2b9a7959 Mon Sep 17 00:00:00 2001 From: earthchen Date: Sat, 16 Nov 2024 17:25:08 +0800 Subject: [PATCH 3/3] task4 --- mover/EarthChen/code/readme.md | 20 +++++++++++++++++++ .../EarthChen/code/task2/faucetcoin/Move.lock | 12 +++++------ .../code/task4/earthchen_game/Move.lock | 6 ++++++ mover/EarthChen/readme.md | 8 ++++---- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/mover/EarthChen/code/readme.md b/mover/EarthChen/code/readme.md index c174e843b..42e5d05a0 100644 --- a/mover/EarthChen/code/readme.md +++ b/mover/EarthChen/code/readme.md @@ -5,3 +5,23 @@ * packageId: 0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd * UpgradeCapID:0x3eea017ced2d484f0593b9b7a4bd7fd9da5504177cebccb7581ec18f39b99271 * guess_number::PrizePoolCap: 0xc362a9db9ecfbe3fa4043dd00be11c1c0e52158554ff457c83d472ae6d49acd6 + + +### faucetcoin + +* pacakgeId: 0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf +* coin: 0x27b93ff04870aa99ce50ca35694fb66d5678629088cacefaa78c6d7d5f20763a + + +## mainnet + +* publish hash: BJT1Dga7cHKK6B5KKPq2JQe1RBzwcaUH3nsRZddMxPmQ +* packageId:0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee +* UpgradeCapID:0x05d90f14cd51264d703c84c837e7febb4f556e16cd0306f8646f265f0352a4ea +* guess_number::PrizePoolCap:0xf88111d290581033164f4222c2cc8f827594b8431406bf1e378f64b138bd72d3 +* inithash: HRaT2c1UsoXfAz5y9EhWLuhMuhqkWn3zzP8gZv5THatj +* poolId: 0x7dddecadd6f32cd78e5897991f12632ac02d9cbe9315835b5406e29c01b45b5f + + + + diff --git a/mover/EarthChen/code/task2/faucetcoin/Move.lock b/mover/EarthChen/code/task2/faucetcoin/Move.lock index 82d2037ad..52de34a46 100644 --- a/mover/EarthChen/code/task2/faucetcoin/Move.lock +++ b/mover/EarthChen/code/task2/faucetcoin/Move.lock @@ -2,7 +2,7 @@ [move] version = 3 -manifest_digest = "040FB3E59D8A1F2E682DCABB7B08CE36CD1FC73BDE7213AB39F548FED3A290C9" +manifest_digest = "36AAF1CDEC036D88764BAC3DCDE58C0D7D361D80DBC1ED0F543FFC7DC8AA1BA6" deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" dependencies = [ { id = "Sui", name = "Sui" }, @@ -10,18 +10,18 @@ dependencies = [ [[move.package]] id = "MoveStdlib" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } +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/mainnet", subdir = "crates/sui-framework/packages/sui-framework" } +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" +compiler-version = "1.37.3" edition = "2024.beta" flavor = "sui" @@ -29,8 +29,8 @@ flavor = "sui" [env.testnet] chain-id = "4c78adac" -original-published-id = "0x586cd3af1a22322f864d4f97aeb94287918e4e8cfe5f82906419ecef0e2df04a" -latest-published-id = "0x586cd3af1a22322f864d4f97aeb94287918e4e8cfe5f82906419ecef0e2df04a" +original-published-id = "0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf" +latest-published-id = "0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf" published-version = "1" [env.mainnet] diff --git a/mover/EarthChen/code/task4/earthchen_game/Move.lock b/mover/EarthChen/code/task4/earthchen_game/Move.lock index 68b065eec..7be1da240 100644 --- a/mover/EarthChen/code/task4/earthchen_game/Move.lock +++ b/mover/EarthChen/code/task4/earthchen_game/Move.lock @@ -41,3 +41,9 @@ chain-id = "4c78adac" original-published-id = "0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd" latest-published-id = "0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd" published-version = "1" + +[env.mainnet] +chain-id = "35834a8a" +original-published-id = "0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee" +latest-published-id = "0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee" +published-version = "1" diff --git a/mover/EarthChen/readme.md b/mover/EarthChen/readme.md index dc3209d4f..2ebab3b63 100644 --- a/mover/EarthChen/readme.md +++ b/mover/EarthChen/readme.md @@ -32,10 +32,10 @@ - [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 :0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee +- [x] deposit Coin hash: 8VXsjH2eVz1TWAc5DkAWrtPYVNoArEgVJZq8tCxnNscc +- [x] withdraw `Coin` hash: HizGTtY5FGAGuEQ3g9idAyFuP5BMh8dnH1hSKsTV9ZD8 +- [x] play game hash: AjYKT5oKewnDWv9fnDvYRvoeRDBzfGuYGmPSMXGpv2cY ## 05 Move Swap - [] swap package id :