Skip to content

Commit

Permalink
Merge pull request #2140 from suiceber/main
Browse files Browse the repository at this point in the history
task4+task5+task6
  • Loading branch information
Sifotd authored Dec 12, 2024
2 parents 8e5ef7e + eebdb46 commit 52204a1
Show file tree
Hide file tree
Showing 31 changed files with 7,745 additions and 13 deletions.
4 changes: 2 additions & 2 deletions mover/suiceber/code/task2/suiceber_coin/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ flavor = "sui"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x1d7b599b6057756f0a080cbae63637f4960d4dbfc34b084d0984475e298ad95f"
latest-published-id = "0x1d7b599b6057756f0a080cbae63637f4960d4dbfc34b084d0984475e298ad95f"
original-published-id = "0x9dba80f1aa2bb039b7da5aecdde81e4569757470c7080f0c04e32ef2a1023b56"
latest-published-id = "0x9dba80f1aa2bb039b7da5aecdde81e4569757470c7080f0c04e32ef2a1023b56"
published-version = "1"
4 changes: 2 additions & 2 deletions mover/suiceber/code/task2/suiceber_faucet_coin/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ flavor = "sui"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xf5f1f09b51d4a7b7e654cb044a63fd0270b89acbb94f72e013aeb10d6409aba8"
latest-published-id = "0xf5f1f09b51d4a7b7e654cb044a63fd0270b89acbb94f72e013aeb10d6409aba8"
original-published-id = "0x9dff1c645fdafdd15d37ba988544aa08955e28fad6783c21d2b539bc216efd4e"
latest-published-id = "0x9dff1c645fdafdd15d37ba988544aa08955e28fad6783c21d2b539bc216efd4e"
published-version = "1"
43 changes: 43 additions & 0 deletions mover/suiceber/code/task4/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "388E0BBB22BA73585ADDC9CB107020E95F3CB5F29DE51FEA0031270CFB08B8F5"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "suiceber_faucet_coin", name = "suiceber_faucet_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 = "suiceber_faucet_coin"
source = { local = "C:\\Users\\62605\\Desktop\\sui\\letsmove\\mover\\suiceber\\code\\task2\\suiceber_faucet_coin" }

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

[move.toolchain-version]
compiler-version = "1.37.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xb9cc5056954ee7a6607a053115248ba5d339925715aad533a5b9a9468b687bc5"
latest-published-id = "0xb9cc5056954ee7a6607a053115248ba5d339925715aad533a5b9a9468b687bc5"
published-version = "1"
38 changes: 38 additions & 0 deletions mover/suiceber/code/task4/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[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 ([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" }
suiceber_faucet_coin = { local = "C:/Users/62605/Desktop/sui/letsmove/mover/suiceber/code/task2/suiceber_faucet_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]
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"

95 changes: 95 additions & 0 deletions mover/suiceber/code/task4/sources/task4.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//感谢前辈提供的笔记,呜呜呜,以后我也要写出这样的笔记!——苏bc
module task4::task4 {
use sui::coin::{Self, Coin};
use suiceber_faucet_coin::suiceber_faucet_coin::SUICEBER_FAUCET_COIN;
use sui::balance::{Self, Balance};
use sui::random::{Self, Random};

const EUserInsufficientBalance: u64 = 1000;
const EGameInsufficientBalance: u64 = 1001;

public struct Game has key {
id: UID,
balance: Balance<SUICEBER_FAUCET_COIN>,
}

public struct Admin has key {
id: UID,
}

fun init(ctx: &mut TxContext) {
let game = Game {
id: object::new(ctx),
balance: balance::zero(),
};
transfer::share_object(game);

let admin = Admin {id: object::new(ctx)};
transfer::transfer(admin, ctx.sender());
}

public entry fun Deposit(
game: &mut Game,
coin: &mut Coin<SUICEBER_FAUCET_COIN>,
amount: u64,
) {
assert!(
coin::value(coin) >= amount,
EUserInsufficientBalance
);
let split_balance = balance::split(coin::balance_mut(coin), amount);
balance::join(&mut game.balance, split_balance);
}

// 只有管理员能够提现
public entry fun Withdraw(
game: &mut Game,
_: &Admin,
amount: u64,
ctx: &mut TxContext
) {
assert!(
game.balance.value() >= amount,
EGameInsufficientBalance
);
let cash = coin::take(&mut game.balance, amount, ctx);
transfer::public_transfer(cash, ctx.sender());
}

// 如果用户猜对了,获得双倍奖励。如果用户猜错了,损失投入的代币

public entry fun Play(
game: &mut Game,
rnd: &Random,
guess: bool,
coin: &mut Coin<SUICEBER_FAUCET_COIN>,
amount: u64,
ctx: &mut TxContext
) {
// 检查合约余额是否充足,确保用户获胜时有足够金额奖励
assert!(
game.balance.value() >= amount,
EGameInsufficientBalance
);
// 检查用户的余额是否充足
assert!(
coin::value(coin) >= amount,
EUserInsufficientBalance
);

// 生成随机数
let mut gen = random::new_generator(rnd, ctx);
let flag = random::generate_bool(&mut gen);

// 如果获胜
if (flag == guess) {
// 投入的代币不变,另外奖励等额的代币
let reward = coin::take(&mut game.balance, amount, ctx);
coin::join(coin, reward);
}
// 猜错了就损失投入的代币
else {
Self::Deposit(game, coin, amount)
}
}
}
18 changes: 18 additions & 0 deletions mover/suiceber/code/task4/tests/task4_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module task4::task4_tests;
// uncomment this line to import the module
// use task4::task4;
const ENotImplemented: u64 = 0;
#[test]
fun test_task4() {
// pass
}
#[test, expected_failure(abort_code = ::task4::task4_tests::ENotImplemented)]
fun test_task4_fail() {
abort ENotImplemented
}
*/
52 changes: 52 additions & 0 deletions mover/suiceber/code/task5/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "B6B1B214F7D9C1D99F0033646BB86CC59A9DDF3F8564699CEA8D0F6A0B4DC9EB"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "suiceber_coin", name = "suiceber_coin" },
{ id = "suiceber_faucet_coin", name = "suiceber_faucet_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 = "suiceber_coin"
source = { local = "C:\\Users\\62605\\Desktop\\sui\\letsmove\\mover\\suiceber\\code\\task2\\suiceber_coin" }

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

[[move.package]]
id = "suiceber_faucet_coin"
source = { local = "C:\\Users\\62605\\Desktop\\sui\\letsmove\\mover\\suiceber\\code\\task2\\suiceber_faucet_coin" }

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

[move.toolchain-version]
compiler-version = "1.37.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xde56fb47cbbfa4dbe2dcd014c7d81c1b510c442b10f573b4f79e028129e33733"
latest-published-id = "0xde56fb47cbbfa4dbe2dcd014c7d81c1b510c442b10f573b4f79e028129e33733"
published-version = "1"
38 changes: 38 additions & 0 deletions mover/suiceber/code/task5/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "task5"
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" }
suiceber_faucet_coin = { local = "C:/Users/62605/Desktop/sui/letsmove/mover/suiceber/code/task2/suiceber_faucet_coin" }
suiceber_coin = { local = "C:/Users/62605/Desktop/sui/letsmove/mover/suiceber/code/task2/suiceber_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]
task5 = "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"

Loading

0 comments on commit 52204a1

Please sign in to comment.