Skip to content

Commit

Permalink
Add license header to all move files
Browse files Browse the repository at this point in the history
  • Loading branch information
666lcz committed Mar 22, 2022
1 parent f2693e0 commit dea171c
Show file tree
Hide file tree
Showing 74 changed files with 318 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example of objects that can be combined to create
/// new objects
module Examples::CombinableObjects {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// An example of a custom object with comments explaining the relevant bits
module Examples::CustomObjectTemplate {
use Sui::ID::VersionedID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module Examples::TicTacToe {
use Std::Option::{Self, Option};
use Std::Vector;
Expand Down Expand Up @@ -263,4 +266,4 @@ module Examples::TicTacToe {
public fun mark_col(mark: &Mark): u64 {
mark.col
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example coin with a trusted owner responsible for minting/burning (e.g., a stablecoin)
module Examples::TrustedCoin {
use Sui::Coin::{Self, TreasuryCap};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example coin with a trusted owner responsible for minting/burning (e.g., a stablecoin)
module Examples::TrustedCoin {
use Sui::Coin::{Self, TreasuryCap};
Expand Down
11 changes: 7 additions & 4 deletions sui_core/src/unit_tests/data/hero/sources/Hero.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example of a game character with basic attributes, inventory, and
/// associated logic.
module Examples::Hero {
Expand Down Expand Up @@ -34,7 +37,7 @@ module Examples::Hero {
/// For healing wounded heroes
struct Potion has key, store {
id: VersionedID,
/// Effectivenss of the potion
/// Effectiveness of the potion
potency: u64
}

Expand Down Expand Up @@ -206,7 +209,7 @@ module Examples::Hero {
let value = Coin::value(&payment);
// ensure the user pays enough for the sword
assert!(value >= MIN_SWORD_COST, EINSUFFICIENT_FUNDS);
// pay the admin for ths sword
// pay the admin for this sword
Transfer::transfer(payment, admin());

// magic of the sword is proportional to the amount you paid, up to
Expand All @@ -225,7 +228,7 @@ module Examples::Hero {
Transfer::transfer(hero, TxContext::sender(ctx))
}

/// Anyone can create a hero if they have a sword. All heros start with the
/// Anyone can create a hero if they have a sword. All heroes start with the
/// same attributes.
public fun create_hero(sword: Sword, ctx: &mut TxContext): Hero {
Hero {
Expand Down Expand Up @@ -338,4 +341,4 @@ module Examples::Hero {
TestScenario::return_object(scenario, hero)
};
}
}
}
3 changes: 3 additions & 0 deletions sui_core/src/unit_tests/data/hero/sources/TrustedCoin.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example coin with a trusted owner responsible for minting/burning (e.g., a stablecoin)
module Examples::TrustedCoin {
use Sui::Coin::{Self, TreasuryCap};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module ObjectOwner::ObjectOwner {
use Std::Option::{Self, Option};
use Sui::ID::{Self, VersionedID};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module ObjectWrapping::ObjectWrapping {
use Std::Option::{Self, Option};
use Sui::Transfer;
Expand Down Expand Up @@ -54,4 +57,4 @@ module ObjectWrapping::ObjectWrapping {
};
Option::destroy_none(child_opt)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module Test::M1 {
use Std::Vector;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module Test::M1 {
use Sui::ID::VersionedID;
use Sui::TxContext::{Self, TxContext};
Expand All @@ -10,13 +13,13 @@ module Test::M1 {
}

fun foo<T: key, T2: drop>(_p1: u64, value1: T, _value2: &Coin<T2>, _p2: u64): T {
value1
value1
}

public fun create(value: u64, recipient: address, ctx: &mut TxContext) {
Transfer::transfer(
Object { id: TxContext::new_id(ctx), value },
recipient
)
}
}
}
13 changes: 8 additions & 5 deletions sui_programmability/examples/basics/sources/Lock.move
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// An example of a module that uses Shared Objects and ID linking/access.
///
/// This module allows any content to be locked inside a 'virtual chest' and later
/// be accessed by putting a 'key' into the 'lock'. Lock is shared and is visible
/// and discoverable by the key owner.
/// and discoverable by the key owner.
module Basics::Lock {
use Sui::ID::{Self, ID, VersionedID};
use Sui::Transfer;
Expand All @@ -18,14 +21,14 @@ module Basics::Lock {
/// Lock already contains something.
const ELOCK_IS_FULL: u64 = 2;

/// Lock that stores any content inside it.
/// Lock that stores any content inside it.
struct Lock<T: store + key> has key, store {
id: VersionedID,
locked: Option<T>
}

/// A key that is created with a Lock; is transferable
/// and contains all the needed information to open the Lock.
/// and contains all the needed information to open the Lock.
struct Key<phantom T: store + key> has key, store {
id: VersionedID,
for: ID,
Expand All @@ -36,7 +39,7 @@ module Basics::Lock {
key.for
}

/// Lock some content inside a shared object. A Key is created and is
/// Lock some content inside a shared object. A Key is created and is
/// sent to the transaction sender.
public fun create<T: store + key>(obj: T, ctx: &mut TxContext) {
let id = TxContext::new_id(ctx);
Expand Down Expand Up @@ -67,7 +70,7 @@ module Basics::Lock {
Option::fill(&mut lock.locked, obj);
}

/// Unlock the Lock with a Key and access its contents.
/// Unlock the Lock with a Key and access its contents.
/// Can only be called if both conditions are met:
/// - key matches the lock
/// - lock is not empty
Expand Down
3 changes: 3 additions & 0 deletions sui_programmability/examples/basics/sources/Object.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// An example of a custom object with comments explaining the relevant bits
module Basics::Object {
use Sui::ID::VersionedID;
Expand Down
3 changes: 3 additions & 0 deletions sui_programmability/examples/basics/sources/Sandwich.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example of objects that can be combined to create
/// new objects
module Basics::Sandwich {
Expand Down
3 changes: 3 additions & 0 deletions sui_programmability/examples/defi/sources/Escrow.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// An escrow for atomic swap of objects that trusts a third party for liveness, but not safety.
module DeFi::Escrow {
use Sui::ID::{Self, ID, VersionedID};
Expand Down
19 changes: 11 additions & 8 deletions sui_programmability/examples/defi/sources/FlashLender.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// A flash loan that works for any Coin type
module DeFi::FlashLender {
use Sui::Coin::{Self, Coin};
Expand Down Expand Up @@ -30,8 +33,8 @@ module DeFi::FlashLender {
repay_amount: u64
}

/// An object conveying the privilege to withdraw funds from and deposit funds to the
/// `FlashLender` instance with ID `flash_lender_id`. Initially granted to the creator
/// An object conveying the privilege to withdraw funds from and deposit funds to the
/// `FlashLender` instance with ID `flash_lender_id`. Initially granted to the creator
/// of the `FlashLender`, and only one `AdminCap` per lender exists.
struct AdminCap has key, store {
id: VersionedID,
Expand Down Expand Up @@ -82,7 +85,7 @@ module DeFi::FlashLender {
// === Core functionality: requesting a loan and repaying it ===

/// Request a loan of `amount` from `lender`. The returned `Receipt<T>` "hot potato" ensures
/// that the borrower will call `repay(lender, ...)` later on in this tx.
/// that the borrower will call `repay(lender, ...)` later on in this tx.
/// Aborts if `amount` is greater that the amount that `lender` has available for lending.
public fun loan<T>(
self: &mut FlashLender<T>, amount: u64, ctx: &mut TxContext
Expand All @@ -91,14 +94,14 @@ module DeFi::FlashLender {
assert!(Coin::value(to_lend) >= amount, ELOAN_TOO_LARGE);
let loan = Coin::withdraw(to_lend, amount, ctx);

let repay_amount = amount + self.fee;
let repay_amount = amount + self.fee;
let receipt = Receipt { flash_lender_id: *ID::id(self), repay_amount };
(loan, receipt)
}

/// Repay the loan recorded by `receipt` to `lender` with `payment`.
/// Aborts if the repayment amount is incorrect or `lender` is not the `FlashLender`
/// that issued the original loan.
/// that issued the original loan.
public fun repay<T>(self: &mut FlashLender<T>, payment: Coin<T>, receipt: Receipt<T>) {
let Receipt { flash_lender_id, repay_amount } = receipt;
assert!(ID::id(self) == &flash_lender_id, EREPAY_TO_WRONG_LENDER);
Expand All @@ -111,9 +114,9 @@ module DeFi::FlashLender {

/// Allow admin for `self` to withdraw funds.
public fun withdraw<T>(
self: &mut FlashLender<T>,
self: &mut FlashLender<T>,
admin_cap: &AdminCap,
amount: u64,
amount: u64,
ctx: &mut TxContext
): Coin<T> {
// only the holder of the `AdminCap` for `self` can withdraw funds
Expand Down Expand Up @@ -169,4 +172,4 @@ module DeFi::FlashLender {
public fun flash_lender_id<T>(self: &Receipt<T>): ID {
self.flash_lender_id
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#[test_only]
module DeFi::FlashLenderTests {
use DeFi::FlashLender::{Self, AdminCap, FlashLender};
Expand Down Expand Up @@ -53,4 +56,4 @@ module DeFi::FlashLenderTests {
TestScenario::return_object(scenario, admin_cap);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example coin with a trusted manager responsible for minting/burning (e.g., a stablecoin)
/// By convention, modules defining custom coin types use upper case names, in constrast to
/// By convention, modules defining custom coin types use upper case names, in contrast to
/// ordinary modules, which use camel case.
module FungibleTokens::MANAGED {
use Sui::Coin::{Self, Coin, TreasuryCap};
Expand Down
3 changes: 3 additions & 0 deletions sui_programmability/examples/games/hero/sources/Hero.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example of a game character with basic attributes, inventory, and
/// associated logic.
module HeroGame::Hero {
Expand Down
3 changes: 3 additions & 0 deletions sui_programmability/examples/games/hero/sources/SeaHero.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Example of a game mod or different game that uses objects from the Hero
/// game.
/// This mod introduces sea monsters that can also be slain with the hero's
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Mod of the economics of the SeaHero game. In the game, a `Hero` can onAly
/// slay a `SeaMonster` if they have sufficient strength. This mod allows a
/// player with a weak `Hero` to ask a player with a stronger `Hero` to slay
Expand Down
Loading

0 comments on commit dea171c

Please sign in to comment.