Skip to content

Commit

Permalink
Merge pull request #2119 from PebblerWon/main
Browse files Browse the repository at this point in the history
完成task4、5
  • Loading branch information
Sifotd authored Dec 9, 2024
2 parents ec86748 + 21a26f9 commit 71fc68d
Show file tree
Hide file tree
Showing 18 changed files with 710 additions and 13 deletions.
8 changes: 6 additions & 2 deletions mover/PebblerWon/code/task2/whn_coin/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# 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" }
Sui = { git = "https://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet" }

# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# Revision can be a branch, a tag, and a commit hash.
Expand All @@ -19,7 +19,11 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram
# Override = { local = "../conflicting/version", override = true }

[addresses]
whn_coin = "0x0"
# testnet
# whn_coin = "0x5bedaf1084a9f6a7c98a205ca56550c75bb13376cc34c07fc3c5bddc6b17d813"

# mainnet
whn_coin = "0xd12d0dbe5c01f8ec8aff8b62d440b3b5c7ef9330e55878c3ee30381694ba57ef"

# Named addresses will be accessible in Move as `@name`. They're also exported:
# for example, `std = "0x1"` is exported by the Standard Library.
Expand Down
4 changes: 2 additions & 2 deletions mover/PebblerWon/code/task2/whn_coin/call.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
--package 0x2 \
--module coin \
--function mint_and_transfer \
--type-args '0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2::whn_coin::WHN_COIN' \
--args 0x19e69a05953b0e065ebcd6a9705db902c21ac97f2bc14eb364ea79a889978d0c 10000 0x60364db3c6fa7128433ad62ce4e32649443a999ab6b54bdcbaf14194ec1a6203
--type-args '0x5bedaf1084a9f6a7c98a205ca56550c75bb13376cc34c07fc3c5bddc6b17d813::whn_coin::WHN_COIN' \
--args 0xbbe765228d36c58cbdfa1cd3ab90ac11ba280866fd5dbe3e1cad15f5571f5316 10000 0x09be6b8995b7f56d8491a67f54519c56059d3fc24124470366b7ee5b51c27a91


## mainnet
Expand Down
8 changes: 6 additions & 2 deletions mover/PebblerWon/code/task2/whn_coin_facuet/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# 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" }
Sui = { git = "https://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet" }

# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# Revision can be a branch, a tag, and a commit hash.
Expand All @@ -19,7 +19,11 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram
# Override = { local = "../conflicting/version", override = true }

[addresses]
whn_coin_facuet = "0x0"
# testnet
# whn_coin_facuet = "0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2"

# mainnet
whn_coin_facuet = "0x498edfc9e864d78d244315e514569ae842cb26c14cea75acb55224f74e933bbd"

# Named addresses will be accessible in Move as `@name`. They're also exported:
# for example, `std = "0x1"` is exported by the Standard Library.
Expand Down
1 change: 1 addition & 0 deletions mover/PebblerWon/code/task2/whn_coin_facuet/call.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# --type-args 是我们自己合约的package id
# --args 第一个参数是treasurycpa的object id

# testnet package id: 0x4c5e927d8dd0fe7bc37cfbca401376d6ccc300f6b79cf40f19a1cf329c521dd2
## mainnet facuet address 1
sui client call \
--package 0x2 \
Expand Down
43 changes: 43 additions & 0 deletions mover/PebblerWon/code/task4/game/Move.lock
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"
40 changes: 40 additions & 0 deletions mover/PebblerWon/code/task4/game/Move.toml
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"

40 changes: 40 additions & 0 deletions mover/PebblerWon/code/task4/game/call.sh
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
55 changes: 55 additions & 0 deletions mover/PebblerWon/code/task4/game/sources/game.move
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 mover/PebblerWon/code/task4/game/sources/game_demo.move.ee
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()
}
18 changes: 18 additions & 0 deletions mover/PebblerWon/code/task4/game/tests/game_tests.move
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
}
*/
58 changes: 58 additions & 0 deletions mover/PebblerWon/code/task5/pebblerwon/Move.lock
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"
Loading

0 comments on commit 71fc68d

Please sign in to comment.