-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2119 from PebblerWon/main
完成task4、5
- Loading branch information
Showing
18 changed files
with
710 additions
and
13 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
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
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
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 = "D23D9D30DA3F2FAC99EBC0898D66C4E2CC5C99CA29FF3A14A90F27C317261014" | ||
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" | ||
dependencies = [ | ||
{ id = "Sui", name = "Sui" }, | ||
{ id = "whn_coin_facuet", name = "whn_coin_facuet" }, | ||
] | ||
|
||
[[move.package]] | ||
id = "MoveStdlib" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } | ||
|
||
[[move.package]] | ||
id = "Sui" | ||
source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } | ||
|
||
dependencies = [ | ||
{ id = "MoveStdlib", name = "MoveStdlib" }, | ||
] | ||
|
||
[[move.package]] | ||
id = "whn_coin_facuet" | ||
source = { local = "../../task2/whn_coin_facuet" } | ||
|
||
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 = "0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2" | ||
latest-published-id = "0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2" | ||
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,40 @@ | ||
[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 (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] | ||
|
||
[dependencies] | ||
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet" } | ||
whn_coin_facuet = { local = "../../task2/whn_coin_facuet"} | ||
|
||
# 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" | ||
whn_coin_facuet = "0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2" | ||
|
||
|
||
# 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,40 @@ | ||
# testnet | ||
# packageid: 0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 | ||
# gameObjectId: 0x059e5357a41ffc783245d9f401896502e959c7804a3dc8d437f2033d155c9169 | ||
# whn_coin balance id: 0x070458113803a01856502677ba38bce5d9eb6f4ed36667af73e24974b8dfea83 | ||
# gameGap object id: 0x677a1efe9f91c0bf4f11dcf7c2983fecc841e1dfec0c7f70b5867b74ec26f14b | ||
|
||
## add_sui | ||
sui client call \ | ||
--package 0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 \ | ||
--module game \ | ||
--function add_sui \ | ||
--args 0x059e5357a41ffc783245d9f401896502e959c7804a3dc8d437f2033d155c9169 0x05c0d8dfd7240318cb83aa30c661a829beaabc210e133fe226176d0291bd5904 \ | ||
--gas-budget 10000000 | ||
|
||
## facuet | ||
sui client call \ | ||
--package 0x2 \ | ||
--module coin \ | ||
--function mint_and_transfer \ | ||
--type-args '0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2::whn_coin::WHN_COIN' \ | ||
--args 0x19e69a05953b0e065ebcd6a9705db902c21ac97f2bc14eb364ea79a889978d0c 10000 0x09be6b8995b7f56d8491a67f54519c56059d3fc24124470366b7ee5b51c27a91 | ||
|
||
## balance object id 0x05c0d8dfd7240318cb83aa30c661a829beaabc210e133fe226176d0291bd5904 | ||
|
||
|
||
## play | ||
sui client call \ | ||
--package 0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 \ | ||
--module game \ | ||
--function play \ | ||
--args 0x059e5357a41ffc783245d9f401896502e959c7804a3dc8d437f2033d155c9169 true 0x05c0d8dfd7240318cb83aa30c661a829beaabc210e133fe226176d0291bd5904 0x8\ | ||
--gas-budget 10000000 | ||
|
||
## withdraw | ||
sui client call \ | ||
--package 0xdb45e9cd2fcf4f816736a9f6d50ca428653bf1a45885568d37b91e7b93ea1ab2 \ | ||
--module game \ | ||
--function withdraw \ | ||
--args 0x677a1efe9f91c0bf4f11dcf7c2983fecc841e1dfec0c7f70b5867b74ec26f14b 0x059e5357a41ffc783245d9f401896502e959c7804a3dc8d437f2033d155c9169 8\ | ||
--gas-budget 10000000 |
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,55 @@ | ||
module game::game; | ||
use sui::balance::{Balance,zero}; | ||
use sui::coin::{Coin, from_balance, into_balance}; | ||
use sui::random; | ||
use whn_coin_facuet::whn_coin::WHN_COIN; | ||
|
||
public struct Game has key{ | ||
id: UID, | ||
balance: Balance<WHN_COIN>, | ||
reward_rate: u64, | ||
} | ||
public struct GameCap has key { | ||
id: UID, | ||
|
||
} | ||
fun init(ctx: &mut TxContext){ | ||
let game = Game{ | ||
id:object::new(ctx), | ||
balance: zero(), | ||
reward_rate:1, | ||
}; | ||
let cap = GameCap{ | ||
id:object::new(ctx) | ||
}; | ||
transfer::share_object(game); | ||
transfer::transfer(cap, ctx.sender()); | ||
} | ||
|
||
public entry fun play(game: &mut Game, flip_value:bool,in: Coin<WHN_COIN>, rand:&random::Random,ctx:&mut TxContext){ | ||
let in_balance_v = in.value(); | ||
assert!(in_balance_v>0 && game.balance.value()>=in_balance_v * game.reward_rate,0x100); | ||
|
||
let mut gen = random::new_generator(rand, ctx); | ||
|
||
let b = gen.generate_bool(); | ||
if(b==flip_value){ | ||
let reward = in_balance_v*game.reward_rate; | ||
let b = game.balance.split(reward); | ||
let coin = from_balance<WHN_COIN>(b, ctx); | ||
transfer::public_transfer(coin, ctx.sender()); | ||
transfer::public_transfer(in, ctx.sender()); | ||
|
||
}else{ | ||
game.balance.join(into_balance(in)); | ||
} | ||
} | ||
|
||
public entry fun add_sui(game:&mut Game,in:Coin<WHN_COIN>,_ctx:&mut TxContext){ | ||
game.balance.join(into_balance(in)); | ||
} | ||
public entry fun withdraw(_: &GameCap, game: &mut Game,amount: u64, ctx: &mut TxContext){ | ||
let b = game.balance.split(amount); | ||
let coin = from_balance(b, ctx); | ||
transfer::public_transfer(coin, ctx.sender()); | ||
} |
72 changes: 72 additions & 0 deletions
72
mover/PebblerWon/code/task4/game/sources/game_demo.move.ee
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,72 @@ | ||
/// Module: game | ||
module game::game; | ||
|
||
use sui::balance::Balance; | ||
use sui::balance; | ||
use sui::random; | ||
use sui::coin::{Coin, from_balance, into_balance}; | ||
use faucet_coin::faucetcoin::FAUCETCOIN; | ||
|
||
public struct Game has key { | ||
id: UID, | ||
balance: Balance<FAUCETCOIN>, | ||
reward_rate: u64, | ||
} | ||
|
||
public struct GameCap has key { | ||
id: UID, | ||
} | ||
|
||
fun init(ctx: &mut TxContext) { | ||
let game = Game { | ||
id: object::new(ctx), | ||
balance: balance::zero(), | ||
reward_rate: 1, | ||
}; | ||
|
||
let cap = GameCap { | ||
id: object::new(ctx), | ||
}; | ||
|
||
transfer::share_object(game); | ||
transfer::transfer(cap, ctx.sender()); | ||
} | ||
|
||
#[allow(lint(public_random))] | ||
public entry fun play(game: &mut Game, flip_value: bool, in: Coin<FAUCETCOIN>, | ||
rand: &random::Random, ctx: &mut TxContext) { | ||
let in_balance_v = in.value(); | ||
assert!(in_balance_v > 0 && game.balance.value() >= in_balance_v * game.reward_rate, 100); | ||
|
||
let mut gen = random::new_generator(rand, ctx); | ||
let b = gen.generate_bool(); | ||
if (b == flip_value) { | ||
let reward = in_balance_v * game.reward_rate; | ||
let b = game.balance.split(reward); | ||
let coin = from_balance<FAUCETCOIN>(b, ctx); | ||
transfer::public_transfer(coin, ctx.sender()); | ||
transfer::public_transfer(in, ctx.sender()); | ||
} else { | ||
game.balance.join(into_balance(in)); | ||
} | ||
} | ||
|
||
public entry fun add_sui(game: &mut Game, in: Coin<FAUCETCOIN>, _ctx: &mut TxContext) { | ||
game.balance.join(into_balance(in)); | ||
} | ||
|
||
public entry fun withdraw(_: &GameCap, game: &mut Game, amount: u64, ctx: &mut TxContext) { | ||
let b = game.balance.split(amount); | ||
let coin = from_balance<FAUCETCOIN>(b, ctx); | ||
transfer::public_transfer(coin, ctx.sender()) | ||
} | ||
|
||
#[test_only] | ||
public fun test_init(ctx: &mut TxContext) { | ||
init(ctx); | ||
} | ||
|
||
#[test_only] | ||
public fun balance(game: &Game): u64 { | ||
game.balance.value() | ||
} |
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 game::game_tests; | ||
// uncomment this line to import the module | ||
// use game::game; | ||
const ENotImplemented: u64 = 0; | ||
#[test] | ||
fun test_game() { | ||
// pass | ||
} | ||
#[test, expected_failure(abort_code = ::game::game_tests::ENotImplemented)] | ||
fun test_game_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,58 @@ | ||
# @generated by Move, please check-in and do not edit manually. | ||
|
||
[move] | ||
version = 3 | ||
manifest_digest = "D44E4A89CE616D7078615B368C1E985CD16409C6A9FBBB40826D9456F276DCF3" | ||
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" | ||
dependencies = [ | ||
{ id = "Sui", name = "Sui" }, | ||
{ id = "whn_coin", name = "whn_coin" }, | ||
{ id = "whn_coin_facuet", name = "whn_coin_facuet" }, | ||
] | ||
|
||
[[move.package]] | ||
id = "MoveStdlib" | ||
source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } | ||
|
||
[[move.package]] | ||
id = "Sui" | ||
source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } | ||
|
||
dependencies = [ | ||
{ id = "MoveStdlib", name = "MoveStdlib" }, | ||
] | ||
|
||
[[move.package]] | ||
id = "whn_coin" | ||
source = { local = "../../task2/whn_coin" } | ||
|
||
dependencies = [ | ||
{ id = "Sui", name = "Sui" }, | ||
] | ||
|
||
[[move.package]] | ||
id = "whn_coin_facuet" | ||
source = { local = "../../task2/whn_coin_facuet" } | ||
|
||
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 = "0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5" | ||
latest-published-id = "0x0ef48bbf55fb1c0b7d228ad5d76ea28d70dace2df21c856dcf8eae78a4cbd6d5" | ||
published-version = "1" | ||
|
||
[env.mainnet] | ||
chain-id = "35834a8a" | ||
original-published-id = "0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296" | ||
latest-published-id = "0x5e0ac630c0bba8295b9de9a7acb7f0a9cd4b476c3ea3f246678e5c46606e1296" | ||
published-version = "1" |
Oops, something went wrong.