Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成task4 5 #1337

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mover/404ll/code/task1/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 ([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" }
Sui = { git = "https://gitee.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.
Expand Down
6 changes: 3 additions & 3 deletions mover/404ll/code/task2/FaucetCoin/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "A3A4289005858BB5EC8B7DFB1830EFFBF1A44FCC005156E36FA379507A61F1BD"
manifest_digest = "EB700C2874596221051E7064E25BE21F4F4B24A9DA2EA7EC75D46094A84A035B"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -29,6 +29,6 @@ flavor = "sui"

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x796fe22eb9df4f8d926e111c888d8ef4447d4348c3131f2cb4a82f1ec09c5e63"
latest-published-id = "0x796fe22eb9df4f8d926e111c888d8ef4447d4348c3131f2cb4a82f1ec09c5e63"
original-published-id = "0x2b26b95bbfe136e0c46e2d322f1c9b48974aff124ecb96f7bd064ed4265f26d9"
latest-published-id = "0x2b26b95bbfe136e0c46e2d322f1c9b48974aff124ecb96f7bd064ed4265f26d9"
published-version = "1"
5 changes: 2 additions & 3 deletions mover/404ll/code/task2/FaucetCoin/Move.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "FaucetCoin"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
published-at = "0x703f3e285af2ee26679bd14ce9d3f0cc840cb41541757a1e1ccd8d58db863fd2"
# license = "" # e.g., "MIT", "GPL", "Apache 2.0"
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"]

Expand All @@ -19,8 +20,7 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram
# Override = { local = "../conflicting/version", override = true }

[addresses]
faucetcoin = "0x0"

FaucetCoin = "0x703f3e285af2ee26679bd14ce9d3f0cc840cb41541757a1e1ccd8d58db863fd2"
# 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"
Expand All @@ -34,4 +34,3 @@ faucetcoin = "0x0"
# The dev-addresses section allows overwriting named addresses for the `--test`
# and `--dev` modes.
# alice = "0xB0B"

2 changes: 1 addition & 1 deletion mover/404ll/code/task2/FaucetCoin/sources/faucetcoin.move
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module faucetcoin::FaucetCoin {
module FaucetCoin::FaucetCoin {
use std::option;
use sui::transfer;
use sui::tx_context::{Self, TxContext};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.28.4"
compiler-version = "1.30.1"
edition = "2024.beta"
flavor = "sui"

Expand Down
38 changes: 38 additions & 0 deletions mover/404ll/code/task2/FireCoin/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "FireCoin"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
published-at = "0x703f3e285af2ee26679bd14ce9d3f0cc840cb41541757a1e1ccd8d58db863fd2"
# 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]
FireCoin = "0x703f3e285af2ee26679bd14ce9d3f0cc840cb41541757a1e1ccd8d58db863fd2"

# 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"

43 changes: 43 additions & 0 deletions mover/404ll/code/task4/flip_coin/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 = 2
manifest_digest = "0D16BD1D8945F1854D54AB65C26FCD9471D514EEF5463C8D0B3748ABC847EE46"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ name = "FaucetCoin" },
{ name = "Sui" },
]

[[move.package]]
name = "FaucetCoin"
source = { local = "..\\..\\task2\\FaucetCoin" }

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.30.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0xb862bfc74b3983a05806ec2bb84be2404135c88c22daa0a102e2b6f966685712"
latest-published-id = "0xb862bfc74b3983a05806ec2bb84be2404135c88c22daa0a102e2b6f966685712"
published-version = "1"
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "FireCoin"
name = "flip_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" }

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" }
Expand All @@ -19,7 +20,7 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram
# Override = { local = "../conflicting/version", override = true }

[addresses]
FireCoin = "0x0"
flip_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.
Expand Down
4 changes: 4 additions & 0 deletions mover/404ll/code/task4/flip_coin/desktop.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ViewState]
Mode=
Vid=
FolderType=Generic
17 changes: 17 additions & 0 deletions mover/404ll/code/task4/flip_coin/sources/call.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 跳过将依赖发布到链上这一步,直接发布,faucet地址必须为0
sui client publish --gas-budget 10000000 --with-unpublished-dependencies
export PACKAGE_ID=0xe29846de0cdfab2b904fd5ded72cb2b2f3345220e4b303be929b4d1fbe42a0dc

# mint faucetcoin
sui client call --function mint_and_transfer --module coin --package 0x2 --gas-budget 5000000 --args 0xe1943d206402458e75a696957d964d48780434cb6df05619e18b03b81cbc0441 100000 0x7b8e0864967427679b4e129f79dc332a885c6087ec9e187b53451a9006ee15f2 --type-args "0xb8d2ea18ced858954e6a228085f9d33f993ecf5ed5589bcd65fc928cb0a88ed6::FaucetCoin::FAUCETCOIN"

sui client call --function mint_and_transfer --module coin --package 0x2 --gas-budget 5000000 --args 0xe1943d206402458e75a696957d964d48780434cb6df05619e18b03b81cbc0441 100000 0x703f3e285af2ee26679bd14ce9d3f0cc840cb41541757a1e1ccd8d58db863fd2 --type-args "0xb8d2ea18ced858954e6a228085f9d33f993ecf5ed5589bcd65fc928cb0a88ed6::FaucetCoin::FAUCETCOIN"
#add coin
sui client call --function deposit --module flip_coin --package 0xb862bfc74b3983a05806ec2bb84be2404135c88c22daa0a102e2b6f966685712 --args 0x28885effffb4912574f0886a0b1d99e0f907d28399ceaa858bdfc136b1a5fea2 0x0d4d2f42a4b900eee094af5141559d2d3727422c8fd46eb3487146353e1e0a71 --gas-budget 100000000
sui client call --function withdral --module flip_coin --package 0xb862bfc74b3983a05806ec2bb84be2404135c88c22daa0a102e2b6f966685712 --args 0x01643a8e587b3ccfc969abd0c1c00bc695205bbc7a0de71dcdbd45d5918a01fa 0x28885effffb4912574f0886a0b1d99e0f907d28399ceaa858bdfc136b1a5fea2 20 --gas-budget 100000000

sui client call --function deposit --module flip_coin --package 0xb862bfc74b3983a05806ec2bb84be2404135c88c22daa0a102e2b6f966685712 --args 0x28885effffb4912574f0886a0b1d99e0f907d28399ceaa858bdfc136b1a5fea2 0xd575deb372cf1a7603270b380d973cc629994154286440ae5a026c12bf6d78be --gas-budget 100000000



sui client call --function deposit --module flip_coin --package 0xb862bfc74b3983a05806ec2bb84be2404135c88c22daa0a102e2b6f966685712 --args 0x01643a8e587b3ccfc969abd0c1c00bc695205bbc7a0de71dcdbd45d5918a01fa 0x8570ebe4201627b1906c9bdbc2baac9b8979fba024554c650325700e081f1740 --gas-budget 100000000
66 changes: 66 additions & 0 deletions mover/404ll/code/task4/flip_coin/sources/flip_coin.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module flip_coin::flip_coin {

use sui::balance;
use sui::balance::Balance;
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};
use sui::tx_context::sender;
use FaucetCoin::FaucetCoin::FAUCETCOIN;

const EOverBalance: u64 = 0;

public struct Pool has key{
id: UID,
balance:Balance<FAUCETCOIN>,
}

public struct AdminCap has key {
id: UID
}

fun init(ctx: &mut TxContext){
let admincap = AdminCap {id: object::new(ctx)};
let pool_vault = Pool {id: object::new(ctx), balance: balance::zero<FAUCETCOIN>()};

share_object(pool_vault);

transfer::transfer(admincap, sender(ctx));
}

public entry fun deposit(pool_vault:&mut Pool,coin:Coin<FAUCETCOIN>,ctx: &mut TxContext){
let inCoin_balance = into_balance(coin);
balance::join(&mut pool_vault.balance, inCoin_balance);
}

public entry fun withdral(_: &AdminCap,pool_vault:&mut Pool,amount: u64, ctx: &mut TxContext){
assert!(amount <= balance::value(&pool_vault.balance), EOverBalance );
let withdral_amount = balance::split(&mut pool_vault.balance, amount);

public_transfer(coin::from_balance(withdral_amount, ctx), sender(ctx));
}
entry fun gameplay( pool_vault:&mut Pool, guess:bool, random: &Random, inCoin:Coin<FAUCETCOIN>,ctx: &mut TxContext) {
let inCoin_value = coin::value(&inCoin);
let play_address = sender(ctx);
let pool_balance = balance::value(&pool_vault.balance);

if(inCoin_value > pool_balance/10){
abort 100u64;
};

let mut gen = random::new_generator(random, ctx);
let mut flag = random::generate_bool(&mut gen);

if(guess == flag){
let win_back = balance::split(&mut pool_vault.balance, inCoin_value );
public_transfer(coin::from_balance(win_back, ctx), play_address);
public_transfer(inCoin, play_address);
}else{
let in_balance = into_balance(inCoin);
balance::join(&mut pool_vault.balance, in_balance);
}

}
}
Loading