Skip to content

Commit

Permalink
Merge pull request #2088 from krypt0n123/main
Browse files Browse the repository at this point in the history
task4
  • Loading branch information
Sifotd authored Dec 4, 2024
2 parents 208c213 + 7cb85c5 commit 9d35d89
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 7 deletions.
Binary file added mover/krypton/co-learn-2411/images/04learn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mover/krypton/co-learn-2411/images/04zhibo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions mover/krypton/co-learn-2411/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
- [X] 第一周:![学习记录截图](./images/01learn.png)
- [x] 第二周:![学习记录截图](./images/02learn.png)
- [x] 第三周:![学习记录截图](./images/03learn.png)
- [] 第四周:![学习记录截图](./images/你的图片地址)
- [x] 第四周:![学习记录截图](./images/04learn.png)

## 参加直播答疑

- [X] 第一周:![学习记录截图](./images/01zhibo.png)
- [x] 第二周:![学习记录截图](./images/02zhibo.png)
- [x] 第三周:![学习记录截图](./images/03learn.png)
- [] 第四周:![学习记录截图](./images/你的图片地址)
- [x] 第三周:![学习记录截图](./images/03zhibo.png)
- [x] 第四周:![学习记录截图](./images/04zhibo.png)

## 群里分享学习笔记

Expand Down
49 changes: 49 additions & 0 deletions mover/krypton/code/task4/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 = "502706A36956E653002EF07D2A9F6E5DC9EBAE1D34DBE3554A144AAE5B257830"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "faucetcoin", name = "faucetcoin" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" }

[[move.package]]
id = "Sui"
source = { git = "https://gitee.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.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x2469a7a56c5c6354c3885847013bff03d3eeab9a399dae54b51b3e8aaca78df5"
latest-published-id = "0x2469a7a56c5c6354c3885847013bff03d3eeab9a399dae54b51b3e8aaca78df5"
published-version = "1"

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

67 changes: 67 additions & 0 deletions mover/krypton/code/task4/game/game.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module game::game{
use sui::coin::{Self, Coin};
use sui::balance::{Self, Balance};
use sui::random::{Self, Random};
use faucetcoin::krypton_faucet_coin::KRYPTON_FAUCET_COIN;

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

public struct Game has key {
id: UID,
balance: Balance<KRYPTON_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"KRYPTON 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<KRYPTON_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<KRYPTON_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)
}
}
}
8 changes: 4 additions & 4 deletions mover/krypton/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
- [x] scan上的NFT截图:![Scan截图](./images/NFT.png)

## 04 Move Game
- [] game package id :
- [] deposit Coin hash:
- [] withdraw `Coin` hash:
- [] play game hash:
- [x] game package id :0x30699f232ac20557d5bac43114fa9db9403c6619ad8faebf6f9d93c09c9fe67c
- [x] deposit Coin hash:Be3D48CP6P6g5pQe4Co1S48YJv2m1eWRkSvfYzg2991a
- [x] withdraw `Coin` hash:2WZKyHVvwmgJoUotZtogeoUVcUtWPPhto9qfX2zQqSsZ
- [x] play game hash:2WZKyHVvwmgJoUotZtogeoUVcUtWPPhto9qfX2zQqSsZ

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

0 comments on commit 9d35d89

Please sign in to comment.