Skip to content

Commit

Permalink
Update move version (includes stdlib rename and entry functions) (Mys…
Browse files Browse the repository at this point in the history
…tenLabs#2514)

* Update move version

- Update move version
- Update stdlib to lower_snake_case
- Switch to entry functions
  • Loading branch information
tnowacki authored Jun 11, 2022
1 parent a156952 commit 74ea62a
Show file tree
Hide file tree
Showing 131 changed files with 1,058 additions and 1,036 deletions.
77 changes: 39 additions & 38 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Test::M1 {
value1
}

public(script) fun create(value: u64, recipient: address, ctx: &mut TxContext) {
public entry fun create(value: u64, recipient: address, ctx: &mut TxContext) {
Transfer::transfer(
Object { id: TxContext::new_id(ctx), value },
recipient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module T3::O3 {
id: VersionedID,
}

public(script) fun create(ctx: &mut TxContext) {
public entry fun create(ctx: &mut TxContext) {
let o = O3 { id: TxContext::new_id(ctx) };
Transfer::transfer(o, TxContext::sender(ctx))
}
Expand All @@ -33,15 +33,15 @@ module T2::O2 {
child: ChildRef<O3>,
}

public(script) fun create_shared(child: O3, ctx: &mut TxContext) {
public entry fun create_shared(child: O3, ctx: &mut TxContext) {
Transfer::share_object(new(child, ctx))
}

public(script) fun create_owned(child: O3, ctx: &mut TxContext) {
public entry fun create_owned(child: O3, ctx: &mut TxContext) {
Transfer::transfer(new(child, ctx), TxContext::sender(ctx))
}

public(script) fun use_o2_o3(_o2: &mut O2, _o3: &mut O3) {}
public entry fun use_o2_o3(_o2: &mut O2, _o3: &mut O3) {}

fun new(child: O3, ctx: &mut TxContext): O2 {
let id = TxContext::new_id(ctx);
Expand All @@ -65,12 +65,12 @@ module T1::O1 {
child: ChildRef<O2>,
}

public(script) fun create_shared(child: O2, ctx: &mut TxContext) {
public entry fun create_shared(child: O2, ctx: &mut TxContext) {
Transfer::share_object(new(child, ctx))
}

// This function will be invalid if _o2 is a shared object and owns _o3.
public(script) fun use_o2_o3(_o2: &mut O2, _o3: &mut O3) {}
public entry fun use_o2_o3(_o2: &mut O2, _o3: &mut O3) {}

fun new(child: O2, ctx: &mut TxContext): O1 {
let id = TxContext::new_id(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ module Test::M {
value: u64
}

public(script) fun mint(ctx: &mut TxContext) {
public entry fun mint(ctx: &mut TxContext) {
Sui::Transfer::transfer(
Obj { id: TxContext::new_id(ctx), value: 0 },
TxContext::sender(ctx),
)
}

public(script) fun incr(obj: &mut Obj) {
public entry fun incr(obj: &mut Obj) {
obj.value = obj.value + 1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ created: object(103)
written: object(102)

task 2 'run'. lines 26-26:
Error: Function visibility is invalid for an entry point to execution: "Can only call functions with 'public(script)' visibility".
Error: Non-`entry` function used for entry point to execution: "Can only call `entry` functions".

task 3 'run'. lines 28-28:
Error: Function visibility is invalid for an entry point to execution: "Can only call functions with 'public(script)' visibility".
Error: Non-`entry` function used for entry point to execution: "Can only call `entry` functions".

task 4 'run'. lines 30-30:
Error: Function visibility is invalid for an entry point to execution: "Can only call functions with 'public(script)' visibility".
Error: Non-`entry` function used for entry point to execution: "Can only call `entry` functions".
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//# publish

module Test::M {
public(script) fun create(_value: u64, _recipient: address) {}
public entry fun create(_value: u64, _recipient: address) {}

}

Expand Down
16 changes: 8 additions & 8 deletions crates/sui-adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ bcs = "0.1.3"
once_cell = "1.11.0"
parking_lot = "0.12.1"

move-binary-format = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-bytecode-verifier = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-core-types = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b", features = ["address20"] }
move-cli = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-vm-runtime = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-vm-types = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-bytecode-verifier = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-core-types = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02", features = ["address20"] }
move-cli = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-vm-runtime = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-vm-types = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }

sui-framework = { path = "../sui-framework" }
sui-verifier = { path = "../sui-verifier" }
sui-types = { path = "../sui-types" }
workspace-hack = { path = "../workspace-hack"}

[dev-dependencies]
move-package = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-package = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
14 changes: 7 additions & 7 deletions crates/sui-adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use move_binary_format::{
access::ModuleAccess,
binary_views::BinaryIndexedView,
errors::PartialVMResult,
file_format::{CompiledModule, LocalIndex, SignatureToken, StructHandleIndex, Visibility},
file_format::{CompiledModule, LocalIndex, SignatureToken, StructHandleIndex},
};
use sui_framework::EventType;
use sui_types::{
Expand Down Expand Up @@ -685,14 +685,14 @@ pub fn resolve_and_type_check(
})
}
};
// Check for script visibility, but ignore for genesis.
// Genesis calls private functions, and bypasses this rule. This is helpful for ensuring the
// functions are not called again later.
// Check for entry modifier, but ignore for genesis.
// Genesis calls non-entry, private functions, and bypasses this rule. This is helpful for
// ensuring the functions are not called again later.
// In other words, this is an implementation detail that we are using `execute` for genesis
// functions, and as such need to bypass this check.
if fdef.visibility != Visibility::Script && !is_genesis {
return Err(SuiError::InvalidFunctionVisibility {
error: "Can only call functions with 'public(script)' visibility".to_string(),
if !fdef.is_entry && !is_genesis {
return Err(SuiError::InvalidNonEntryFunction {
error: "Can only call `entry` functions".to_string(),
});
}
let fhandle = module.function_handle_at(fdef.function);
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ tracing = "0.1.34"

narwhal-config = { git = "https://github.com/MystenLabs/narwhal", rev = "2c5e8236c0702a3ff47dd769c2bbc94b029bf4a9", package = "config" }
narwhal-crypto = { git = "https://github.com/MystenLabs/narwhal", rev = "2c5e8236c0702a3ff47dd769c2bbc94b029bf4a9", package = "crypto" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-package = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-package = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }

sui-framework = { path = "../sui-framework" }

Expand Down
12 changes: 6 additions & 6 deletions crates/sui-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ sui-storage = { path = "../sui-storage" }
sui-config = { path = "../sui-config" }
sui-json = { path = "../sui-json" }

move-binary-format = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-core-types = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b", features = ["address20"] }
move-package = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-vm-runtime = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-vm-types = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-core-types = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02", features = ["address20"] }
move-package = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-vm-runtime = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }
move-vm-types = { git = "https://github.com/move-language/move", rev = "4e15a34ecf155b7e2d9729d3b07f83c146149f02" }

typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev = "ff5c1d69057fe93be658377462ca2875a57a0223"}

Expand Down
24 changes: 12 additions & 12 deletions crates/sui-core/src/unit_tests/data/hero/sources/Hero.move
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Examples::Hero {
use Sui::Math;
use Sui::Transfer;
use Sui::TxContext::{Self, TxContext};
use Std::Option::{Self, Option};
use std::option::{Self, Option};

/// Our hero!
struct Hero has key, store {
Expand Down Expand Up @@ -114,7 +114,7 @@ module Examples::Hero {

/// Slay the `boar` with the `hero`'s sword, get experience.
/// Aborts if the hero has 0 HP or is not strong enough to slay the boar
public(script) fun slay(hero: &mut Hero, boar: Boar, ctx: &mut TxContext) {
public entry fun slay(hero: &mut Hero, boar: Boar, ctx: &mut TxContext) {
let Boar { id: boar_id, strength: boar_strength, hp } = boar;
let hero_strength = hero_strength(hero);
let boar_hp = hp;
Expand All @@ -134,8 +134,8 @@ module Examples::Hero {
// hero gains experience proportional to the boar, sword grows in
// strength by one (if hero is using a sword)
hero.experience = hero.experience + hp;
if (Option::is_some(&hero.sword)) {
level_up_sword(Option::borrow_mut(&mut hero.sword), 1)
if (option::is_some(&hero.sword)) {
level_up_sword(option::borrow_mut(&mut hero.sword), 1)
};
// let the world know about the hero's triumph by emitting an event!
Event::emit(BoarSlainEvent {
Expand All @@ -154,8 +154,8 @@ module Examples::Hero {
return 0
};

let sword_strength = if (Option::is_some(&hero.sword)) {
sword_strength(Option::borrow(&hero.sword))
let sword_strength = if (option::is_some(&hero.sword)) {
sword_strength(option::borrow(&hero.sword))
} else {
// hero can fight without a sword, but will not be very strong
0
Expand Down Expand Up @@ -187,14 +187,14 @@ module Examples::Hero {
/// Add `new_sword` to the hero's inventory and return the old sword
/// (if any)
public fun equip_sword(hero: &mut Hero, new_sword: Sword): Option<Sword> {
Option::swap_or_fill(&mut hero.sword, new_sword)
option::swap_or_fill(&mut hero.sword, new_sword)
}

/// Disarm the hero by returning their sword.
/// Aborts if the hero does not have a sword.
public fun remove_sword(hero: &mut Hero): Sword {
assert!(Option::is_some(&hero.sword), ENO_SWORD);
Option::extract(&mut hero.sword)
assert!(option::is_some(&hero.sword), ENO_SWORD);
option::extract(&mut hero.sword)
}

// --- Object creation ---
Expand Down Expand Up @@ -222,7 +222,7 @@ module Examples::Hero {
}
}

public(script) fun acquire_hero(payment: Coin<EXAMPLE>, ctx: &mut TxContext) {
public entry fun acquire_hero(payment: Coin<EXAMPLE>, ctx: &mut TxContext) {
let sword = create_sword(payment, ctx);
let hero = create_hero(sword, ctx);
Transfer::transfer(hero, TxContext::sender(ctx))
Expand All @@ -235,7 +235,7 @@ module Examples::Hero {
id: TxContext::new_id(ctx),
hp: 100,
experience: 0,
sword: Option::some(sword),
sword: option::some(sword),
}
}

Expand Down Expand Up @@ -283,7 +283,7 @@ module Examples::Hero {
public fun delete_hero_for_testing(hero: Hero) {
let Hero { id, hp: _, experience: _, sword } = hero;
ID::delete(id);
let sword = Option::destroy_some(sword);
let sword = option::destroy_some(sword);
let Sword { id, magic: _, strength: _ } = sword;
ID::delete(id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ module Examples::TrustedCoin {
Transfer::transfer(treasury_cap, TxContext::sender(ctx))
}

public(script) fun mint(treasury_cap: &mut TreasuryCap<EXAMPLE>, amount: u64, ctx: &mut TxContext) {
public entry fun mint(treasury_cap: &mut TreasuryCap<EXAMPLE>, amount: u64, ctx: &mut TxContext) {
let coin = Coin::mint<EXAMPLE>(amount, treasury_cap, ctx);
Coin::transfer(coin, TxContext::sender(ctx));
}

public(script) fun transfer(treasury_cap: TreasuryCap<EXAMPLE>, recipient: address) {
public entry fun transfer(treasury_cap: TreasuryCap<EXAMPLE>, recipient: address) {
Coin::transfer_cap<EXAMPLE>(treasury_cap, recipient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

module ObjectOwner::ObjectOwner {
use Std::Option::{Self, Option};
use std::option::{Self, Option};
use Sui::ID::{Self, VersionedID};
use Sui::Transfer::{Self, ChildRef};
use Sui::TxContext::{Self, TxContext};
Expand All @@ -21,72 +21,72 @@ module ObjectOwner::ObjectOwner {
child: ChildRef<Child>,
}

public(script) fun create_child(ctx: &mut TxContext) {
public entry fun create_child(ctx: &mut TxContext) {
Transfer::transfer(
Child { id: TxContext::new_id(ctx) },
TxContext::sender(ctx),
);
}

public(script) fun create_parent(ctx: &mut TxContext) {
public entry fun create_parent(ctx: &mut TxContext) {
let parent = Parent {
id: TxContext::new_id(ctx),
child: Option::none(),
child: option::none(),
};
Transfer::transfer(parent, TxContext::sender(ctx));
}

public(script) fun create_parent_and_child(ctx: &mut TxContext) {
public entry fun create_parent_and_child(ctx: &mut TxContext) {
let parent_id = TxContext::new_id(ctx);
let child = Child { id: TxContext::new_id(ctx) };
let (parent_id, child_ref) = Transfer::transfer_to_object_id(child, parent_id);
let parent = Parent {
id: parent_id,
child: Option::some(child_ref),
child: option::some(child_ref),
};
Transfer::transfer(parent, TxContext::sender(ctx));
}

public(script) fun add_child(parent: &mut Parent, child: Child) {
public entry fun add_child(parent: &mut Parent, child: Child) {
let child_ref = Transfer::transfer_to_object(child, parent);
Option::fill(&mut parent.child, child_ref);
option::fill(&mut parent.child, child_ref);
}

// Call to mutate_child will fail if its owned by a parent,
// since all owners must be in the arguments for authentication.
public(script) fun mutate_child(_child: &mut Child) {}
public entry fun mutate_child(_child: &mut Child) {}

// This should always succeeds, even when child is not owned by parent.
public(script) fun mutate_child_with_parent(_child: &mut Child, _parent: &mut Parent) {}
public entry fun mutate_child_with_parent(_child: &mut Child, _parent: &mut Parent) {}

public(script) fun transfer_child(parent: &mut Parent, child: Child, new_parent: &mut Parent) {
let child_ref = Option::extract(&mut parent.child);
public entry fun transfer_child(parent: &mut Parent, child: Child, new_parent: &mut Parent) {
let child_ref = option::extract(&mut parent.child);
let new_child_ref = Transfer::transfer_child_to_object(child, child_ref, new_parent);
Option::fill(&mut new_parent.child, new_child_ref);
option::fill(&mut new_parent.child, new_child_ref);
}

public(script) fun remove_child(parent: &mut Parent, child: Child, ctx: &mut TxContext) {
let child_ref = Option::extract(&mut parent.child);
public entry fun remove_child(parent: &mut Parent, child: Child, ctx: &mut TxContext) {
let child_ref = option::extract(&mut parent.child);
Transfer::transfer_child_to_address(child, child_ref, TxContext::sender(ctx));
}

// Call to delete_child can fail if it's still owned by a parent.
public(script) fun delete_child(child: Child, _parent: &mut Parent) {
public entry fun delete_child(child: Child, _parent: &mut Parent) {
let Child { id } = child;
ID::delete(id);
}

public(script) fun delete_parent_and_child(parent: Parent, child: Child) {
public entry fun delete_parent_and_child(parent: Parent, child: Child) {
let Parent { id: parent_id, child: child_ref_opt } = parent;
let child_ref = Option::extract(&mut child_ref_opt);
Option::destroy_none(child_ref_opt);
let child_ref = option::extract(&mut child_ref_opt);
option::destroy_none(child_ref_opt);
ID::delete(parent_id);

let Child { id: child_id } = child;
Transfer::delete_child_object(child_id, child_ref);
}

public(script) fun create_another_parent(child: Child, ctx: &mut TxContext) {
public entry fun create_another_parent(child: Child, ctx: &mut TxContext) {
let id = TxContext::new_id(ctx);
let (id, child_ref) = Transfer::transfer_to_object_id(child, id);
let parent = AnotherParent {
Expand Down
Loading

0 comments on commit 74ea62a

Please sign in to comment.