Skip to content

Commit

Permalink
[chore] ECamelCase me (MystenLabs#1650)
Browse files Browse the repository at this point in the history
  • Loading branch information
damirka authored Apr 28, 2022
1 parent bb8da0a commit 9979b25
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 153 deletions.
14 changes: 7 additions & 7 deletions sui_programmability/examples/basics/sources/Lock.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ module Basics::Lock {
use Std::Option::{Self, Option};

/// Lock is empty, nothing to take.
const ELOCK_IS_EMPTY: u64 = 0;
const ELockIsEmpty: u64 = 0;

/// Key does not match the Lock.
const EKEY_MISMATCH: u64 = 1;
const EKeyMismatch: u64 = 1;

/// Lock already contains something.
const ELOCK_IS_FULL: u64 = 2;
const ELockIsFull: u64 = 2;

/// Lock that stores any content inside it.
struct Lock<T: store + key> has key, store {
Expand Down Expand Up @@ -64,8 +64,8 @@ module Basics::Lock {
key: &Key<T>,
_ctx: &mut TxContext,
) {
assert!(Option::is_none(&lock.locked), ELOCK_IS_FULL);
assert!(&key.for == ID::id(lock), EKEY_MISMATCH);
assert!(Option::is_none(&lock.locked), ELockIsFull);
assert!(&key.for == ID::id(lock), EKeyMismatch);

Option::fill(&mut lock.locked, obj);
}
Expand All @@ -78,8 +78,8 @@ module Basics::Lock {
lock: &mut Lock<T>,
key: &Key<T>,
): T {
assert!(Option::is_some(&lock.locked), ELOCK_IS_EMPTY);
assert!(&key.for == ID::id(lock), EKEY_MISMATCH);
assert!(Option::is_some(&lock.locked), ELockIsEmpty);
assert!(&key.for == ID::id(lock), EKeyMismatch);

Option::extract(&mut lock.locked)
}
Expand Down
11 changes: 5 additions & 6 deletions sui_programmability/examples/basics/sources/Sandwich.move
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ module Basics::Sandwich {
const BREAD_PRICE: u64 = 2;

/// Not enough funds to pay for the good in question
const EINSUFFICIENT_FUNDS: u64 = 0;

const EInsufficientFunds: u64 = 0;
/// Nothing to withdraw
const ENO_PROFITS: u64 = 1;
const ENoProfits: u64 = 1;

/// On module init, create a grocery
fun init(ctx: &mut TxContext) {
Expand All @@ -62,7 +61,7 @@ module Basics::Sandwich {
c: Coin<SUI>,
ctx: &mut TxContext
) {
assert!(Coin::value(&c) == HAM_PRICE, EINSUFFICIENT_FUNDS);
assert!(Coin::value(&c) == HAM_PRICE, EInsufficientFunds);
Coin::join(&mut grocery.profits, c);
Transfer::transfer(Ham { id: TxContext::new_id(ctx) }, TxContext::sender(ctx))
}
Expand All @@ -73,7 +72,7 @@ module Basics::Sandwich {
c: Coin<SUI>,
ctx: &mut TxContext
) {
assert!(Coin::value(&c) == BREAD_PRICE, EINSUFFICIENT_FUNDS);
assert!(Coin::value(&c) == BREAD_PRICE, EInsufficientFunds);
Coin::join(&mut grocery.profits, c);
Transfer::transfer(Bread { id: TxContext::new_id(ctx) }, TxContext::sender(ctx))
}
Expand All @@ -98,7 +97,7 @@ module Basics::Sandwich {
public(script) fun collect_profits(_cap: &GroceryOwnerCapability, grocery: &mut Grocery, ctx: &mut TxContext) {
let amount = Coin::value(&grocery.profits);

assert!(amount > 0, ENO_PROFITS);
assert!(amount > 0, ENoProfits);

let coin = Coin::withdraw(&mut grocery.profits, amount, ctx);
Transfer::transfer(coin, TxContext::sender(ctx));
Expand Down
12 changes: 6 additions & 6 deletions sui_programmability/examples/defi/sources/Escrow.move
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ module DeFi::Escrow {

// Error codes
/// The `sender` and `recipient` of the two escrowed objects do not match
const EMISMATCHED_SENDER_RECIPIENT: u64 = 0;
const EMismatchedSenderRecipient: u64 = 0;
/// The `exchange_for` fields of the two escrowed objects do not match
const EMISMATCHED_EXCHANGE_OBJECT: u64 = 1;
const EMismatchedExchangeObject: u64 = 1;

/// Create an escrow for exchanging goods with
/// `counterparty`, mediated by a `third_party`
Expand Down Expand Up @@ -73,11 +73,11 @@ module DeFi::Escrow {
ID::delete(id1);
ID::delete(id2);
// check sender/recipient compatibility
assert!(&sender1 == &recipient2, EMISMATCHED_SENDER_RECIPIENT);
assert!(&sender2 == &recipient1, EMISMATCHED_SENDER_RECIPIENT);
assert!(&sender1 == &recipient2, EMismatchedSenderRecipient);
assert!(&sender2 == &recipient1, EMismatchedSenderRecipient);
// check object ID compatibility
assert!(ID::id(&escrowed1) == &exchange_for2, EMISMATCHED_EXCHANGE_OBJECT);
assert!(ID::id(&escrowed2) == &exchange_for1, EMISMATCHED_EXCHANGE_OBJECT);
assert!(ID::id(&escrowed1) == &exchange_for2, EMismatchedExchangeObject);
assert!(ID::id(&escrowed2) == &exchange_for1, EMismatchedExchangeObject);
// everything matches. do the swap!
Transfer::transfer(escrowed1, sender2);
Transfer::transfer(escrowed2, sender1)
Expand Down
20 changes: 10 additions & 10 deletions sui_programmability/examples/defi/sources/FlashLender.move
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ module DeFi::FlashLender {

/// Attempted to borrow more than the `FlashLender` has.
/// Try borrowing a smaller amount.
const ELOAN_TOO_LARGE: u64 = 0;
const ELoanTooLarge: u64 = 0;

/// Tried to repay an amount other than `repay_amount` (i.e., the amount borrowed + the fee).
/// Try repaying the proper amount.
const EINVALID_REPAYMENT_AMOUNT: u64 = 1;
const EInvalidRepaymentAmount: u64 = 1;

/// Attempted to repay a `FlashLender` that was not the source of this particular debt.
/// Try repaying the correct lender.
const EREPAY_TO_WRONG_LENDER: u64 = 2;
const ERepayToWrongLender: u64 = 2;

/// Attempted to perform an admin-only operation without valid permissions
/// Try using the correct `AdminCap`
const EADMIN_ONLY: u64 = 3;
const EAdminOnly: u64 = 3;

/// Attempted to withdraw more than the `FlashLender` has.
/// Try withdrawing a smaller amount.
const EWITHDRAW_TOO_LARGE: u64 = 4;
const EWithdrawTooLarge: u64 = 4;

// === Creating a flash lender ===

Expand Down Expand Up @@ -91,7 +91,7 @@ module DeFi::FlashLender {
self: &mut FlashLender<T>, amount: u64, ctx: &mut TxContext
): (Coin<T>, Receipt<T>) {
let to_lend = &mut self.to_lend;
assert!(Coin::value(to_lend) >= amount, ELOAN_TOO_LARGE);
assert!(Coin::value(to_lend) >= amount, ELoanTooLarge);
let loan = Coin::withdraw(to_lend, amount, ctx);

let repay_amount = amount + self.fee;
Expand All @@ -104,8 +104,8 @@ module DeFi::FlashLender {
/// 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);
assert!(Coin::value(&payment) == repay_amount, EINVALID_REPAYMENT_AMOUNT);
assert!(ID::id(self) == &flash_lender_id, ERepayToWrongLender);
assert!(Coin::value(&payment) == repay_amount, EInvalidRepaymentAmount);

Coin::join(&mut self.to_lend, payment)
}
Expand All @@ -123,7 +123,7 @@ module DeFi::FlashLender {
check_admin(self, admin_cap);

let to_lend = &mut self.to_lend;
assert!(Coin::value(to_lend) >= amount, EWITHDRAW_TOO_LARGE);
assert!(Coin::value(to_lend) >= amount, EWithdrawTooLarge);
Coin::withdraw(to_lend, amount, ctx)
}

Expand All @@ -148,7 +148,7 @@ module DeFi::FlashLender {
}

fun check_admin<T>(self: &FlashLender<T>, admin_cap: &AdminCap) {
assert!(ID::id(self) == &admin_cap.flash_lender_id, EADMIN_ONLY);
assert!(ID::id(self) == &admin_cap.flash_lender_id, EAdminOnly);
}

// === Reads ===
Expand Down
18 changes: 9 additions & 9 deletions sui_programmability/examples/defi/sources/SharedEscrow.move
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ module DeFi::SharedEscrow {

// Error codes
/// An attempt to cancel escrow by a different user than the owner
const EWRONG_OWNER: u64 = 0;
const EWrongOwner: u64 = 0;
/// Exchange by a different user than the `recipient` of the escrowed object
const EWRONG_RECIPIENT: u64 = 1;
const EWrongRecipient: u64 = 1;
/// Exchange with a different item than the `exchange_for` field
const EWRONG_EXCHANGE_OBJECT: u64 = 2;
const EWrongExchangeObject: u64 = 2;
/// The escrow has already been exchanged or cancelled
const EALREADY_EXCHANGED_OR_CANCELLED: u64 = 3;
const EAlreadyExchangedOrCancelled: u64 = 3;

/// Create an escrow for exchanging goods with counterparty
public fun create<T: key + store, ExchangeForT: key + store>(
Expand All @@ -55,10 +55,10 @@ module DeFi::SharedEscrow {
escrow: &mut EscrowedObj<T, ExchangeForT>,
ctx: &mut TxContext
) {
assert!(Option::is_some(&escrow.escrowed), EALREADY_EXCHANGED_OR_CANCELLED);
assert!(Option::is_some(&escrow.escrowed), EAlreadyExchangedOrCancelled);
let escrowed_item = Option::extract<T>(&mut escrow.escrowed);
assert!(&TxContext::sender(ctx) == &escrow.recipient, EWRONG_RECIPIENT);
assert!(ID::id(&obj) == &escrow.exchange_for, EWRONG_EXCHANGE_OBJECT);
assert!(&TxContext::sender(ctx) == &escrow.recipient, EWrongRecipient);
assert!(ID::id(&obj) == &escrow.exchange_for, EWrongExchangeObject);
// everything matches. do the swap!
Transfer::transfer(escrowed_item, TxContext::sender(ctx));
Transfer::transfer(obj, escrow.creator);
Expand All @@ -69,8 +69,8 @@ module DeFi::SharedEscrow {
escrow: &mut EscrowedObj<T, ExchangeForT>,
ctx: &mut TxContext
) {
assert!(&TxContext::sender(ctx) == &escrow.creator, EWRONG_OWNER);
assert!(Option::is_some(&escrow.escrowed), EALREADY_EXCHANGED_OR_CANCELLED);
assert!(&TxContext::sender(ctx) == &escrow.creator, EWrongOwner);
assert!(Option::is_some(&escrow.escrowed), EAlreadyExchangedOrCancelled);
Transfer::transfer(Option::extract<T>(&mut escrow.escrowed), escrow.creator);
}
}
12 changes: 6 additions & 6 deletions sui_programmability/examples/defi/tests/EscrowTests.move
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module DeFi::EscrowTests {
const RANDOM_ADDRESS: address = @123;

// Error codes.
const ESWAP_TRANSFER_FAILED: u64 = 0;
const ERETURN_TRANSFER_FAILED: u64 = 0;
const ESwapTransferFailed: u64 = 0;
const EReturnTransferFailed: u64 = 0;

// Example of an object type used for exchange
struct ItemA has key, store {
Expand All @@ -35,8 +35,8 @@ module DeFi::EscrowTests {
swap(scenario, &THIRD_PARTY_ADDRESS);

// Alice now owns item B, and Bob now owns item A
assert!(owns_object<ItemB>(scenario, &ALICE_ADDRESS), ESWAP_TRANSFER_FAILED);
assert!(owns_object<ItemA>(scenario, &BOB_ADDRESS), ESWAP_TRANSFER_FAILED);
assert!(owns_object<ItemB>(scenario, &ALICE_ADDRESS), ESwapTransferFailed);
assert!(owns_object<ItemA>(scenario, &BOB_ADDRESS), ESwapTransferFailed);
}

#[test]
Expand All @@ -57,8 +57,8 @@ module DeFi::EscrowTests {
};

// Alice now owns item A, and Bob now owns item B
assert!(owns_object<ItemA>(scenario, &ALICE_ADDRESS), ERETURN_TRANSFER_FAILED);
assert!(owns_object<ItemB>(scenario, &BOB_ADDRESS), ERETURN_TRANSFER_FAILED);
assert!(owns_object<ItemA>(scenario, &ALICE_ADDRESS), EReturnTransferFailed);
assert!(owns_object<ItemB>(scenario, &BOB_ADDRESS), EReturnTransferFailed);
}

#[test]
Expand Down
16 changes: 8 additions & 8 deletions sui_programmability/examples/defi/tests/SharedEscrowTest.move
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module DeFi::SharedEscrowTests {
const RANDOM_ADDRESS: address = @123;

// Error codes.
const ESWAP_TRANSFER_FAILED: u64 = 0;
const ERETURN_TRANSFER_FAILED: u64 = 0;
const ESwapTransferFailed: u64 = 0;
const EReturnTransferFailed: u64 = 0;

// Example of an object type used for exchange
struct ItemA has key, store {
Expand All @@ -37,8 +37,8 @@ module DeFi::SharedEscrowTests {
exchange(&mut scenario, &BOB_ADDRESS, item_b_versioned_id);

// Alice now owns item B, and Bob now owns item A
assert!(owns_object<ItemB>(&mut scenario, &ALICE_ADDRESS), ESWAP_TRANSFER_FAILED);
assert!(owns_object<ItemA>(&mut scenario, &BOB_ADDRESS), ESWAP_TRANSFER_FAILED);
assert!(owns_object<ItemB>(&mut scenario, &ALICE_ADDRESS), ESwapTransferFailed);
assert!(owns_object<ItemA>(&mut scenario, &BOB_ADDRESS), ESwapTransferFailed);
}

#[test]
Expand All @@ -48,13 +48,13 @@ module DeFi::SharedEscrowTests {
ID::delete(id);
let scenario = &mut scenario;
// Alice does not own item A
assert!(!owns_object<ItemA>(scenario, &ALICE_ADDRESS), ERETURN_TRANSFER_FAILED);
assert!(!owns_object<ItemA>(scenario, &ALICE_ADDRESS), EReturnTransferFailed);

// Alice cancels the escrow
cancel(scenario, &ALICE_ADDRESS);

// Alice now owns item A
assert!(owns_object<ItemA>(scenario, &ALICE_ADDRESS), ERETURN_TRANSFER_FAILED);
assert!(owns_object<ItemA>(scenario, &ALICE_ADDRESS), EReturnTransferFailed);
}

#[test]
Expand Down Expand Up @@ -103,13 +103,13 @@ module DeFi::SharedEscrowTests {
ID::delete(id);
let scenario = &mut scenario;
// Alice does not own item A
assert!(!owns_object<ItemA>(scenario, &ALICE_ADDRESS), ERETURN_TRANSFER_FAILED);
assert!(!owns_object<ItemA>(scenario, &ALICE_ADDRESS), EReturnTransferFailed);

// Alice cancels the escrow
cancel(scenario, &ALICE_ADDRESS);

// Alice now owns item A
assert!(owns_object<ItemA>(scenario, &ALICE_ADDRESS), ERETURN_TRANSFER_FAILED);
assert!(owns_object<ItemA>(scenario, &ALICE_ADDRESS), EReturnTransferFailed);

// Alice tries to cancel the escrow again
cancel(scenario, &ALICE_ADDRESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module FungibleTokens::BASKET {
}

/// Needed to deposit a 1:1 ratio of SUI and MANAGED for minting, but deposited a different ratio
const EBAD_DEPOSIT_RATIO: u64 = 0;
const EBadDepositRatio: u64 = 0;

fun init(ctx: &mut TxContext) {
// Get a treasury cap for the coin put it in the reserve
Expand All @@ -50,7 +50,7 @@ module FungibleTokens::BASKET {
reserve: &mut Reserve, sui: Coin<SUI>, managed: Coin<MANAGED>, ctx: &mut TxContext
): Coin<BASKET> {
let num_sui = Coin::value(&sui);
assert!(num_sui == Coin::value(&managed), EBAD_DEPOSIT_RATIO);
assert!(num_sui == Coin::value(&managed), EBadDepositRatio);

Coin::join(&mut reserve.sui, sui);
Coin::join(&mut reserve.managed, managed);
Expand Down
16 changes: 8 additions & 8 deletions sui_programmability/examples/games/sources/SharedTicTacToe.move
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ module Games::SharedTicTacToe {

// Error codes
/// Trying to place a mark when it's not your turn.
const EINVALID_TURN: u64 = 0;
const EInvalidTurn: u64 = 0;
/// Trying to place a mark when the game has already ended.
const EGAME_ENDED: u64 = 1;
const EGameEnded: u64 = 1;
/// Trying to place a mark in an invalid location, i.e. row/column out of bound.
const EINVALID_LOCATION: u64 = 2;
const EInvalidLocation: u64 = 2;
/// The cell to place a new mark at is already oocupied.
const ECELL_OCCUPIED: u64 = 3;
const ECellOccupied: u64 = 3;

struct TicTacToe has key {
id: VersionedID,
Expand Down Expand Up @@ -84,13 +84,13 @@ module Games::SharedTicTacToe {
}

public(script) fun place_mark(game: &mut TicTacToe, row: u8, col: u8, ctx: &mut TxContext) {
assert!(row < 3 && col < 3, EINVALID_LOCATION);
assert!(game.game_status == IN_PROGRESS, EGAME_ENDED);
assert!(row < 3 && col < 3, EInvalidLocation);
assert!(game.game_status == IN_PROGRESS, EGameEnded);
let addr = get_cur_turn_address(game);
assert!(addr == TxContext::sender(ctx), EINVALID_TURN);
assert!(addr == TxContext::sender(ctx), EInvalidTurn);

let cell = Vector::borrow_mut(Vector::borrow_mut(&mut game.gameboard, (row as u64)), (col as u64));
assert!(*cell == MARK_EMPTY, ECELL_OCCUPIED);
assert!(*cell == MARK_EMPTY, ECellOccupied);

*cell = game.cur_turn % 2;
update_winner(game);
Expand Down
8 changes: 4 additions & 4 deletions sui_programmability/examples/games/sources/TicTacToe.move
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module Games::TicTacToe {
const FINAL_TURN: u8 = 8;

// Error codes
const INVALID_LOCATION: u64 = 0;
const NO_MORE_MARK: u64 = 1;
const EInvalidLocation: u64 = 0;
const ENoMoreMark: u64 = 1;

struct TicTacToe has key {
id: VersionedID,
Expand Down Expand Up @@ -119,7 +119,7 @@ module Games::TicTacToe {
ctx: &mut TxContext,
) {
if (row > 2 || col > 2) {
abort INVALID_LOCATION
abort EInvalidLocation
};
let mark = mint_mark(cap, row, col, ctx);
// Once an event is emitted, it should be observed by a game server.
Expand Down Expand Up @@ -195,7 +195,7 @@ module Games::TicTacToe {

fun mint_mark(cap: &mut MarkMintCap, row: u64, col: u64, ctx: &mut TxContext): Mark {
if (cap.remaining_supply == 0) {
abort NO_MORE_MARK
abort ENoMoreMark
};
cap.remaining_supply = cap.remaining_supply - 1;
Mark {
Expand Down
Loading

0 comments on commit 9979b25

Please sign in to comment.