Skip to content

Commit

Permalink
完成task4 task5
Browse files Browse the repository at this point in the history
  • Loading branch information
1pzq committed Aug 30, 2024
1 parent 3f3310d commit 446f8ee
Show file tree
Hide file tree
Showing 14 changed files with 484 additions and 32 deletions.
10 changes: 5 additions & 5 deletions mover/1pzq/code/task3/my_nft/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ dependencies = [
]

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

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x2248d5ab22fd89d3790742f6182307f53b3c42872e4b28147e8c749808ecf67e"
latest-published-id = "0x2248d5ab22fd89d3790742f6182307f53b3c42872e4b28147e8c749808ecf67e"
original-published-id = "0xb9636fdf52b15ae1947019458e23418766a21f69b746f40b501493b59c27b171"
latest-published-id = "0xb9636fdf52b15ae1947019458e23418766a21f69b746f40b501493b59c27b171"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xae98f7099f2417d0a32e1089d6ea36f138926a62a7eba85f57cda01815a530cf"
latest-published-id = "0xae98f7099f2417d0a32e1089d6ea36f138926a62a7eba85f57cda01815a530cf"
original-published-id = "0xdc877fbc90f0f25d97f33e41c8426d9f2716fc93e0ebf02122ac5036a3e88d2b"
latest-published-id = "0xdc877fbc90f0f25d97f33e41c8426d9f2716fc93e0ebf02122ac5036a3e88d2b"
published-version = "1"
2 changes: 1 addition & 1 deletion mover/1pzq/code/task3/my_nft/sources/kite.move
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module my_nft::kite {
utf8(b"{name}"),
utf8(b"https://sui-heroes.io/hero/{id}"),
utf8(b"{image_url}"),
utf8(b"A true Hero of the Sui ecosystem!"),
utf8(b"He Jing Yi's birthday!"),
utf8(b"https://sui-heroes.io"),
utf8(b"Unknown Sui Fan")
];
Expand Down
40 changes: 40 additions & 0 deletions mover/1pzq/code/task4/game/Move.lock
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 = "09E96EFF150B65B8C2F33F9094E1DCF127B543DB3BF332FE094BF07CD9DAE41E"
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.30.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x914eca20238f4bf2ec175a3a419bdc6b7bc30bf47eefdb78edd921e205625b91"
latest-published-id = "0x914eca20238f4bf2ec175a3a419bdc6b7bc30bf47eefdb78edd921e205625b91"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xa08f96ff2fbe01c8e1cc131c7e4c27dea2368292bfcf0bb810cac819e0837bcf"
latest-published-id = "0xa08f96ff2fbe01c8e1cc131c7e4c27dea2368292bfcf0bb810cac819e0837bcf"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/1pzq/code/task4/game/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[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 = "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]
game = "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"

23 changes: 23 additions & 0 deletions mover/1pzq/code/task4/game/sources/facet.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// Module: coinfacet
module game::coinfacet {

use sui::coin::{Self, TreasuryCap};
use sui::tx_context::TxContext;

public struct COINFACET has drop {}

fun init(witness: COINFACET, ctx: &mut TxContext) {
let (mint_id, metadata) = coin::create_currency(witness, 6, b"COINFACET", b"", b"", std::option::none(), ctx);
transfer::public_freeze_object(metadata);
transfer::public_share_object(mint_id)
}

public entry fun mint(
treasury_cap: &mut TreasuryCap<COINFACET>,
ctx: &mut TxContext,
) {
let coinfacet_coin = coin::mint(treasury_cap, 10000000, ctx);
transfer::public_transfer(coinfacet_coin, tx_context::sender(ctx))
}

}
49 changes: 49 additions & 0 deletions mover/1pzq/code/task4/game/sources/game.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module game::game_pzq {
use std::string;
use sui::clock::{Self, Clock};
use sui::coin::{TreasuryCap};
use sui::event;
use game::coinfacet::{Self, COINFACET};

const Small: u64 = 0;
const Big: u64 = 1;

const ErrInvalidGuess: u64 = 1;

public struct GameOut has drop, copy {
player_guess: u64,
machine_result: u64,
outcome: string::String
}


fun random_result(clock: &Clock): u64 {
clock::timestamp_ms(clock) % 2
}

public fun playGame(treasury_cap: &mut TreasuryCap<COINFACET>, guessNum: u64, clock: &Clock, ctx: &mut TxContext) {
assert!(guessNum == Small || guessNum == Big, ErrInvalidGuess);
let result = random_result(clock);
let outcome = if (guessNum == result) { true } else { false };
let finalResult = if (outcome) {
string::utf8(b"you win this game")
} else {
string::utf8(b"You lost this game")
};

let game_outcome = GameOut {
player_guess : guessNum,
machine_result : result,
outcome : finalResult,
};

if (outcome) {
coinfacet::mint(treasury_cap,ctx);
};

event::emit(game_outcome);
}
}
/*
packageId
*/
19 changes: 19 additions & 0 deletions mover/1pzq/code/task4/game/tests/game_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
#[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
}
}
*/
34 changes: 34 additions & 0 deletions mover/1pzq/code/task5/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 2
manifest_digest = "CD93CDC6B007155F81F5153B144E4F8F15B34537C7124A2BFF31535BD5BAE488"
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.30.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xd4ce61db015c09854c782cb898eb2af8ee6ec2f54d3f8c154e40b469530c5315"
latest-published-id = "0xd4ce61db015c09854c782cb898eb2af8ee6ec2f54d3f8c154e40b469530c5315"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/1pzq/code/task5/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "swap"
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 = "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]
swap = "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"

37 changes: 37 additions & 0 deletions mover/1pzq/code/task5/sources/coin_a.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module swap::coin_a {
use sui::coin::{Self, Coin, TreasuryCap};
public struct COIN_A has drop {}

fun init(witness: COIN_A, ctx: &mut TxContext) {
let (treasury_cap, metadata) = coin::create_currency<COIN_A>(
witness,
3,
b"COIN_A",
b"CA",
b"coin_A",
option::none(),
ctx
);

transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury_cap, tx_context::sender(ctx));
}

public fun mint(
treasury_cap: &mut TreasuryCap<COIN_A>,
amount: u64,
recipient: address,
ctx: &mut TxContext
) {
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx);
}

public fun burn(treasury_cap: &mut TreasuryCap<COIN_A>, coin: Coin<COIN_A>) {
coin::burn(treasury_cap, coin);
}

#[test_only]
public fun test_init(ctx: &mut TxContext) {
init(COIN_A {}, ctx);
}
}
37 changes: 37 additions & 0 deletions mover/1pzq/code/task5/sources/coin_b.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module swap::coin_b {
use sui::coin::{Self, Coin, TreasuryCap};
public struct COIN_B has drop {}

fun init(witness: COIN_B, ctx: &mut TxContext) {
let (treasury_cap, metadata) = coin::create_currency<COIN_B>(
witness,
3,
b"COIN_B",
b"CB",
b"coin_b",
option::none(),
ctx
);

transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury_cap, tx_context::sender(ctx));
}

public fun mint(
treasury_cap: &mut TreasuryCap<COIN_B>,
amount: u64,
recipient: address,
ctx: &mut TxContext
) {
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx);
}

public fun burn(treasury_cap: &mut TreasuryCap<COIN_B>, coin: Coin<COIN_B>) {
coin::burn(treasury_cap, coin);
}

#[test_only]
public fun test_init(ctx: &mut TxContext) {
init(COIN_B {}, ctx);
}
}
Loading

0 comments on commit 446f8ee

Please sign in to comment.