-
Notifications
You must be signed in to change notification settings - Fork 89
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
57 changed files
with
1,127 additions
and
1,135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
/// The module `hello_world` under named address `hello_world`. | ||
/// The named address is set in the `Move.toml`. | ||
module hello_world::hello_world { | ||
// Imports the `String` type from the Standard Library | ||
use std::string::String; | ||
module hello_world::hello_world; | ||
|
||
/// Returns the "Hello World!" as a `String`. | ||
public fun hello_world(): String { | ||
b"Hello, World!".to_string() | ||
} | ||
// Imports the `String` type from the Standard Library | ||
use std::string::String; | ||
|
||
/// Returns the "Hello World!" as a `String`. | ||
public fun hello_world(): String { | ||
b"Hello, World!".to_string() | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#[test_only] | ||
module hello_world::hello_world_tests { | ||
use hello_world::hello_world; | ||
module hello_world::hello_world_tests; | ||
|
||
#[test] | ||
fun test_hello_world() { | ||
assert!(hello_world::hello_world() == b"Hello, World!".to_string(), 0); | ||
} | ||
use hello_world::hello_world; | ||
|
||
#[test] | ||
fun test_hello_world() { | ||
assert!(hello_world::hello_world() == b"Hello, World!".to_string(), 0); | ||
} |
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,20 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[allow(unused_function)] | ||
// ANCHOR: main | ||
module book::comments_block; | ||
|
||
fun /* you can comment everywhere */ go_wild() { | ||
/* here | ||
there | ||
everywhere */ let a = 10; | ||
let b = /* even here */ 10; /* and again */ | ||
a + b; | ||
} | ||
/* you can use it to remove certain expressions or definitions | ||
fun empty_commented_out() { | ||
} | ||
*/ | ||
// ANCHOR_END: main |
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,21 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[allow(unused_function, unused_const, unused_variable, unused_field)] | ||
// ANCHOR: main | ||
/// Module has documentation! | ||
module book::comments_doc; | ||
|
||
/// This is a 0x0 address constant! | ||
const AN_ADDRESS: address = @0x0; | ||
|
||
/// This is a struct! | ||
public struct AStruct { | ||
/// This is a field of a struct! | ||
a_field: u8, | ||
} | ||
|
||
/// This function does something! | ||
/// And it's documented! | ||
fun do_something() {} | ||
// ANCHOR_END: main |
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,15 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[allow(unused_function, unused_variable)] | ||
// ANCHOR: main | ||
module book::comments_line; | ||
|
||
// let's add a note to everything! | ||
fun some_function_with_numbers() { | ||
let a = 10; | ||
// let b = 10 this line is commented and won't be executed | ||
let b = 5; // here comment is placed after code | ||
a + b; // result is 15, not 10! | ||
} | ||
// ANCHOR_END: main |
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
packages/samples/sources/move-basics/constants-config.move
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,17 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// ANCHOR: config | ||
module book::config; | ||
|
||
const ITEM_PRICE: u64 = 100; | ||
const TAX_RATE: u64 = 10; | ||
const SHIPPING_COST: u64 = 5; | ||
|
||
/// Returns the price of an item. | ||
public fun item_price(): u64 { ITEM_PRICE } | ||
/// Returns the tax rate. | ||
public fun tax_rate(): u64 { TAX_RATE } | ||
/// Returns the shipping cost. | ||
public fun shipping_cost(): u64 { SHIPPING_COST } | ||
// ANCHOR_END: config |
13 changes: 13 additions & 0 deletions
13
packages/samples/sources/move-basics/constants-naming.move
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,13 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[allow(unused_const)] | ||
module book::naming; | ||
|
||
// ANCHOR: naming | ||
/// Price of the item used at the shop. | ||
const ITEM_PRICE: u64 = 100; | ||
|
||
/// Error constant. | ||
const EItemNotFound: u64 = 1; | ||
// ANCHOR_END: naming |
25 changes: 25 additions & 0 deletions
25
packages/samples/sources/move-basics/constants-shop-price.move
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,25 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// ANCHOR: shop_price | ||
module book::shop_price; | ||
|
||
use sui::{coin::Coin, sui::SUI}; | ||
|
||
/// The price of an item in the shop. | ||
const ITEM_PRICE: u64 = 100; | ||
/// The owner of the shop, an address. | ||
const SHOP_OWNER: address = @0xa11ce; | ||
|
||
/// An item sold in the shop. | ||
public struct Item {} | ||
|
||
/// Purchase an item from the shop. | ||
public fun purchase(coin: Coin<SUI>): Item { | ||
assert!(coin.value() == ITEM_PRICE, 0); | ||
|
||
transfer::public_transfer(coin, SHOP_OWNER); | ||
|
||
Item {} | ||
} | ||
// ANCHOR_END: shop_price |
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 |
---|---|---|
@@ -1,67 +1,16 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
module book::constants { | ||
const MAX: u64 = 100; | ||
module book::constants; | ||
|
||
// however you can pass constant outside using a function | ||
public fun max(): u64 { | ||
MAX | ||
} | ||
const MAX: u64 = 100; | ||
|
||
// or using | ||
public fun is_max(num: u64): bool { | ||
num == MAX | ||
} | ||
// however you can pass constant outside using a function | ||
public fun max(): u64 { | ||
MAX | ||
} | ||
|
||
// ANCHOR: shop_price | ||
module book::shop_price { | ||
use sui::coin::Coin; | ||
use sui::sui::SUI; | ||
|
||
/// The price of an item in the shop. | ||
const ITEM_PRICE: u64 = 100; | ||
/// The owner of the shop, an address. | ||
const SHOP_OWNER: address = @0xa11ce; | ||
|
||
/// An item sold in the shop. | ||
public struct Item { /* ... */ } | ||
|
||
/// Purchase an item from the shop. | ||
public fun purchase(coin: Coin<SUI>): Item { | ||
assert!(coin.value() == ITEM_PRICE, 0); | ||
|
||
transfer::public_transfer(coin, SHOP_OWNER); | ||
|
||
Item { /* ... */ } | ||
} | ||
} | ||
// ANCHOR_END: shop_price | ||
#[allow(unused_const)] | ||
module book::naming { | ||
|
||
// ANCHOR: naming | ||
/// Price of the item used at the shop. | ||
const ITEM_PRICE: u64 = 100; | ||
|
||
/// Error constant. | ||
const EItemNotFound: u64 = 1; | ||
// ANCHOR_END: naming | ||
|
||
} | ||
|
||
// ANCHOR: config | ||
module book::config { | ||
const ITEM_PRICE: u64 = 100; | ||
const TAX_RATE: u64 = 10; | ||
const SHIPPING_COST: u64 = 5; | ||
|
||
/// Returns the price of an item. | ||
public fun item_price(): u64 { ITEM_PRICE } | ||
/// Returns the tax rate. | ||
public fun tax_rate(): u64 { TAX_RATE } | ||
/// Returns the shipping cost. | ||
public fun shipping_cost(): u64 { SHIPPING_COST } | ||
// or using | ||
public fun is_max(num: u64): bool { | ||
num == MAX | ||
} | ||
// ANCHOR_END: config |
Oops, something went wrong.