-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chin xyz
- Loading branch information
Showing
8 changed files
with
226 additions
and
11 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...yptoctl/code/task2/0x75938a798055f27d5d3332b8460befb89c4ba2be9b25affe792f5191ff25f5ed.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ANtiPY0Dt07pjl+uL+59aXoFoHmBk2ASftqtyx+AwakX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ name = "task2" | |
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])"] | ||
published-at = "0x595755e12a700673fd174e05eac9a6e22cfb5d202de027d5830c256bd20d5b3a" | ||
|
||
[dependencies] | ||
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } | ||
|
@@ -19,7 +20,10 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram | |
# Override = { local = "../conflicting/version", override = true } | ||
|
||
[addresses] | ||
# mainnet | ||
task2 = "0x595755e12a700673fd174e05eac9a6e22cfb5d202de027d5830c256bd20d5b3a" | ||
# testnet | ||
# task2 = "0x260cf370e2f907c25e21cdf2b285224a88b3b839f74fb3b25fa3e0fb063f14bd" | ||
|
||
# Named addresses will be accessible in Move as `@name`. They're also exported: | ||
# for example, `std = "0x1"` is exported by the Standard Library. | ||
|
@@ -29,9 +33,3 @@ task2 = "0x595755e12a700673fd174e05eac9a6e22cfb5d202de027d5830c256bd20d5b3a" | |
# 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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "DE039AFB413BCB1F8EB657E4505F2237C9429034C55BA5EA4E9698CF9FA36946" | ||
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" | ||
dependencies = [ | ||
{ id = "Sui", name = "Sui" }, | ||
{ id = "task2", name = "task2" }, | ||
] | ||
|
||
[[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 = "task2" | ||
source = { local = "..\\task2" } | ||
|
||
dependencies = [ | ||
{ id = "Sui", name = "Sui" }, | ||
] | ||
|
||
[move.toolchain-version] | ||
compiler-version = "1.37.2" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0x76c5be08481759db8a418253eb5fba7c08b2615a94427dc801b375e667442c87" | ||
latest-published-id = "0x76c5be08481759db8a418253eb5fba7c08b2615a94427dc801b375e667442c87" | ||
published-version = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
task2 = { local="../task2" } | ||
# 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" | ||
task2 = "0x595755e12a700673fd174e05eac9a6e22cfb5d202de027d5830c256bd20d5b3a" | ||
|
||
# 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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
/// Module: task4*/ | ||
module task4::game; | ||
|
||
use sui::balance::{Balance}; | ||
use sui::balance; | ||
use sui::coin::{Coin, into_balance}; | ||
use sui::coin; | ||
// use sui::{from_balance,into_balance}; | ||
use sui::random; | ||
use sui::random::Random; | ||
use sui::transfer::{share_object,transfer,public_transfer}; | ||
use sui::tx_context::sender; | ||
use task2::faucet_coin::FAUCET_COIN; | ||
const EGameInsufficientBalance: u64 = 1001; | ||
const EUserInsufficientBalance: u64 = 1002; | ||
|
||
public struct AdminCap has key{ | ||
id:UID | ||
} | ||
|
||
public struct CryptoCtl_Game has key, store{ | ||
id:UID, | ||
balance: Balance<FAUCET_COIN>, | ||
} | ||
|
||
public struct GAME has drop {} | ||
|
||
fun init(_otw:GAME, ctx: &mut TxContext) { | ||
let game = CryptoCtl_Game { | ||
id: object::new(ctx), | ||
balance: balance::zero<FAUCET_COIN>() | ||
}; | ||
share_object(game); | ||
|
||
let admin = AdminCap {id: object::new(ctx)}; | ||
transfer(admin, sender(ctx)); | ||
} | ||
|
||
public entry fun deposit( | ||
game: &mut CryptoCtl_Game, | ||
coin:&mut Coin<FAUCET_COIN>, | ||
amount: u64, | ||
ctx:&mut TxContext | ||
){ | ||
assert!( | ||
coin.value() >= amount, | ||
EUserInsufficientBalance | ||
); | ||
let split_coin = coin.split(amount, ctx); | ||
|
||
game.balance.join(into_balance(split_coin)); | ||
|
||
//let into_balance = into_balance(coin); | ||
//game.balance.join(into_balance); | ||
} | ||
|
||
public entry fun withdraw(_admin:&AdminCap, game:&mut CryptoCtl_Game, amount:u64, to:address, ctx:&mut TxContext){ | ||
|
||
assert!( | ||
game.balance.value() >= amount, | ||
EGameInsufficientBalance | ||
); | ||
|
||
let cash = coin::take(&mut game.balance, amount, ctx); | ||
public_transfer(cash, to); | ||
} | ||
|
||
// 如果用户猜对了,获得双倍奖励。如果用户猜错了,损失投入的代币 | ||
|
||
public entry fun play( | ||
game: &mut CryptoCtl_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) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters