Skip to content

Commit

Permalink
[examples] Run formatter over examples/move (#20330)
Browse files Browse the repository at this point in the history
## Description 

Autoformatted all .move files in the `examples/move` folder.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
damirka authored Nov 21, 2024
1 parent 2542d8e commit c138be2
Show file tree
Hide file tree
Showing 63 changed files with 7,982 additions and 8,078 deletions.
16 changes: 8 additions & 8 deletions examples/move/basics/sources/clock.move
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module basics::clock {
use sui::{clock::Clock, event};
module basics::clock;

public struct TimeEvent has copy, drop, store {
timestamp_ms: u64,
}
use sui::{clock::Clock, event};

entry fun access(clock: &Clock) {
event::emit(TimeEvent { timestamp_ms: clock.timestamp_ms() });
}
public struct TimeEvent has copy, drop, store {
timestamp_ms: u64,
}

entry fun access(clock: &Clock) {
event::emit(TimeEvent { timestamp_ms: clock.timestamp_ms() });
}
8 changes: 4 additions & 4 deletions examples/move/basics/sources/counter.move
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module basics::counter {
public struct Counter has key {
id: UID,
owner: address,
value: u64
value: u64,
}

public fun owner(counter: &Counter): address {
Expand All @@ -27,7 +27,7 @@ module basics::counter {
transfer::share_object(Counter {
id: object::new(ctx),
owner: tx_context::sender(ctx),
value: 0
value: 0,
})
}

Expand All @@ -50,15 +50,15 @@ module basics::counter {
/// Delete counter (only runnable by the Counter owner)
public fun delete(counter: Counter, ctx: &TxContext) {
assert!(counter.owner == ctx.sender(), 0);
let Counter {id, owner:_, value:_} = counter;
let Counter { id, owner: _, value: _ } = counter;
id.delete();
}
}

#[test_only]
module basics::counter_test {
use sui::test_scenario as ts;
use basics::counter::{Self, Counter};
use sui::test_scenario as ts;

#[test]
fun test_counter() {
Expand Down
116 changes: 58 additions & 58 deletions examples/move/basics/sources/object_basics.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,62 @@
// SPDX-License-Identifier: Apache-2.0

/// Test CTURD object basics (create, transfer, update, read, delete)
module basics::object_basics {
use sui::event;

public struct Object has key, store {
id: UID,
value: u64,
}

public struct Wrapper has key {
id: UID,
o: Object
}

public struct NewValueEvent has copy, drop {
new_value: u64
}

public fun create(value: u64, recipient: address, ctx: &mut TxContext) {
transfer::public_transfer(
Object { id: object::new(ctx), value },
recipient
)
}

public fun transfer(o: Object, recipient: address) {
transfer::public_transfer(o, recipient)
}

public fun freeze_object(o: Object) {
transfer::public_freeze_object(o)
}

public fun set_value(o: &mut Object, value: u64) {
o.value = value;
}

// test that reading o2 and updating o1 works
public fun update(o1: &mut Object, o2: &Object) {
o1.value = o2.value;
// emit an event so the world can see the new value
event::emit(NewValueEvent { new_value: o2.value })
}

public fun delete(o: Object) {
let Object { id, value: _ } = o;
id.delete();
}

public fun wrap(o: Object, ctx: &mut TxContext) {
transfer::transfer(Wrapper { id: object::new(ctx), o }, ctx.sender());
}

#[lint_allow(self_transfer)]
public fun unwrap(w: Wrapper, ctx: &TxContext) {
let Wrapper { id, o } = w;
id.delete();
transfer::public_transfer(o, ctx.sender());
}
module basics::object_basics;

use sui::event;

public struct Object has key, store {
id: UID,
value: u64,
}

public struct Wrapper has key {
id: UID,
o: Object,
}

public struct NewValueEvent has copy, drop {
new_value: u64,
}

public fun create(value: u64, recipient: address, ctx: &mut TxContext) {
transfer::public_transfer(
Object { id: object::new(ctx), value },
recipient,
)
}

public fun transfer(o: Object, recipient: address) {
transfer::public_transfer(o, recipient)
}

public fun freeze_object(o: Object) {
transfer::public_freeze_object(o)
}

public fun set_value(o: &mut Object, value: u64) {
o.value = value;
}

// test that reading o2 and updating o1 works
public fun update(o1: &mut Object, o2: &Object) {
o1.value = o2.value;
// emit an event so the world can see the new value
event::emit(NewValueEvent { new_value: o2.value })
}

public fun delete(o: Object) {
let Object { id, value: _ } = o;
id.delete();
}

public fun wrap(o: Object, ctx: &mut TxContext) {
transfer::transfer(Wrapper { id: object::new(ctx), o }, ctx.sender());
}

#[lint_allow(self_transfer)]
public fun unwrap(w: Wrapper, ctx: &TxContext) {
let Wrapper { id, o } = w;
id.delete();
transfer::public_transfer(o, ctx.sender());
}
21 changes: 10 additions & 11 deletions examples/move/basics/sources/random.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

/// This example demonstrates emitting a random u128 (e.g., for an offchain lottery)
module basics::random {
use sui::event;
use sui::random::Random;
module basics::random;

public struct RandomU128Event has copy, drop {
value: u128,
}
use sui::{event, random::Random};

entry fun new(r: &Random, ctx: &mut TxContext) {
let mut gen = r.new_generator(ctx);
let value = gen.generate_u128();
event::emit(RandomU128Event { value });
}
public struct RandomU128Event has copy, drop {
value: u128,
}

entry fun new(r: &Random, ctx: &mut TxContext) {
let mut gen = r.new_generator(ctx);
let value = gen.generate_u128();
event::emit(RandomU128Event { value });
}
30 changes: 15 additions & 15 deletions examples/move/basics/sources/resolve_args.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// SPDX-License-Identifier: Apache-2.0

/// Functions and types to test argument resolution in JSON-RPC.
module basics::resolve_args {
public struct Foo has key {
id: UID,
}
module basics::resolve_args;

public fun foo(
_foo: &mut Foo,
_bar: vector<Foo>,
_name: vector<u8>,
_index: u64,
_flag: u8,
_recipient: address,
_ctx: &mut TxContext,
) {
abort 0
}
public struct Foo has key {
id: UID,
}

public fun foo(
_foo: &mut Foo,
_bar: vector<Foo>,
_name: vector<u8>,
_index: u64,
_flag: u8,
_recipient: address,
_ctx: &mut TxContext,
) {
abort 0
}
58 changes: 33 additions & 25 deletions examples/move/coin/sources/my_coin.move
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module examples::my_coin {
use sui::coin::{Self, TreasuryCap};
module examples::my_coin;

// The type identifier of coin. The coin will have a type
// tag of kind: `Coin<package_object::mycoin::MYCOIN>`
// Make sure that the name of the type matches the module's name.
public struct MY_COIN has drop {}
use sui::coin::{Self, TreasuryCap};

// Module initializer is called once on module publish. A treasury
// cap is sent to the publisher, who then controls minting and burning.
fun init(witness: MY_COIN, ctx: &mut TxContext) {
let (treasury, metadata) = coin::create_currency(witness, 6, b"MY_COIN", b"", b"", option::none(), ctx);
// Freezing this object makes the metadata immutable, including the title, name, and icon image.
// If you want to allow mutability, share it with public_share_object instead.
transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury, ctx.sender())
}
// The type identifier of coin. The coin will have a type
// tag of kind: `Coin<package_object::mycoin::MYCOIN>`
// Make sure that the name of the type matches the module's name.
public struct MY_COIN has drop {}

// Create MY_COINs using the TreasuryCap.
public fun mint(
treasury_cap: &mut TreasuryCap<MY_COIN>,
amount: u64,
recipient: address,
ctx: &mut TxContext,
) {
let coin = coin::mint(treasury_cap, amount, ctx);
transfer::public_transfer(coin, recipient)
}
// Module initializer is called once on module publish. A treasury
// cap is sent to the publisher, who then controls minting and burning.
fun init(witness: MY_COIN, ctx: &mut TxContext) {
let (treasury, metadata) = coin::create_currency(
witness,
6,
b"MY_COIN",
b"",
b"",
option::none(),
ctx,
);
// Freezing this object makes the metadata immutable, including the title, name, and icon image.
// If you want to allow mutability, share it with public_share_object instead.
transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury, ctx.sender())
}

// Create MY_COINs using the TreasuryCap.
public fun mint(
treasury_cap: &mut TreasuryCap<MY_COIN>,
amount: u64,
recipient: address,
ctx: &mut TxContext,
) {
let coin = coin::mint(treasury_cap, amount, ctx);
transfer::public_transfer(coin, recipient)
}
71 changes: 35 additions & 36 deletions examples/move/coin/sources/regcoin.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,43 @@
// SPDX-License-Identifier: Apache-2.0

//docs::#regulate
module examples::regcoin {
use sui::coin::{Self, DenyCapV2};
use sui::deny_list::{DenyList};
module examples::regcoin;

public struct REGCOIN has drop {}
use sui::{coin::{Self, DenyCapV2}, deny_list::DenyList};

fun init(witness: REGCOIN, ctx: &mut TxContext) {
let (treasury, deny_cap, metadata) = coin::create_regulated_currency_v2(
witness,
6,
b"REGCOIN",
b"",
b"",
option::none(),
false,
ctx,
);
transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury, ctx.sender());
transfer::public_transfer(deny_cap, ctx.sender())
}
public struct REGCOIN has drop {}

//docs::/#regulate}
public fun add_addr_from_deny_list(
denylist: &mut DenyList,
denycap: &mut DenyCapV2<REGCOIN>,
denyaddy: address,
ctx: &mut TxContext,
) {
coin::deny_list_v2_add(denylist, denycap, denyaddy, ctx);
}
fun init(witness: REGCOIN, ctx: &mut TxContext) {
let (treasury, deny_cap, metadata) = coin::create_regulated_currency_v2(
witness,
6,
b"REGCOIN",
b"",
b"",
option::none(),
false,
ctx,
);
transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury, ctx.sender());
transfer::public_transfer(deny_cap, ctx.sender())
}

//docs::/#regulate}
public fun add_addr_from_deny_list(
denylist: &mut DenyList,
denycap: &mut DenyCapV2<REGCOIN>,
denyaddy: address,
ctx: &mut TxContext,
) {
coin::deny_list_v2_add(denylist, denycap, denyaddy, ctx);
}

public fun remove_addr_from_deny_list(
denylist: &mut DenyList,
denycap: &mut DenyCapV2<REGCOIN>,
denyaddy: address,
ctx: &mut TxContext,
) {
coin::deny_list_v2_remove(denylist, denycap, denyaddy, ctx);
}
public fun remove_addr_from_deny_list(
denylist: &mut DenyList,
denycap: &mut DenyCapV2<REGCOIN>,
denyaddy: address,
ctx: &mut TxContext,
) {
coin::deny_list_v2_remove(denylist, denycap, denyaddy, ctx);
}
Loading

0 comments on commit c138be2

Please sign in to comment.