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

task4 #2002

Merged
merged 1 commit into from
Nov 25, 2024
Merged

task4 #2002

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
38 changes: 38 additions & 0 deletions mover/flatflax/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://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }
faucet_coin = { local = "../task2/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"

64 changes: 64 additions & 0 deletions mover/flatflax/code/task4/sources/task4.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// Module: task4
module task4::game {
use sui::coin::{Self, Coin};
use sui::balance::{Self, Balance};
use sui::random::{Self, Random};
use faucet_coin::faucet_coin::FAUCET_COIN;

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

public struct Game has key {
id: UID,
balance: Balance<FAUCET_COIN>,
game_name:vector<u8>
}

public struct Admin has key {
id: UID,
}

fun init(ctx: &mut TxContext) {
let game = Game {
id: object::new(ctx),
balance: balance::zero(),
game_name:b"FLATFLAX GAME"

};
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<FAUCET_COIN>, amount: u64, ctx: &mut TxContext) {
assert!(coin.value() >= amount, EUserInsufficientBalance);
let split_balance = coin::balance_mut(coin).split(amount);
game.balance.join(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<FAUCET_COIN>, amount: u64, ctx: &mut TxContext) {
assert!(game.balance.value() >= amount, EGameInsufficientBalance);
assert!(coin.value() >= 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(reward);
}else {
//猜错,将赌注存入奖池
Self::deposit(game, coin, amount,ctx)
}
}
}


18 changes: 18 additions & 0 deletions mover/flatflax/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
}
*/
10 changes: 5 additions & 5 deletions mover/flatflax/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- [] Sui cli version: sui 1.37.0-6646b75dd688
- [] Sui钱包截图: ![Sui钱包截图](./images/qb.png)
- [] package id: 0x808c08151f326aa453ccd40de9ae7b14e082e4375f4cfd5a80ede9d71d214ebf (发到devnet上了)
- [] package id 在 scan上的查看截图:![Scan截图](./images/l.png)
- [] package id 在 scan上的查看截图:![Scan截图](./images/l.jpg)

## 02 move coin
- [] My Coin package id : 0xea5e2369e8d9d502f4aca15d2c72ce4235610381d4a6238e2800ed617a5c28c1
Expand All @@ -31,10 +31,10 @@
- [] scan上的NFT截图:![Scan截图](./images/task3_nft.png)

## 04 Move Game
- [] game package id :
- [] deposit Coin hash:
- [] withdraw `Coin` hash:
- [] play game hash:
- [] game package id :0xe9589c26b6c9e879a7f77c700ad02e8c084a7cbae4e8dc446db6cdb60dfe7073
- [] deposit Coin hash: EBsWTXRFJw1DM4pPg3hoKxMbtfoVeDkHzufNZSrxrfwS
- [] withdraw `Coin` hash: EbqmdVwTdBVGpngYQNsyc8H9D5TAyyS4GuYNY417uswT
- [] play game hash: G84JB8K1TBEQowPG1srqFLsWTQWANgrWThNjQYpjKaAz

## 05 Move Swap
- [] swap package id :
Expand Down