-
Notifications
You must be signed in to change notification settings - Fork 888
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ajin.liu
committed
Jul 26, 2024
1 parent
e37864c
commit 6b983dc
Showing
10 changed files
with
338 additions
and
7 deletions.
There are no files selected for viewing
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,40 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 2 | ||
manifest_digest = "D46641486D6A8D6BBF0261E25607FA6E33DA8FAB9481199B043464314CFDE88F" | ||
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" | ||
dependencies = [ | ||
{ name = "Sui" }, | ||
] | ||
|
||
[[move.package]] | ||
name = "MoveStdlib" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } | ||
|
||
[[move.package]] | ||
name = "Sui" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } | ||
|
||
dependencies = [ | ||
{ name = "MoveStdlib" }, | ||
] | ||
|
||
[move.toolchain-version] | ||
compiler-version = "1.29.0" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0x4123c8ba91d71254de2bc6de82ef9eef0507c3cbc3d8544e3ad71ee8474e65f7" | ||
latest-published-id = "0x4123c8ba91d71254de2bc6de82ef9eef0507c3cbc3d8544e3ad71ee8474e65f7" | ||
published-version = "1" | ||
|
||
[env.testnet] | ||
chain-id = "4c78adac" | ||
original-published-id = "0x1925e6fbe5dab7b3c5e9b8ec92a2c97620765f12b41222d5a2ed9ba3e5b31999" | ||
latest-published-id = "0x1925e6fbe5dab7b3c5e9b8ec92a2c97620765f12b41222d5a2ed9ba3e5b31999" | ||
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,37 @@ | ||
[package] | ||
name = "ajin_faucet_coin" | ||
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" } | ||
|
||
# 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] | ||
ajin_faucet_coin = "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
38
mover/ajin8898/code/task2/ajin_faucet_coin/sources/ajin_faucet_coin.move
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 @@ | ||
module ajin_faucet_coin::ajin_faucet_coin { | ||
|
||
use sui::coin::create_currency; | ||
use sui::transfer::{public_freeze_object, public_share_object}; | ||
use sui::coin::{Self, Coin, TreasuryCap}; | ||
use sui::url::{Url, Self}; | ||
|
||
public struct AJIN_FAUCET_COIN has drop {} | ||
|
||
fun init(witness: AJIN_FAUCET_COIN, ctx: &mut TxContext) { | ||
let icon_url = option::none(); | ||
let (treasury_cap, coin_metadata) = create_currency( | ||
witness, | ||
8, | ||
b"Ajin Faucet", | ||
b"Ajin Faucet", | ||
b"Ajin faucet coin", | ||
icon_url, | ||
ctx | ||
); | ||
|
||
// 所有权共享出去,不可变 | ||
public_freeze_object(coin_metadata); | ||
// 所有权共享出去 | ||
public_share_object(treasury_cap); | ||
} | ||
|
||
// 铸造代币 | ||
public entry fun mint(treasury_cap: &mut TreasuryCap<AJIN_FAUCET_COIN>, amount: u64, recipient: address, ctx: &mut TxContext) { | ||
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx); | ||
} | ||
|
||
// 销毁代币 | ||
public entry fun burn(treasury_cap: &mut TreasuryCap<AJIN_FAUCET_COIN>, coin: Coin<AJIN_FAUCET_COIN>) { | ||
coin::burn(treasury_cap, coin); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
mover/ajin8898/code/task2/ajin_faucet_coin/tests/ajin_faucet_coin_tests.move
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,19 @@ | ||
/* | ||
#[test_only] | ||
module ajin_faucet_coin::ajin_faucet_coin_tests { | ||
// uncomment this line to import the module | ||
// use ajin_faucet_coin::ajin_faucet_coin; | ||
const ENotImplemented: u64 = 0; | ||
#[test] | ||
fun test_ajin_faucet_coin() { | ||
// pass | ||
} | ||
#[test, expected_failure(abort_code = ::ajin_faucet_coin::ajin_faucet_coin_tests::ENotImplemented)] | ||
fun test_ajin_faucet_coin_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
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 = 2 | ||
manifest_digest = "008130794F614F874155EB75CEA43FC08EFC9615B49435BE86B974C978019ACE" | ||
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" | ||
dependencies = [ | ||
{ name = "Sui" }, | ||
{ name = "ajin_faucet_coin" }, | ||
] | ||
|
||
[[move.package]] | ||
name = "MoveStdlib" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } | ||
|
||
[[move.package]] | ||
name = "Sui" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } | ||
|
||
dependencies = [ | ||
{ name = "MoveStdlib" }, | ||
] | ||
|
||
[[move.package]] | ||
name = "ajin_faucet_coin" | ||
source = { local = "../../task2/ajin_faucet_coin" } | ||
|
||
dependencies = [ | ||
{ name = "Sui" }, | ||
] | ||
|
||
[move.toolchain-version] | ||
compiler-version = "1.29.0" | ||
edition = "2024.beta" | ||
flavor = "sui" | ||
|
||
[env] | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0x81ab36916b0a2adc9b217027ad660481ff36170ee0ed2c5771952ad0afa2a8dc" | ||
latest-published-id = "0x81ab36916b0a2adc9b217027ad660481ff36170ee0ed2c5771952ad0afa2a8dc" | ||
published-version = "1" | ||
|
||
[env.testnet] | ||
chain-id = "4c78adac" | ||
original-published-id = "0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0" | ||
latest-published-id = "0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0" | ||
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 = "taiSaiGame" | ||
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" } | ||
ajin_faucet_coin = { local = "../../task2/ajin_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] | ||
taisaigame = "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" | ||
|
81 changes: 81 additions & 0 deletions
81
mover/ajin8898/code/task4/taiSaiGame/sources/taisaigame.move
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,81 @@ | ||
/// Module: taisaigame | ||
module taisaigame::taisaigame { | ||
|
||
use sui::sui::SUI; | ||
use sui::balance::{Self, Balance}; | ||
use sui::transfer; | ||
use sui::tx_context::sender; | ||
use ajin_faucet_coin::ajin_faucet_coin::{Self, AJIN_FAUCET_COIN}; | ||
use sui::coin; | ||
use sui::coin::{Coin, from_balance, into_balance}; | ||
use sui::random; | ||
use sui::random::Random; | ||
use sui::transfer::{share_object, transfer, public_transfer}; | ||
|
||
|
||
public struct Game has key { | ||
id : UID, | ||
val: Balance<AJIN_FAUCET_COIN> | ||
} | ||
|
||
public struct AdminCap has key { | ||
id : UID, | ||
} | ||
|
||
fun init(ctx : &mut TxContext) { | ||
let game = Game { | ||
id : object::new(ctx), | ||
val : balance::zero() | ||
}; | ||
transfer::share_object(game); | ||
|
||
let admin = AdminCap{ | ||
id:object::new(ctx) | ||
}; | ||
transfer::transfer(admin, sender(ctx)); | ||
} | ||
|
||
entry fun play(game: &mut Game, flip_value: bool, in: Coin<AJIN_FAUCET_COIN>, rand: &Random, ctx: &mut TxContext) { | ||
let coin_value = coin::value(&in); | ||
|
||
let play_address = sender(ctx); | ||
let game_val = balance::value(&game.val) ; | ||
|
||
if (game_val < coin_value) { | ||
abort 1; | ||
}; | ||
|
||
//防止 all in 战神,限制每次最大是合约里面钱的10分之一 | ||
if (game_val < coin_value*10) { | ||
abort 2; | ||
}; | ||
|
||
let mut gen = random::new_generator(rand, ctx); | ||
|
||
let mut flag = random::generate_bool(&mut gen); | ||
if (flip_value == flag) { | ||
let win_balance = balance::split(&mut game.val, coin_value); | ||
let win_coin = from_balance(win_balance, ctx); | ||
public_transfer(win_coin, play_address); | ||
public_transfer(in, play_address); | ||
}else {//输了,放到余额 | ||
let in_balance = into_balance(in); | ||
balance::join(&mut game.val, in_balance); | ||
} | ||
} | ||
|
||
|
||
public entry fun deposit(game: &mut Game, in: Coin<AJIN_FAUCET_COIN>, ctx: &TxContext) { | ||
let in_balance = into_balance(in); | ||
balance::join(&mut game.val, in_balance); | ||
} | ||
|
||
public entry fun withdraw(_: &AdminCap, game: &mut Game, amt: u64, ctx: &mut TxContext) { | ||
let win_balance = balance::split(&mut game.val, amt); | ||
let win_coin = from_balance(win_balance, ctx); | ||
public_transfer(win_coin, sender(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,8 @@ | ||
gameId:0x585a3deb820ebe94b42dd49aa12e1887a2cc27a67aaa4fd4e81c1160519f08fb | ||
packageID:0x81ab36916b0a2adc9b217027ad660481ff36170ee0ed2c5771952ad0afa2a8dc | ||
0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 | ||
sui client call --function deposit --module taisaigame --package $PACKAGE_ID --gas-budget 3000000 --args $Game_Share_ID $Coin_ID | ||
sui client call --function deposit --module taisaigame --package 0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 --gas-budget 3000000 --args 0x649658a65d4334c933bc1c65cabe7705c728c0b871f27b24b19b1289d4841098 0x634b1890e1c41e6c46ffb51fb2e60cdde5bcda98a2d8c06d160304a47701fb63 | ||
sui client call --function withdraw --module taisaigame --package $GAME_PACKAGE_ID --gas-budget 3000000 --args $adminCap $Game_Share_ID 1000000 | ||
sui client call --function withdraw --module taisaigame --package 0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 --gas-budget 3000000 --args 0x9d729e0aeab6130bc55b459e17b56f9d9fa704771ea8f02c891e4e5ba6ea7485 0x649658a65d4334c933bc1c65cabe7705c728c0b871f27b24b19b1289d4841098 100000000 | ||
sui client call --function play --module taisaigame --package 0x5535158c0fdb6fb0d4537b9460d347cf30ffb7788585c420ce55744b0391c4c0 --gas-budget 3000000 --args 0x649658a65d4334c933bc1c65cabe7705c728c0b871f27b24b19b1289d4841098 true 0xe0777777dea58f72720f30aafb76391a259af8ddad5fece433f23bd036710fe9 0x8 |
19 changes: 19 additions & 0 deletions
19
mover/ajin8898/code/task4/taiSaiGame/tests/taisaigame_tests.move
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,19 @@ | ||
/* | ||
#[test_only] | ||
module taisaigame::taisaigame_tests { | ||
// uncomment this line to import the module | ||
// use taisaigame::taisaigame; | ||
const ENotImplemented: u64 = 0; | ||
#[test] | ||
fun test_taisaigame() { | ||
// pass | ||
} | ||
#[test, expected_failure(abort_code = ::taisaigame::taisaigame_tests::ENotImplemented)] | ||
fun test_taisaigame_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