Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task5 #1909

Merged
merged 4 commits into from
Nov 19, 2024
Merged

Task5 #1909

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions mover/EarthChen/code/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# task4 猜数游戏信息

## testnet

* packageId: 0x549616dbefd766ce256f00b4662eca840964dff08174f6206d141157e9b2bebd
* UpgradeCapID:0x3eea017ced2d484f0593b9b7a4bd7fd9da5504177cebccb7581ec18f39b99271
* guess_number::PrizePoolCap: 0xc362a9db9ecfbe3fa4043dd00be11c1c0e52158554ff457c83d472ae6d49acd6


### faucetcoin

* pacakgeId: 0x5d56e4b9ef9e4d7eed8ea64b337eb9220d9ca55c34e795f2db49f1b26fe248bf
* 0x2::package::UpgradeCap: 0x1443e8d5e94f7080ae73e0c2b1c9907b3d16df740d98e361b5264f7325535b62
* coin: 0x27b93ff04870aa99ce50ca35694fb66d5678629088cacefaa78c6d7d5f20763a


## mainnet

* publish hash: BJT1Dga7cHKK6B5KKPq2JQe1RBzwcaUH3nsRZddMxPmQ
* packageId:0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee
* UpgradeCapID:0x05d90f14cd51264d703c84c837e7febb4f556e16cd0306f8646f265f0352a4ea
* guess_number::PrizePoolCap:0xf88111d290581033164f4222c2cc8f827594b8431406bf1e378f64b138bd72d3
* inithash: HRaT2c1UsoXfAz5y9EhWLuhMuhqkWn3zzP8gZv5THatj
* poolId: 0x7dddecadd6f32cd78e5897991f12632ac02d9cbe9315835b5406e29c01b45b5f



# task5 bank

## testnet

* packageId: 0xdd4c3f39b2446f596a0abb7c764266b43719adc4f4b8a9c488b81d096a8663c4
* earthchen::Bank : 0x1965c930d133fc49dcdc1ac55b6b18a8ac5b782125796d94902ddbc52216f64a
* amdin: 0x15c02c340a6948e80fb74723a9c15af3192cbf4651dc603c879dbd7a9656d1dc
* deposit_mycoin hash: 8SPPuNUjoorqYQa4xo5P3jFYakjFFtky1EDyLFC8B33p
* deposit_faucetcoin hash: APpff8GhwNfd2Z494frcaLoDPuWNFkFfYFsPPgCqrtsD
* swap_mycoin hash: 3vLWRgDJMefi4449HS9KSjQS5PQwKjQmpLzdeZWHgBbX


## mainnet

* packageId: 0x6d4dd7fffe36cce18887a19a935df4cd45633546c947756ce7d45d1fbca9766e
* bank: 0x0a307a8b9d0a97d911973ad395cdeb9e9e213b2370087e33dea48bee16b7e149
* deposit_mycoin hash:C1MnhbfeTsnwdNRjf1jmaAcLRW71K6LDCb12LAk8GmMa
* swap_
12 changes: 6 additions & 6 deletions mover/EarthChen/code/task2/faucetcoin/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@

[move]
version = 3
manifest_digest = "040FB3E59D8A1F2E682DCABB7B08CE36CD1FC73BDE7213AB39F548FED3A290C9"
manifest_digest = "36AAF1CDEC036D88764BAC3DCDE58C0D7D361D80DBC1ED0F543FFC7DC8AA1BA6"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ id = "Sui", name = "Sui" },
]

[[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"

[env]

[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]
Expand Down
49 changes: 49 additions & 0 deletions mover/EarthChen/code/task4/earthchen_game/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# @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"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee"
latest-published-id = "0x472b8f0ff90d472069fb57f33a9899243debb7c3201f1dc3bb2b49d15ec537ee"
published-version = "1"
38 changes: 38 additions & 0 deletions mover/EarthChen/code/task4/earthchen_game/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([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" }
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"

38 changes: 38 additions & 0 deletions mover/EarthChen/code/task4/earthchen_game/sources/Move.toml
Original file line number Diff line number Diff line change
@@ -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 ([email protected])", "John Snow ([email protected])"]

[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"

113 changes: 113 additions & 0 deletions mover/EarthChen/code/task4/earthchen_game/sources/earthchen_game.move
Original file line number Diff line number Diff line change
@@ -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<FAUCETCOIN>,
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<FAUCETCOIN>, 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<FAUCETCOIN>) {
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<FAUCETCOIN>, 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);
}
}
58 changes: 58 additions & 0 deletions mover/EarthChen/code/task5/earthchen/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "BD917155367008DF694FFC9BE7067220688091408D96879871417DE548347128"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "faucetcoin", name = "faucetcoin" },
{ id = "mycoin", name = "mycoin" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", 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" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[[move.package]]
id = "faucetcoin"
source = { local = "../../task2/faucetcoin" }

dependencies = [
{ id = "Sui", name = "Sui" },
]

[[move.package]]
id = "mycoin"
source = { local = "../../task2/mycoin" }

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 = "0xdd4c3f39b2446f596a0abb7c764266b43719adc4f4b8a9c488b81d096a8663c4"
latest-published-id = "0xdd4c3f39b2446f596a0abb7c764266b43719adc4f4b8a9c488b81d096a8663c4"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x6d4dd7fffe36cce18887a19a935df4cd45633546c947756ce7d45d1fbca9766e"
latest-published-id = "0x6d4dd7fffe36cce18887a19a935df4cd45633546c947756ce7d45d1fbca9766e"
published-version = "1"
Loading