-
Notifications
You must be signed in to change notification settings - Fork 731
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
Showing
14 changed files
with
484 additions
and
32 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
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" |
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 = "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" | ||
|
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,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)) | ||
} | ||
|
||
} |
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 @@ | ||
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 | ||
*/ |
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 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,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" |
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 = "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" | ||
|
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 @@ | ||
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); | ||
} | ||
} |
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 @@ | ||
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); | ||
} | ||
} |
Oops, something went wrong.