From d4428d95083463ee435d449e68e2c3965c739f04 Mon Sep 17 00:00:00 2001 From: Todd Nowacki Date: Fri, 3 Jun 2022 12:51:12 -0600 Subject: [PATCH] [cleanup][Sui Framework] Remove unused TxContexts (#2399) * [cleanup][Sui Framework] Remove unused TxContexts - Remove unused transaction contexts, now that it is optional --- Cargo.lock | 1 + .../tests/children/child_of_shared_object.move | 4 ++-- .../tests/sui/move_call_args_type_mismatch.exp | 8 ++++---- .../sui/move_call_args_type_mismatch.move | 3 +-- .../data/hero/sources/TrustedCoin.move | 2 +- .../data/object_owner/sources/ObjectOwner.move | 12 ++++++------ .../sources/ObjectWrapping.move | 4 ++-- crates/sui-framework/sources/Coin.move | 4 ++-- .../sources/Governance/Delegation.move | 4 ++-- crates/sui-framework/sources/ObjectBasics.move | 10 +++++----- crates/sui-framework/sources/SUI.move | 2 +- crates/sui-json/Cargo.toml | 1 + crates/sui-json/src/lib.rs | 9 ++++++++- .../sources/TicTacToe.move | 6 +++--- .../sources/TrustedCoin.move | 2 +- .../sources/TrustedCoin.move | 2 +- .../examples/basics/sources/Counter.move | 12 ++++++------ .../examples/basics/sources/Lock.move | 1 - .../examples/defi/sources/Escrow.move | 2 -- .../examples/defi/sources/FlashLender.move | 4 ++-- .../examples/defi/tests/EscrowTests.move | 9 +++------ .../fungible_tokens/sources/MANAGED.move | 4 ++-- .../games/sources/RockPaperScissors.move | 4 ++-- .../games/sources/SharedTicTacToe.move | 4 ++-- .../examples/games/sources/TicTacToe.move | 6 +++--- .../games/tests/RockPaperScissorsTests.move | 8 ++++---- .../examples/nfts/sources/Chat.move | 2 +- .../examples/nfts/sources/DiscountCoupon.move | 6 +++--- .../examples/nfts/sources/Geniteam.move | 6 +----- .../objects_tutorial/sources/ColorObject.move | 18 +++++++----------- sui_programmability/tutorial/sources/M1.move | 2 +- 31 files changed, 78 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bb464999317b..0331be2a64337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6032,6 +6032,7 @@ dependencies = [ "sui-adapter", "sui-framework", "sui-types", + "sui-verifier", "test-fuzz", "workspace-hack", ] diff --git a/crates/sui-adapter-transactional-tests/tests/children/child_of_shared_object.move b/crates/sui-adapter-transactional-tests/tests/children/child_of_shared_object.move index 4008bdaf77d86..219f0ce9cd89d 100644 --- a/crates/sui-adapter-transactional-tests/tests/children/child_of_shared_object.move +++ b/crates/sui-adapter-transactional-tests/tests/children/child_of_shared_object.move @@ -41,7 +41,7 @@ module T2::O2 { Transfer::transfer(new(child, ctx), TxContext::sender(ctx)) } - public(script) fun use_o2_o3(_o2: &mut O2, _o3: &mut O3, _ctx: &mut TxContext) {} + public(script) fun use_o2_o3(_o2: &mut O2, _o3: &mut O3) {} fun new(child: O3, ctx: &mut TxContext): O2 { let id = TxContext::new_id(ctx); @@ -70,7 +70,7 @@ module T1::O1 { } // 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, _ctx: &mut TxContext) {} + public(script) fun use_o2_o3(_o2: &mut O2, _o3: &mut O3) {} fun new(child: O2, ctx: &mut TxContext): O1 { let id = TxContext::new_id(ctx); diff --git a/crates/sui-adapter-transactional-tests/tests/sui/move_call_args_type_mismatch.exp b/crates/sui-adapter-transactional-tests/tests/sui/move_call_args_type_mismatch.exp index 1ddc4de899a7a..040b55b60e4b0 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/move_call_args_type_mismatch.exp +++ b/crates/sui-adapter-transactional-tests/tests/sui/move_call_args_type_mismatch.exp @@ -1,11 +1,11 @@ processed 4 tasks -task 1 'publish'. lines 6-14: +task 1 'publish'. lines 6-13: created: object(103) written: object(102) -task 2 'run'. lines 15-17: -Error: Function signature is invalid: "Expected 3 arguments calling function 'create', but found 2". +task 2 'run'. lines 14-16: +Error: Function signature is invalid: "Expected 2 arguments calling function 'create', but found 1". -task 3 'run'. lines 18-18: +task 3 'run'. lines 17-17: Error: Execution aborted: "VMError with status FAILED_TO_DESERIALIZE_ARGUMENT at location UNDEFINED". diff --git a/crates/sui-adapter-transactional-tests/tests/sui/move_call_args_type_mismatch.move b/crates/sui-adapter-transactional-tests/tests/sui/move_call_args_type_mismatch.move index 00914eefbfe5d..6caa5f368f5d2 100644 --- a/crates/sui-adapter-transactional-tests/tests/sui/move_call_args_type_mismatch.move +++ b/crates/sui-adapter-transactional-tests/tests/sui/move_call_args_type_mismatch.move @@ -6,8 +6,7 @@ //# publish module Test::M { - use Sui::TxContext::TxContext; - public(script) fun create(_value: u64, _recipient: address, _ctx: &mut TxContext) {} + public(script) fun create(_value: u64, _recipient: address) {} } diff --git a/crates/sui-core/src/unit_tests/data/hero/sources/TrustedCoin.move b/crates/sui-core/src/unit_tests/data/hero/sources/TrustedCoin.move index 007ba3187dc04..d057a13aeb7e3 100644 --- a/crates/sui-core/src/unit_tests/data/hero/sources/TrustedCoin.move +++ b/crates/sui-core/src/unit_tests/data/hero/sources/TrustedCoin.move @@ -25,7 +25,7 @@ module Examples::TrustedCoin { Coin::transfer(coin, TxContext::sender(ctx)); } - public(script) fun transfer(treasury_cap: TreasuryCap, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer(treasury_cap: TreasuryCap, recipient: address) { Coin::transfer_cap(treasury_cap, recipient); } diff --git a/crates/sui-core/src/unit_tests/data/object_owner/sources/ObjectOwner.move b/crates/sui-core/src/unit_tests/data/object_owner/sources/ObjectOwner.move index d3d3a4c2cd48a..431c42e60633f 100644 --- a/crates/sui-core/src/unit_tests/data/object_owner/sources/ObjectOwner.move +++ b/crates/sui-core/src/unit_tests/data/object_owner/sources/ObjectOwner.move @@ -47,19 +47,19 @@ module ObjectOwner::ObjectOwner { Transfer::transfer(parent, TxContext::sender(ctx)); } - public(script) fun add_child(parent: &mut Parent, child: Child, _ctx: &mut TxContext) { + public(script) fun add_child(parent: &mut Parent, child: Child) { let child_ref = Transfer::transfer_to_object(child, parent); 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, _ctx: &mut TxContext) {} + public(script) 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, _ctx: &mut TxContext) {} + public(script) 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, _ctx: &mut TxContext) { + public(script) 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); @@ -71,12 +71,12 @@ module ObjectOwner::ObjectOwner { } // Call to delete_child can fail if it's still owned by a parent. - public(script) fun delete_child(child: Child, _parent: &mut Parent, _ctx: &mut TxContext) { + public(script) 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, _ctx: &mut TxContext) { + public(script) 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); diff --git a/crates/sui-core/src/unit_tests/data/object_wrapping/sources/ObjectWrapping.move b/crates/sui-core/src/unit_tests/data/object_wrapping/sources/ObjectWrapping.move index 74acfa16a1463..530b2d5a931ca 100644 --- a/crates/sui-core/src/unit_tests/data/object_wrapping/sources/ObjectWrapping.move +++ b/crates/sui-core/src/unit_tests/data/object_wrapping/sources/ObjectWrapping.move @@ -35,7 +35,7 @@ module ObjectWrapping::ObjectWrapping { ) } - public(script) fun set_child(parent: &mut Parent, child: Child, _ctx: &mut TxContext) { + public(script) fun set_child(parent: &mut Parent, child: Child) { Option::fill(&mut parent.child, child) } @@ -47,7 +47,7 @@ module ObjectWrapping::ObjectWrapping { ) } - public(script) fun delete_parent(parent: Parent, _ctx: &mut TxContext) { + public(script) fun delete_parent(parent: Parent) { let Parent { id: parent_id, child: child_opt } = parent; ID::delete(parent_id); if (Option::is_some(&child_opt)) { diff --git a/crates/sui-framework/sources/Coin.move b/crates/sui-framework/sources/Coin.move index 28659500563db..412cd023126ad 100644 --- a/crates/sui-framework/sources/Coin.move +++ b/crates/sui-framework/sources/Coin.move @@ -178,12 +178,12 @@ module Sui::Coin { /// Consume the coin `c` and add its value to `self`. /// Aborts if `c.value + self.value > U64_MAX` - public(script) fun join_(self: &mut Coin, c: Coin, _ctx: &mut TxContext) { + public(script) fun join_(self: &mut Coin, c: Coin) { join(self, c) } /// Join everything in `coins` with `self` - public(script) fun join_vec_(self: &mut Coin, coins: vector>, _ctx: &mut TxContext) { + public(script) fun join_vec_(self: &mut Coin, coins: vector>) { join_vec(self, coins) } diff --git a/crates/sui-framework/sources/Governance/Delegation.move b/crates/sui-framework/sources/Governance/Delegation.move index 8c58da677903a..aed34d282eea3 100644 --- a/crates/sui-framework/sources/Governance/Delegation.move +++ b/crates/sui-framework/sources/Governance/Delegation.move @@ -87,7 +87,7 @@ module Sui::Delegation { /// Destroy the delegation object. This can be done only when the delegation /// is inactive and all reward have been claimed. - public(script) fun burn(self: Delegation, _ctx: &mut TxContext) { + public(script) fun burn(self: Delegation) { assert!(!is_active(&self), 0); let Delegation { @@ -104,7 +104,7 @@ module Sui::Delegation { assert!(next_reward_unclaimed_epoch == ending_epoch, 0); } - public(script) fun transfer(self: Delegation, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer(self: Delegation, recipient: address) { Transfer::transfer(self, recipient) } diff --git a/crates/sui-framework/sources/ObjectBasics.move b/crates/sui-framework/sources/ObjectBasics.move index bfdb67c648bef..a7d84f0e8843e 100644 --- a/crates/sui-framework/sources/ObjectBasics.move +++ b/crates/sui-framework/sources/ObjectBasics.move @@ -29,26 +29,26 @@ module Sui::ObjectBasics { ) } - public(script) fun transfer(o: Object, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer(o: Object, recipient: address) { Transfer::transfer(o, recipient) } - public(script) fun freeze_object(o: Object, _ctx: &mut TxContext) { + public(script) fun freeze_object(o: Object) { Transfer::freeze_object(o) } - public(script) fun set_value(o: &mut Object, value: u64, _ctx: &mut TxContext) { + public(script) fun set_value(o: &mut Object, value: u64) { o.value = value; } // test that reading o2 and updating o1 works - public(script) fun update(o1: &mut Object, o2: &Object, _ctx: &mut TxContext) { + public(script) 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(script) fun delete(o: Object, _ctx: &mut TxContext) { + public(script) fun delete(o: Object) { let Object { id, value: _ } = o; ID::delete(id); } diff --git a/crates/sui-framework/sources/SUI.move b/crates/sui-framework/sources/SUI.move index c399f96ae7be3..85f3edbcb38c2 100644 --- a/crates/sui-framework/sources/SUI.move +++ b/crates/sui-framework/sources/SUI.move @@ -19,7 +19,7 @@ module Sui::SUI { } /// Transfer to a recipient - public(script) fun transfer(c: Coin::Coin, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer(c: Coin::Coin, recipient: address) { Coin::transfer(c, recipient) } diff --git a/crates/sui-json/Cargo.toml b/crates/sui-json/Cargo.toml index b5f219a25f78a..9380114d4cc3e 100644 --- a/crates/sui-json/Cargo.toml +++ b/crates/sui-json/Cargo.toml @@ -15,6 +15,7 @@ serde_json = "1.0.79" schemars = "0.8.8" sui-types = { path = "../sui-types" } +sui-verifier = { path = "../sui-verifier" } move-binary-format = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b" } move-core-types = { git = "https://github.com/move-language/move", rev = "1b2d3b4274345f5b4b6a1a1bde5aee452003ab5b", features = ["address20"] } diff --git a/crates/sui-json/src/lib.rs b/crates/sui-json/src/lib.rs index e8ef510554bdb..9349c3b47abe9 100644 --- a/crates/sui-json/src/lib.rs +++ b/crates/sui-json/src/lib.rs @@ -4,6 +4,7 @@ use anyhow::{anyhow, bail}; use move_binary_format::{ access::ModuleAccess, + binary_views::BinaryIndexedView, file_format::{SignatureToken, Visibility}, }; use move_core_types::account_address::AccountAddress; @@ -18,6 +19,7 @@ use std::collections::VecDeque; use std::fmt::{Debug, Formatter}; use sui_types::base_types::{decode_bytes_hex, ObjectID, SuiAddress}; use sui_types::move_package::MovePackage; +use sui_verifier::entry_points_verifier::is_tx_context; const HEX_PREFIX: &str = "0x"; @@ -375,7 +377,12 @@ pub fn resolve_move_function_args( } // Lengths have to match, less one, due to TxContext - let expected_len = parameters.len() - 1; + let expected_len = match parameters.last() { + Some(param) if is_tx_context(&BinaryIndexedView::Module(&module), param) => { + parameters.len() - 1 + } + _ => parameters.len(), + }; if combined_args_json.len() != expected_len { return Err(anyhow!( "Expected {} args, found {}", diff --git a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TicTacToe.move b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TicTacToe.move index 4069837d25f08..8e2f2c84f57f9 100644 --- a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TicTacToe.move +++ b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TicTacToe.move @@ -138,7 +138,7 @@ module Examples::TicTacToe { } } - public(script) fun delete_game(game: TicTacToe, _ctx: &mut TxContext) { + public(script) fun delete_game(game: TicTacToe) { let TicTacToe { id, gameboard, cur_turn: _, game_status: _, x_address: _, o_address: _ } = game; while (Vector::length(&gameboard) > 0) { let row = Vector::pop_back(&mut gameboard); @@ -156,12 +156,12 @@ module Examples::TicTacToe { ID::delete(id); } - public(script) fun delete_trophy(trophy: Trophy, _ctx: &mut TxContext) { + public(script) fun delete_trophy(trophy: Trophy) { let Trophy { id } = trophy; ID::delete(id); } - public(script) fun delete_cap(cap: MarkMintCap, _ctx: &mut TxContext) { + public(script) fun delete_cap(cap: MarkMintCap) { let MarkMintCap { id, game_id: _, remaining_supply: _ } = cap; ID::delete(id); } diff --git a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TrustedCoin.move b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TrustedCoin.move index 007ba3187dc04..d057a13aeb7e3 100644 --- a/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TrustedCoin.move +++ b/crates/sui/src/unit_tests/data/custom_genesis_package_1/sources/TrustedCoin.move @@ -25,7 +25,7 @@ module Examples::TrustedCoin { Coin::transfer(coin, TxContext::sender(ctx)); } - public(script) fun transfer(treasury_cap: TreasuryCap, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer(treasury_cap: TreasuryCap, recipient: address) { Coin::transfer_cap(treasury_cap, recipient); } diff --git a/crates/sui/src/unit_tests/data/dummy_modules_publish/sources/TrustedCoin.move b/crates/sui/src/unit_tests/data/dummy_modules_publish/sources/TrustedCoin.move index 007ba3187dc04..d057a13aeb7e3 100644 --- a/crates/sui/src/unit_tests/data/dummy_modules_publish/sources/TrustedCoin.move +++ b/crates/sui/src/unit_tests/data/dummy_modules_publish/sources/TrustedCoin.move @@ -25,7 +25,7 @@ module Examples::TrustedCoin { Coin::transfer(coin, TxContext::sender(ctx)); } - public(script) fun transfer(treasury_cap: TreasuryCap, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer(treasury_cap: TreasuryCap, recipient: address) { Coin::transfer_cap(treasury_cap, recipient); } diff --git a/sui_programmability/examples/basics/sources/Counter.move b/sui_programmability/examples/basics/sources/Counter.move index 8bd4476992b52..add9a5ffe7f32 100644 --- a/sui_programmability/examples/basics/sources/Counter.move +++ b/sui_programmability/examples/basics/sources/Counter.move @@ -36,7 +36,7 @@ module Basics::Counter { } /// Increment a counter by 1. - public(script) fun increment(counter: &mut Counter, _ctx: &mut TxContext) { + public(script) fun increment(counter: &mut Counter) { counter.value = counter.value + 1; } @@ -47,7 +47,7 @@ module Basics::Counter { } /// Assert a value for the counter. - public(script) fun assert_value(counter: &Counter, value: u64, _ctx: &mut TxContext) { + public(script) fun assert_value(counter: &Counter, value: u64) { assert!(counter.value == value, 0) } } @@ -77,9 +77,9 @@ module Basics::CounterTest { assert!(Counter::owner(counter) == owner, 0); assert!(Counter::value(counter) == 0, 1); - Counter::increment(counter, TestScenario::ctx(scenario)); - Counter::increment(counter, TestScenario::ctx(scenario)); - Counter::increment(counter, TestScenario::ctx(scenario)); + Counter::increment(counter); + Counter::increment(counter); + Counter::increment(counter); TestScenario::return_shared(scenario, counter_wrapper); }; @@ -104,7 +104,7 @@ module Basics::CounterTest { assert!(Counter::owner(counter) == owner, 0); assert!(Counter::value(counter) == 100, 1); - Counter::increment(counter, TestScenario::ctx(scenario)); + Counter::increment(counter); assert!(Counter::value(counter) == 101, 2); diff --git a/sui_programmability/examples/basics/sources/Lock.move b/sui_programmability/examples/basics/sources/Lock.move index a98ddd7914a14..7620e8d8017b9 100644 --- a/sui_programmability/examples/basics/sources/Lock.move +++ b/sui_programmability/examples/basics/sources/Lock.move @@ -62,7 +62,6 @@ module Basics::Lock { obj: T, lock: &mut Lock, key: &Key, - _ctx: &mut TxContext, ) { assert!(Option::is_none(&lock.locked), ELockIsFull); assert!(&key.for == ID::id(lock), EKeyMismatch); diff --git a/sui_programmability/examples/defi/sources/Escrow.move b/sui_programmability/examples/defi/sources/Escrow.move index 53a2d1bedaaed..035edf46f11f9 100644 --- a/sui_programmability/examples/defi/sources/Escrow.move +++ b/sui_programmability/examples/defi/sources/Escrow.move @@ -54,7 +54,6 @@ module DeFi::Escrow { public(script) fun swap( obj1: EscrowedObj, obj2: EscrowedObj, - _ctx: &mut TxContext ) { let EscrowedObj { id: id1, @@ -86,7 +85,6 @@ module DeFi::Escrow { /// Trusted third party can always return an escrowed object to its original owner public(script) fun return_to_sender( obj: EscrowedObj, - _ctx: &mut TxContext ) { let EscrowedObj { id, sender, recipient: _, exchange_for: _, escrowed diff --git a/sui_programmability/examples/defi/sources/FlashLender.move b/sui_programmability/examples/defi/sources/FlashLender.move index 06f8e48611633..32f17985a8a72 100644 --- a/sui_programmability/examples/defi/sources/FlashLender.move +++ b/sui_programmability/examples/defi/sources/FlashLender.move @@ -130,7 +130,7 @@ module DeFi::FlashLender { /// Allow admin to add more funds to `self` public(script) fun deposit( - self: &mut FlashLender, admin_cap: &AdminCap, coin: Coin, _ctx: &mut TxContext + self: &mut FlashLender, admin_cap: &AdminCap, coin: Coin ) { // only the holder of the `AdminCap` for `self` can deposit funds check_admin(self, admin_cap); @@ -139,7 +139,7 @@ module DeFi::FlashLender { /// Allow admin to update the fee for `self` public(script) fun update_fee( - self: &mut FlashLender, admin_cap: &AdminCap, new_fee: u64, _ctx: &mut TxContext + self: &mut FlashLender, admin_cap: &AdminCap, new_fee: u64 ) { // only the holder of the `AdminCap` for `self` can update the fee check_admin(self, admin_cap); diff --git a/sui_programmability/examples/defi/tests/EscrowTests.move b/sui_programmability/examples/defi/tests/EscrowTests.move index 312cd8f8d90aa..28b3fdeaad3ce 100644 --- a/sui_programmability/examples/defi/tests/EscrowTests.move +++ b/sui_programmability/examples/defi/tests/EscrowTests.move @@ -48,12 +48,10 @@ module DeFi::EscrowTests { TestScenario::next_tx(scenario, &THIRD_PARTY_ADDRESS); { let item_a = TestScenario::take_owned>(scenario); - let ctx = TestScenario::ctx(scenario); - Escrow::return_to_sender(item_a, ctx); + Escrow::return_to_sender(item_a); let item_b = TestScenario::take_owned>(scenario); - let ctx = TestScenario::ctx(scenario); - Escrow::return_to_sender(item_b, ctx); + Escrow::return_to_sender(item_b); }; // Alice now owns item A, and Bob now owns item B @@ -84,8 +82,7 @@ module DeFi::EscrowTests { { let item_a = TestScenario::take_owned>(scenario); let item_b = TestScenario::take_owned>(scenario); - let ctx = TestScenario::ctx(scenario); - Escrow::swap(item_a, item_b, ctx); + Escrow::swap(item_a, item_b); }; } diff --git a/sui_programmability/examples/fungible_tokens/sources/MANAGED.move b/sui_programmability/examples/fungible_tokens/sources/MANAGED.move index 570ebc2bacfe0..7f3d9c59588fd 100644 --- a/sui_programmability/examples/fungible_tokens/sources/MANAGED.move +++ b/sui_programmability/examples/fungible_tokens/sources/MANAGED.move @@ -28,12 +28,12 @@ module FungibleTokens::MANAGED { } /// Manager can burn coins - public(script) fun burn(treasury_cap: &mut TreasuryCap, coin: Coin, _ctx: &mut TxContext) { + public(script) fun burn(treasury_cap: &mut TreasuryCap, coin: Coin) { Coin::burn(coin, treasury_cap) } /// Manager can transfer the treasury capability to a new manager - public(script) fun transfer_cap(treasury_cap: TreasuryCap, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer_cap(treasury_cap: TreasuryCap, recipient: address) { Coin::transfer_cap(treasury_cap, recipient); } diff --git a/sui_programmability/examples/games/sources/RockPaperScissors.move b/sui_programmability/examples/games/sources/RockPaperScissors.move index 9c1168def3e2f..47dd1aee9e5ae 100644 --- a/sui_programmability/examples/games/sources/RockPaperScissors.move +++ b/sui_programmability/examples/games/sources/RockPaperScissors.move @@ -144,7 +144,7 @@ module Games::RockPaperScissors { /// Add a hashed gesture to the game. Store it as a `hash_one` or `hash_two` depending /// on the player number (one or two) - public(script) fun add_hash(game: &mut Game, cap: PlayerTurn, _ctx: &mut TxContext) { + public(script) fun add_hash(game: &mut Game, cap: PlayerTurn) { let PlayerTurn { hash, id, player } = cap; let status = status(game); @@ -175,7 +175,7 @@ module Games::RockPaperScissors { /// Use submitted [`Secret`]'s salt to find the gesture played by the player and set it /// in the [`Game`] object. /// TODO: think of ways to - public(script) fun match_secret(game: &mut Game, secret: Secret, _ctx: &mut TxContext) { + public(script) fun match_secret(game: &mut Game, secret: Secret) { let Secret { salt, player, id } = secret; assert!(player == game.player_one || player == game.player_two, 0); diff --git a/sui_programmability/examples/games/sources/SharedTicTacToe.move b/sui_programmability/examples/games/sources/SharedTicTacToe.move index 833db65d96c81..11fe8569bcc54 100644 --- a/sui_programmability/examples/games/sources/SharedTicTacToe.move +++ b/sui_programmability/examples/games/sources/SharedTicTacToe.move @@ -107,12 +107,12 @@ module Games::SharedTicTacToe { } } - public(script) fun delete_game(game: TicTacToe, _ctx: &mut TxContext) { + public(script) fun delete_game(game: TicTacToe) { let TicTacToe { id, gameboard: _, cur_turn: _, game_status: _, x_address: _, o_address: _ } = game; ID::delete(id); } - public(script) fun delete_trophy(trophy: Trophy, _ctx: &mut TxContext) { + public(script) fun delete_trophy(trophy: Trophy) { let Trophy { id } = trophy; ID::delete(id); } diff --git a/sui_programmability/examples/games/sources/TicTacToe.move b/sui_programmability/examples/games/sources/TicTacToe.move index 8842280e5a28c..a40e358f10e08 100644 --- a/sui_programmability/examples/games/sources/TicTacToe.move +++ b/sui_programmability/examples/games/sources/TicTacToe.move @@ -161,7 +161,7 @@ module Games::TicTacToe { } } - public(script) fun delete_game(game: TicTacToe, _ctx: &mut TxContext) { + public(script) fun delete_game(game: TicTacToe) { let TicTacToe { id, gameboard, cur_turn: _, game_status: _, x_address: _, o_address: _ } = game; while (Vector::length(&gameboard) > 0) { let row = Vector::pop_back(&mut gameboard); @@ -179,12 +179,12 @@ module Games::TicTacToe { ID::delete(id); } - public(script) fun delete_trophy(trophy: Trophy, _ctx: &mut TxContext) { + public(script) fun delete_trophy(trophy: Trophy) { let Trophy { id } = trophy; ID::delete(id); } - public(script) fun delete_cap(cap: MarkMintCap, _ctx: &mut TxContext) { + public(script) fun delete_cap(cap: MarkMintCap) { let MarkMintCap { id, game_id: _, remaining_supply: _ } = cap; ID::delete(id); } diff --git a/sui_programmability/examples/games/tests/RockPaperScissorsTests.move b/sui_programmability/examples/games/tests/RockPaperScissorsTests.move index c0564e9607703..4d81eab97def6 100644 --- a/sui_programmability/examples/games/tests/RockPaperScissorsTests.move +++ b/sui_programmability/examples/games/tests/RockPaperScissorsTests.move @@ -36,7 +36,7 @@ module Games::RockPaperScissorsTests { assert!(Game::status(&game) == 0, 0); // STATUS_READY - Game::add_hash(&mut game, cap, TestScenario::ctx(scenario)); + Game::add_hash(&mut game, cap); assert!(Game::status(&game) == 1, 0); // STATUS_HASH_SUBMISSION @@ -54,7 +54,7 @@ module Games::RockPaperScissorsTests { { let game = TestScenario::take_owned(scenario); let cap = TestScenario::take_owned(scenario); - Game::add_hash(&mut game, cap, TestScenario::ctx(scenario)); + Game::add_hash(&mut game, cap); assert!(Game::status(&game) == 2, 0); // STATUS_HASHES_SUBMITTED @@ -71,7 +71,7 @@ module Games::RockPaperScissorsTests { { let game = TestScenario::take_owned(scenario); let secret = TestScenario::take_owned(scenario); - Game::match_secret(&mut game, secret, TestScenario::ctx(scenario)); + Game::match_secret(&mut game, secret); assert!(Game::status(&game) == 3, 0); // STATUS_REVEALING @@ -87,7 +87,7 @@ module Games::RockPaperScissorsTests { { let game = TestScenario::take_owned(scenario); let secret = TestScenario::take_owned(scenario); - Game::match_secret(&mut game, secret, TestScenario::ctx(scenario)); + Game::match_secret(&mut game, secret); assert!(Game::status(&game) == 4, 0); // STATUS_REVEALED diff --git a/sui_programmability/examples/nfts/sources/Chat.move b/sui_programmability/examples/nfts/sources/Chat.move index cca426844f001..38ff75bc59476 100644 --- a/sui_programmability/examples/nfts/sources/Chat.move +++ b/sui_programmability/examples/nfts/sources/Chat.move @@ -77,7 +77,7 @@ module NFTs::Chat { } /// Burn a Chat object. - public(script) fun burn(chat: Chat, _ctx: &mut TxContext) { + public(script) fun burn(chat: Chat) { let Chat { id, app_id: _, text: _, ref_id: _, metadata: _ } = chat; ID::delete(id); } diff --git a/sui_programmability/examples/nfts/sources/DiscountCoupon.move b/sui_programmability/examples/nfts/sources/DiscountCoupon.move index 98c83ea380847..06df9b143e167 100644 --- a/sui_programmability/examples/nfts/sources/DiscountCoupon.move +++ b/sui_programmability/examples/nfts/sources/DiscountCoupon.move @@ -46,11 +46,11 @@ module NFTs::DiscountCoupon { expiration, }; Transfer::transfer(coupon, recipient); - SUI::transfer(coin, recipient, ctx); + SUI::transfer(coin, recipient); } /// Burn DiscountCoupon. - public(script) fun burn(nft: DiscountCoupon, _ctx: &mut TxContext) { + public(script) fun burn(nft: DiscountCoupon) { let DiscountCoupon { id, issuer: _, discount: _, expiration: _ } = nft; ID::delete(id); } @@ -58,7 +58,7 @@ module NFTs::DiscountCoupon { /// Transfer DiscountCoupon to issuer only. // TODO: Consider adding more valid recipients. // If we stick with issuer-as-receiver only, then `recipient` input won't be required). - public(script) fun transfer(coupon: DiscountCoupon, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer(coupon: DiscountCoupon, recipient: address) { assert!(&coupon.issuer == &recipient, EWrongRecipient); Transfer::transfer(coupon, recipient); } diff --git a/sui_programmability/examples/nfts/sources/Geniteam.move b/sui_programmability/examples/nfts/sources/Geniteam.move index 24079d23b8c4a..11534d1775dc5 100644 --- a/sui_programmability/examples/nfts/sources/Geniteam.move +++ b/sui_programmability/examples/nfts/sources/Geniteam.move @@ -204,7 +204,6 @@ module NFTs::Geniteam { fire_runes_count: u64, wind_runes_count: u64, earth_runes_count: u64, - _ctx: &mut TxContext ) { player.water_runes_count = water_runes_count; player.fire_runes_count = fire_runes_count; @@ -224,7 +223,6 @@ module NFTs::Geniteam { affection_level: u64, buddy_level: u8, display: vector, - _ctx: &mut TxContext ) { self.monster_affinity = monster_affinity; self.monster_level = monster_level; @@ -240,7 +238,6 @@ module NFTs::Geniteam { /// Update the attributes of the farm public fun update_farm_stats( _player: &mut Player, farm: &mut Farm, level: u64, current_xp: u64, - _ctx: &mut TxContext ) { farm.current_xp = current_xp; farm.level = level; @@ -249,7 +246,7 @@ module NFTs::Geniteam { /// Apply the cosmetic to the Farm from the inventory public fun update_farm_cosmetics( _player: &mut Player, farm: &mut Farm, _inventory: &mut Bag, - farm_cosmetic: FarmCosmetic, cosmetic_slot_id: u64, _ctx: &mut TxContext + farm_cosmetic: FarmCosmetic, cosmetic_slot_id: u64 ) { // Only 2 slots allowed assert!(cosmetic_slot_id <= 1 , EInvalidCosmeticsSlot); @@ -272,7 +269,6 @@ module NFTs::Geniteam { _player: &mut Player, _farm: &mut Farm, monster: &mut Monster, _inventory: &mut Bag, monster_cosmetic: MonsterCosmetic, _pet_monsters: &mut Collection, cosmetic_slot_id: u64, - _ctx: &mut TxContext ) { // Only 2 slots allowed assert!(cosmetic_slot_id <= 1 , EInvalidCosmeticsSlot); diff --git a/sui_programmability/examples/objects_tutorial/sources/ColorObject.move b/sui_programmability/examples/objects_tutorial/sources/ColorObject.move index f08a8200cc8c0..15b82350f6e91 100644 --- a/sui_programmability/examples/objects_tutorial/sources/ColorObject.move +++ b/sui_programmability/examples/objects_tutorial/sources/ColorObject.move @@ -36,24 +36,24 @@ module Tutorial::ColorObject { // == Functions covered in Chapter 2 == /// Copies the values of `from_object` into `into_object`. - public(script) fun copy_into(from_object: &ColorObject, into_object: &mut ColorObject, _ctx: &mut TxContext) { + public(script) fun copy_into(from_object: &ColorObject, into_object: &mut ColorObject) { into_object.red = from_object.red; into_object.green = from_object.green; into_object.blue = from_object.blue; } - public(script) fun delete(object: ColorObject, _ctx: &mut TxContext) { + public(script) fun delete(object: ColorObject) { let ColorObject { id, red: _, green: _, blue: _ } = object; ID::delete(id); } - public(script) fun transfer(object: ColorObject, recipient: address, _ctx: &mut TxContext) { + public(script) fun transfer(object: ColorObject, recipient: address) { Transfer::transfer(object, recipient) } // == Functions covered in Chapter 3 == - public(script) fun freeze_object(object: ColorObject, _ctx: &mut TxContext) { + public(script) fun freeze_object(object: ColorObject) { Transfer::freeze_object(object) } @@ -65,7 +65,6 @@ module Tutorial::ColorObject { public(script) fun update( object: &mut ColorObject, red: u8, green: u8, blue: u8, - _ctx: &mut TxContext, ) { object.red = red; object.green = green; @@ -129,8 +128,7 @@ module Tutorial::ColorObjectTests { let (red, green, blue) = ColorObject::get_color(&obj1); assert!(red == 255 && green == 255 && blue == 255, 0); - let ctx = TestScenario::ctx(scenario); - ColorObject::copy_into(&obj2, &mut obj1, ctx); + ColorObject::copy_into(&obj2, &mut obj1); TestScenario::return_owned(scenario, obj1); TestScenario::return_owned(scenario, obj2); }; @@ -156,8 +154,7 @@ module Tutorial::ColorObjectTests { TestScenario::next_tx(scenario, &owner); { let object = TestScenario::take_owned(scenario); - let ctx = TestScenario::ctx(scenario); - ColorObject::delete(object, ctx); + ColorObject::delete(object); }; // Verify that the object was indeed deleted. TestScenario::next_tx(scenario, &owner); @@ -180,8 +177,7 @@ module Tutorial::ColorObjectTests { TestScenario::next_tx(scenario, &owner); { let object = TestScenario::take_owned(scenario); - let ctx = TestScenario::ctx(scenario); - ColorObject::transfer(object, recipient, ctx); + ColorObject::transfer(object, recipient); }; // Check that owner no longer owns the object. TestScenario::next_tx(scenario, &owner); diff --git a/sui_programmability/tutorial/sources/M1.move b/sui_programmability/tutorial/sources/M1.move index e118d67a1cf5a..5cf62fb808bd9 100644 --- a/sui_programmability/tutorial/sources/M1.move +++ b/sui_programmability/tutorial/sources/M1.move @@ -55,7 +55,7 @@ module MyFirstPackage::M1 { forge.swords_created = forge.swords_created + 1; } - public(script) fun sword_transfer(sword: Sword, recipient: address, _ctx: &mut TxContext) { + public(script) fun sword_transfer(sword: Sword, recipient: address) { use Sui::Transfer; // transfer the sword Transfer::transfer(sword, recipient);