From 809c81aef3125c986308437936da31ffe06d6902 Mon Sep 17 00:00:00 2001 From: Cam Swords Date: Sun, 24 Mar 2024 18:54:48 -0700 Subject: [PATCH] [move-2024] Method syntax for `sui-framework` (#16754) Stacked on #16466 (and also #16634 as a result) This translates `sui-framework` to Move 2024. Public use funs: ``` sources/balance.move 10: public use fun sui::coin::from_balance as Balance.into_coin; sources/kiosk/kiosk.move 97: public use fun kiosk_owner_cap_for as KioskOwnerCap.kiosk; sources/coin.move 16: public use fun sui::pay::split_vec as Coin.split_vec; 19: public use fun sui::pay::join_vec as Coin.join_vec; 22: public use fun sui::pay::split_and_transfer as Coin.split_and_transfer; 25: public use fun sui::pay::divide_and_keep as Coin.divide_and_keep; sources/object.move 19: public use fun id_to_address as ID.to_address; 22: public use fun id_to_bytes as ID.to_bytes; 25: public use fun uid_as_inner as UID.as_inner; 28: public use fun uid_to_inner as UID.to_inner; 31: public use fun uid_to_address as UID.to_address; 34: public use fun uid_to_bytes as UID.to_bytes; sources/address.move 12: public use fun sui::object::id_from_address as address.to_id; ``` Tests are unchanged. Note that many of the tests may be rewritten to also use method syntax, but this change is already large enough that it seemed prudent to do the tests in a separate diff. --- If your changes are not user-facing and do not break anything, you can skip the following section. Otherwise, please briefly describe what has changed under the Release Notes section. - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration --------- Co-authored-by: Todd Nowacki --- crates/sui-framework/docs/deepbook/clob_v2.md | 30 +++- .../docs/sui-framework/address.md | 14 +- .../docs/sui-framework/authenticator_state.md | 100 ++++++------ .../sui-framework/docs/sui-framework/bag.md | 2 +- .../docs/sui-framework/balance.md | 4 +- .../sui-framework/docs/sui-framework/bcs.md | 80 +++++----- .../docs/sui-framework/borrow.md | 6 +- .../sui-framework/docs/sui-framework/clock.md | 4 +- .../sui-framework/docs/sui-framework/coin.md | 43 +++-- .../docs/sui-framework/deny_list.md | 47 +++--- .../docs/sui-framework/display.md | 30 ++-- .../docs/sui-framework/dynamic_field.md | 22 +-- .../sui-framework/dynamic_object_field.md | 10 +- .../docs/sui-framework/groth16.md | 12 +- .../docs/sui-framework/group_ops.md | 102 ++++++------ .../sui-framework/docs/sui-framework/hex.md | 14 +- .../sui-framework/docs/sui-framework/kiosk.md | 102 ++++++------ .../docs/sui-framework/kiosk_extension.md | 24 +-- .../docs/sui-framework/linked_table.md | 44 ++--- .../docs/sui-framework/object.md | 6 +- .../docs/sui-framework/object_bag.md | 2 +- .../docs/sui-framework/object_table.md | 2 +- .../docs/sui-framework/package.md | 29 ++-- .../sui-framework/docs/sui-framework/pay.md | 37 ++--- .../docs/sui-framework/poseidon.md | 8 +- .../docs/sui-framework/priority_queue.md | 36 ++--- .../docs/sui-framework/random.md | 17 +- .../sui-framework/docs/sui-framework/sui.md | 10 +- .../sui-framework/docs/sui-framework/table.md | 4 +- .../docs/sui-framework/table_vec.md | 44 ++--- .../sui-framework/docs/sui-framework/token.md | 132 +++++++-------- .../docs/sui-framework/transfer.md | 6 +- .../docs/sui-framework/transfer_policy.md | 34 ++-- .../sui-framework/docs/sui-framework/url.md | 2 +- .../docs/sui-framework/vec_map.md | 72 ++++----- .../docs/sui-framework/vec_set.md | 20 +-- .../docs/sui-framework/versioned.md | 2 +- .../docs/sui-framework/zklogin_verified_id.md | 2 +- .../sui-framework/zklogin_verified_issuer.md | 6 +- .../sui-framework/packages/deepbook/Move.lock | 4 +- .../packages/sui-framework/Move.lock | 6 +- .../sui-framework/sources/address.move | 19 ++- .../sources/authenticator_state.move | 111 ++++++------- .../packages/sui-framework/sources/bag.move | 6 +- .../sui-framework/sources/balance.move | 26 +-- .../packages/sui-framework/sources/bcs.move | 146 +++++++++-------- .../sui-framework/sources/borrow.move | 19 +-- .../packages/sui-framework/sources/clock.move | 9 +- .../packages/sui-framework/sources/coin.move | 64 ++++---- .../sui-framework/sources/crypto/groth16.move | 13 +- .../sources/crypto/group_ops.move | 73 +++++---- .../sources/crypto/poseidon.move | 9 +- .../sources/crypto/zklogin_verified_id.move | 5 +- .../crypto/zklogin_verified_issuer.move | 11 +- .../sui-framework/sources/deny_list.move | 53 +++--- .../sui-framework/sources/display.move | 52 +++--- .../sui-framework/sources/dynamic_field.move | 24 ++- .../sources/dynamic_object_field.move | 12 +- .../packages/sui-framework/sources/hex.move | 15 +- .../sui-framework/sources/kiosk/kiosk.move | 110 ++++++------- .../sources/kiosk/kiosk_extension.move | 27 ++-- .../sources/kiosk/transfer_policy.move | 40 +++-- .../sui-framework/sources/linked_table.move | 49 +++--- .../sui-framework/sources/object.move | 27 +++- .../sui-framework/sources/object_bag.move | 7 +- .../sui-framework/sources/object_table.move | 7 +- .../sui-framework/sources/package.move | 41 +++-- .../packages/sui-framework/sources/pay.move | 40 +++-- .../sui-framework/sources/priority_queue.move | 37 +++-- .../sui-framework/sources/random.move | 23 ++- .../packages/sui-framework/sources/sui.move | 15 +- .../packages/sui-framework/sources/table.move | 8 +- .../sui-framework/sources/table_vec.move | 71 +++++--- .../sources/test/test_random.move | 9 +- .../sources/test/test_scenario.move | 33 ++-- .../sources/test/test_utils.move | 2 +- .../packages/sui-framework/sources/token.move | 151 +++++++++--------- .../sui-framework/sources/transfer.move | 7 +- .../sui-framework/sources/tx_context.move | 7 +- .../packages/sui-framework/sources/url.move | 4 +- .../sui-framework/sources/vec_map.move | 76 ++++----- .../sui-framework/sources/vec_set.move | 22 ++- .../sui-framework/sources/versioned.move | 5 +- .../packages/sui-system/Move.lock | 6 +- ..._populated_genesis_snapshot_matches-2.snap | 28 ++-- .../src/test_adapter.rs | 3 +- .../move/crates/move-model/src/model.rs | 9 +- 87 files changed, 1339 insertions(+), 1363 deletions(-) diff --git a/crates/sui-framework/docs/deepbook/clob_v2.md b/crates/sui-framework/docs/deepbook/clob_v2.md index 79e0ff40e70fd..7e2be304c07cb 100644 --- a/crates/sui-framework/docs/deepbook/clob_v2.md +++ b/crates/sui-framework/docs/deepbook/clob_v2.md @@ -3830,8 +3830,19 @@ The latter is the corresponding depth list if (price_low < price_low_) price_low = price_low_; if (price_high > price_high_) price_high = price_high_; - price_low = critbit::find_closest_key(&pool.bids, price_low); - price_high = critbit::find_closest_key(&pool.bids, price_high); + let closest_low = critbit::find_closest_key(&pool.bids, price_low); + let closest_high = critbit::find_closest_key(&pool.bids, price_high); + if (price_low <= closest_low){ + price_low = closest_low; + } else { + (price_low, _) = critbit::next_leaf(&pool.bids, closest_low); + }; + if (price_high >= closest_high){ + price_high = closest_high; + } else { + (price_high, _) = critbit::previous_leaf(&pool.bids, closest_high); + }; + while (price_low <= price_high) { let depth = get_level2_book_status( &pool.bids, @@ -3892,8 +3903,19 @@ The latter is the corresponding depth list if (price_low < price_low_) price_low = price_low_; let (price_high_, _) = critbit::max_leaf(&pool.asks); if (price_high > price_high_) price_high = price_high_; - price_low = critbit::find_closest_key(&pool.asks, price_low); - price_high = critbit::find_closest_key(&pool.asks, price_high); + let closest_low = critbit::find_closest_key(&pool.asks, price_low); + let closest_high = critbit::find_closest_key(&pool.asks, price_high); + if (price_low <= closest_low){ + price_low = closest_low; + } else { + (price_low, _) = critbit::next_leaf(&pool.bids, closest_low); + }; + if (price_high >= closest_high){ + price_high = closest_high; + } else { + (price_high, _) = critbit::previous_leaf(&pool.bids, closest_high); + }; + while (price_low <= price_high) { let depth = get_level2_book_status( &pool.asks, diff --git a/crates/sui-framework/docs/sui-framework/address.md b/crates/sui-framework/docs/sui-framework/address.md index e0f0422194bd6..8816c76a2482b 100644 --- a/crates/sui-framework/docs/sui-framework/address.md +++ b/crates/sui-framework/docs/sui-framework/address.md @@ -174,7 +174,7 @@ Convert a to a hex-encoded ASCII string
public fun to_ascii_string(a: address): ascii::String {
-    ascii::string(hex::encode(to_bytes(a)))
+    hex::encode(to_bytes(a)).to_ascii_string()
 }
 
@@ -186,7 +186,7 @@ Convert a to a hex-encoded ASCII string ## Function `to_string` -Convert a to a hex-encoded ASCII string +Convert a to a hex-encoded string
public fun to_string(a: address): string::String
@@ -199,7 +199,7 @@ Convert a to a hex-encoded ASCII string
 
 
 
public fun to_string(a: address): string::String {
-    string::from_ascii(to_ascii_string(a))
+    to_ascii_string(a).to_string()
 }
 
@@ -229,13 +229,13 @@ or if an invalid character is encountered.
public fun from_ascii_bytes(bytes: &vector<u8>): address {
-    assert!(vector::length(bytes) == 64, EAddressParseError);
+    assert!(bytes.length() == 64, EAddressParseError);
     let mut hex_bytes = vector[];
     let mut i = 0;
     while (i < 64) {
-        let hi = hex_char_value(*vector::borrow(bytes, i));
-        let lo = hex_char_value(*vector::borrow(bytes, i + 1));
-        vector::push_back(&mut hex_bytes, (hi << 4) | lo);
+        let hi = hex_char_value(bytes[i]);
+        let lo = hex_char_value(bytes[i+1]);
+        hex_bytes.push_back((hi << 4) | lo);
         i = i + 2;
     };
     from_bytes(hex_bytes)
diff --git a/crates/sui-framework/docs/sui-framework/authenticator_state.md b/crates/sui-framework/docs/sui-framework/authenticator_state.md
index de8c3bebcb85c..b0c3b75726ec8 100644
--- a/crates/sui-framework/docs/sui-framework/authenticator_state.md
+++ b/crates/sui-framework/docs/sui-framework/authenticator_state.md
@@ -359,18 +359,18 @@ Sender is not @0x0 the system address.
 
 
 
fun string_bytes_lt(a: &String, b: &String): bool {
-    let a_bytes = string::bytes(a);
-    let b_bytes = string::bytes(b);
+    let a_bytes = a.bytes();
+    let b_bytes = b.bytes();
 
-    if (vector::length(a_bytes) < vector::length(b_bytes)) {
+    if (a_bytes.length() < b_bytes.length()) {
         true
-    } else if (vector::length(a_bytes) > vector::length(b_bytes)) {
+    } else if (a_bytes.length() > b_bytes.length()) {
         false
     } else {
         let mut i = 0;
-        while (i < vector::length(a_bytes)) {
-            let a_byte = *vector::borrow(a_bytes, i);
-            let b_byte = *vector::borrow(b_bytes, i);
+        while (i < a_bytes.length()) {
+            let a_byte = a_bytes[i];
+            let b_byte = b_bytes[i];
             if (a_byte < b_byte) {
                 return true
             } else if (a_byte > b_byte) {
@@ -447,7 +447,7 @@ Can only be called by genesis or change_epoch transactions.
 
 
 
fun create(ctx: &TxContext) {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
 
     let version = CurrentVersion;
 
@@ -555,9 +555,9 @@ Can only be called by genesis or change_epoch transactions.
 
 
fun check_sorted(new_active_jwks: &vector<ActiveJwk>) {
     let mut i = 0;
-    while (i < vector::length(new_active_jwks) - 1) {
-        let a = vector::borrow(new_active_jwks, i);
-        let b = vector::borrow(new_active_jwks, i + 1);
+    while (i < new_active_jwks.length() - 1) {
+        let a = &new_active_jwks[i];
+        let b = &new_active_jwks[i + 1];
         assert!(jwk_lt(a, b), EJwksNotSorted);
         i = i + 1;
     };
@@ -593,52 +593,52 @@ indicate that the JWK has been validated in the current epoch and should not be
     ctx: &TxContext,
 ) {
     // Validator will make a special system call with sender set as 0x0.
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
 
     check_sorted(&new_active_jwks);
     let new_active_jwks = deduplicate(new_active_jwks);
 
-    let inner = load_inner_mut(self);
+    let inner = self.load_inner_mut();
 
     let mut res = vector[];
     let mut i = 0;
     let mut j = 0;
-    let active_jwks_len = vector::length(&inner.active_jwks);
-    let new_active_jwks_len = vector::length(&new_active_jwks);
+    let active_jwks_len = inner.active_jwks.length();
+    let new_active_jwks_len = new_active_jwks.length();
 
     while (i < active_jwks_len && j < new_active_jwks_len) {
-        let old_jwk = vector::borrow(&inner.active_jwks, i);
-        let new_jwk = vector::borrow(&new_active_jwks, j);
+        let old_jwk = &inner.active_jwks[i];
+        let new_jwk = &new_active_jwks[j];
 
         // when they are equal, push only one, but use the max epoch of the two
         if (active_jwk_equal(old_jwk, new_jwk)) {
             let mut jwk = *old_jwk;
             jwk.epoch = math::max(old_jwk.epoch, new_jwk.epoch);
-            vector::push_back(&mut res, jwk);
+            res.push_back(jwk);
             i = i + 1;
             j = j + 1;
         } else if (jwk_id_equal(&old_jwk.jwk_id, &new_jwk.jwk_id)) {
             // if only jwk_id is equal, then the key has changed. Providers should not send
             // JWKs like this, but if they do, we must ignore the new JWK to avoid having a
             // liveness / forking issues
-            vector::push_back(&mut res, *old_jwk);
+            res.push_back(*old_jwk);
             i = i + 1;
             j = j + 1;
         } else if (jwk_lt(old_jwk, new_jwk)) {
-            vector::push_back(&mut res, *old_jwk);
+            res.push_back(*old_jwk);
             i = i + 1;
         } else {
-            vector::push_back(&mut res, *new_jwk);
+            res.push_back(*new_jwk);
             j = j + 1;
         }
     };
 
     while (i < active_jwks_len) {
-        vector::push_back(&mut res, *vector::borrow(&inner.active_jwks, i));
+        res.push_back(inner.active_jwks[i]);
         i = i + 1;
     };
     while (j < new_active_jwks_len) {
-        vector::push_back(&mut res, *vector::borrow(&new_active_jwks, j));
+        res.push_back(new_active_jwks[j]);
         j = j + 1;
     };
 
@@ -669,18 +669,18 @@ indicate that the JWK has been validated in the current epoch and should not be
     let mut res = vector[];
     let mut i = 0;
     let mut prev: Option<JwkId> = option::none();
-    while (i < vector::length(&jwks)) {
-        let jwk = vector::borrow(&jwks, i);
-        if (option::is_none(&prev)) {
-            option::fill(&mut prev, jwk.jwk_id);
-        } else if (jwk_id_equal(option::borrow(&prev), &jwk.jwk_id)) {
+    while (i < jwks.length()) {
+        let jwk = &jwks[i];
+        if (prev.is_none()) {
+            prev.fill(jwk.jwk_id);
+        } else if (jwk_id_equal(prev.borrow(), &jwk.jwk_id)) {
             // skip duplicate jwks in input
             i = i + 1;
             continue
         } else {
-            *option::borrow_mut(&mut prev) = jwk.jwk_id;
+            *prev.borrow_mut() = jwk.jwk_id;
         };
-        vector::push_back(&mut res, *jwk);
+        res.push_back(*jwk);
         i = i + 1;
     };
     res
@@ -712,11 +712,11 @@ indicate that the JWK has been validated in the current epoch and should not be
     min_epoch: u64,
     ctx: &TxContext) {
     // This will only be called by sui_system::advance_epoch
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
 
     let inner = load_inner_mut(self);
 
-    let len = vector::length(&inner.active_jwks);
+    let len = inner.active_jwks.length();
 
     // first we count how many jwks from each issuer are above the min_epoch
     // and store the counts in a vector that parallels the (sorted) active_jwks vector
@@ -725,19 +725,19 @@ indicate that the JWK has been validated in the current epoch and should not be
     let mut prev_issuer: Option<String> = option::none();
 
     while (i < len) {
-        let cur = vector::borrow(&inner.active_jwks, i);
+        let cur = &inner.active_jwks[i];
         let cur_iss = &cur.jwk_id.iss;
-        if (option::is_none(&prev_issuer)) {
-            option::fill(&mut prev_issuer, *cur_iss);
-            vector::push_back(&mut issuer_max_epochs, cur.epoch);
+        if (prev_issuer.is_none()) {
+            prev_issuer.fill(*cur_iss);
+            issuer_max_epochs.push_back(cur.epoch);
         } else {
-            if (cur_iss == option::borrow(&prev_issuer)) {
-                let back = vector::length(&issuer_max_epochs) - 1;
-                let prev_max_epoch = vector::borrow_mut(&mut issuer_max_epochs, back);
+            if (cur_iss == prev_issuer.borrow()) {
+                let back = issuer_max_epochs.length() - 1;
+                let prev_max_epoch = &mut issuer_max_epochs[back];
                 *prev_max_epoch = math::max(*prev_max_epoch, cur.epoch);
             } else {
-                *option::borrow_mut(&mut prev_issuer) = *cur_iss;
-                vector::push_back(&mut issuer_max_epochs, cur.epoch);
+                *prev_issuer.borrow_mut() = *cur_iss;
+                issuer_max_epochs.push_back(cur.epoch);
             }
         };
         i = i + 1;
@@ -750,22 +750,22 @@ indicate that the JWK has been validated in the current epoch and should not be
     let mut i = 0;
     let mut j = 0;
     while (i < len) {
-        let jwk = vector::borrow(&inner.active_jwks, i);
+        let jwk = &inner.active_jwks[i];
         let cur_iss = &jwk.jwk_id.iss;
 
-        if (option::is_none(&prev_issuer)) {
-            option::fill(&mut prev_issuer, *cur_iss);
-        } else if (cur_iss != option::borrow(&prev_issuer)) {
-            *option::borrow_mut(&mut prev_issuer) = *cur_iss;
+        if (prev_issuer.is_none()) {
+            prev_issuer.fill(*cur_iss);
+        } else if (cur_iss != prev_issuer.borrow()) {
+            *prev_issuer.borrow_mut() = *cur_iss;
             j = j + 1;
         };
 
-        let max_epoch_for_iss = vector::borrow(&issuer_max_epochs, j);
+        let max_epoch_for_iss = &issuer_max_epochs[j];
 
         // TODO: if the iss for this jwk has *no* jwks that meet the minimum epoch,
         // then expire nothing.
         if (*max_epoch_for_iss < min_epoch || jwk.epoch >= min_epoch) {
-            vector::push_back(&mut new_active_jwks, *jwk);
+            new_active_jwks.push_back(*jwk);
         };
         i = i + 1;
     };
@@ -798,8 +798,8 @@ JWK state from the chain.
     self: &AuthenticatorState,
     ctx: &TxContext,
 ): vector<ActiveJwk> {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
-    load_inner(self).active_jwks
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
+    self.load_inner().active_jwks
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/bag.md b/crates/sui-framework/docs/sui-framework/bag.md index 1499790c9c0f4..4537c9e4852ae 100644 --- a/crates/sui-framework/docs/sui-framework/bag.md +++ b/crates/sui-framework/docs/sui-framework/bag.md @@ -359,7 +359,7 @@ Aborts with EBagNot
public fun destroy_empty(bag: Bag) {
     let Bag { id, size } = bag;
     assert!(size == 0, EBagNotEmpty);
-    object::delete(id)
+    id.delete()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/balance.md b/crates/sui-framework/docs/sui-framework/balance.md index 3a4a12aedfdd1..715b72d809d52 100644 --- a/crates/sui-framework/docs/sui-framework/balance.md +++ b/crates/sui-framework/docs/sui-framework/balance.md @@ -414,7 +414,7 @@ and nowhere else.
fun create_staking_rewards<T>(value: u64, ctx: &TxContext): Balance<T> {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
     Balance { value }
 }
 
@@ -442,7 +442,7 @@ and nowhere else.
fun destroy_storage_rebates<T>(self: Balance<T>, ctx: &TxContext) {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
     let Balance { value: _ } = self;
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/bcs.md b/crates/sui-framework/docs/sui-framework/bcs.md index cd1fde81792c5..471eb385fbba2 100644 --- a/crates/sui-framework/docs/sui-framework/bcs.md +++ b/crates/sui-framework/docs/sui-framework/bcs.md @@ -24,12 +24,12 @@ use sui::bcs::{Self, BCS}; let prepared: BCS = bcs::new(bytes); let (u8_value, u64_value) = ( -bcs::peel_u8(&mut prepared), -bcs::peel_u64(&mut prepared) +prepared.peel_u8(), +prepared.peel_u64() ); // unpack bcs struct -let leftovers = bcs::into_remainder_bytes(prepared); +let leftovers = prepared.into_remainder_bytes(); (u8_value, u64_value, leftovers) } @@ -178,7 +178,7 @@ bytes for better performance.
public fun new(mut bytes: vector<u8>): BCS {
-    v::reverse(&mut bytes);
+    bytes.reverse();
     BCS { bytes }
 }
 
@@ -206,7 +206,7 @@ Useful for passing the data further after partial deserialization.
public fun into_remainder_bytes(bcs: BCS): vector<u8> {
     let BCS { mut bytes } = bcs;
-    v::reverse(&mut bytes);
+    bytes.reverse();
     bytes
 }
 
@@ -232,10 +232,10 @@ Read address from the bcs-serialized bytes.
public fun peel_address(bcs: &mut BCS): address {
-    assert!(v::length(&bcs.bytes) >= address::length(), EOutOfRange);
-    let (mut addr_bytes, mut i) = (v::empty(), 0);
+    assert!(bcs.bytes.length() >= address::length(), EOutOfRange);
+    let (mut addr_bytes, mut i) = (vector[], 0);
     while (i < address::length()) {
-        v::push_back(&mut addr_bytes, v::pop_back(&mut bcs.bytes));
+        addr_bytes.push_back(bcs.bytes.pop_back());
         i = i + 1;
     };
     address::from_bytes(addr_bytes)
@@ -263,7 +263,7 @@ Read a bool value from bcs-serialized bytes.
 
 
 
public fun peel_bool(bcs: &mut BCS): bool {
-    let value = peel_u8(bcs);
+    let value = bcs.peel_u8();
     if (value == 0) {
         false
     } else if (value == 1) {
@@ -295,8 +295,8 @@ Read u8 value from bcs-serialized bytes.
 
 
 
public fun peel_u8(bcs: &mut BCS): u8 {
-    assert!(v::length(&bcs.bytes) >= 1, EOutOfRange);
-    v::pop_back(&mut bcs.bytes)
+    assert!(bcs.bytes.length() >= 1, EOutOfRange);
+    bcs.bytes.pop_back()
 }
 
@@ -321,11 +321,11 @@ Read u64 value from bcs-serialized bytes.
public fun peel_u64(bcs: &mut BCS): u64 {
-    assert!(v::length(&bcs.bytes) >= 8, EOutOfRange);
+    assert!(bcs.bytes.length() >= 8, EOutOfRange);
 
     let (mut value, mut i) = (0u64, 0u8);
     while (i < 64) {
-        let byte = (v::pop_back(&mut bcs.bytes) as u64);
+        let byte = (bcs.bytes.pop_back() as u64);
         value = value + (byte << i);
         i = i + 8;
     };
@@ -355,11 +355,11 @@ Read u128 value from bcs-serialized bytes.
 
 
 
public fun peel_u128(bcs: &mut BCS): u128 {
-    assert!(v::length(&bcs.bytes) >= 16, EOutOfRange);
+    assert!(bcs.bytes.length() >= 16, EOutOfRange);
 
     let (mut value, mut i) = (0u128, 0u8);
     while (i < 128) {
-        let byte = (v::pop_back(&mut bcs.bytes) as u128);
+        let byte = (bcs.bytes.pop_back() as u128);
         value = value + (byte << i);
         i = i + 8;
     };
@@ -389,11 +389,11 @@ Read u256 value from bcs-serialized bytes.
 
 
 
public fun peel_u256(bcs: &mut BCS): u256 {
-    assert!(v::length(&bcs.bytes) >= 32, EOutOfRange);
+    assert!(bcs.bytes.length() >= 32, EOutOfRange);
 
     let (mut value, mut i) = (0u256, 0u16);
     while (i < 256) {
-        let byte = (v::pop_back(&mut bcs.bytes) as u256);
+        let byte = (bcs.bytes.pop_back() as u256);
         value = value + (byte << (i as u8));
         i = i + 8;
     };
@@ -430,7 +430,7 @@ See more here: https://en.wikipedia.org/wiki/LEB128
     let (mut total, mut shift, mut len) = (0u64, 0, 0);
     while (true) {
         assert!(len <= 4, ELenOutOfRange);
-        let byte = (v::pop_back(&mut bcs.bytes) as u64);
+        let byte = (bcs.bytes.pop_back() as u64);
         len = len + 1;
         total = total | ((byte & 0x7f) << shift);
         if ((byte & 0x80) == 0) {
@@ -463,9 +463,9 @@ Peel a vector of address from serialized bytes.
 
 
 
public fun peel_vec_address(bcs: &mut BCS): vector<address> {
-    let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]);
+    let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]);
     while (i < len) {
-        v::push_back(&mut res, peel_address(bcs));
+        res.push_back(bcs.peel_address());
         i = i + 1;
     };
     res
@@ -493,9 +493,9 @@ Peel a vector of address from serialized bytes.
 
 
 
public fun peel_vec_bool(bcs: &mut BCS): vector<bool> {
-    let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]);
+    let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]);
     while (i < len) {
-        v::push_back(&mut res, peel_bool(bcs));
+        res.push_back(bcs.peel_bool());
         i = i + 1;
     };
     res
@@ -523,9 +523,9 @@ Peel a vector of u8 (eg string) from serialized bytes.
 
 
 
public fun peel_vec_u8(bcs: &mut BCS): vector<u8> {
-    let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]);
+    let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]);
     while (i < len) {
-        v::push_back(&mut res, peel_u8(bcs));
+        res.push_back(bcs.peel_u8());
         i = i + 1;
     };
     res
@@ -553,9 +553,9 @@ Peel a vector<public fun peel_vec_vec_u8(bcs: &mut BCS): vector<vector<u8>> {
-    let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]);
+    let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]);
     while (i < len) {
-        v::push_back(&mut res, peel_vec_u8(bcs));
+        res.push_back(bcs.peel_vec_u8());
         i = i + 1;
     };
     res
@@ -583,9 +583,9 @@ Peel a vector of u64 from serialized bytes.
 
 
 
public fun peel_vec_u64(bcs: &mut BCS): vector<u64> {
-    let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]);
+    let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]);
     while (i < len) {
-        v::push_back(&mut res, peel_u64(bcs));
+        res.push_back(bcs.peel_u64());
         i = i + 1;
     };
     res
@@ -613,9 +613,9 @@ Peel a vector of u128 from serialized bytes.
 
 
 
public fun peel_vec_u128(bcs: &mut BCS): vector<u128> {
-    let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]);
+    let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]);
     while (i < len) {
-        v::push_back(&mut res, peel_u128(bcs));
+        res.push_back(bcs.peel_u128());
         i = i + 1;
     };
     res
@@ -643,8 +643,8 @@ Peel Option<address> from serialized bytes.
 
 
 
public fun peel_option_address(bcs: &mut BCS): Option<address> {
-    if (peel_bool(bcs)) {
-        option::some(peel_address(bcs))
+    if (bcs.peel_bool()) {
+        option::some(bcs.peel_address())
     } else {
         option::none()
     }
@@ -672,8 +672,8 @@ Peel Option<bool> from serialized bytes.
 
 
 
public fun peel_option_bool(bcs: &mut BCS): Option<bool> {
-    if (peel_bool(bcs)) {
-        option::some(peel_bool(bcs))
+    if (bcs.peel_bool()) {
+        option::some(bcs.peel_bool())
     } else {
         option::none()
     }
@@ -701,8 +701,8 @@ Peel Option<u8> from serialized bytes.
 
 
 
public fun peel_option_u8(bcs: &mut BCS): Option<u8> {
-    if (peel_bool(bcs)) {
-        option::some(peel_u8(bcs))
+    if (bcs.peel_bool()) {
+        option::some(bcs.peel_u8())
     } else {
         option::none()
     }
@@ -730,8 +730,8 @@ Peel Option<u64> from serialized bytes.
 
 
 
public fun peel_option_u64(bcs: &mut BCS): Option<u64> {
-    if (peel_bool(bcs)) {
-        option::some(peel_u64(bcs))
+    if (bcs.peel_bool()) {
+        option::some(bcs.peel_u64())
     } else {
         option::none()
     }
@@ -759,8 +759,8 @@ Peel Option<u128> from serialized bytes.
 
 
 
public fun peel_option_u128(bcs: &mut BCS): Option<u128> {
-    if (peel_bool(bcs)) {
-        option::some(peel_u128(bcs))
+    if (bcs.peel_bool()) {
+        option::some(bcs.peel_u128())
     } else {
         option::none()
     }
diff --git a/crates/sui-framework/docs/sui-framework/borrow.md b/crates/sui-framework/docs/sui-framework/borrow.md
index b8b1d21fdc2a3..aa292c7c3bf61 100644
--- a/crates/sui-framework/docs/sui-framework/borrow.md
+++ b/crates/sui-framework/docs/sui-framework/borrow.md
@@ -165,7 +165,7 @@ hot potato.
 
 
 
public fun borrow<T: key + store>(self: &mut Referent<T>): (T, Borrow) {
-    let value = option::extract(&mut self.value);
+    let value = self.value.extract();
     let id = object::id(&value);
 
     (value, Borrow {
@@ -200,7 +200,7 @@ Put an object and the Borrowassert!(object::id(&value) == obj, EWrongValue);
     assert!(self.id == ref, EWrongBorrow);
-    option::fill(&mut self.value, value);
+    self.value.fill(value);
 }
 
@@ -226,7 +226,7 @@ Unpack the Referent str
public fun destroy<T: key + store>(self: Referent<T>): T {
     let Referent { id: _, value } = self;
-    option::destroy_some(value)
+    value.destroy_some()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/clock.md b/crates/sui-framework/docs/sui-framework/clock.md index 418a9ab978b86..eb8aa686a6fcb 100644 --- a/crates/sui-framework/docs/sui-framework/clock.md +++ b/crates/sui-framework/docs/sui-framework/clock.md @@ -124,7 +124,7 @@ called exactly once, during genesis.
fun create(ctx: &TxContext) {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
 
     transfer::share_object(Clock {
         id: object::clock(),
@@ -161,7 +161,7 @@ called exactly once, during genesis.
     ctx: &TxContext,
 ) {
     // Validator will make a special system call with sender set as 0x0.
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
 
     clock.timestamp_ms = timestamp_ms
 }
diff --git a/crates/sui-framework/docs/sui-framework/coin.md b/crates/sui-framework/docs/sui-framework/coin.md
index b27d2b041c7ba..46217db22eff1 100644
--- a/crates/sui-framework/docs/sui-framework/coin.md
+++ b/crates/sui-framework/docs/sui-framework/coin.md
@@ -386,7 +386,7 @@ to different security guarantees (TreasuryCap can be created only once for a typ
 
 
public fun treasury_into_supply<T>(treasury: TreasuryCap<T>): Supply<T> {
     let TreasuryCap { id, total_supply } = treasury;
-    object::delete(id);
+    id.delete();
     total_supply
 }
 
@@ -462,7 +462,7 @@ Public getter for the coin's value
public fun value<T>(self: &Coin<T>): u64 {
-    balance::value(&self.balance)
+    self.balance.value()
 }
 
@@ -563,7 +563,7 @@ Destruct a Coin wrapper and keep the balance.
public fun into_balance<T>(coin: Coin<T>): Balance<T> {
     let Coin { id, balance } = coin;
-    object::delete(id);
+    id.delete();
     balance
 }
 
@@ -594,7 +594,7 @@ Aborts if value > bal ): Coin<T> { Coin { id: object::new(ctx), - balance: balance::split(balance, value) + balance: balance.split(value) } }
@@ -620,7 +620,7 @@ Put a Coin<T>public fun put<T>(balance: &mut Balance<T>, coin: Coin<T>) { - balance::join(balance, into_balance(coin)); + balance.join(into_balance(coin)); }
@@ -647,8 +647,8 @@ Aborts if c.value + self.value > U64_MAX
public entry fun join<T>(self: &mut Coin<T>, c: Coin<T>) {
     let Coin { id, balance } = c;
-    object::delete(id);
-    balance::join(&mut self.balance, balance);
+    id.delete();
+    self.balance.join(balance);
 }
 
@@ -707,11 +707,11 @@ Split coin self into n - 1 coins with equal balances. assert!(n > 0, EInvalidArg); assert!(n <= value(self), ENotEnough); - let mut vec = vector::empty<Coin<T>>(); + let mut vec = vector[]; let mut i = 0; let split_amount = value(self) / n; while (i < n - 1) { - vector::push_back(&mut vec, split(self, split_amount, ctx)); + vec.push_back(self.split(split_amount, ctx)); i = i + 1; }; vec @@ -766,8 +766,8 @@ Destroy a coin with value zero
public fun destroy_zero<T>(c: Coin<T>) {
     let Coin { id, balance } = c;
-    object::delete(id);
-    balance::destroy_zero(balance)
+    id.delete();
+    balance.destroy_zero()
 }
 
@@ -900,7 +900,7 @@ in cap accordingly. ): Coin<T> { Coin { id: object::new(ctx), - balance: balance::increase_supply(&mut cap.total_supply, value) + balance: cap.total_supply.increase_supply(value) } }
@@ -930,7 +930,7 @@ Aborts if value + cap.total_supply >= U64_MAX
public fun mint_balance<T>(
     cap: &mut TreasuryCap<T>, value: u64
 ): Balance<T> {
-    balance::increase_supply(&mut cap.total_supply, value)
+    cap.total_supply.increase_supply(value)
 }
 
@@ -957,8 +957,8 @@ accordingly.
public entry fun burn<T>(cap: &mut TreasuryCap<T>, c: Coin<T>): u64 {
     let Coin { id, balance } = c;
-    object::delete(id);
-    balance::decrease_supply(&mut cap.total_supply, balance)
+    id.delete();
+    cap.total_supply.decrease_supply(balance)
 }
 
@@ -990,7 +990,7 @@ from interacting with the specified coin type as an input to a transaction. _ctx: &mut TxContext ) { let `type` = - ascii::into_bytes(type_name::into_string(type_name::get_with_original_ids<T>())); + type_name::into_string(type_name::get_with_original_ids<T>()).into_bytes(); deny_list::add( deny_list, DENY_LIST_COIN_INDEX, @@ -1028,7 +1028,7 @@ Aborts with ENotFrozen if the address is not already in the list. _ctx: &mut TxContext ) { let `type` = - ascii::into_bytes(type_name::into_string(type_name::get_with_original_ids<T>())); + type_name::into_string(type_name::get_with_original_ids<T>()).into_bytes(); deny_list::remove( deny_list, DENY_LIST_COIN_INDEX, @@ -1066,13 +1066,8 @@ return false if given a non-coin type. let name = type_name::get_with_original_ids<T>(); if (type_name::is_primitive(&name)) return false; - let `type` = ascii::into_bytes(type_name::into_string(name)); - deny_list::contains( - freezer, - DENY_LIST_COIN_INDEX, - `type`, - addr, - ) + let `type` = type_name::into_string(name).into_bytes(); + freezer.contains(DENY_LIST_COIN_INDEX, `type`, addr) }
diff --git a/crates/sui-framework/docs/sui-framework/deny_list.md b/crates/sui-framework/docs/sui-framework/deny_list.md index 4132f74a82c53..db662a46e084a 100644 --- a/crates/sui-framework/docs/sui-framework/deny_list.md +++ b/crates/sui-framework/docs/sui-framework/deny_list.md @@ -168,7 +168,8 @@ the type specified is the type of the coin, not the coin type itself. For exampl `type`: vector<u8>, addr: address, ) { - per_type_list_add(bag::borrow_mut(&mut deny_list.lists, per_type_index), `type`, addr) + let bag_entry: &mut PerTypeList = &mut deny_list.lists[per_type_index]; + bag_entry.per_type_list_add(`type`, addr) }
@@ -196,18 +197,18 @@ the type specified is the type of the coin, not the coin type itself. For exampl `type`: vector<u8>, addr: address, ) { - if (!table::contains(&list.denied_addresses, `type`)) { - table::add(&mut list.denied_addresses, `type`, vec_set::empty()); + if (!list.denied_addresses.contains(`type`)) { + list.denied_addresses.add(`type`, vec_set::empty()); }; - let denied_addresses = table::borrow_mut(&mut list.denied_addresses, `type`); - let already_denied = vec_set::contains(denied_addresses, &addr); + let denied_addresses = &mut list.denied_addresses[`type`]; + let already_denied = denied_addresses.contains(&addr); if (already_denied) return; - vec_set::insert(denied_addresses, addr); - if (!table::contains(&list.denied_count, addr)) { - table::add(&mut list.denied_count, addr, 0); + denied_addresses.insert(addr); + if (!list.denied_count.contains(addr)) { + list.denied_count.add(addr, 0); }; - let denied_count = table::borrow_mut(&mut list.denied_count, addr); + let denied_count = &mut list.denied_count[addr]; *denied_count = *denied_count + 1; }
@@ -239,7 +240,7 @@ Aborts with vector<u8>, addr: address, ) { - per_type_list_remove(bag::borrow_mut(&mut deny_list.lists, per_type_index), `type`, addr) + per_type_list_remove(&mut deny_list.lists[per_type_index], `type`, addr) }
@@ -267,13 +268,13 @@ Aborts with vector<u8>, addr: address, ) { - let denied_addresses = table::borrow_mut(&mut list.denied_addresses, `type`); - assert!(vec_set::contains(denied_addresses, &addr), ENotDenied); - vec_set::remove(denied_addresses, &addr); - let denied_count = table::borrow_mut(&mut list.denied_count, addr); + let denied_addresses = &mut list.denied_addresses[`type`]; + assert!(denied_addresses.contains(&addr), ENotDenied); + denied_addresses.remove(&addr); + let denied_count = &mut list.denied_count[addr]; *denied_count = *denied_count - 1; if (*denied_count == 0) { - table::remove(&mut list.denied_count, addr); + list.denied_count.remove(addr); } }
@@ -304,7 +305,7 @@ Returns true iff the given address is denied for the given type. `type`: vector<u8>, addr: address, ): bool { - per_type_list_contains(bag::borrow(&deny_list.lists, per_type_index), `type`, addr) + per_type_list_contains(&deny_list.lists[per_type_index], `type`, addr) }
@@ -332,15 +333,15 @@ Returns true iff the given address is denied for the given type. `type`: vector<u8>, addr: address, ): bool { - if (!table::contains(&list.denied_count, addr)) return false; + if (!list.denied_count.contains(addr)) return false; - let denied_count = table::borrow(&list.denied_count, addr); + let denied_count = &list.denied_count[addr]; if (*denied_count == 0) return false; - if (!table::contains(&list.denied_addresses, `type`)) return false; + if (!list.denied_addresses.contains(`type`)) return false; - let denied_addresses = table::borrow(&list.denied_addresses, `type`); - vec_set::contains(denied_addresses, &addr) + let denied_addresses = &list.denied_addresses[`type`]; + denied_addresses.contains(&addr) }
@@ -366,10 +367,10 @@ via a system transaction.
fun create(ctx: &mut TxContext) {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
 
     let mut lists = bag::new(ctx);
-    bag::add(&mut lists, COIN_INDEX, per_type_list(ctx));
+    lists.add(COIN_INDEX, per_type_list(ctx));
     let deny_list_object = DenyList {
         id: object::sui_deny_list_object_id(),
         lists,
diff --git a/crates/sui-framework/docs/sui-framework/display.md b/crates/sui-framework/docs/sui-framework/display.md
index 36047148ddacb..67e06ac6babe8 100644
--- a/crates/sui-framework/docs/sui-framework/display.md
+++ b/crates/sui-framework/docs/sui-framework/display.md
@@ -250,13 +250,13 @@ Create a new Display object with a set of fields.
 
public fun new_with_fields<T: key>(
     pub: &Publisher, fields: vector<String>, values: vector<String>, ctx: &mut TxContext
 ): Display<T> {
-    let len = vector::length(&fields);
-    assert!(len == vector::length(&values), EVecLengthMismatch);
+    let len = fields.length();
+    assert!(len == values.length(), EVecLengthMismatch);
 
     let mut i = 0;
     let mut display = new<T>(pub, ctx);
     while (i < len) {
-        add_internal(&mut display, *vector::borrow(&fields, i), *vector::borrow(&values, i));
+        display.add_internal(fields[i], values[i]);
         i = i + 1;
     };
 
@@ -285,7 +285,7 @@ Create a new empty Display object and keep it.
 
 
 
entry public fun create_and_keep<T: key>(pub: &Publisher, ctx: &mut TxContext) {
-    transfer::public_transfer(new<T>(pub, ctx), sender(ctx))
+    transfer::public_transfer(new<T>(pub, ctx), ctx.sender())
 }
 
@@ -316,7 +316,7 @@ Manually bump the version and emit an event with the updated version's contents. event::emit(VersionUpdated<T> { version: display.version, fields: *&display.fields, - id: object::uid_to_inner(&display.id), + id: display.id.to_inner(), }) }
@@ -342,7 +342,7 @@ Sets a custom name field with the value.
entry public fun add<T: key>(self: &mut Display<T>, name: String, value: String) {
-    add_internal(self, name, value)
+    self.add_internal(name, value)
 }
 
@@ -369,12 +369,12 @@ Sets multiple fields with values.
entry public fun add_multiple<T: key>(
     self: &mut Display<T>, fields: vector<String>, values: vector<String>
 ) {
-    let len = vector::length(&fields);
-    assert!(len == vector::length(&values), EVecLengthMismatch);
+    let len = fields.length();
+    assert!(len == values.length(), EVecLengthMismatch);
 
     let mut i = 0;
     while (i < len) {
-        add_internal(self, *vector::borrow(&fields, i), *vector::borrow(&values, i));
+        self.add_internal(fields[i], values[i]);
         i = i + 1;
     };
 }
@@ -402,8 +402,8 @@ TODO (long run): version changes;
 
 
 
entry public fun edit<T: key>(self: &mut Display<T>, name: String, value: String) {
-    let (_, _) = vec_map::remove(&mut self.fields, &name);
-    add_internal(self, name, value)
+    let (_, _) = self.fields.remove(&name);
+    self.add_internal(name, value)
 }
 
@@ -428,7 +428,7 @@ Remove the key from the Display.
entry public fun remove<T: key>(self: &mut Display<T>, name: String) {
-    vec_map::remove(&mut self.fields, &name);
+    self.fields.remove(&name);
 }
 
@@ -453,7 +453,7 @@ Authorization check; can be performed externally to implement protection rules f
public fun is_authorized<T: key>(pub: &Publisher): bool {
-    from_package<T>(pub)
+    pub.from_package<T>()
 }
 
@@ -531,7 +531,7 @@ Internal function to create a new let uid = object::new(ctx); event::emit(DisplayCreated<T> { - id: object::uid_to_inner(&uid) + id: uid.to_inner() }); Display { @@ -563,7 +563,7 @@ Private method for inserting fields without security checks.
fun add_internal<T: key>(display: &mut Display<T>, name: String, value: String) {
-    vec_map::insert(&mut display.fields, name, value)
+    display.fields.insert(name, value)
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/dynamic_field.md b/crates/sui-framework/docs/sui-framework/dynamic_field.md index b698415781eec..2319331516030 100644 --- a/crates/sui-framework/docs/sui-framework/dynamic_field.md +++ b/crates/sui-framework/docs/sui-framework/dynamic_field.md @@ -157,7 +157,7 @@ Aborts with object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); assert!(!has_child_object(object_addr, hash), EFieldAlreadyExists); let field = Field { @@ -196,7 +196,7 @@ type. object: &UID, name: Name, ): &Value { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let field = borrow_child_object<Field<Name, Value>>(object, hash); &field.value @@ -230,7 +230,7 @@ type. object: &mut UID, name: Name, ): &mut Value { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let field = borrow_child_object_mut<Field<Name, Value>>(object, hash); &mut field.value @@ -265,10 +265,10 @@ type. object: &mut UID, name: Name, ): Value { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let Field { id, name: _, value } = remove_child_object<Field<Name, Value>>(object_addr, hash); - object::delete(id); + id.delete(); value }
@@ -298,7 +298,7 @@ Returns true if and only if the object: &UID, name: Name, ): bool { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); has_child_object(object_addr, hash) } @@ -361,7 +361,7 @@ Returns true if and only if the object: &UID, name: Name, ): bool { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); has_child_object_with_ty<Field<Name, Value>>(object_addr, hash) } @@ -390,10 +390,10 @@ Returns true if and only if the object: &UID, name: Name, ): (&UID, address) { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let Field { id, name: _, value } = borrow_child_object<Field<Name, ID>>(object, hash); - (id, object::id_to_address(value)) + (id, value.to_address()) }
@@ -420,10 +420,10 @@ Returns true if and only if the object: &mut UID, name: Name, ): (&mut UID, address) { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let Field { id, name: _, value } = borrow_child_object_mut<Field<Name, ID>>(object, hash); - (id, object::id_to_address(value)) + (id, value.to_address()) }
diff --git a/crates/sui-framework/docs/sui-framework/dynamic_object_field.md b/crates/sui-framework/docs/sui-framework/dynamic_object_field.md index b96d0d571e3cd..df9fd9455128f 100644 --- a/crates/sui-framework/docs/sui-framework/dynamic_object_field.md +++ b/crates/sui-framework/docs/sui-framework/dynamic_object_field.md @@ -80,7 +80,7 @@ Aborts with EFieldAlreadyExists if the object already has that fiel let id = object::id(&value); field::add(object, key, id); let (field, _) = field::field_info<Wrapper<Name>>(object, key); - add_child_object(object::uid_to_address(field), value); + add_child_object(field.to_address(), value); }
@@ -180,7 +180,7 @@ specified type. ): Value { let key = Wrapper { name }; let (field, value_id) = field::field_info<Wrapper<Name>>(object, key); - let value = remove_child_object<Value>(object::uid_to_address(field), value_id); + let value = remove_child_object<Value>(field.to_address(), value_id); field::remove<Wrapper<Name>, ID>(object, key); value } @@ -244,7 +244,7 @@ Returns true if and only if the Wrapper { name }; if (!field::exists_with_type<Wrapper<Name>, ID>(object, key)) return false; let (field, value_id) = field::field_info<Wrapper<Name>>(object, key); - field::has_child_object_with_ty<Value>(object::uid_to_address(field), value_id) + field::has_child_object_with_ty<Value>(field.to_address(), value_id) }
@@ -275,8 +275,8 @@ Returns none otherwise ): Option<ID> { let key = Wrapper { name }; if (!field::exists_with_type<Wrapper<Name>, ID>(object, key)) return option::none(); - let (_field, value_id) = field::field_info<Wrapper<Name>>(object, key); - option::some(object::id_from_address(value_id)) + let (_field, value_addr) = field::field_info<Wrapper<Name>>(object, key); + option::some(value_addr.to_id()) }
diff --git a/crates/sui-framework/docs/sui-framework/groth16.md b/crates/sui-framework/docs/sui-framework/groth16.md index a56f0ba004349..026332fd5fa9d 100644 --- a/crates/sui-framework/docs/sui-framework/groth16.md +++ b/crates/sui-framework/docs/sui-framework/groth16.md @@ -282,12 +282,12 @@ Returns bytes of the four components of the pvk_to_bytes(pvk: PreparedVerifyingKey): vector<vector<u8>> { - let mut res = vector::empty(); - vector::push_back(&mut res, pvk.vk_gamma_abc_g1_bytes); - vector::push_back(&mut res, pvk.alpha_g1_beta_g2_bytes); - vector::push_back(&mut res, pvk.gamma_g2_neg_pc_bytes); - vector::push_back(&mut res, pvk.delta_g2_neg_pc_bytes); - res + vector[ + pvk.vk_gamma_abc_g1_bytes, + pvk.alpha_g1_beta_g2_bytes, + pvk.gamma_g2_neg_pc_bytes, + pvk.delta_g2_neg_pc_bytes, + ] }
diff --git a/crates/sui-framework/docs/sui-framework/group_ops.md b/crates/sui-framework/docs/sui-framework/group_ops.md index 44e2edf23a504..c38c0f8b6836f 100644 --- a/crates/sui-framework/docs/sui-framework/group_ops.md +++ b/crates/sui-framework/docs/sui-framework/group_ops.md @@ -157,7 +157,7 @@ Generic Move and native functions for group operations. -
public(friend) fun from_bytes<G>(type: u8, bytes: &vector<u8>, is_trusted: bool): group_ops::Element<G>
+
public(friend) fun from_bytes<G>(type_: u8, bytes: &vector<u8>, is_trusted: bool): group_ops::Element<G>
 
@@ -166,8 +166,8 @@ Generic Move and native functions for group operations. Implementation -
public(package) fun from_bytes<G>(`type`: u8, bytes: &vector<u8>, is_trusted: bool): Element<G> {
-    assert!(is_trusted || internal_validate(`type`, bytes), EInvalidInput);
+
public(package) fun from_bytes<G>(type_: u8, bytes: &vector<u8>, is_trusted: bool): Element<G> {
+    assert!(is_trusted || internal_validate(type_, bytes), EInvalidInput);
     Element<G> { bytes: *bytes }
 }
 
@@ -182,7 +182,7 @@ Generic Move and native functions for group operations. -
public(friend) fun add<G>(type: u8, e1: &group_ops::Element<G>, e2: &group_ops::Element<G>): group_ops::Element<G>
+
public(friend) fun add<G>(type_: u8, e1: &group_ops::Element<G>, e2: &group_ops::Element<G>): group_ops::Element<G>
 
@@ -191,8 +191,8 @@ Generic Move and native functions for group operations. Implementation -
public(package) fun add<G>(`type`: u8, e1: &Element<G>, e2: &Element<G>): Element<G> {
-    Element<G> { bytes: internal_add(`type`, &e1.bytes, &e2.bytes) }
+
public(package) fun add<G>(type_: u8, e1: &Element<G>, e2: &Element<G>): Element<G> {
+    Element<G> { bytes: internal_add(type_, &e1.bytes, &e2.bytes) }
 }
 
@@ -206,7 +206,7 @@ Generic Move and native functions for group operations. -
public(friend) fun sub<G>(type: u8, e1: &group_ops::Element<G>, e2: &group_ops::Element<G>): group_ops::Element<G>
+
public(friend) fun sub<G>(type_: u8, e1: &group_ops::Element<G>, e2: &group_ops::Element<G>): group_ops::Element<G>
 
@@ -215,8 +215,8 @@ Generic Move and native functions for group operations. Implementation -
public(package) fun sub<G>(`type`: u8, e1: &Element<G>, e2: &Element<G>): Element<G> {
-    Element<G> { bytes: internal_sub(`type`, &e1.bytes, &e2.bytes) }
+
public(package) fun sub<G>(type_: u8, e1: &Element<G>, e2: &Element<G>): Element<G> {
+    Element<G> { bytes: internal_sub(type_, &e1.bytes, &e2.bytes) }
 }
 
@@ -230,7 +230,7 @@ Generic Move and native functions for group operations. -
public(friend) fun mul<S, G>(type: u8, scalar: &group_ops::Element<S>, e: &group_ops::Element<G>): group_ops::Element<G>
+
public(friend) fun mul<S, G>(type_: u8, scalar: &group_ops::Element<S>, e: &group_ops::Element<G>): group_ops::Element<G>
 
@@ -239,8 +239,8 @@ Generic Move and native functions for group operations. Implementation -
public(package) fun mul<S, G>(`type`: u8, scalar: &Element<S>, e: &Element<G>): Element<G> {
-    Element<G> { bytes: internal_mul(`type`, &scalar.bytes, &e.bytes) }
+
public(package) fun mul<S, G>(type_: u8, scalar: &Element<S>, e: &Element<G>): Element<G> {
+    Element<G> { bytes: internal_mul(type_, &scalar.bytes, &e.bytes) }
 }
 
@@ -255,7 +255,7 @@ Generic Move and native functions for group operations. Fails if scalar = 0. Else returns 1/scalar * e. -
public(friend) fun div<S, G>(type: u8, scalar: &group_ops::Element<S>, e: &group_ops::Element<G>): group_ops::Element<G>
+
public(friend) fun div<S, G>(type_: u8, scalar: &group_ops::Element<S>, e: &group_ops::Element<G>): group_ops::Element<G>
 
@@ -264,8 +264,8 @@ Fails if scalar = 0. Else returns 1/scalar * e. Implementation -
public(package) fun div<S, G>(`type`: u8, scalar: &Element<S>, e: &Element<G>): Element<G> {
-    Element<G> { bytes: internal_div(`type`, &scalar.bytes, &e.bytes) }
+
public(package) fun div<S, G>(type_: u8, scalar: &Element<S>, e: &Element<G>): Element<G> {
+    Element<G> { bytes: internal_div(type_, &scalar.bytes, &e.bytes) }
 }
 
@@ -279,7 +279,7 @@ Fails if scalar = 0. Else returns 1/scalar * e. -
public(friend) fun hash_to<G>(type: u8, m: &vector<u8>): group_ops::Element<G>
+
public(friend) fun hash_to<G>(type_: u8, m: &vector<u8>): group_ops::Element<G>
 
@@ -288,8 +288,8 @@ Fails if scalar = 0. Else returns 1/scalar * e. Implementation -
public(package) fun hash_to<G>(`type`: u8, m: &vector<u8>): Element<G> {
-    Element<G> { bytes: internal_hash_to(`type`, m) }
+
public(package) fun hash_to<G>(type_: u8, m: &vector<u8>): Element<G> {
+    Element<G> { bytes: internal_hash_to(type_, m) }
 }
 
@@ -304,7 +304,7 @@ Fails if scalar = 0. Else returns 1/scalar * e. Aborts with EInputTooLong if the vectors are too long. -
public(friend) fun multi_scalar_multiplication<S, G>(type: u8, scalars: &vector<group_ops::Element<S>>, elements: &vector<group_ops::Element<G>>): group_ops::Element<G>
+
public(friend) fun multi_scalar_multiplication<S, G>(type_: u8, scalars: &vector<group_ops::Element<S>>, elements: &vector<group_ops::Element<G>>): group_ops::Element<G>
 
@@ -313,21 +313,21 @@ Aborts with EInputTooLo Implementation -
public(package) fun multi_scalar_multiplication<S, G>(`type`: u8, scalars: &vector<Element<S>>, elements: &vector<Element<G>>): Element<G> {
-    assert!(vector::length(scalars) > 0, EInvalidInput);
-    assert!(vector::length(scalars) == vector::length(elements), EInvalidInput);
+
public(package) fun multi_scalar_multiplication<S, G>(type_: u8, scalars: &vector<Element<S>>, elements: &vector<Element<G>>): Element<G> {
+    assert!(scalars.length() > 0, EInvalidInput);
+    assert!(scalars.length() == elements.length(), EInvalidInput);
 
-    let mut scalars_bytes = vector::empty<u8>();
-    let mut elements_bytes = vector::empty<u8>();
+    let mut scalars_bytes: vector<u8> = vector[];
+    let mut elements_bytes: vector<u8>  = vector[];
     let mut i = 0;
-    while (i < vector::length(scalars)) {
-        let scalar_vec = *vector::borrow(scalars, i);
-        vector::append(&mut scalars_bytes, scalar_vec.bytes);
-        let element_vec = *vector::borrow(elements, i);
-        vector::append(&mut elements_bytes, element_vec.bytes);
+    while (i < scalars.length()) {
+        let scalar_vec = scalars[i];
+        scalars_bytes.append(scalar_vec.bytes);
+        let element_vec = elements[i];
+        elements_bytes.append(element_vec.bytes);
         i = i + 1;
     };
-    Element<G> { bytes: internal_multi_scalar_mul(`type`, &scalars_bytes, &elements_bytes) }
+    Element<G> { bytes: internal_multi_scalar_mul(type_, &scalars_bytes, &elements_bytes) }
 }
 
@@ -341,7 +341,7 @@ Aborts with EInputTooLo -
public(friend) fun pairing<G1, G2, G3>(type: u8, e1: &group_ops::Element<G1>, e2: &group_ops::Element<G2>): group_ops::Element<G3>
+
public(friend) fun pairing<G1, G2, G3>(type_: u8, e1: &group_ops::Element<G1>, e2: &group_ops::Element<G2>): group_ops::Element<G3>
 
@@ -350,8 +350,8 @@ Aborts with EInputTooLo Implementation -
public(package) fun pairing<G1, G2, G3>(`type`: u8, e1: &Element<G1>, e2: &Element<G2>): Element<G3> {
-    Element<G3> { bytes: internal_pairing(`type`, &e1.bytes, &e2.bytes) }
+
public(package) fun pairing<G1, G2, G3>(type_: u8, e1: &Element<G1>, e2: &Element<G2>): Element<G3> {
+    Element<G3> { bytes: internal_pairing(type_, &e1.bytes, &e2.bytes) }
 }
 
@@ -365,7 +365,7 @@ Aborts with EInputTooLo -
fun internal_validate(type: u8, bytes: &vector<u8>): bool
+
fun internal_validate(type_: u8, bytes: &vector<u8>): bool
 
@@ -374,7 +374,7 @@ Aborts with EInputTooLo Implementation -
native fun internal_validate(`type`: u8, bytes: &vector<u8>): bool;
+
native fun internal_validate(type_: u8, bytes: &vector<u8>): bool;
 
@@ -387,7 +387,7 @@ Aborts with EInputTooLo -
fun internal_add(type: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
+
fun internal_add(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
 
@@ -396,7 +396,7 @@ Aborts with EInputTooLo Implementation -
native fun internal_add(`type`: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
+
native fun internal_add(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
 
@@ -409,7 +409,7 @@ Aborts with EInputTooLo -
fun internal_sub(type: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
+
fun internal_sub(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
 
@@ -418,7 +418,7 @@ Aborts with EInputTooLo Implementation -
native fun internal_sub(`type`: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
+
native fun internal_sub(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
 
@@ -431,7 +431,7 @@ Aborts with EInputTooLo -
fun internal_mul(type: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
+
fun internal_mul(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
 
@@ -440,7 +440,7 @@ Aborts with EInputTooLo Implementation -
native fun internal_mul(`type`: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
+
native fun internal_mul(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
 
@@ -453,7 +453,7 @@ Aborts with EInputTooLo -
fun internal_div(type: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
+
fun internal_div(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
 
@@ -462,7 +462,7 @@ Aborts with EInputTooLo Implementation -
native fun internal_div(`type`: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
+
native fun internal_div(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
 
@@ -475,7 +475,7 @@ Aborts with EInputTooLo -
fun internal_hash_to(type: u8, m: &vector<u8>): vector<u8>
+
fun internal_hash_to(type_: u8, m: &vector<u8>): vector<u8>
 
@@ -484,7 +484,7 @@ Aborts with EInputTooLo Implementation -
native fun internal_hash_to(`type`: u8, m: &vector<u8>): vector<u8>;
+
native fun internal_hash_to(type_: u8, m: &vector<u8>): vector<u8>;
 
@@ -497,7 +497,7 @@ Aborts with EInputTooLo -
fun internal_multi_scalar_mul(type: u8, scalars: &vector<u8>, elements: &vector<u8>): vector<u8>
+
fun internal_multi_scalar_mul(type_: u8, scalars: &vector<u8>, elements: &vector<u8>): vector<u8>
 
@@ -506,7 +506,7 @@ Aborts with EInputTooLo Implementation -
native fun internal_multi_scalar_mul(`type`: u8, scalars: &vector<u8>, elements: &vector<u8>): vector<u8>;
+
native fun internal_multi_scalar_mul(type_: u8, scalars: &vector<u8>, elements: &vector<u8>): vector<u8>;
 
@@ -519,7 +519,7 @@ Aborts with EInputTooLo -
fun internal_pairing(type: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
+
fun internal_pairing(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>
 
@@ -528,7 +528,7 @@ Aborts with EInputTooLo Implementation -
native fun internal_pairing(`type`:u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
+
native fun internal_pairing(type_: u8, e1: &vector<u8>, e2: &vector<u8>): vector<u8>;
 
@@ -551,13 +551,13 @@ Aborts with EInputTooLo
public(package) fun set_as_prefix(x: u64, big_endian: bool, buffer: &mut vector<u8>) {
-    let buffer_len = vector::length(buffer);
+    let buffer_len = buffer.length();
     assert!(buffer_len > 7, EInvalidBufferLength);
     let x_as_bytes = bcs::to_bytes(&x); // little endian
     let mut i = 0;
     while (i < 8) {
         let position = if (big_endian) { buffer_len - i - 1 } else { i };
-        *vector::borrow_mut(buffer, position) = *vector::borrow(&x_as_bytes, i);
+        *(&mut buffer[position]) = x_as_bytes[i];
         i = i + 1;
     };
 }
diff --git a/crates/sui-framework/docs/sui-framework/hex.md b/crates/sui-framework/docs/sui-framework/hex.md
index c38dd6a554fc7..cbe643128c72d 100644
--- a/crates/sui-framework/docs/sui-framework/hex.md
+++ b/crates/sui-framework/docs/sui-framework/hex.md
@@ -67,13 +67,10 @@ Encode bytes in lowercase hex
 
 
 
public fun encode(bytes: vector<u8>): vector<u8> {
-    let (mut i, mut r, l) = (0, vector[], vector::length(&bytes));
+    let (mut i, mut r, l) = (0, vector[], bytes.length());
     let hex_vector = HEX;
     while (i < l) {
-        vector::append(
-            &mut r,
-            *vector::borrow(&hex_vector, (*vector::borrow(&bytes, i) as u64))
-        );
+        r.append(hex_vector[(bytes[i] as u64)]);
         i = i + 1;
     };
     r
@@ -106,12 +103,11 @@ Aborts if the hex string contains non-valid hex characters (valid characters are
 
 
 
public fun decode(hex: vector<u8>): vector<u8> {
-    let (mut i, mut r, l) = (0, vector[], vector::length(&hex));
+    let (mut i, mut r, l) = (0, vector[], hex.length());
     assert!(l % 2 == 0, EInvalidHexLength);
     while (i < l) {
-        let decimal = (decode_byte(*vector::borrow(&hex, i)) * 16) +
-                      decode_byte(*vector::borrow(&hex, i + 1));
-        vector::push_back(&mut r, decimal);
+        let decimal = decode_byte(hex[i]) * 16 + decode_byte(hex[i + 1]);
+        r.push_back(decimal);
         i = i + 2;
     };
     r
diff --git a/crates/sui-framework/docs/sui-framework/kiosk.md b/crates/sui-framework/docs/sui-framework/kiosk.md
index 75cc5a638b687..bdd93d907f6cc 100644
--- a/crates/sui-framework/docs/sui-framework/kiosk.md
+++ b/crates/sui-framework/docs/sui-framework/kiosk.md
@@ -730,7 +730,7 @@ Creates a new Kiosk in a default configuration: sender receives the
 
 
entry fun default(ctx: &mut TxContext) {
     let (kiosk, cap) = new(ctx);
-    sui::transfer::transfer(cap, sender(ctx));
+    sui::transfer::transfer(cap, ctx.sender());
     sui::transfer::share_object(kiosk);
 }
 
@@ -759,7 +759,7 @@ Creates a new Kiosk with a m let kiosk = Kiosk { id: object::new(ctx), profits: balance::zero(), - owner: sender(ctx), + owner: ctx.sender(), item_count: 0, allow_extensions: false }; @@ -801,13 +801,13 @@ case where there's no items inside and a Kiosk { id, profits, owner: _, item_count, allow_extensions: _ } = self; let KioskOwnerCap { id: cap_id, `for` } = cap; - assert!(object::uid_to_inner(&id) == `for`, ENotOwner); + assert!(id.to_inner() == `for`, ENotOwner); assert!(item_count == 0, ENotEmpty); - object::delete(cap_id); - object::delete(id); + cap_id.delete(); + id.delete(); - coin::from_balance(profits, ctx) + profits.into_coin(ctx) }
@@ -837,8 +837,8 @@ in a third party module.
public fun set_owner(
     self: &mut Kiosk, cap: &KioskOwnerCap, ctx: &TxContext
 ) {
-    assert!(has_access(self, cap), ENotOwner);
-    self.owner = sender(ctx);
+    assert!(self.has_access(cap), ENotOwner);
+    self.owner = ctx.sender();
 }
 
@@ -866,7 +866,7 @@ implementing a custom logic that relies on the set_owner_custom( self: &mut Kiosk, cap: &KioskOwnerCap, owner: address ) { - assert!(has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); self.owner = owner }
@@ -895,8 +895,8 @@ Performs an authorization check to make sure only owner can do that.
public fun place<T: key + store>(
     self: &mut Kiosk, cap: &KioskOwnerCap, item: T
 ) {
-    assert!(has_access(self, cap), ENotOwner);
-    place_internal(self, item)
+    assert!(self.has_access(cap), ENotOwner);
+    self.place_internal(item)
 }
 
@@ -928,8 +928,8 @@ and the item can be sold, otherwise the asset might be locked forever.
public fun lock<T: key + store>(
     self: &mut Kiosk, cap: &KioskOwnerCap, _policy: &TransferPolicy<T>, item: T
 ) {
-    assert!(has_access(self, cap), ENotOwner);
-    lock_internal(self, item)
+    assert!(self.has_access(cap), ENotOwner);
+    self.lock_internal(item)
 }
 
@@ -957,10 +957,10 @@ Performs an authorization check to make sure only owner can do that.
public fun take<T: key + store>(
     self: &mut Kiosk, cap: &KioskOwnerCap, id: ID
 ): T {
-    assert!(has_access(self, cap), ENotOwner);
-    assert!(!is_locked(self, id), EItemLocked);
-    assert!(!is_listed_exclusively(self, id), EListedExclusively);
-    assert!(has_item(self, id), EItemNotFound);
+    assert!(self.has_access(cap), ENotOwner);
+    assert!(!self.is_locked(id), EItemLocked);
+    assert!(!self.is_listed_exclusively(id), EListedExclusively);
+    assert!(self.has_item(id), EItemNotFound);
 
     self.item_count = self.item_count - 1;
     df::remove_if_exists<Listing, u64>(&mut self.id, Listing { id, is_exclusive: false });
@@ -992,9 +992,9 @@ Performs an authorization check to make sure only owner can sell.
 
public fun list<T: key + store>(
     self: &mut Kiosk, cap: &KioskOwnerCap, id: ID, price: u64
 ) {
-    assert!(has_access(self, cap), ENotOwner);
-    assert!(has_item_with_type<T>(self, id), EItemNotFound);
-    assert!(!is_listed_exclusively(self, id), EListedExclusively);
+    assert!(self.has_access(cap), ENotOwner);
+    assert!(self.has_item_with_type<T>(id), EItemNotFound);
+    assert!(!self.is_listed_exclusively(id), EListedExclusively);
 
     df::add(&mut self.id, Listing { id, is_exclusive: false }, price);
     event::emit(ItemListed<T> { kiosk: object::id(self), id, price })
@@ -1025,8 +1025,8 @@ Calls place and list together - simplifies the flow.
     self: &mut Kiosk, cap: &KioskOwnerCap, item: T, price: u64
 ) {
     let id = object::id(&item);
-    place(self, cap, item);
-    list<T>(self, cap, id, price)
+    self.place(cap, item);
+    self.list<T>(cap, id, price)
 }
 
@@ -1054,10 +1054,10 @@ user Kiosk. Can only be performed by the owner of the delist<T: key + store>( self: &mut Kiosk, cap: &KioskOwnerCap, id: ID ) { - assert!(has_access(self, cap), ENotOwner); - assert!(has_item_with_type<T>(self, id), EItemNotFound); - assert!(!is_listed_exclusively(self, id), EListedExclusively); - assert!(is_listed(self, id), ENotListed); + assert!(self.has_access(cap), ENotOwner); + assert!(self.has_item_with_type<T>(id), EItemNotFound); + assert!(!self.is_listed_exclusively(id), EListedExclusively); + assert!(self.is_listed(id), ENotListed); df::remove<Listing, u64>(&mut self.id, Listing { id, is_exclusive: false }); event::emit(ItemDelisted<T> { kiosk: object::id(self), id }) @@ -1097,7 +1097,7 @@ finalized. let inner = dof::remove<Item, T>(&mut self.id, Item { id }); self.item_count = self.item_count - 1; - assert!(price == coin::value(&payment), EIncorrectAmount); + assert!(price == payment.value(), EIncorrectAmount); df::remove_if_exists<Lock, bool>(&mut self.id, Lock { id }); coin::put(&mut self.profits, payment); @@ -1131,9 +1131,9 @@ for any price equal or higher than the min_price.
public fun list_with_purchase_cap<T: key + store>(
     self: &mut Kiosk, cap: &KioskOwnerCap, id: ID, min_price: u64, ctx: &mut TxContext
 ): PurchaseCap<T> {
-    assert!(has_access(self, cap), ENotOwner);
-    assert!(has_item_with_type<T>(self, id), EItemNotFound);
-    assert!(!is_listed(self, id), EAlreadyListed);
+    assert!(self.has_access(cap), ENotOwner);
+    assert!(self.has_item_with_type<T>(id), EItemNotFound);
+    assert!(!self.is_listed(id), EAlreadyListed);
 
     df::add(&mut self.id, Listing { id, is_exclusive: true }, min_price);
 
@@ -1171,10 +1171,10 @@ as the price for the listing making sure it's no less than min_amountmut Kiosk, purchase_cap: PurchaseCap<T>, payment: Coin<SUI>
 ): (T, TransferRequest<T>) {
     let PurchaseCap { id, item_id, kiosk_id, min_price } = purchase_cap;
-    object::delete(id);
+    id.delete();
 
     let id = item_id;
-    let paid = coin::value(&payment);
+    let paid = payment.value();
     assert!(paid >= min_price, EIncorrectAmount);
     assert!(object::id(self) == kiosk_id, EWrongKiosk);
 
@@ -1217,7 +1217,7 @@ allow the item for taking. Can only be returned to its object::id(self) == kiosk_id, EWrongKiosk);
     df::remove<Listing, u64>(&mut self.id, Listing { id: item_id, is_exclusive: true });
-    object::delete(id)
+    id.delete()
 }
 
@@ -1244,14 +1244,14 @@ Withdraw profits from the Kiosk.
public fun withdraw(
     self: &mut Kiosk, cap: &KioskOwnerCap, amount: Option<u64>, ctx: &mut TxContext
 ): Coin<SUI> {
-    assert!(has_access(self, cap), ENotOwner);
+    assert!(self.has_access(cap), ENotOwner);
 
-    let amount = if (option::is_some(&amount)) {
-        let amt = option::destroy_some(amount);
-        assert!(amt <= balance::value(&self.profits), ENotEnough);
+    let amount = if (amount.is_some()) {
+        let amt = amount.destroy_some();
+        assert!(amt <= self.profits.value(), ENotEnough);
         amt
     } else {
-        balance::value(&self.profits)
+        self.profits.value()
     };
 
     coin::take(&mut self.profits, amount, ctx)
@@ -1280,7 +1280,7 @@ Internal: "lock" an item disabling the take action.
 
 
public(package) fun lock_internal<T: key + store>(self: &mut Kiosk, item: T) {
     df::add(&mut self.id, Lock { id: object::id(&item) }, true);
-    place_internal(self, item)
+    self.place_internal(item)
 }
 
@@ -1434,7 +1434,7 @@ Check whether an item is listed (exclusively or non exclusively).
public fun is_listed(self: &Kiosk, id: ID): bool {
     df::exists_(&self.id, Listing { id, is_exclusive: false })
-    || is_listed_exclusively(self, id)
+    || self.is_listed_exclusively(id)
 }
 
@@ -1511,7 +1511,7 @@ Access the UID using the uid_mut_as_owner( self: &mut Kiosk, cap: &KioskOwnerCap ): &mut UID { - assert!(has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); &mut self.id }
@@ -1541,7 +1541,7 @@ setting.
public fun set_allow_extensions(
     self: &mut Kiosk, cap: &KioskOwnerCap, allow_extensions: bool
 ) {
-    assert!(has_access(self, cap), ENotOwner);
+    assert!(self.has_access(cap), ENotOwner);
     self.allow_extensions = allow_extensions;
 }
 
@@ -1673,7 +1673,7 @@ Get the amount of profits collected by selling items.
public fun profits_amount(self: &Kiosk): u64 {
-    balance::value(&self.profits)
+    self.profits.value()
 }
 
@@ -1698,7 +1698,7 @@ Get mutable access to profits - owner only action.
public fun profits_mut(self: &mut Kiosk, cap: &KioskOwnerCap): &mut Balance<SUI> {
-    assert!(has_access(self, cap), ENotOwner);
+    assert!(self.has_access(cap), ENotOwner);
     &mut self.profits
 }
 
@@ -1728,7 +1728,7 @@ at any time. self: &Kiosk, cap: &KioskOwnerCap, id: ID ): &T { assert!(object::id(self) == cap.`for`, ENotOwner); - assert!(has_item(self, id), EItemNotFound); + assert!(self.has_item(id), EItemNotFound); dof::borrow(&self.id, Item { id }) } @@ -1758,9 +1758,9 @@ Item can be borrow_muted only if it's not is_listed.
public fun borrow_mut<T: key + store>(
     self: &mut Kiosk, cap: &KioskOwnerCap, id: ID
 ): &mut T {
-    assert!(has_access(self, cap), ENotOwner);
-    assert!(has_item(self, id), EItemNotFound);
-    assert!(!is_listed(self, id), EItemIsListed);
+    assert!(self.has_access(cap), ENotOwner);
+    assert!(self.has_item(id), EItemNotFound);
+    assert!(!self.is_listed(id), EItemIsListed);
 
     dof::borrow_mut(&mut self.id, Item { id })
 }
@@ -1790,9 +1790,9 @@ Item can be borrow_val-ed only if it's not is_listed.
 
public fun borrow_val<T: key + store>(
     self: &mut Kiosk, cap: &KioskOwnerCap, id: ID
 ): (T, Borrow) {
-    assert!(has_access(self, cap), ENotOwner);
-    assert!(has_item(self, id), EItemNotFound);
-    assert!(!is_listed(self, id), EItemIsListed);
+    assert!(self.has_access(cap), ENotOwner);
+    assert!(self.has_item(id), EItemNotFound);
+    assert!(!self.is_listed(id), EItemIsListed);
 
     (
         dof::remove(&mut self.id, Item { id }),
diff --git a/crates/sui-framework/docs/sui-framework/kiosk_extension.md b/crates/sui-framework/docs/sui-framework/kiosk_extension.md
index f354555cbc459..92bcff35ba845 100644
--- a/crates/sui-framework/docs/sui-framework/kiosk_extension.md
+++ b/crates/sui-framework/docs/sui-framework/kiosk_extension.md
@@ -258,9 +258,9 @@ permissions in the custom add call.
     permissions: u128,
     ctx: &mut TxContext
 ) {
-    assert!(kiosk::has_access(self, cap), ENotOwner);
+    assert!(self.has_access(cap), ENotOwner);
     df::add(
-        kiosk::uid_mut_as_owner(self, cap),
+        self.uid_mut_as_owner(cap),
         ExtensionKey<Ext> {},
         Extension {
             storage: bag::new(ctx),
@@ -297,7 +297,7 @@ The storage is still available to the extension (until it's removed).
     self: &mut Kiosk,
     cap: &KioskOwnerCap,
 ) {
-    assert!(kiosk::has_access(self, cap), ENotOwner);
+    assert!(self.has_access(cap), ENotOwner);
     assert!(is_installed<Ext>(self), EExtensionNotInstalled);
     extension_mut<Ext>(self).is_enabled = false;
 }
@@ -329,7 +329,7 @@ owner can disable them via disable call.
     self: &mut Kiosk,
     cap: &KioskOwnerCap,
 ) {
-    assert!(kiosk::has_access(self, cap), ENotOwner);
+    assert!(self.has_access(cap), ENotOwner);
     assert!(is_installed<Ext>(self), EExtensionNotInstalled);
     extension_mut<Ext>(self).is_enabled = true;
 }
@@ -359,16 +359,16 @@ the extension storage must be empty for the transaction to succeed.
 
public fun remove<Ext: drop>(
     self: &mut Kiosk, cap: &KioskOwnerCap
 ) {
-    assert!(kiosk::has_access(self, cap), ENotOwner);
+    assert!(self.has_access(cap), ENotOwner);
     assert!(is_installed<Ext>(self), EExtensionNotInstalled);
 
     let Extension {
         storage,
         permissions: _,
         is_enabled: _,
-    } = df::remove(kiosk::uid_mut_as_owner(self, cap), ExtensionKey<Ext> {});
+    } = df::remove(self.uid_mut_as_owner(cap), ExtensionKey<Ext> {});
 
-    bag::destroy_empty(storage);
+    storage.destroy_empty();
 }
 
@@ -471,7 +471,7 @@ requires a TransferPolicy for the placed type to exist. assert!(is_installed<Ext>(self), EExtensionNotInstalled); assert!(can_place<Ext>(self) || can_lock<Ext>(self), EExtensionNotAllowed); - kiosk::place_internal(self, item) + self.place_internal(item) }
@@ -502,7 +502,7 @@ authorized extension. The extension must have the lock permission. assert!(is_installed<Ext>(self), EExtensionNotInstalled); assert!(can_lock<Ext>(self), EExtensionNotAllowed); - kiosk::lock_internal(self, item) + self.lock_internal(item) }
@@ -527,7 +527,7 @@ Check whether an extension of type Ext is installed.
public fun is_installed<Ext: drop>(self: &Kiosk): bool {
-    df::exists_(kiosk::uid(self), ExtensionKey<Ext> {})
+    df::exists_(self.uid(), ExtensionKey<Ext> {})
 }
 
@@ -628,7 +628,7 @@ Internal: get a read-only access to the Extension.
fun extension<Ext: drop>(self: &Kiosk): &Extension {
-    df::borrow(kiosk::uid(self), ExtensionKey<Ext> {})
+    df::borrow(self.uid(), ExtensionKey<Ext> {})
 }
 
@@ -653,7 +653,7 @@ Internal: get a mutable access to the Extension.
fun extension_mut<Ext: drop>(self: &mut Kiosk): &mut Extension {
-    df::borrow_mut(kiosk::uid_mut_internal(self), ExtensionKey<Ext> {})
+    df::borrow_mut(self.uid_mut_internal(), ExtensionKey<Ext> {})
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/linked_table.md b/crates/sui-framework/docs/sui-framework/linked_table.md index bf62d5e08e2a1..f34b1ae567a6e 100644 --- a/crates/sui-framework/docs/sui-framework/linked_table.md +++ b/crates/sui-framework/docs/sui-framework/linked_table.md @@ -248,11 +248,11 @@ that key k: K. k: K, value: V, ) { - let old_head = option::swap_or_fill(&mut table.head, k); - if (option::is_none(&table.tail)) option::fill(&mut table.tail, k); + let old_head = table.head.swap_or_fill(k); + if (table.tail.is_none()) table.tail.fill(k); let prev = option::none(); - let next = if (option::is_some(&old_head)) { - let old_head_k = option::destroy_some(old_head); + let next = if (old_head.is_some()) { + let old_head_k = old_head.destroy_some(); field::borrow_mut<K, Node<K, V>>(&mut table.id, old_head_k).prev = option::some(k); option::some(old_head_k) } else { @@ -291,10 +291,10 @@ that key k: K. k: K, value: V, ) { - if (option::is_none(&table.head)) option::fill(&mut table.head, k); - let old_tail = option::swap_or_fill(&mut table.tail, k); - let prev = if (option::is_some(&old_tail)) { - let old_tail_k = option::destroy_some(old_tail); + if (table.head.is_none()) table.head.fill(k); + let old_tail = table.tail.swap_or_fill(k); + let prev = if (old_tail.is_some()) { + let old_tail_k = old_tail.destroy_some(); field::borrow_mut<K, Node<K, V>>(&mut table.id, old_tail_k).next = option::some(k); option::some(old_tail_k) } else { @@ -445,14 +445,14 @@ that key k: K. Note: this is also what happens when the table is em
public fun remove<K: copy + drop + store, V: store>(table: &mut LinkedTable<K, V>, k: K): V {
     let Node<K, V> { prev, next, value } = field::remove(&mut table.id, k);
     table.size = table.size - 1;
-    if (option::is_some(&prev)) {
-        field::borrow_mut<K, Node<K, V>>(&mut table.id, *option::borrow(&prev)).next = next
+    if (prev.is_some()) {
+        field::borrow_mut<K, Node<K, V>>(&mut table.id, *prev.borrow()).next = next
     };
-    if (option::is_some(&next)) {
-        field::borrow_mut<K, Node<K, V>>(&mut table.id, *option::borrow(&next)).prev = prev
+    if (next.is_some()) {
+        field::borrow_mut<K, Node<K, V>>(&mut table.id, *next.borrow()).prev = prev
     };
-    if (option::borrow(&table.head) == &k) table.head = next;
-    if (option::borrow(&table.tail) == &k) table.tail = prev;
+    if (table.head.borrow() == &k) table.head = next;
+    if (table.tail.borrow() == &k) table.tail = prev;
     value
 }
 
@@ -479,9 +479,9 @@ Aborts with pop_front<K: copy + drop + store, V: store>(table: &mut LinkedTable<K, V>): (K, V) { - assert!(option::is_some(&table.head), ETableIsEmpty); - let head = *option::borrow(&table.head); - (head, remove(table, head)) + assert!(table.head.is_some(), ETableIsEmpty); + let head = *table.head.borrow(); + (head, table.remove(head)) }
@@ -507,9 +507,9 @@ Aborts with pop_back<K: copy + drop + store, V: store>(table: &mut LinkedTable<K, V>): (K, V) { - assert!(option::is_some(&table.tail), ETableIsEmpty); - let tail = *option::borrow(&table.tail); - (tail, remove(table, tail)) + assert!(table.tail.is_some(), ETableIsEmpty); + let tail = *table.tail.borrow(); + (tail, table.remove(tail)) }
@@ -613,7 +613,7 @@ Aborts with destroy_empty<K: copy + drop + store, V: store>(table: LinkedTable<K, V>) { let LinkedTable { id, size, head: _, tail: _ } = table; assert!(size == 0, ETableNotEmpty); - object::delete(id) + id.delete() }
@@ -640,7 +640,7 @@ Usable only if the value type V has the drop ability
public fun drop<K: copy + drop + store, V: drop + store>(table: LinkedTable<K, V>) {
     let LinkedTable { id, size: _, head: _, tail: _ } = table;
-    object::delete(id)
+    id.delete()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/object.md b/crates/sui-framework/docs/sui-framework/object.md index 92ae488e16948..1b2bd684a7372 100644 --- a/crates/sui-framework/docs/sui-framework/object.md +++ b/crates/sui-framework/docs/sui-framework/object.md @@ -239,7 +239,7 @@ Make an ID f
public fun id_from_bytes(bytes: vector<u8>): ID {
-    id_from_address(address::from_bytes(bytes))
+    address::from_bytes(bytes).to_id()
 }
 
@@ -290,7 +290,7 @@ This should only be called once from sui_system.
fun sui_system_state(ctx: &TxContext): UID {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
     UID {
         id: ID { bytes: SUI_SYSTEM_STATE_OBJECT_ID },
     }
@@ -532,7 +532,7 @@ This is the only way to create new(ctx: &mut TxContext): UID {
     UID {
-        id: ID { bytes: tx_context::fresh_object_address(ctx) },
+        id: ID { bytes: ctx.fresh_object_address() },
     }
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/object_bag.md b/crates/sui-framework/docs/sui-framework/object_bag.md index 8102974947532..cf55ae03bcc62 100644 --- a/crates/sui-framework/docs/sui-framework/object_bag.md +++ b/crates/sui-framework/docs/sui-framework/object_bag.md @@ -345,7 +345,7 @@ Aborts with EBagNotEmp
public fun destroy_empty(bag: ObjectBag) {
     let ObjectBag { id, size } = bag;
     assert!(size == 0, EBagNotEmpty);
-    object::delete(id)
+    id.delete()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/object_table.md b/crates/sui-framework/docs/sui-framework/object_table.md index 8a380e23dd497..ab435543208f4 100644 --- a/crates/sui-framework/docs/sui-framework/object_table.md +++ b/crates/sui-framework/docs/sui-framework/object_table.md @@ -316,7 +316,7 @@ Aborts with ETab
public fun destroy_empty<K: copy + drop + store, V: key + store>(table: ObjectTable<K, V>) {
     let ObjectTable { id, size } = table;
     assert!(size == 0, ETableNotEmpty);
-    object::delete(id)
+    id.delete()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/package.md b/crates/sui-framework/docs/sui-framework/package.md index a898c91a45022..cc9e4194c9912 100644 --- a/crates/sui-framework/docs/sui-framework/package.md +++ b/crates/sui-framework/docs/sui-framework/package.md @@ -341,12 +341,12 @@ but multiple per package (!).
public fun claim<OTW: drop>(otw: OTW, ctx: &mut TxContext): Publisher {
     assert!(types::is_one_time_witness(&otw), ENotOneTimeWitness);
 
-    let `type` = type_name::get_with_original_ids<OTW>();
+    let tyname = type_name::get_with_original_ids<OTW>();
 
     Publisher {
         id: object::new(ctx),
-        package: type_name::get_address(&`type`),
-        module_name: type_name::get_module(&`type`),
+        package: tyname.get_address(),
+        module_name: tyname.get_module(),
     }
 }
 
@@ -374,7 +374,7 @@ the sender is the publisher.
public fun claim_and_keep<OTW: drop>(otw: OTW, ctx: &mut TxContext) {
-    sui::transfer::public_transfer(claim(otw, ctx), sender(ctx))
+    sui::transfer::public_transfer(claim(otw, ctx), ctx.sender())
 }
 
@@ -401,7 +401,7 @@ associated with it.
public fun burn_publisher(self: Publisher) {
     let Publisher { id, package: _, module_name: _ } = self;
-    object::delete(id);
+    id.delete();
 }
 
@@ -426,9 +426,7 @@ Check whether type belongs to the same package as the publisher object.
public fun from_package<T>(self: &Publisher): bool {
-    let `type` = type_name::get_with_original_ids<T>();
-
-    (type_name::get_address(&`type`) == self.package)
+    type_name::get_with_original_ids<T>().get_address() == self.package
 }
 
@@ -453,10 +451,9 @@ Check whether a type belongs to the same module as the publisher object.
public fun from_module<T>(self: &Publisher): bool {
-    let `type` = type_name::get_with_original_ids<T>();
+    let tyname = type_name::get_with_original_ids<T>();
 
-    (type_name::get_address(&`type`) == self.package)
-        && (type_name::get_module(&`type`) == self.module_name)
+    (tyname.get_address() == self.package) && (tyname.get_module() == self.module_name)
 }
 
@@ -818,7 +815,7 @@ change dependencies.
public entry fun only_additive_upgrades(cap: &mut UpgradeCap) {
-    restrict(cap, ADDITIVE)
+    cap.restrict(ADDITIVE)
 }
 
@@ -844,7 +841,7 @@ dependencies.
public entry fun only_dep_upgrades(cap: &mut UpgradeCap) {
-    restrict(cap, DEP_ONLY)
+    cap.restrict(DEP_ONLY)
 }
 
@@ -870,7 +867,7 @@ Discard the UpgradeCappublic entry fun make_immutable(cap: UpgradeCap) { let UpgradeCap { id, package: _, version: _, policy: _ } = cap; - object::delete(id); + id.delete(); }
@@ -908,7 +905,7 @@ for the upgrade to succeed. policy: u8, digest: vector<u8> ): UpgradeTicket { - let id_zero = object::id_from_address(@0x0); + let id_zero = @0x0.to_id(); assert!(cap.package != id_zero, EAlreadyAuthorized); assert!(policy >= cap.policy, ETooPermissive); @@ -952,7 +949,7 @@ the upgrade. let UpgradeReceipt { cap: cap_id, package } = receipt; assert!(object::id(cap) == cap_id, EWrongUpgradeCap); - assert!(object::id_to_address(&cap.package) == @0x0, ENotAuthorized); + assert!(cap.package.to_address() == @0x0, ENotAuthorized); cap.package = package; cap.version = cap.version + 1; diff --git a/crates/sui-framework/docs/sui-framework/pay.md b/crates/sui-framework/docs/sui-framework/pay.md index 0fbfa4a7a8cec..2a9d0837fe083 100644 --- a/crates/sui-framework/docs/sui-framework/pay.md +++ b/crates/sui-framework/docs/sui-framework/pay.md @@ -56,7 +56,7 @@ Transfer c to the sender of the current transaction
public fun keep<T>(c: Coin<T>, ctx: &TxContext) {
-    transfer::public_transfer(c, tx_context::sender(ctx))
+    transfer::public_transfer(c, ctx.sender())
 }
 
@@ -72,7 +72,7 @@ Split coin self to two coins, one with balance split_amountself. -
public entry fun split<T>(self: &mut coin::Coin<T>, split_amount: u64, ctx: &mut tx_context::TxContext)
+
public entry fun split<T>(coin: &mut coin::Coin<T>, split_amount: u64, ctx: &mut tx_context::TxContext)
 
@@ -82,9 +82,9 @@ and the remaining balance is left is self.
public entry fun split<T>(
-    self: &mut Coin<T>, split_amount: u64, ctx: &mut TxContext
+    coin: &mut Coin<T>, split_amount: u64, ctx: &mut TxContext
 ) {
-    keep(coin::split(self, split_amount, ctx), ctx)
+    keep(coin.split(split_amount, ctx), ctx)
 }
 
@@ -112,9 +112,9 @@ in split_amounts. Remaining balance is left in self.
public entry fun split_vec<T>(
     self: &mut Coin<T>, split_amounts: vector<u64>, ctx: &mut TxContext
 ) {
-    let (mut i, len) = (0, vector::length(&split_amounts));
+    let (mut i, len) = (0, split_amounts.length());
     while (i < len) {
-        split(self, *vector::borrow(&split_amounts, i), ctx);
+        split(self, split_amounts[i], ctx);
         i = i + 1;
     };
 }
@@ -144,7 +144,7 @@ Aborts with EVALUE if amount is greater than or equal
 
public entry fun split_and_transfer<T>(
     c: &mut Coin<T>, amount: u64, recipient: address, ctx: &mut TxContext
 ) {
-    transfer::public_transfer(coin::split(c, amount, ctx), recipient)
+    transfer::public_transfer(c.split(amount, ctx), recipient)
 }
 
@@ -172,13 +172,13 @@ not evenly divisible by n, the remainder is left in selfpublic entry fun divide_and_keep<T>( self: &mut Coin<T>, n: u64, ctx: &mut TxContext ) { - let mut vec: vector<Coin<T>> = coin::divide_into_n(self, n, ctx); - let (mut i, len) = (0, vector::length(&vec)); + let mut vec: vector<Coin<T>> = self.divide_into_n(n, ctx); + let (mut i, len) = (0, vec.length()); while (i < len) { - transfer::public_transfer(vector::pop_back(&mut vec), tx_context::sender(ctx)); + transfer::public_transfer(vec.pop_back(), ctx.sender()); i = i + 1; }; - vector::destroy_empty(vec); + vec.destroy_empty(); }
@@ -191,6 +191,7 @@ not evenly divisible by n, the remainder is left in selfcoin into self. Re-exports coin::join function. +Deprecated: you should call coin.join(other) directly.
public entry fun join<T>(self: &mut coin::Coin<T>, coin: coin::Coin<T>)
@@ -203,7 +204,7 @@ Join coin into public entry fun join<T>(self: &mut Coin<T>, coin: Coin<T>) {
-    coin::join(self, coin)
+    self.join(coin)
 }
 
@@ -228,14 +229,14 @@ Join everything in coins with self
public entry fun join_vec<T>(self: &mut Coin<T>, mut coins: vector<Coin<T>>) {
-    let (mut i, len) = (0, vector::length(&coins));
+    let (mut i, len) = (0, coins.length());
     while (i < len) {
-        let coin = vector::pop_back(&mut coins);
-        coin::join(self, coin);
+        let coin = coins.pop_back();
+        self.join(coin);
         i = i + 1
     };
     // safe because we've drained the vector
-    vector::destroy_empty(coins)
+    coins.destroy_empty()
 }
 
@@ -260,9 +261,9 @@ Join a vector of Coin into a single object and transfer it to public entry fun join_vec_and_transfer<T>(mut coins: vector<Coin<T>>, receiver: address) { - assert!(vector::length(&coins) > 0, ENoCoins); + assert!(coins.length() > 0, ENoCoins); - let mut self = vector::pop_back(&mut coins); + let mut self = coins.pop_back(); join_vec(&mut self, coins); transfer::public_transfer(self, receiver) } diff --git a/crates/sui-framework/docs/sui-framework/poseidon.md b/crates/sui-framework/docs/sui-framework/poseidon.md index 8016b868ad195..f5a5075aa3c42 100644 --- a/crates/sui-framework/docs/sui-framework/poseidon.md +++ b/crates/sui-framework/docs/sui-framework/poseidon.md @@ -73,16 +73,16 @@ scalar field size which is 21888242871839275222246405745257275088548364400416034
public fun poseidon_bn254(data: &vector<u256>): u256 {
-    let (mut i, mut b, l) = (0, vector[], vector::length(data));
+    let (mut i, mut b, l) = (0, vector[], data.length());
     assert!(l > 0, EEmptyInput);
     while (i < l) {
-        let field_element = vector::borrow(data, i);
+        let field_element = &data[i];
         assert!(*field_element < BN254_MAX, ENonCanonicalInput);
-        vector::push_back(&mut b, bcs::to_bytes(vector::borrow(data, i)));
+        b.push_back(bcs::to_bytes(&data[i]));
         i = i + 1;
     };
     let binary_output = poseidon_bn254_internal(&b);
-    bcs::peel_u256(&mut bcs::new(binary_output))
+    bcs::new(binary_output).peel_u256()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/priority_queue.md b/crates/sui-framework/docs/sui-framework/priority_queue.md index 5a5ada79abcf8..03479fb1a2325 100644 --- a/crates/sui-framework/docs/sui-framework/priority_queue.md +++ b/crates/sui-framework/docs/sui-framework/priority_queue.md @@ -121,7 +121,7 @@ Create a new priority queue from the input entry vectors.
public fun new<T: drop>(mut entries: vector<Entry<T>>) : PriorityQueue<T> {
-    let len = vector::length(&entries);
+    let len = entries.length();
     let mut i = len / 2;
     // Max heapify from the first node that is a parent (node at len / 2).
     while (i > 0) {
@@ -153,10 +153,10 @@ Pop the entry with the highest priority value.
 
 
 
public fun pop_max<T: drop>(pq: &mut PriorityQueue<T>) : (u64, T) {
-    let len = vector::length(&pq.entries);
+    let len = pq.entries.length();
     assert!(len > 0, EPopFromEmptyHeap);
     // Swap the max element with the last element in the entries and remove the max element.
-    let Entry { priority, value } = vector::swap_remove(&mut pq.entries, 0);
+    let Entry { priority, value } = pq.entries.swap_remove(0);
     // Now the max heap property has been violated at the root node, but nowhere else
     // so we call max heapify on the root node.
     max_heapify_recursive(&mut pq.entries, len - 1, 0);
@@ -185,8 +185,8 @@ Insert a new entry into the queue.
 
 
 
public fun insert<T: drop>(pq: &mut PriorityQueue<T>, priority: u64, value: T) {
-    vector::push_back(&mut pq.entries, Entry { priority, value});
-    let index = vector::length(&pq.entries) - 1;
+    pq.entries.push_back(Entry { priority, value});
+    let index = pq.entries.length() - 1;
     restore_heap_recursive(&mut pq.entries, index);
 }
 
@@ -235,14 +235,14 @@ Insert a new entry into the queue.
public fun create_entries<T: drop>(mut p: vector<u64>, mut v: vector<T>): vector<Entry<T>> {
-    let len = vector::length(&p);
-    assert!(vector::length(&v) == len, 0);
-    let mut res = vector::empty();
+    let len = p.length();
+    assert!(v.length() == len, 0);
+    let mut res = vector[];
     let mut i = 0;
     while (i < len) {
-        let priority = vector::remove(&mut p, 0);
-        let value = vector::remove(&mut v, 0);
-        vector::push_back(&mut res, Entry { priority, value });
+        let priority = p.remove(0);
+        let value = v.remove(0);
+        res.push_back(Entry { priority, value });
         i = i + 1;
     };
     res
@@ -276,8 +276,8 @@ Insert a new entry into the queue.
 
     // If new elem is greater than its parent, swap them and recursively
     // do the restoration upwards.
-    if (vector::borrow(v, i).priority > vector::borrow(v, parent).priority) {
-        vector::swap(v, i, parent);
+    if (*&v[i].priority > *&v[parent].priority) {
+        v.swap(i, parent);
         restore_heap_recursive(v, parent);
     }
 }
@@ -316,16 +316,16 @@ do satisfy the max heap property.
     let right = left + 1;
     let mut max = i;
     // Find the node with highest priority among node `i` and its two children.
-    if (left < len && vector::borrow(v, left).priority> vector::borrow(v, max).priority) {
+    if (left < len && *&v[left].priority > *&v[max].priority) {
         max = left;
     };
-    if (right < len && vector::borrow(v, right).priority > vector::borrow(v, max).priority) {
+    if (right < len && *&v[right].priority > *&v[max].priority) {
         max = right;
     };
     // If the parent node (node `i`) doesn't have the highest priority, we swap the parent with the
     // max priority node.
     if (max != i) {
-        vector::swap(v, max, i);
+        v.swap(max, i);
         // After the swap, we have restored the property at node `i` but now the max heap property
         // may be violated at node `max` since this node now has a new value. So we need to now
         // max heapify the subtree rooted at node `max`.
@@ -356,8 +356,8 @@ do satisfy the max heap property.
 
public fun priorities<T: drop>(pq: &PriorityQueue<T>): vector<u64> {
     let mut res = vector[];
     let mut i = 0;
-    while (i < vector::length(&pq.entries)) {
-        vector::push_back(&mut res, vector::borrow(&pq.entries, i).priority);
+    while (i < pq.entries.length()) {
+        res.push_back(pq.entries[i].priority);
         i = i +1;
     };
     res
diff --git a/crates/sui-framework/docs/sui-framework/random.md b/crates/sui-framework/docs/sui-framework/random.md
index a00c385f2b753..da993568f8905 100644
--- a/crates/sui-framework/docs/sui-framework/random.md
+++ b/crates/sui-framework/docs/sui-framework/random.md
@@ -263,13 +263,13 @@ Can only be called by genesis or change_epoch transactions.
 
 
 
fun create(ctx: &mut TxContext) {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
 
     let version = CURRENT_VERSION;
 
     let inner = RandomInner {
         version,
-        epoch: tx_context::epoch(ctx),
+        epoch: ctx.epoch(),
         randomness_round: 0,
         random_bytes: vector[],
     };
@@ -374,13 +374,12 @@ transaction.
     ctx: &TxContext,
 ) {
     // Validator will make a special system call with sender set as 0x0.
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
 
     // Randomness should only be incremented.
-    let epoch = tx_context::epoch(ctx);
-    let inner = load_inner_mut(self);
-    if (inner.randomness_round == 0 && inner.epoch == 0 &&
-        vector::is_empty(&inner.random_bytes)) {
+    let epoch = ctx.epoch();
+    let inner = self.load_inner_mut();
+    if (inner.randomness_round == 0 && inner.epoch == 0 && inner.random_bytes.is_empty()) {
         // First update should be for round zero.
         assert!(new_round == 0, EInvalidRandomnessUpdate);
     } else {
@@ -394,7 +393,7 @@ transaction.
         );
     };
 
-    inner.epoch = tx_context::epoch(ctx);
+    inner.epoch = ctx.epoch();
     inner.randomness_round = new_round;
     inner.random_bytes = new_bytes;
 }
@@ -424,7 +423,7 @@ Create a generator. Can be used to derive up to MAX_U16 * 32 random bytes.
     let inner = load_inner(r);
     let seed = hmac_sha3_256(
         &inner.random_bytes,
-        &to_bytes(fresh_object_address(ctx))
+        &ctx.fresh_object_address().to_bytes()
     );
     RandomGenerator { seed, counter: 0, buffer: vector[] }
 }
diff --git a/crates/sui-framework/docs/sui-framework/sui.md b/crates/sui-framework/docs/sui-framework/sui.md
index eaed2e9507bfd..377044653883d 100644
--- a/crates/sui-framework/docs/sui-framework/sui.md
+++ b/crates/sui-framework/docs/sui-framework/sui.md
@@ -124,8 +124,8 @@ This should be called only once during genesis creation.
 
 
 
fun new(ctx: &mut TxContext): Balance<SUI> {
-    assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress);
-    assert!(tx_context::epoch(ctx) == 0, EAlreadyMinted);
+    assert!(ctx.sender() == @0x0, ENotSystemAddress);
+    assert!(ctx.epoch() == 0, EAlreadyMinted);
 
     let (treasury, metadata) = coin::create_currency(
         SUI {},
@@ -138,9 +138,9 @@ This should be called only once during genesis creation.
         ctx
     );
     transfer::public_freeze_object(metadata);
-    let mut supply = coin::treasury_into_supply(treasury);
-    let total_sui = balance::increase_supply(&mut supply, TOTAL_SUPPLY_MIST);
-    balance::destroy_supply(supply);
+    let mut supply = treasury.treasury_into_supply();
+    let total_sui = supply.increase_supply(TOTAL_SUPPLY_MIST);
+    supply.destroy_supply();
     total_sui
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/table.md b/crates/sui-framework/docs/sui-framework/table.md index 99be17a063bc3..7d068104f3f23 100644 --- a/crates/sui-framework/docs/sui-framework/table.md +++ b/crates/sui-framework/docs/sui-framework/table.md @@ -322,7 +322,7 @@ Aborts with E
public fun destroy_empty<K: copy + drop + store, V: store>(table: Table<K, V>) {
     let Table { id, size } = table;
     assert!(size == 0, ETableNotEmpty);
-    object::delete(id)
+    id.delete()
 }
 
@@ -349,7 +349,7 @@ Usable only if the value type V has the drop ability
public fun drop<K: copy + drop + store, V: drop + store>(table: Table<K, V>) {
     let Table { id, size: _ } = table;
-    object::delete(id)
+    id.delete()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/table_vec.md b/crates/sui-framework/docs/sui-framework/table_vec.md index 148434b15178d..b50877784b01f 100644 --- a/crates/sui-framework/docs/sui-framework/table_vec.md +++ b/crates/sui-framework/docs/sui-framework/table_vec.md @@ -123,7 +123,7 @@ Return a TableVec of size one containing element e.
public fun singleton<Element: store>(e: Element, ctx: &mut TxContext): TableVec<Element> {
     let mut t = empty(ctx);
-    push_back(&mut t, e);
+    t.push_back(e);
     t
 }
 
@@ -149,7 +149,7 @@ Return the length of the TableVec.
public fun length<Element: store>(t: &TableVec<Element>): u64 {
-    table::length(&t.contents)
+    t.contents.length()
 }
 
@@ -174,7 +174,7 @@ Return if the TableVec is empty or not.
public fun is_empty<Element: store>(t: &TableVec<Element>): bool {
-    length(t) == 0
+    t.length() == 0
 }
 
@@ -200,8 +200,8 @@ Aborts if i is out of bounds.
public fun borrow<Element: store>(t: &TableVec<Element>, i: u64): &Element {
-    assert!(length(t) > i, EIndexOutOfBound);
-    table::borrow(&t.contents, i)
+    assert!(t.length() > i, EIndexOutOfBound);
+    &t.contents[i]
 }
 
@@ -226,8 +226,8 @@ Add element e to the end of the TableVec t.
public fun push_back<Element: store>(t: &mut TableVec<Element>, e: Element) {
-    let key = length(t);
-    table::add(&mut t.contents, key, e);
+    let key = t.length();
+    t.contents.add(key, e);
 }
 
@@ -253,8 +253,8 @@ Aborts if i is out of bounds.
public fun borrow_mut<Element: store>(t: &mut TableVec<Element>, i: u64): &mut Element {
-    assert!(length(t) > i, EIndexOutOfBound);
-    table::borrow_mut(&mut t.contents, i)
+    assert!(t.length() > i, EIndexOutOfBound);
+    &mut t.contents[i]
 }
 
@@ -282,7 +282,7 @@ Aborts if t is empty.
public fun pop_back<Element: store>(t: &mut TableVec<Element>): Element {
     let length = length(t);
     assert!(length > 0, EIndexOutOfBound);
-    table::remove(&mut t.contents, length - 1)
+    t.contents.remove(length - 1)
 }
 
@@ -310,7 +310,7 @@ Aborts if t is not empty.
public fun destroy_empty<Element: store>(t: TableVec<Element>) {
     assert!(length(&t) == 0, ETableNonEmpty);
     let TableVec { contents } = t;
-    table::destroy_empty(contents);
+    contents.destroy_empty();
 }
 
@@ -337,7 +337,7 @@ Usable only if the value type Element has the drop abi
public fun drop<Element: drop + store>(t: TableVec<Element>) {
     let TableVec { contents } = t;
-    table::drop(contents)
+    contents.drop()
 }
 
@@ -363,13 +363,13 @@ Aborts if i or j is out of bounds.
public fun swap<Element: store>(t: &mut TableVec<Element>, i: u64, j: u64) {
-    assert!(length(t) > i, EIndexOutOfBound);
-    assert!(length(t) > j, EIndexOutOfBound);
+    assert!(t.length() > i, EIndexOutOfBound);
+    assert!(t.length() > j, EIndexOutOfBound);
     if (i == j) { return };
-    let element_i = table::remove(&mut t.contents, i);
-    let element_j = table::remove(&mut t.contents, j);
-    table::add(&mut t.contents, j, element_i);
-    table::add(&mut t.contents, i, element_j);
+    let element_i = t.contents.remove(i);
+    let element_j = t.contents.remove(j);
+    t.contents.add(j, element_i);
+    t.contents.add(i, element_j);
 }
 
@@ -396,10 +396,10 @@ Aborts if i is out of bounds.
public fun swap_remove<Element: store>(t: &mut TableVec<Element>, i: u64): Element {
-    assert!(length(t) > i, EIndexOutOfBound);
-    let last_idx = length(t) - 1;
-    swap(t, i, last_idx);
-    pop_back(t)
+    assert!(t.length() > i, EIndexOutOfBound);
+    let last_idx = t.length() - 1;
+    t.swap(i, last_idx);
+    t.pop_back()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/token.md b/crates/sui-framework/docs/sui-framework/token.md index 6dd0a73097dca..82b11980bd0cf 100644 --- a/crates/sui-framework/docs/sui-framework/token.md +++ b/crates/sui-framework/docs/sui-framework/token.md @@ -570,7 +570,7 @@ to be used in verification.
public fun transfer<T>(
     t: Token<T>, recipient: address, ctx: &mut TxContext
 ): ActionRequest<T> {
-    let amount = balance::value(&t.balance);
+    let amount = t.balance.value();
     transfer::transfer(t, recipient);
 
     new_request(
@@ -610,11 +610,11 @@ request and join the spent balance with the spend<T>(t: Token<T>, ctx: &mut TxContext): ActionRequest<T> {
     let Token { id, balance } = t;
-    object::delete(id);
+    id.delete();
 
     new_request(
         spend_action(),
-        balance::value(&balance),
+        balance.value(),
         option::none(),
         option::some(balance),
         ctx
@@ -647,11 +647,11 @@ Convert Token into an open <
     t: Token<T>, ctx: &mut TxContext
 ): (Coin<T>, ActionRequest<T>) {
     let Token { id, balance } = t;
-    let amount = balance::value(&balance);
-    object::delete(id);
+    let amount = balance.value();
+    id.delete();
 
     (
-        coin::from_balance(balance, ctx),
+        balance.into_coin(ctx),
         new_request(
             to_coin_action(),
             amount,
@@ -687,10 +687,10 @@ the "from_coin" action.
 
public fun from_coin<T>(
     coin: Coin<T>, ctx: &mut TxContext
 ): (Token<T>, ActionRequest<T>) {
-    let amount = coin::value(&coin);
+    let amount = coin.value();
     let token = Token {
         id: object::new(ctx),
-        balance: coin::into_balance(coin)
+        balance: coin.into_balance()
     };
 
     (
@@ -728,8 +728,8 @@ Join two Tokens into one, al
 
 
public fun join<T>(token: &mut Token<T>, another: Token<T>) {
     let Token { id, balance } = another;
-    balance::join(&mut token.balance, balance);
-    object::delete(id);
+    token.balance.join(balance);
+    id.delete();
 }
 
@@ -757,10 +757,10 @@ Aborts if the Token.split<T>( token: &mut Token<T>, amount: u64, ctx: &mut TxContext ): Token<T> { - assert!(balance::value(&token.balance) >= amount, EBalanceTooLow); + assert!(token.balance.value() >= amount, EBalanceTooLow); Token { id: object::new(ctx), - balance: balance::split(&mut token.balance, amount), + balance: token.balance.split(amount), } }
@@ -816,9 +816,9 @@ Aborts if the Token.destroy_zero<T>(token: Token<T>) { let Token { id, balance } = token; - assert!(balance::value(&balance) == 0, ENotZero); - balance::destroy_zero(balance); - object::delete(id); + assert!(balance.value() == 0, ENotZero); + balance.destroy_zero(); + id.delete(); }
@@ -843,7 +843,7 @@ Transfer the Token to the tr
public fun keep<T>(token: Token<T>, ctx: &mut TxContext) {
-    transfer::transfer(token, tx_context::sender(ctx))
+    transfer::transfer(token, ctx.sender())
 }
 
@@ -880,7 +880,7 @@ Publicly available method to allow for custom actions. amount, recipient, spent_balance, - sender: tx_context::sender(ctx), + sender: ctx.sender(), approvals: vec_set::empty(), } } @@ -920,8 +920,8 @@ Aborts if: request: ActionRequest<T>, _ctx: &mut TxContext ): (String, u64, address, Option<address>) { - assert!(option::is_none(&request.spent_balance), ECantConsumeBalance); - assert!(vec_map::contains(&policy.rules, &request.name), EUnknownAction); + assert!(request.spent_balance.is_none(), ECantConsumeBalance); + assert!(policy.rules.contains(&request.name), EUnknownAction); let ActionRequest { name, approvals, @@ -929,15 +929,15 @@ Aborts if: amount, sender, recipient, } = request; - option::destroy_none(spent_balance); + spent_balance.destroy_none(); - let rules = &vec_set::into_keys(*vec_map::get(&policy.rules, &name)); - let rules_len = vector::length(rules); + let rules = &(*policy.rules.get(&name)).into_keys(); + let rules_len = rules.length(); let mut i = 0; while (i < rules_len) { - let rule = vector::borrow(rules, i); - assert!(vec_set::contains(&approvals, rule), ENotApproved); + let rule = &rules[i]; + assert!(approvals.contains(rule), ENotApproved); i = i + 1; }; @@ -977,13 +977,10 @@ See confirm_request for the list of abort conditions. mut request: ActionRequest<T>, ctx: &mut TxContext ): (String, u64, address, Option<address>) { - assert!(vec_map::contains(&policy.rules, &request.name), EUnknownAction); - assert!(option::is_some(&request.spent_balance), EUseImmutableConfirm); + assert!(policy.rules.contains(&request.name), EUnknownAction); + assert!(request.spent_balance.is_some(), EUseImmutableConfirm); - balance::join( - &mut policy.spent_balance, - option::extract(&mut request.spent_balance) - ); + policy.spent_balance.join(request.spent_balance.extract()); confirm_request(policy, request, ctx) } @@ -1020,13 +1017,13 @@ Aborts if request contains spent_balance due to inability of the request: ActionRequest<T>, _ctx: &mut TxContext ): (String, u64, address, Option<address>) { - assert!(option::is_none(&request.spent_balance), ECantConsumeBalance); + assert!(request.spent_balance.is_none(), ECantConsumeBalance); let ActionRequest { name, amount, sender, recipient, approvals: _, spent_balance } = request; - option::destroy_none(spent_balance); + spent_balance.destroy_none(); (name, amount, sender, recipient) } @@ -1067,13 +1064,10 @@ to be consumed, decreasing the total_supply of the option::is_some(&spent_balance)) { - balance::decrease_supply( - coin::supply_mut(treasury_cap), - option::destroy_some(spent_balance) - ); + if (spent_balance.is_some()) { + treasury_cap.supply_mut().decrease_supply(spent_balance.destroy_some()); } else { - option::destroy_none(spent_balance); + spent_balance.destroy_none(); }; (name, amount, sender, recipient) @@ -1106,7 +1100,7 @@ required by the TokenPolicypublic fun add_approval<T, W: drop>( _t: W, request: &mut ActionRequest<T>, _ctx: &mut TxContext ) { - vec_set::insert(&mut request.approvals, type_name::get<W>()) + request.approvals.insert(type_name::get<W>()) }
@@ -1343,7 +1337,7 @@ Aborts if the TokenPolicyCapmut TxContext ) { assert!(object::id(self) == cap.`for`, ENotAuthorized); - vec_map::insert(&mut self.rules, action, vec_set::empty()); + self.rules.insert(action, vec_set::empty()); }
@@ -1377,7 +1371,7 @@ Aborts if the TokenPolicyCapmut TxContext ) { assert!(object::id(self) == cap.`for`, ENotAuthorized); - vec_map::remove(&mut self.rules, &action); + self.rules.remove(&action); }
@@ -1410,14 +1404,11 @@ Aborts if the TokenPolicyCapmut TxContext ) { assert!(object::id(self) == cap.`for`, ENotAuthorized); - if (!vec_map::contains(&self.rules, &action)) { + if (!self.rules.contains(&action)) { allow(self, cap, action, ctx); }; - vec_set::insert( - vec_map::get_mut(&mut self.rules, &action), - type_name::get<Rule>() - ) + self.rules.get_mut(&action).insert(type_name::get<Rule>()) }
@@ -1452,10 +1443,7 @@ Aborts if the TokenPolicyCapassert!(object::id(self) == cap.`for`, ENotAuthorized); - vec_set::remove( - vec_map::get_mut(&mut self.rules, &action), - &type_name::get<Rule>() - ) + self.rules.get_mut(&action).remove(&type_name::get<Rule>()) }
@@ -1482,7 +1470,7 @@ Mint a Token with a given public fun mint<T>( cap: &mut TreasuryCap<T>, amount: u64, ctx: &mut TxContext ): Token<T> { - let balance = balance::increase_supply(coin::supply_mut(cap), amount); + let balance = cap.supply_mut().increase_supply(amount); Token { id: object::new(ctx), balance } }
@@ -1509,8 +1497,8 @@ Burn a Token using the public fun burn<T>(cap: &mut TreasuryCap<T>, token: Token<T>) { let Token { id, balance } = token; - balance::decrease_supply(coin::supply_mut(cap), balance); - object::delete(id); + cap.supply_mut().decrease_supply(balance); + id.delete(); }
@@ -1540,9 +1528,9 @@ action is only available to the TreasuryCap owner. cap: &mut TreasuryCap<T>, _ctx: &mut TxContext ): u64 { - let amount = balance::value(&self.spent_balance); - let balance = balance::split(&mut self.spent_balance, amount); - balance::decrease_supply(coin::supply_mut(cap), balance) + let amount = self.spent_balance.value(); + let balance = self.spent_balance.split(amount); + cap.supply_mut().decrease_supply(balance) }
@@ -1567,7 +1555,7 @@ Check whether an action is present in the rules VecMap.
public fun is_allowed<T>(self: &TokenPolicy<T>, action: &String): bool {
-    vec_map::contains(&self.rules, action)
+    self.rules.contains(action)
 }
 
@@ -1594,7 +1582,7 @@ Returns the rules required for a specific action.
public fun rules<T>(
     self: &TokenPolicy<T>, action: &String
 ): VecSet<TypeName> {
-    *vec_map::get(&self.rules, action)
+    *self.rules.get(action)
 }
 
@@ -1619,7 +1607,7 @@ Returns the spent_balance of the spent_balance<T>(self: &TokenPolicy<T>): u64 { - balance::value(&self.spent_balance) + self.spent_balance.value() }
@@ -1644,7 +1632,7 @@ Returns the balance of the public fun value<T>(t: &Token<T>): u64 { - balance::value(&t.balance) + t.balance.value() }
@@ -1668,7 +1656,10 @@ Name of the Transfer action. Implementation -
public fun transfer_action(): String { string::utf8(TRANSFER) }
+
public fun transfer_action(): String {
+    let transfer_str = TRANSFER;
+    transfer_str.to_string()
+}
 
@@ -1691,7 +1682,10 @@ Name of the Spend action. Implementation -
public fun spend_action(): String { string::utf8(SPEND) }
+
public fun spend_action(): String {
+    let spend_str = SPEND;
+    spend_str.to_string()
+}
 
@@ -1714,7 +1708,10 @@ Name of the ToCoin action. Implementation -
public fun to_coin_action(): String { string::utf8(TO_COIN) }
+
public fun to_coin_action(): String {
+    let to_coin_str = TO_COIN;
+    to_coin_str.to_string()
+}
 
@@ -1737,7 +1734,10 @@ Name of the FromCoin action. Implementation -
public fun from_coin_action(): String { string::utf8(FROM_COIN) }
+
public fun from_coin_action(): String {
+    let from_coin_str = FROM_COIN;
+    from_coin_str.to_string()
+}
 
@@ -1880,8 +1880,8 @@ Burned balance of the ActionReq
public fun spent<T>(self: &ActionRequest<T>): Option<u64> {
-    if (option::is_some(&self.spent_balance)) {
-        option::some(balance::value(option::borrow(&self.spent_balance)))
+    if (self.spent_balance.is_some()) {
+        option::some(self.spent_balance.borrow().value())
     } else {
         option::none()
     }
diff --git a/crates/sui-framework/docs/sui-framework/transfer.md b/crates/sui-framework/docs/sui-framework/transfer.md
index 53a8f8fa2b68c..863a07362b1e6 100644
--- a/crates/sui-framework/docs/sui-framework/transfer.md
+++ b/crates/sui-framework/docs/sui-framework/transfer.md
@@ -326,7 +326,7 @@ that T is an object defined in the module where receivereceive_impl(object::uid_to_address(parent), id, version)
+    receive_impl(parent.to_address(), id, version)
 }
 
@@ -358,7 +358,7 @@ The object must have store to be received outside of its defining m id, version, } = to_receive; - receive_impl(object::uid_to_address(parent), id, version) + receive_impl(parent.to_address(), id, version) }
@@ -472,7 +472,7 @@ Return the object ID that the given receive_impl<T: key>(parent: address, to_receive: object::ID, version: u64): T; +
native fun receive_impl<T: key>(parent: address, to_receive: ID, version: u64): T;
 
diff --git a/crates/sui-framework/docs/sui-framework/transfer_policy.md b/crates/sui-framework/docs/sui-framework/transfer_policy.md index 1e08fe1ed6ce0..646863b3dd3df 100644 --- a/crates/sui-framework/docs/sui-framework/transfer_policy.md +++ b/crates/sui-framework/docs/sui-framework/transfer_policy.md @@ -410,7 +410,7 @@ available for use, the type can not be traded in kiosks. ): (TransferPolicy<T>, TransferPolicyCap<T>) { assert!(package::from_package<T>(pub), 0); let id = object::new(ctx); - let policy_id = object::uid_to_inner(&id); + let policy_id = id.to_inner(); event::emit(TransferPolicyCreated<T> { id: policy_id }); @@ -446,7 +446,7 @@ sender.
entry fun default<T>(pub: &Publisher, ctx: &mut TxContext) {
     let (policy, cap) = new<T>(pub, ctx);
     sui::transfer::share_object(policy);
-    sui::transfer::transfer(cap, sender(ctx));
+    sui::transfer::transfer(cap, ctx.sender());
 }
 
@@ -479,12 +479,12 @@ is not specified, all profits are withdrawn. ): Coin<SUI> { assert!(object::id(self) == cap.policy_id, ENotOwner); - let amount = if (option::is_some(&amount)) { - let amt = option::destroy_some(amount); - assert!(amt <= balance::value(&self.balance), ENotEnough); + let amount = if (amount.is_some()) { + let amt = amount.destroy_some(); + assert!(amt <= self.balance.value(), ENotEnough); amt } else { - balance::value(&self.balance) + self.balance.value() }; coin::take(&mut self.balance, amount, ctx) @@ -520,10 +520,10 @@ Can be performed by any party as long as they own it. let TransferPolicyCap { id: cap_id, policy_id } = cap; let TransferPolicy { id, rules: _, balance } = self; - object::delete(id); - object::delete(cap_id); + id.delete(); + cap_id.delete(); event::emit(TransferPolicyDestroyed<T> { id: policy_id }); - coin::from_balance(balance, ctx) + balance.into_coin(ctx) }
@@ -556,14 +556,14 @@ Kiosk trades will not be possible. self: &TransferPolicy<T>, request: TransferRequest<T> ): (ID, u64, ID) { let TransferRequest { item, paid, from, receipts } = request; - let mut completed = vec_set::into_keys(receipts); - let mut total = vector::length(&completed); + let mut completed = receipts.into_keys(); + let mut total = completed.length(); - assert!(total == vec_set::size(&self.rules), EPolicyNotSatisfied); + assert!(total == self.rules.size(), EPolicyNotSatisfied); while (total > 0) { - let rule_type = vector::pop_back(&mut completed); - assert!(vec_set::contains(&self.rules, &rule_type), EIllegalRule); + let rule_type = completed.pop_back(); + assert!(self.rules.contains(&rule_type), EIllegalRule); total = total - 1; }; @@ -605,7 +605,7 @@ even if graceful unpacking has not been implemented in a "rule module". assert!(object::id(policy) == cap.policy_id, ENotOwner); assert!(!has_rule<T, Rule>(policy), ERuleAlreadySet); df::add(&mut policy.id, RuleKey<Rule> {}, cfg); - vec_set::insert(&mut policy.rules, type_name::get<Rule>()) + policy.rules.insert(type_name::get<Rule>()) }
@@ -688,7 +688,7 @@ confirming that the policy requirements are satisfied.
public fun add_receipt<T, Rule: drop>(
     _: Rule, request: &mut TransferRequest<T>
 ) {
-    vec_set::insert(&mut request.receipts, type_name::get<Rule>())
+    request.receipts.insert(type_name::get<Rule>())
 }
 
@@ -742,7 +742,7 @@ Remove the Rule from the object::id(policy) == cap.policy_id, ENotOwner); let _: Config = df::remove(&mut policy.id, RuleKey<Rule> {}); - vec_set::remove(&mut policy.rules, &type_name::get<Rule>()); + policy.rules.remove(&type_name::get<Rule>()); }
diff --git a/crates/sui-framework/docs/sui-framework/url.md b/crates/sui-framework/docs/sui-framework/url.md index 5e887b3c82343..c08b858ee1b4f 100644 --- a/crates/sui-framework/docs/sui-framework/url.md +++ b/crates/sui-framework/docs/sui-framework/url.md @@ -89,7 +89,7 @@ Note: this will abort if bytes is not valid ASCII
public fun new_unsafe_from_bytes(bytes: vector<u8>): Url {
-    let url = ascii::string(bytes);
+    let url = bytes.to_ascii_string();
     Url { url }
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/vec_map.md b/crates/sui-framework/docs/sui-framework/vec_map.md index 3b938acdb7ff8..63b02036e804b 100644 --- a/crates/sui-framework/docs/sui-framework/vec_map.md +++ b/crates/sui-framework/docs/sui-framework/vec_map.md @@ -173,7 +173,7 @@ Create an empty V
public fun empty<K: copy, V>(): VecMap<K,V> {
-    VecMap { contents: vector::empty() }
+    VecMap { contents: vector[] }
 }
 
@@ -199,8 +199,8 @@ Aborts if key is already bound in self.
public fun insert<K: copy, V>(self: &mut VecMap<K,V>, key: K, value: V) {
-    assert!(!contains(self, &key), EKeyAlreadyExists);
-    vector::push_back(&mut self.contents, Entry { key, value })
+    assert!(!self.contains(&key), EKeyAlreadyExists);
+    self.contents.push_back(Entry { key, value })
 }
 
@@ -225,8 +225,8 @@ Remove the entry key |-> value from self. Aborts if public fun remove<K: copy, V>(self: &mut VecMap<K,V>, key: &K): (K, V) { - let idx = get_idx(self, key); - let Entry { key, value } = vector::remove(&mut self.contents, idx); + let idx = self.get_idx(key); + let Entry { key, value } = self.contents.remove(idx); (key, value) }
@@ -252,8 +252,8 @@ Pop the most recently inserted entry from the map. Aborts if the map is empty.
public fun pop<K: copy, V>(self: &mut VecMap<K,V>): (K, V) {
-    assert!(!vector::is_empty(&self.contents), EMapEmpty);
-    let Entry { key, value } = vector::pop_back(&mut self.contents);
+    assert!(!self.contents.is_empty(), EMapEmpty);
+    let Entry { key, value } = self.contents.pop_back();
     (key, value)
 }
 
@@ -280,8 +280,8 @@ Aborts if key is not bound in self.
public fun get_mut<K: copy, V>(self: &mut VecMap<K,V>, key: &K): &mut V {
-    let idx = get_idx(self, key);
-    let entry = vector::borrow_mut(&mut self.contents, idx);
+    let idx = self.get_idx(key);
+    let entry = &mut self.contents[idx];
     &mut entry.value
 }
 
@@ -308,8 +308,8 @@ Aborts if key is not bound in self.
public fun get<K: copy, V>(self: &VecMap<K,V>, key: &K): &V {
-    let idx = get_idx(self, key);
-    let entry = vector::borrow(&self.contents, idx);
+    let idx = self.get_idx(key);
+    let entry = &self.contents[idx];
     &entry.value
 }
 
@@ -337,7 +337,7 @@ Only works for a "copyable" value as references cannot be stored in public fun try_get<K: copy, V: copy>(self: &VecMap<K,V>, key: &K): Option<V> { - if (contains(self, key)) { + if (self.contains(key)) { option::some(*get(self, key)) } else { option::none() @@ -366,7 +366,7 @@ Return true if self contains an entry for key, false o
public fun contains<K: copy, V>(self: &VecMap<K, V>, key: &K): bool {
-    option::is_some(&get_idx_opt(self, key))
+    get_idx_opt(self, key).is_some()
 }
 
@@ -391,7 +391,7 @@ Return the number of entries in self
public fun size<K: copy, V>(self: &VecMap<K,V>): u64 {
-    vector::length(&self.contents)
+    self.contents.length()
 }
 
@@ -416,7 +416,7 @@ Return true if self has 0 elements, false otherwise
public fun is_empty<K: copy, V>(self: &VecMap<K,V>): bool {
-    size(self) == 0
+    self.size() == 0
 }
 
@@ -442,8 +442,8 @@ Destroy an empty map. Aborts if self is not empty
public fun destroy_empty<K: copy, V>(self: VecMap<K, V>) {
     let VecMap { contents } = self;
-    assert!(vector::is_empty(&contents), EMapNotEmpty);
-    vector::destroy_empty(contents)
+    assert!(contents.is_empty(), EMapNotEmpty);
+    contents.destroy_empty()
 }
 
@@ -471,18 +471,18 @@ The output keys and values are stored in insertion order, *not* sorted by key.
public fun into_keys_values<K: copy, V>(self: VecMap<K, V>): (vector<K>, vector<V>) {
     let VecMap { mut contents } = self;
     // reverse the vector so the output keys and values will appear in insertion order
-    vector::reverse(&mut contents);
+    contents.reverse();
     let mut i = 0;
-    let n = vector::length(&contents);
-    let mut keys = vector::empty();
-    let mut values = vector::empty();
+    let n = contents.length();
+    let mut keys = vector[];
+    let mut values = vector[];
     while (i < n) {
-        let Entry { key, value } = vector::pop_back(&mut contents);
-        vector::push_back(&mut keys, key);
-        vector::push_back(&mut values, value);
+        let Entry { key, value } = contents.pop_back();
+        keys.push_back(key);
+        values.push_back(value);
         i = i + 1;
     };
-    vector::destroy_empty(contents);
+    contents.destroy_empty();
     (keys, values)
 }
 
@@ -510,11 +510,11 @@ Do not assume any particular ordering.
public fun keys<K: copy, V>(self: &VecMap<K, V>): vector<K> {
     let mut i = 0;
-    let n = vector::length(&self.contents);
-    let mut keys = vector::empty();
+    let n = self.contents.length();
+    let mut keys = vector[];
     while (i < n) {
-        let entry = vector::borrow(&self.contents, i);
-        vector::push_back(&mut keys, entry.key);
+        let entry = self.contents.borrow(i);
+        keys.push_back(entry.key);
         i = i + 1;
     };
     keys
@@ -546,7 +546,7 @@ Note that map entries are stored in insertion order, *not* sorted by key.
     let mut i = 0;
     let n = size(self);
     while (i < n) {
-        if (&vector::borrow(&self.contents, i).key == key) {
+        if (&self.contents[i].key == key) {
             return option::some(i)
         };
         i = i + 1;
@@ -577,9 +577,9 @@ Note that map entries are stored in insertion order, *not* sorted by key.
 
 
 
public fun get_idx<K: copy, V>(self: &VecMap<K,V>, key: &K): u64 {
-    let idx_opt = get_idx_opt(self, key);
-    assert!(option::is_some(&idx_opt), EKeyDoesNotExist);
-    option::destroy_some(idx_opt)
+    let idx_opt = self.get_idx_opt(key);
+    assert!(idx_opt.is_some(), EKeyDoesNotExist);
+    idx_opt.destroy_some()
 }
 
@@ -607,7 +607,7 @@ Aborts if idx is greater than or equal to get_entry_by_idx<K: copy, V>(self: &VecMap<K, V>, idx: u64): (&K, &V) { assert!(idx < size(self), EIndexOutOfBounds); - let entry = vector::borrow(&self.contents, idx); + let entry = &self.contents[idx]; (&entry.key, &entry.value) }
@@ -636,7 +636,7 @@ Aborts if idx is greater than or equal to get_entry_by_idx_mut<K: copy, V>(self: &mut VecMap<K, V>, idx: u64): (&K, &mut V) { assert!(idx < size(self), EIndexOutOfBounds); - let entry = vector::borrow_mut(&mut self.contents, idx); + let entry = &mut self.contents[idx]; (&entry.key, &mut entry.value) }
@@ -664,7 +664,7 @@ Aborts if idx is greater than or equal to remove_entry_by_idx<K: copy, V>(self: &mut VecMap<K, V>, idx: u64): (K, V) { assert!(idx < size(self), EIndexOutOfBounds); - let Entry { key, value } = vector::remove(&mut self.contents, idx); + let Entry { key, value } = self.contents.remove(idx); (key, value) }
diff --git a/crates/sui-framework/docs/sui-framework/vec_set.md b/crates/sui-framework/docs/sui-framework/vec_set.md index 7e951837b424c..70b307ba35dce 100644 --- a/crates/sui-framework/docs/sui-framework/vec_set.md +++ b/crates/sui-framework/docs/sui-framework/vec_set.md @@ -100,7 +100,7 @@ Create an empty V
public fun empty<K: copy + drop>(): VecSet<K> {
-    VecSet { contents: vector::empty() }
+    VecSet { contents: vector[] }
 }
 
@@ -125,7 +125,7 @@ Create a singleton singleton<K: copy + drop>(key: K): VecSet<K> { - VecSet { contents: vector::singleton(key) } + VecSet { contents: vector[key] } }
@@ -151,8 +151,8 @@ Aborts if key is already present in self.
public fun insert<K: copy + drop>(self: &mut VecSet<K>, key: K) {
-    assert!(!contains(self, &key), EKeyAlreadyExists);
-    vector::push_back(&mut self.contents, key)
+    assert!(!self.contains(&key), EKeyAlreadyExists);
+    self.contents.push_back(key)
 }
 
@@ -178,7 +178,7 @@ Remove the entry key from self. Aborts if key is not p
public fun remove<K: copy + drop>(self: &mut VecSet<K>, key: &K) {
     let idx = get_idx(self, key);
-    vector::remove(&mut self.contents, idx);
+    self.contents.remove(idx);
 }
 
@@ -203,7 +203,7 @@ Return true if self contains an entry for key, false o
public fun contains<K: copy + drop>(self: &VecSet<K>, key: &K): bool {
-    option::is_some(&get_idx_opt(self, key))
+    get_idx_opt(self, key).is_some()
 }
 
@@ -228,7 +228,7 @@ Return the number of entries in self
public fun size<K: copy + drop>(self: &VecSet<K>): u64 {
-    vector::length(&self.contents)
+    self.contents.length()
 }
 
@@ -336,7 +336,7 @@ Note that keys are stored in insertion order, *not* sorted. let mut i = 0; let n = size(self); while (i < n) { - if (vector::borrow(&self.contents, i) == key) { + if (&self.contents[i] == key) { return option::some(i) }; i = i + 1; @@ -368,8 +368,8 @@ Note that map entries are stored in insertion order, *not* sorted.
fun get_idx<K: copy + drop>(self: &VecSet<K>, key: &K): u64 {
     let idx_opt = get_idx_opt(self, key);
-    assert!(option::is_some(&idx_opt), EKeyDoesNotExist);
-    option::destroy_some(idx_opt)
+    assert!(idx_opt.is_some(), EKeyDoesNotExist);
+    idx_opt.destroy_some()
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/versioned.md b/crates/sui-framework/docs/sui-framework/versioned.md index a806f22a06f67..527402e185ed8 100644 --- a/crates/sui-framework/docs/sui-framework/versioned.md +++ b/crates/sui-framework/docs/sui-framework/versioned.md @@ -300,7 +300,7 @@ Destroy this Versioned container, and return the inner object.
public fun destroy<T: store>(self: Versioned): T {
     let Versioned { mut id, version } = self;
     let ret = dynamic_field::remove(&mut id, version);
-    object::delete(id);
+    id.delete();
     ret
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/zklogin_verified_id.md b/crates/sui-framework/docs/sui-framework/zklogin_verified_id.md index e27860ac1e733..28b2021e94517 100644 --- a/crates/sui-framework/docs/sui-framework/zklogin_verified_id.md +++ b/crates/sui-framework/docs/sui-framework/zklogin_verified_id.md @@ -240,7 +240,7 @@ Delete a VerifiedID
public fun delete(verified_id: VerifiedID) {
     let VerifiedID { id, owner: _, key_claim_name: _, key_claim_value: _, issuer: _, audience: _ } = verified_id;
-    object::delete(id);
+    id.delete();
 }
 
diff --git a/crates/sui-framework/docs/sui-framework/zklogin_verified_issuer.md b/crates/sui-framework/docs/sui-framework/zklogin_verified_issuer.md index 8185be435441e..eff47b4face1d 100644 --- a/crates/sui-framework/docs/sui-framework/zklogin_verified_issuer.md +++ b/crates/sui-framework/docs/sui-framework/zklogin_verified_issuer.md @@ -157,7 +157,7 @@ Delete a VerifiedIssuer
public fun delete(verified_issuer: VerifiedIssuer) {
     let VerifiedIssuer { id, owner: _, issuer: _ } = verified_issuer;
-    object::delete(id);
+    id.delete();
 }
 
@@ -189,7 +189,7 @@ Aborts with tx_context::sender(ctx); + let sender = ctx.sender(); assert!(check_zklogin_issuer(sender, address_seed, &issuer), EInvalidProof); transfer::transfer( VerifiedIssuer { @@ -227,7 +227,7 @@ Returns true if address was created using zklogin with the g address_seed: u256, issuer: &String, ): bool { - check_zklogin_issuer_internal(address, address_seed, std::string::bytes(issuer)) + check_zklogin_issuer_internal(address, address_seed, issuer.bytes()) }
diff --git a/crates/sui-framework/packages/deepbook/Move.lock b/crates/sui-framework/packages/deepbook/Move.lock index fb86e3de4b156..40c594faa0e54 100644 --- a/crates/sui-framework/packages/deepbook/Move.lock +++ b/crates/sui-framework/packages/deepbook/Move.lock @@ -1,7 +1,7 @@ # @generated by Move, please check-in and do not edit manually. [move] -version = 0 +version = 1 manifest_digest = "E7FF1D7441FA0105B981EE018AEF168A18B22984DEABBF2F111AA6FBB3C3CB81" deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" @@ -23,6 +23,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.21.0" +compiler-version = "1.22.0" edition = "legacy" flavor = "sui" diff --git a/crates/sui-framework/packages/sui-framework/Move.lock b/crates/sui-framework/packages/sui-framework/Move.lock index 5a17a8b0e0275..e38ac909eb150 100644 --- a/crates/sui-framework/packages/sui-framework/Move.lock +++ b/crates/sui-framework/packages/sui-framework/Move.lock @@ -1,8 +1,8 @@ # @generated by Move, please check-in and do not edit manually. [move] -version = 0 -manifest_digest = "20751505E200B1A5E766A503B01DF098239F2D7596998DA04016D9A34FC3E203" +version = 1 +manifest_digest = "ED5DEFBBF556EE89312E639A53F21DE24320F9B13C2087D3BFE2989D5B2B5DAF" deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" dependencies = [ @@ -14,6 +14,6 @@ name = "MoveStdlib" source = { local = "../move-stdlib" } [move.toolchain-version] -compiler-version = "1.17.0" +compiler-version = "1.22.0" edition = "legacy" flavor = "sui" diff --git a/crates/sui-framework/packages/sui-framework/sources/address.move b/crates/sui-framework/packages/sui-framework/sources/address.move index 89f9051757f82..129908910df05 100644 --- a/crates/sui-framework/packages/sui-framework/sources/address.move +++ b/crates/sui-framework/packages/sui-framework/sources/address.move @@ -1,12 +1,15 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 +#[defines_primitive(address)] module sui::address { use sui::hex; use std::ascii; use std::bcs; use std::string; - use std::vector; + + /// Allows calling `.to_id()` on an address to get its `ID`. + public use fun sui::object::id_from_address as address.to_id; /// The length of an address, in bytes const LENGTH: u64 = 32; @@ -37,12 +40,12 @@ module sui::address { /// Convert `a` to a hex-encoded ASCII string public fun to_ascii_string(a: address): ascii::String { - ascii::string(hex::encode(to_bytes(a))) + hex::encode(to_bytes(a)).to_ascii_string() } - /// Convert `a` to a hex-encoded ASCII string + /// Convert `a` to a hex-encoded string public fun to_string(a: address): string::String { - string::from_ascii(to_ascii_string(a)) + to_ascii_string(a).to_string() } /// Converts an ASCII string to an address, taking the numerical value for each character. The @@ -52,13 +55,13 @@ module sui::address { /// Aborts with `EAddressParseError` if the length of `s` is not 64, /// or if an invalid character is encountered. public fun from_ascii_bytes(bytes: &vector): address { - assert!(vector::length(bytes) == 64, EAddressParseError); + assert!(bytes.length() == 64, EAddressParseError); let mut hex_bytes = vector[]; let mut i = 0; while (i < 64) { - let hi = hex_char_value(*vector::borrow(bytes, i)); - let lo = hex_char_value(*vector::borrow(bytes, i + 1)); - vector::push_back(&mut hex_bytes, (hi << 4) | lo); + let hi = hex_char_value(bytes[i]); + let lo = hex_char_value(bytes[i+1]); + hex_bytes.push_back((hi << 4) | lo); i = i + 2; }; from_bytes(hex_bytes) diff --git a/crates/sui-framework/packages/sui-framework/sources/authenticator_state.move b/crates/sui-framework/packages/sui-framework/sources/authenticator_state.move index 68afa45e7a905..d6d1b7dcdfd86 100644 --- a/crates/sui-framework/packages/sui-framework/sources/authenticator_state.move +++ b/crates/sui-framework/packages/sui-framework/sources/authenticator_state.move @@ -9,13 +9,8 @@ // state to the chain for auditability + restore from snapshot purposes. module sui::authenticator_state { use std::string; - use std::option::{Self, Option}; - use std::vector; use sui::dynamic_field; use std::string::{String, utf8}; - use sui::object::{Self, UID}; - use sui::transfer; - use sui::tx_context::{Self, TxContext}; use sui::math; /// Sender is not @0x0 the system address. @@ -100,18 +95,18 @@ module sui::authenticator_state { // ordering is not necessarily the same as the string ordering, but we just need some // canonical that is cheap to compute. fun string_bytes_lt(a: &String, b: &String): bool { - let a_bytes = string::bytes(a); - let b_bytes = string::bytes(b); + let a_bytes = a.bytes(); + let b_bytes = b.bytes(); - if (vector::length(a_bytes) < vector::length(b_bytes)) { + if (a_bytes.length() < b_bytes.length()) { true - } else if (vector::length(a_bytes) > vector::length(b_bytes)) { + } else if (a_bytes.length() > b_bytes.length()) { false } else { let mut i = 0; - while (i < vector::length(a_bytes)) { - let a_byte = *vector::borrow(a_bytes, i); - let b_byte = *vector::borrow(b_bytes, i); + while (i < a_bytes.length()) { + let a_byte = a_bytes[i]; + let b_byte = b_bytes[i]; if (a_byte < b_byte) { return true } else if (a_byte > b_byte) { @@ -149,7 +144,7 @@ module sui::authenticator_state { /// the authenticator state object is first created. /// Can only be called by genesis or change_epoch transactions. fun create(ctx: &TxContext) { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); let version = CurrentVersion; @@ -197,9 +192,9 @@ module sui::authenticator_state { fun check_sorted(new_active_jwks: &vector) { let mut i = 0; - while (i < vector::length(new_active_jwks) - 1) { - let a = vector::borrow(new_active_jwks, i); - let b = vector::borrow(new_active_jwks, i + 1); + while (i < new_active_jwks.length() - 1) { + let a = &new_active_jwks[i]; + let b = &new_active_jwks[i + 1]; assert!(jwk_lt(a, b), EJwksNotSorted); i = i + 1; }; @@ -216,52 +211,52 @@ module sui::authenticator_state { ctx: &TxContext, ) { // Validator will make a special system call with sender set as 0x0. - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); check_sorted(&new_active_jwks); let new_active_jwks = deduplicate(new_active_jwks); - let inner = load_inner_mut(self); + let inner = self.load_inner_mut(); let mut res = vector[]; let mut i = 0; let mut j = 0; - let active_jwks_len = vector::length(&inner.active_jwks); - let new_active_jwks_len = vector::length(&new_active_jwks); + let active_jwks_len = inner.active_jwks.length(); + let new_active_jwks_len = new_active_jwks.length(); while (i < active_jwks_len && j < new_active_jwks_len) { - let old_jwk = vector::borrow(&inner.active_jwks, i); - let new_jwk = vector::borrow(&new_active_jwks, j); + let old_jwk = &inner.active_jwks[i]; + let new_jwk = &new_active_jwks[j]; // when they are equal, push only one, but use the max epoch of the two if (active_jwk_equal(old_jwk, new_jwk)) { let mut jwk = *old_jwk; jwk.epoch = math::max(old_jwk.epoch, new_jwk.epoch); - vector::push_back(&mut res, jwk); + res.push_back(jwk); i = i + 1; j = j + 1; } else if (jwk_id_equal(&old_jwk.jwk_id, &new_jwk.jwk_id)) { // if only jwk_id is equal, then the key has changed. Providers should not send // JWKs like this, but if they do, we must ignore the new JWK to avoid having a // liveness / forking issues - vector::push_back(&mut res, *old_jwk); + res.push_back(*old_jwk); i = i + 1; j = j + 1; } else if (jwk_lt(old_jwk, new_jwk)) { - vector::push_back(&mut res, *old_jwk); + res.push_back(*old_jwk); i = i + 1; } else { - vector::push_back(&mut res, *new_jwk); + res.push_back(*new_jwk); j = j + 1; } }; while (i < active_jwks_len) { - vector::push_back(&mut res, *vector::borrow(&inner.active_jwks, i)); + res.push_back(inner.active_jwks[i]); i = i + 1; }; while (j < new_active_jwks_len) { - vector::push_back(&mut res, *vector::borrow(&new_active_jwks, j)); + res.push_back(new_active_jwks[j]); j = j + 1; }; @@ -272,18 +267,18 @@ module sui::authenticator_state { let mut res = vector[]; let mut i = 0; let mut prev: Option = option::none(); - while (i < vector::length(&jwks)) { - let jwk = vector::borrow(&jwks, i); - if (option::is_none(&prev)) { - option::fill(&mut prev, jwk.jwk_id); - } else if (jwk_id_equal(option::borrow(&prev), &jwk.jwk_id)) { + while (i < jwks.length()) { + let jwk = &jwks[i]; + if (prev.is_none()) { + prev.fill(jwk.jwk_id); + } else if (jwk_id_equal(prev.borrow(), &jwk.jwk_id)) { // skip duplicate jwks in input i = i + 1; continue } else { - *option::borrow_mut(&mut prev) = jwk.jwk_id; + *prev.borrow_mut() = jwk.jwk_id; }; - vector::push_back(&mut res, *jwk); + res.push_back(*jwk); i = i + 1; }; res @@ -297,11 +292,11 @@ module sui::authenticator_state { min_epoch: u64, ctx: &TxContext) { // This will only be called by sui_system::advance_epoch - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); let inner = load_inner_mut(self); - let len = vector::length(&inner.active_jwks); + let len = inner.active_jwks.length(); // first we count how many jwks from each issuer are above the min_epoch // and store the counts in a vector that parallels the (sorted) active_jwks vector @@ -310,19 +305,19 @@ module sui::authenticator_state { let mut prev_issuer: Option = option::none(); while (i < len) { - let cur = vector::borrow(&inner.active_jwks, i); + let cur = &inner.active_jwks[i]; let cur_iss = &cur.jwk_id.iss; - if (option::is_none(&prev_issuer)) { - option::fill(&mut prev_issuer, *cur_iss); - vector::push_back(&mut issuer_max_epochs, cur.epoch); + if (prev_issuer.is_none()) { + prev_issuer.fill(*cur_iss); + issuer_max_epochs.push_back(cur.epoch); } else { - if (cur_iss == option::borrow(&prev_issuer)) { - let back = vector::length(&issuer_max_epochs) - 1; - let prev_max_epoch = vector::borrow_mut(&mut issuer_max_epochs, back); + if (cur_iss == prev_issuer.borrow()) { + let back = issuer_max_epochs.length() - 1; + let prev_max_epoch = &mut issuer_max_epochs[back]; *prev_max_epoch = math::max(*prev_max_epoch, cur.epoch); } else { - *option::borrow_mut(&mut prev_issuer) = *cur_iss; - vector::push_back(&mut issuer_max_epochs, cur.epoch); + *prev_issuer.borrow_mut() = *cur_iss; + issuer_max_epochs.push_back(cur.epoch); } }; i = i + 1; @@ -335,22 +330,22 @@ module sui::authenticator_state { let mut i = 0; let mut j = 0; while (i < len) { - let jwk = vector::borrow(&inner.active_jwks, i); + let jwk = &inner.active_jwks[i]; let cur_iss = &jwk.jwk_id.iss; - if (option::is_none(&prev_issuer)) { - option::fill(&mut prev_issuer, *cur_iss); - } else if (cur_iss != option::borrow(&prev_issuer)) { - *option::borrow_mut(&mut prev_issuer) = *cur_iss; + if (prev_issuer.is_none()) { + prev_issuer.fill(*cur_iss); + } else if (cur_iss != prev_issuer.borrow()) { + *prev_issuer.borrow_mut() = *cur_iss; j = j + 1; }; - let max_epoch_for_iss = vector::borrow(&issuer_max_epochs, j); + let max_epoch_for_iss = &issuer_max_epochs[j]; // TODO: if the iss for this jwk has *no* jwks that meet the minimum epoch, // then expire nothing. if (*max_epoch_for_iss < min_epoch || jwk.epoch >= min_epoch) { - vector::push_back(&mut new_active_jwks, *jwk); + new_active_jwks.push_back(*jwk); }; i = i + 1; }; @@ -364,8 +359,8 @@ module sui::authenticator_state { self: &AuthenticatorState, ctx: &TxContext, ): vector { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); - load_inner(self).active_jwks + assert!(ctx.sender() == @0x0, ENotSystemAddress); + self.load_inner().active_jwks } #[test_only] @@ -379,7 +374,7 @@ module sui::authenticator_state { new_active_jwks: vector, ctx: &TxContext, ) { - update_authenticator_state(self, new_active_jwks, ctx); + self.update_authenticator_state(new_active_jwks, ctx); } #[test_only] @@ -388,7 +383,7 @@ module sui::authenticator_state { min_epoch: u64, ctx: &TxContext, ) { - expire_jwks(self, min_epoch, ctx); + self.expire_jwks(min_epoch, ctx); } #[test_only] @@ -396,6 +391,6 @@ module sui::authenticator_state { self: &AuthenticatorState, ctx: &TxContext, ): vector { - get_active_jwks(self, ctx) + self.get_active_jwks(ctx) } } diff --git a/crates/sui-framework/packages/sui-framework/sources/bag.move b/crates/sui-framework/packages/sui-framework/sources/bag.move index 79e571f6861e3..99a59e93722f6 100644 --- a/crates/sui-framework/packages/sui-framework/sources/bag.move +++ b/crates/sui-framework/packages/sui-framework/sources/bag.move @@ -22,9 +22,7 @@ /// deleted, even if it has dynamic fields associated with it, but a bag, on the other hand, must be /// empty to be destroyed. module sui::bag { - use sui::object::{Self, UID}; use sui::dynamic_field as field; - use sui::tx_context::TxContext; // Attempted to destroy a non-empty bag const EBagNotEmpty: u64 = 0; @@ -52,6 +50,7 @@ module sui::bag { bag.size = bag.size + 1; } + #[syntax(index)] /// Immutable borrows the value associated with the key in the bag `bag: &Bag`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the bag does not have an entry with /// that key `k: K`. @@ -61,6 +60,7 @@ module sui::bag { field::borrow(&bag.id, k) } + #[syntax(index)] /// Mutably borrows the value associated with the key in the bag `bag: &mut Bag`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the bag does not have an entry with /// that key `k: K`. @@ -107,6 +107,6 @@ module sui::bag { public fun destroy_empty(bag: Bag) { let Bag { id, size } = bag; assert!(size == 0, EBagNotEmpty); - object::delete(id) + id.delete() } } diff --git a/crates/sui-framework/packages/sui-framework/sources/balance.move b/crates/sui-framework/packages/sui-framework/sources/balance.move index 1bdb56cbc6b1a..57247c2110985 100644 --- a/crates/sui-framework/packages/sui-framework/sources/balance.move +++ b/crates/sui-framework/packages/sui-framework/sources/balance.move @@ -5,7 +5,9 @@ /// module to allow balance operations and can be used to implement /// custom coins with `Supply` and `Balance`s. module sui::balance { - use sui::tx_context::{Self, TxContext}; + + /// Allows calling `.into_coin()` on a `Balance` to turn it into a coin. + public use fun sui::coin::from_balance as Balance.into_coin; /* friend sui::sui; */ @@ -96,7 +98,7 @@ module sui::balance { /// It should only be called by the epoch change system txn to create staking rewards, /// and nowhere else. fun create_staking_rewards(value: u64, ctx: &TxContext): Balance { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); Balance { value } } @@ -105,7 +107,7 @@ module sui::balance { /// It should only be called by the epoch change system txn to destroy storage rebates, /// and nowhere else. fun destroy_storage_rebates(self: Balance, ctx: &TxContext) { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); let Balance { value: _ } = self; } @@ -146,19 +148,19 @@ module sui::balance_tests { let mut balance = balance::zero(); let another = balance::create_for_testing(1000); - balance::join(&mut balance, another); + balance.join(another); - assert!(balance::value(&balance) == 1000, 0); + assert!(balance.value() == 1000, 0); - let balance1 = balance::split(&mut balance, 333); - let balance2 = balance::split(&mut balance, 333); - let balance3 = balance::split(&mut balance, 334); + let balance1 = balance.split(333); + let balance2 = balance.split(333); + let balance3 = balance.split(334); - balance::destroy_zero(balance); + balance.destroy_zero(); - assert!(balance::value(&balance1) == 333, 1); - assert!(balance::value(&balance2) == 333, 2); - assert!(balance::value(&balance3) == 334, 3); + assert!(balance1.value() == 333, 1); + assert!(balance2.value() == 333, 2); + assert!(balance3.value() == 334, 3); test_utils::destroy(balance1); test_utils::destroy(balance2); diff --git a/crates/sui-framework/packages/sui-framework/sources/bcs.move b/crates/sui-framework/packages/sui-framework/sources/bcs.move index 6653928f6bde8..f8d1f570b14f6 100644 --- a/crates/sui-framework/packages/sui-framework/sources/bcs.move +++ b/crates/sui-framework/packages/sui-framework/sources/bcs.move @@ -22,19 +22,17 @@ /// /// let prepared: BCS = bcs::new(bytes); /// let (u8_value, u64_value) = ( -/// bcs::peel_u8(&mut prepared), -/// bcs::peel_u64(&mut prepared) +/// prepared.peel_u8(), +/// prepared.peel_u64() /// ); /// /// // unpack bcs struct -/// let leftovers = bcs::into_remainder_bytes(prepared); +/// let leftovers = prepared.into_remainder_bytes(); /// /// (u8_value, u64_value, leftovers) /// } /// ``` module sui::bcs { - use std::option::{Self, Option}; - use std::vector as v; use sui::address; use std::bcs; @@ -61,7 +59,7 @@ module sui::bcs { /// Creates a new instance of BCS wrapper that holds inversed /// bytes for better performance. public fun new(mut bytes: vector): BCS { - v::reverse(&mut bytes); + bytes.reverse(); BCS { bytes } } @@ -69,16 +67,16 @@ module sui::bcs { /// Useful for passing the data further after partial deserialization. public fun into_remainder_bytes(bcs: BCS): vector { let BCS { mut bytes } = bcs; - v::reverse(&mut bytes); + bytes.reverse(); bytes } /// Read address from the bcs-serialized bytes. public fun peel_address(bcs: &mut BCS): address { - assert!(v::length(&bcs.bytes) >= address::length(), EOutOfRange); - let (mut addr_bytes, mut i) = (v::empty(), 0); + assert!(bcs.bytes.length() >= address::length(), EOutOfRange); + let (mut addr_bytes, mut i) = (vector[], 0); while (i < address::length()) { - v::push_back(&mut addr_bytes, v::pop_back(&mut bcs.bytes)); + addr_bytes.push_back(bcs.bytes.pop_back()); i = i + 1; }; address::from_bytes(addr_bytes) @@ -86,7 +84,7 @@ module sui::bcs { /// Read a `bool` value from bcs-serialized bytes. public fun peel_bool(bcs: &mut BCS): bool { - let value = peel_u8(bcs); + let value = bcs.peel_u8(); if (value == 0) { false } else if (value == 1) { @@ -98,17 +96,17 @@ module sui::bcs { /// Read `u8` value from bcs-serialized bytes. public fun peel_u8(bcs: &mut BCS): u8 { - assert!(v::length(&bcs.bytes) >= 1, EOutOfRange); - v::pop_back(&mut bcs.bytes) + assert!(bcs.bytes.length() >= 1, EOutOfRange); + bcs.bytes.pop_back() } /// Read `u64` value from bcs-serialized bytes. public fun peel_u64(bcs: &mut BCS): u64 { - assert!(v::length(&bcs.bytes) >= 8, EOutOfRange); + assert!(bcs.bytes.length() >= 8, EOutOfRange); let (mut value, mut i) = (0u64, 0u8); while (i < 64) { - let byte = (v::pop_back(&mut bcs.bytes) as u64); + let byte = (bcs.bytes.pop_back() as u64); value = value + (byte << i); i = i + 8; }; @@ -118,11 +116,11 @@ module sui::bcs { /// Read `u128` value from bcs-serialized bytes. public fun peel_u128(bcs: &mut BCS): u128 { - assert!(v::length(&bcs.bytes) >= 16, EOutOfRange); + assert!(bcs.bytes.length() >= 16, EOutOfRange); let (mut value, mut i) = (0u128, 0u8); while (i < 128) { - let byte = (v::pop_back(&mut bcs.bytes) as u128); + let byte = (bcs.bytes.pop_back() as u128); value = value + (byte << i); i = i + 8; }; @@ -132,11 +130,11 @@ module sui::bcs { /// Read `u256` value from bcs-serialized bytes. public fun peel_u256(bcs: &mut BCS): u256 { - assert!(v::length(&bcs.bytes) >= 32, EOutOfRange); + assert!(bcs.bytes.length() >= 32, EOutOfRange); let (mut value, mut i) = (0u256, 0u16); while (i < 256) { - let byte = (v::pop_back(&mut bcs.bytes) as u256); + let byte = (bcs.bytes.pop_back() as u256); value = value + (byte << (i as u8)); i = i + 8; }; @@ -155,7 +153,7 @@ module sui::bcs { let (mut total, mut shift, mut len) = (0u64, 0, 0); while (true) { assert!(len <= 4, ELenOutOfRange); - let byte = (v::pop_back(&mut bcs.bytes) as u64); + let byte = (bcs.bytes.pop_back() as u64); len = len + 1; total = total | ((byte & 0x7f) << shift); if ((byte & 0x80) == 0) { @@ -168,9 +166,9 @@ module sui::bcs { /// Peel a vector of `address` from serialized bytes. public fun peel_vec_address(bcs: &mut BCS): vector
{ - let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]); + let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]); while (i < len) { - v::push_back(&mut res, peel_address(bcs)); + res.push_back(bcs.peel_address()); i = i + 1; }; res @@ -178,9 +176,9 @@ module sui::bcs { /// Peel a vector of `address` from serialized bytes. public fun peel_vec_bool(bcs: &mut BCS): vector { - let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]); + let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]); while (i < len) { - v::push_back(&mut res, peel_bool(bcs)); + res.push_back(bcs.peel_bool()); i = i + 1; }; res @@ -188,9 +186,9 @@ module sui::bcs { /// Peel a vector of `u8` (eg string) from serialized bytes. public fun peel_vec_u8(bcs: &mut BCS): vector { - let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]); + let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]); while (i < len) { - v::push_back(&mut res, peel_u8(bcs)); + res.push_back(bcs.peel_u8()); i = i + 1; }; res @@ -198,9 +196,9 @@ module sui::bcs { /// Peel a `vector>` (eg vec of string) from serialized bytes. public fun peel_vec_vec_u8(bcs: &mut BCS): vector> { - let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]); + let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]); while (i < len) { - v::push_back(&mut res, peel_vec_u8(bcs)); + res.push_back(bcs.peel_vec_u8()); i = i + 1; }; res @@ -208,9 +206,9 @@ module sui::bcs { /// Peel a vector of `u64` from serialized bytes. public fun peel_vec_u64(bcs: &mut BCS): vector { - let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]); + let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]); while (i < len) { - v::push_back(&mut res, peel_u64(bcs)); + res.push_back(bcs.peel_u64()); i = i + 1; }; res @@ -218,9 +216,9 @@ module sui::bcs { /// Peel a vector of `u128` from serialized bytes. public fun peel_vec_u128(bcs: &mut BCS): vector { - let (len, mut i, mut res) = (peel_vec_length(bcs), 0, vector[]); + let (len, mut i, mut res) = (bcs.peel_vec_length(), 0, vector[]); while (i < len) { - v::push_back(&mut res, peel_u128(bcs)); + res.push_back(bcs.peel_u128()); i = i + 1; }; res @@ -230,8 +228,8 @@ module sui::bcs { /// Peel `Option
` from serialized bytes. public fun peel_option_address(bcs: &mut BCS): Option
{ - if (peel_bool(bcs)) { - option::some(peel_address(bcs)) + if (bcs.peel_bool()) { + option::some(bcs.peel_address()) } else { option::none() } @@ -239,8 +237,8 @@ module sui::bcs { /// Peel `Option` from serialized bytes. public fun peel_option_bool(bcs: &mut BCS): Option { - if (peel_bool(bcs)) { - option::some(peel_bool(bcs)) + if (bcs.peel_bool()) { + option::some(bcs.peel_bool()) } else { option::none() } @@ -248,8 +246,8 @@ module sui::bcs { /// Peel `Option` from serialized bytes. public fun peel_option_u8(bcs: &mut BCS): Option { - if (peel_bool(bcs)) { - option::some(peel_u8(bcs)) + if (bcs.peel_bool()) { + option::some(bcs.peel_u8()) } else { option::none() } @@ -257,8 +255,8 @@ module sui::bcs { /// Peel `Option` from serialized bytes. public fun peel_option_u64(bcs: &mut BCS): Option { - if (peel_bool(bcs)) { - option::some(peel_u64(bcs)) + if (bcs.peel_bool()) { + option::some(bcs.peel_u64()) } else { option::none() } @@ -266,8 +264,8 @@ module sui::bcs { /// Peel `Option` from serialized bytes. public fun peel_option_u128(bcs: &mut BCS): Option { - if (peel_bool(bcs)) { - option::some(peel_u128(bcs)) + if (bcs.peel_bool()) { + option::some(bcs.peel_u128()) } else { option::none() } @@ -283,7 +281,7 @@ module sui::bcs { fun test_uleb_len_fail() { let value = vector[0xff, 0xff, 0xff, 0xff, 0xff]; let mut bytes = new(to_bytes(&value)); - let _fail = peel_vec_length(&mut bytes); + let _fail = bytes.peel_vec_length(); abort 2 // TODO: make this test fail } @@ -291,7 +289,7 @@ module sui::bcs { #[expected_failure(abort_code = ENotBool)] fun test_bool_fail() { let mut bytes = new(to_bytes(&10u8)); - let _fail = peel_bool(&mut bytes); + let _fail = bytes.peel_bool(); } #[test] @@ -299,37 +297,37 @@ module sui::bcs { { let value = option::some(true); let mut bytes = new(to_bytes(&value)); - assert!(value == peel_option_bool(&mut bytes), 0); + assert!(value == bytes.peel_option_bool(), 0); }; { let value = option::some(10u8); let mut bytes = new(to_bytes(&value)); - assert!(value == peel_option_u8(&mut bytes), 0); + assert!(value == bytes.peel_option_u8(), 0); }; { let value = option::some(10000u64); let mut bytes = new(to_bytes(&value)); - assert!(value == peel_option_u64(&mut bytes), 0); + assert!(value == bytes.peel_option_u64(), 0); }; { let value = option::some(10000999999u128); let mut bytes = new(to_bytes(&value)); - assert!(value == peel_option_u128(&mut bytes), 0); + assert!(value == bytes.peel_option_u128(), 0); }; { let value = option::some(@0xC0FFEE); let mut bytes = new(to_bytes(&value)); - assert!(value == peel_option_address(&mut bytes), 0); + assert!(value == bytes.peel_option_address(), 0); }; { let value: Option = option::none(); let mut bytes = new(to_bytes(&value)); - assert!(value == peel_option_bool(&mut bytes), 0); + assert!(value == bytes.peel_option_bool(), 0); }; } @@ -338,49 +336,49 @@ module sui::bcs { { let value = @0xC0FFEE; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_address(&mut bytes), 0); + assert!(value == bytes.peel_address(), 0); }; { // boolean: true let value = true; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_bool(&mut bytes), 0); + assert!(value == bytes.peel_bool(), 0); }; { // boolean: false let value = false; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_bool(&mut bytes), 0); + assert!(value == bytes.peel_bool(), 0); }; { // u8 let value = 100u8; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_u8(&mut bytes), 0); + assert!(value == bytes.peel_u8(), 0); }; { // u64 (4 bytes) let value = 1000100u64; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_u64(&mut bytes), 0); + assert!(value == bytes.peel_u64(), 0); }; { // u64 (8 bytes) let value = 100000000000000u64; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_u64(&mut bytes), 0); + assert!(value == bytes.peel_u64(), 0); }; { // u128 (16 bytes) let value = 100000000000000000000000000u128; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_u128(&mut bytes), 0); + assert!(value == bytes.peel_u128(), 0); }; { // vector length let value = vector[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; let mut bytes = new(to_bytes(&value)); - assert!(v::length(&value) == peel_vec_length(&mut bytes), 0); + assert!(value.length() == bytes.peel_vec_length(), 0); }; { // vector length (more data) @@ -394,29 +392,29 @@ module sui::bcs { ]; let mut bytes = new(to_bytes(&value)); - assert!(v::length(&value) == peel_vec_length(&mut bytes), 0); + assert!(value.length() == bytes.peel_vec_length(), 0); }; { // full deserialization test (ordering) let info = Info { a: true, b: 100, c: 9999, d: 112333, k: vector[true, false, true, false], s: @0xAAAAAAAAAAA }; let mut bytes = new(to_bytes(&info)); - assert!(info.a == peel_bool(&mut bytes), 0); - assert!(info.b == peel_u8(&mut bytes), 0); - assert!(info.c == peel_u64(&mut bytes), 0); - assert!(info.d == peel_u128(&mut bytes), 0); + assert!(info.a == bytes.peel_bool(), 0); + assert!(info.b == bytes.peel_u8(), 0); + assert!(info.c == bytes.peel_u64(), 0); + assert!(info.d == bytes.peel_u128(), 0); - let len = peel_vec_length(&mut bytes); + let len = bytes.peel_vec_length(); - assert!(v::length(&info.k) == len, 0); + assert!(info.k.length() == len, 0); let mut i = 0; - while (i < v::length(&info.k)) { - assert!(*v::borrow(&info.k, i) == peel_bool(&mut bytes), 0); + while (i < info.k.length()) { + assert!(info.k[i] == bytes.peel_bool(), 0); i = i + 1; }; - assert!(info.s == peel_address(&mut bytes), 0); + assert!(info.s == bytes.peel_address(), 0); }; { // read vector of bytes directly @@ -426,37 +424,37 @@ module sui::bcs { vector[1,2,3,4,5] ]; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_vec_vec_u8(&mut bytes), 0); + assert!(value == bytes.peel_vec_vec_u8(), 0); }; { // read vector of bytes directly let value = vector[1,2,3,4,5]; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_vec_u8(&mut bytes), 0); + assert!(value == bytes.peel_vec_u8(), 0); }; { // read vector of bytes directly let value = vector[1,2,3,4,5]; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_vec_u64(&mut bytes), 0); + assert!(value == bytes.peel_vec_u64(), 0); }; { // read vector of bytes directly let value = vector[1,2,3,4,5]; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_vec_u128(&mut bytes), 0); + assert!(value == bytes.peel_vec_u128(), 0); }; { // read vector of bytes directly let value = vector[true, false, true, false]; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_vec_bool(&mut bytes), 0); + assert!(value == bytes.peel_vec_bool(), 0); }; { // read vector of address directly let value = vector[@0x0, @0x1, @0x2, @0x3]; let mut bytes = new(to_bytes(&value)); - assert!(value == peel_vec_address(&mut bytes), 0); + assert!(value == bytes.peel_vec_address(), 0); }; } } diff --git a/crates/sui-framework/packages/sui-framework/sources/borrow.move b/crates/sui-framework/packages/sui-framework/sources/borrow.move index 4a71a65095797..55eb1e1ae5bd3 100644 --- a/crates/sui-framework/packages/sui-framework/sources/borrow.move +++ b/crates/sui-framework/packages/sui-framework/sources/borrow.move @@ -7,9 +7,6 @@ /// a transaction, use it and put back in the end. Hot-potato `Borrow` makes /// sure the object is returned and was not swapped for another one. module sui::borrow { - use sui::object::{Self, ID}; - use std::option::{Self, Option}; - use sui::tx_context::{Self, TxContext}; /// The `Borrow` does not match the `Referent`. const EWrongBorrow: u64 = 0; @@ -36,7 +33,7 @@ module sui::borrow { /// Borrow the `T` from the `Referent` receiving the `T` and a `Borrow` /// hot potato. public fun borrow(self: &mut Referent): (T, Borrow) { - let value = option::extract(&mut self.value); + let value = self.value.extract(); let id = object::id(&value); (value, Borrow { @@ -51,13 +48,13 @@ module sui::borrow { assert!(object::id(&value) == obj, EWrongValue); assert!(self.id == ref, EWrongBorrow); - option::fill(&mut self.value, value); + self.value.fill(value); } /// Unpack the `Referent` struct and return the value. public fun destroy(self: Referent): T { let Referent { id: _, value } = self; - option::destroy_some(value) + value.destroy_some() } #[test_only] @@ -74,7 +71,7 @@ module sui::borrow { put_back(&mut ref, value, borrow); let Test { id } = destroy(ref); - object::delete(id); + id.delete(); } #[test] @@ -92,10 +89,10 @@ module sui::borrow { put_back(&mut ref_2, v_1, b_2); let Test { id } = destroy(ref_1); - object::delete(id); + id.delete(); let Test { id } = destroy(ref_2); - object::delete(id); + id.delete(); } #[test] @@ -113,9 +110,9 @@ module sui::borrow { put_back(&mut ref_2, v_1, b_1); let Test { id } = destroy(ref_1); - object::delete(id); + id.delete(); let Test { id } = destroy(ref_2); - object::delete(id); + id.delete(); } } diff --git a/crates/sui-framework/packages/sui-framework/sources/clock.move b/crates/sui-framework/packages/sui-framework/sources/clock.move index 87a05c60016aa..72e661e5ba40f 100644 --- a/crates/sui-framework/packages/sui-framework/sources/clock.move +++ b/crates/sui-framework/packages/sui-framework/sources/clock.move @@ -4,9 +4,6 @@ /// APIs for accessing time from move calls, via the `Clock`: a unique /// shared object that is created at 0x6 during genesis. module sui::clock { - use sui::object::{Self, UID}; - use sui::transfer; - use sui::tx_context::{Self, TxContext}; /// Sender is not @0x0 the system address. const ENotSystemAddress: u64 = 0; @@ -38,7 +35,7 @@ module sui::clock { /// Create and share the singleton Clock -- this function is /// called exactly once, during genesis. fun create(ctx: &TxContext) { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); transfer::share_object(Clock { id: object::clock(), @@ -56,7 +53,7 @@ module sui::clock { ctx: &TxContext, ) { // Validator will make a special system call with sender set as 0x0. - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); clock.timestamp_ms = timestamp_ms } @@ -91,6 +88,6 @@ module sui::clock { #[test_only] public fun destroy_for_testing(clock: Clock) { let Clock { id, timestamp_ms: _ } = clock; - object::delete(id); + id.delete(); } } diff --git a/crates/sui-framework/packages/sui-framework/sources/coin.move b/crates/sui-framework/packages/sui-framework/sources/coin.move index 8448f2796a82a..8982932534640 100644 --- a/crates/sui-framework/packages/sui-framework/sources/coin.move +++ b/crates/sui-framework/packages/sui-framework/sources/coin.move @@ -7,16 +7,23 @@ module sui::coin { use std::string; use std::ascii; - use std::option::{Self, Option}; use sui::balance::{Self, Balance, Supply}; - use sui::tx_context::TxContext; - use sui::object::{Self, UID, ID}; - use sui::transfer; use sui::url::{Self, Url}; - use std::vector; use sui::deny_list::{Self, DenyList}; use std::type_name; + // Allows calling `.split_vec(amounts, ctx)` on `coin` + public use fun sui::pay::split_vec as Coin.split_vec; + + // Allows calling `.join_vec(coins)` on `coin` + public use fun sui::pay::join_vec as Coin.join_vec; + + // Allows calling `.split_and_transfer(amount, recipient, ctx)` on `coin` + public use fun sui::pay::split_and_transfer as Coin.split_and_transfer; + + // Allows calling `.divide_and_keep(n, ctx)` on `coin` + public use fun sui::pay::divide_and_keep as Coin.divide_and_keep; + /// A type passed to create_supply is not a one-time witness. const EBadWitness: u64 = 0; /// Invalid arguments are passed to a function. @@ -85,7 +92,7 @@ module sui::coin { /// to different security guarantees (TreasuryCap can be created only once for a type) public fun treasury_into_supply(treasury: TreasuryCap): Supply { let TreasuryCap { id, total_supply } = treasury; - object::delete(id); + id.delete(); total_supply } @@ -103,7 +110,7 @@ module sui::coin { /// Public getter for the coin's value public fun value(self: &Coin): u64 { - balance::value(&self.balance) + self.balance.value() } /// Get immutable reference to the balance of a coin. @@ -124,7 +131,7 @@ module sui::coin { /// Destruct a Coin wrapper and keep the balance. public fun into_balance(coin: Coin): Balance { let Coin { id, balance } = coin; - object::delete(id); + id.delete(); balance } @@ -135,13 +142,13 @@ module sui::coin { ): Coin { Coin { id: object::new(ctx), - balance: balance::split(balance, value) + balance: balance.split(value) } } /// Put a `Coin` to the `Balance`. public fun put(balance: &mut Balance, coin: Coin) { - balance::join(balance, into_balance(coin)); + balance.join(into_balance(coin)); } // === Base Coin functionality === @@ -150,8 +157,8 @@ module sui::coin { /// Aborts if `c.value + self.value > U64_MAX` public entry fun join(self: &mut Coin, c: Coin) { let Coin { id, balance } = c; - object::delete(id); - balance::join(&mut self.balance, balance); + id.delete(); + self.balance.join(balance); } /// Split coin `self` to two coins, one with balance `split_amount`, @@ -170,11 +177,11 @@ module sui::coin { assert!(n > 0, EInvalidArg); assert!(n <= value(self), ENotEnough); - let mut vec = vector::empty>(); + let mut vec = vector[]; let mut i = 0; let split_amount = value(self) / n; while (i < n - 1) { - vector::push_back(&mut vec, split(self, split_amount, ctx)); + vec.push_back(self.split(split_amount, ctx)); i = i + 1; }; vec @@ -189,8 +196,8 @@ module sui::coin { /// Destroy a coin with value zero public fun destroy_zero(c: Coin) { let Coin { id, balance } = c; - object::delete(id); - balance::destroy_zero(balance) + id.delete(); + balance.destroy_zero() } // === Registering new coin types and managing the coin supply === @@ -265,7 +272,7 @@ module sui::coin { ): Coin { Coin { id: object::new(ctx), - balance: balance::increase_supply(&mut cap.total_supply, value) + balance: cap.total_supply.increase_supply(value) } } @@ -275,15 +282,15 @@ module sui::coin { public fun mint_balance( cap: &mut TreasuryCap, value: u64 ): Balance { - balance::increase_supply(&mut cap.total_supply, value) + cap.total_supply.increase_supply(value) } /// Destroy the coin `c` and decrease the total supply in `cap` /// accordingly. public entry fun burn(cap: &mut TreasuryCap, c: Coin): u64 { let Coin { id, balance } = c; - object::delete(id); - balance::decrease_supply(&mut cap.total_supply, balance) + id.delete(); + cap.total_supply.decrease_supply(balance) } /// The index into the deny list vector for the `sui::coin::Coin` type. @@ -298,7 +305,7 @@ module sui::coin { _ctx: &mut TxContext ) { let `type` = - ascii::into_bytes(type_name::into_string(type_name::get_with_original_ids())); + type_name::into_string(type_name::get_with_original_ids()).into_bytes(); deny_list::add( deny_list, DENY_LIST_COIN_INDEX, @@ -316,7 +323,7 @@ module sui::coin { _ctx: &mut TxContext ) { let `type` = - ascii::into_bytes(type_name::into_string(type_name::get_with_original_ids())); + type_name::into_string(type_name::get_with_original_ids()).into_bytes(); deny_list::remove( deny_list, DENY_LIST_COIN_INDEX, @@ -334,13 +341,8 @@ module sui::coin { let name = type_name::get_with_original_ids(); if (type_name::is_primitive(&name)) return false; - let `type` = ascii::into_bytes(type_name::into_string(name)); - deny_list::contains( - freezer, - DENY_LIST_COIN_INDEX, - `type`, - addr, - ) + let `type` = type_name::into_string(name).into_bytes(); + freezer.contains(DENY_LIST_COIN_INDEX, `type`, addr) } // === Entrypoints === @@ -416,8 +418,8 @@ module sui::coin { /// Burn coins of any type for testing purposes only public fun burn_for_testing(coin: Coin): u64 { let Coin { id, balance } = coin; - object::delete(id); - balance::destroy_for_testing(balance) + id.delete(); + balance.destroy_for_testing() } #[test_only] diff --git a/crates/sui-framework/packages/sui-framework/sources/crypto/groth16.move b/crates/sui-framework/packages/sui-framework/sources/crypto/groth16.move index 9e0a5650a0c2d..e1b5804028fa4 100644 --- a/crates/sui-framework/packages/sui-framework/sources/crypto/groth16.move +++ b/crates/sui-framework/packages/sui-framework/sources/crypto/groth16.move @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 module sui::groth16 { - use std::vector; #[allow(unused_const)] // Error for input is not a valid Arkwork representation of a verifying key. @@ -48,12 +47,12 @@ module sui::groth16 { /// Returns bytes of the four components of the `PreparedVerifyingKey`. public fun pvk_to_bytes(pvk: PreparedVerifyingKey): vector> { - let mut res = vector::empty(); - vector::push_back(&mut res, pvk.vk_gamma_abc_g1_bytes); - vector::push_back(&mut res, pvk.alpha_g1_beta_g2_bytes); - vector::push_back(&mut res, pvk.gamma_g2_neg_pc_bytes); - vector::push_back(&mut res, pvk.delta_g2_neg_pc_bytes); - res + vector[ + pvk.vk_gamma_abc_g1_bytes, + pvk.alpha_g1_beta_g2_bytes, + pvk.gamma_g2_neg_pc_bytes, + pvk.delta_g2_neg_pc_bytes, + ] } /// A `PublicProofInputs` wrapper around its serialized bytes. diff --git a/crates/sui-framework/packages/sui-framework/sources/crypto/group_ops.move b/crates/sui-framework/packages/sui-framework/sources/crypto/group_ops.move index 2b3be4fdefe20..ff1d077d02b00 100644 --- a/crates/sui-framework/packages/sui-framework/sources/crypto/group_ops.move +++ b/crates/sui-framework/packages/sui-framework/sources/crypto/group_ops.move @@ -4,7 +4,6 @@ /// Generic Move and native functions for group operations. module sui::group_ops { - use std::vector; use sui::bcs; /* friend sui::bls12381; */ @@ -29,58 +28,58 @@ module sui::group_ops { public fun bytes(e: &Element): &vector { &e.bytes } - + public fun equal(e1: &Element, e2: &Element): bool { &e1.bytes == &e2.bytes } // Fails if the bytes are not a valid group element and 'is_trusted' is false. - public(package) fun from_bytes(`type`: u8, bytes: &vector, is_trusted: bool): Element { - assert!(is_trusted || internal_validate(`type`, bytes), EInvalidInput); + public(package) fun from_bytes(type_: u8, bytes: &vector, is_trusted: bool): Element { + assert!(is_trusted || internal_validate(type_, bytes), EInvalidInput); Element { bytes: *bytes } } - public(package) fun add(`type`: u8, e1: &Element, e2: &Element): Element { - Element { bytes: internal_add(`type`, &e1.bytes, &e2.bytes) } + public(package) fun add(type_: u8, e1: &Element, e2: &Element): Element { + Element { bytes: internal_add(type_, &e1.bytes, &e2.bytes) } } - public(package) fun sub(`type`: u8, e1: &Element, e2: &Element): Element { - Element { bytes: internal_sub(`type`, &e1.bytes, &e2.bytes) } + public(package) fun sub(type_: u8, e1: &Element, e2: &Element): Element { + Element { bytes: internal_sub(type_, &e1.bytes, &e2.bytes) } } - public(package) fun mul(`type`: u8, scalar: &Element, e: &Element): Element { - Element { bytes: internal_mul(`type`, &scalar.bytes, &e.bytes) } + public(package) fun mul(type_: u8, scalar: &Element, e: &Element): Element { + Element { bytes: internal_mul(type_, &scalar.bytes, &e.bytes) } } /// Fails if scalar = 0. Else returns 1/scalar * e. - public(package) fun div(`type`: u8, scalar: &Element, e: &Element): Element { - Element { bytes: internal_div(`type`, &scalar.bytes, &e.bytes) } + public(package) fun div(type_: u8, scalar: &Element, e: &Element): Element { + Element { bytes: internal_div(type_, &scalar.bytes, &e.bytes) } } - public(package) fun hash_to(`type`: u8, m: &vector): Element { - Element { bytes: internal_hash_to(`type`, m) } + public(package) fun hash_to(type_: u8, m: &vector): Element { + Element { bytes: internal_hash_to(type_, m) } } /// Aborts with `EInputTooLong` if the vectors are too long. - public(package) fun multi_scalar_multiplication(`type`: u8, scalars: &vector>, elements: &vector>): Element { - assert!(vector::length(scalars) > 0, EInvalidInput); - assert!(vector::length(scalars) == vector::length(elements), EInvalidInput); + public(package) fun multi_scalar_multiplication(type_: u8, scalars: &vector>, elements: &vector>): Element { + assert!(scalars.length() > 0, EInvalidInput); + assert!(scalars.length() == elements.length(), EInvalidInput); - let mut scalars_bytes = vector::empty(); - let mut elements_bytes = vector::empty(); + let mut scalars_bytes: vector = vector[]; + let mut elements_bytes: vector = vector[]; let mut i = 0; - while (i < vector::length(scalars)) { - let scalar_vec = *vector::borrow(scalars, i); - vector::append(&mut scalars_bytes, scalar_vec.bytes); - let element_vec = *vector::borrow(elements, i); - vector::append(&mut elements_bytes, element_vec.bytes); + while (i < scalars.length()) { + let scalar_vec = scalars[i]; + scalars_bytes.append(scalar_vec.bytes); + let element_vec = elements[i]; + elements_bytes.append(element_vec.bytes); i = i + 1; }; - Element { bytes: internal_multi_scalar_mul(`type`, &scalars_bytes, &elements_bytes) } + Element { bytes: internal_multi_scalar_mul(type_, &scalars_bytes, &elements_bytes) } } - public(package) fun pairing(`type`: u8, e1: &Element, e2: &Element): Element { - Element { bytes: internal_pairing(`type`, &e1.bytes, &e2.bytes) } + public(package) fun pairing(type_: u8, e1: &Element, e2: &Element): Element { + Element { bytes: internal_pairing(type_, &e1.bytes, &e2.bytes) } } ////////////////////////////// @@ -90,30 +89,30 @@ module sui::group_ops { // Ristrertto255's G). The caller to the above functions is responsible for that. // 'type' specifies the type of all elements. - native fun internal_validate(`type`: u8, bytes: &vector): bool; - native fun internal_add(`type`: u8, e1: &vector, e2: &vector): vector; - native fun internal_sub(`type`: u8, e1: &vector, e2: &vector): vector; + native fun internal_validate(type_: u8, bytes: &vector): bool; + native fun internal_add(type_: u8, e1: &vector, e2: &vector): vector; + native fun internal_sub(type_: u8, e1: &vector, e2: &vector): vector; // 'type' represents the type of e2, and the type of e1 is determined automatically from e2. e1 is a scalar // and e2 is a group/scalar element. - native fun internal_mul(`type`: u8, e1: &vector, e2: &vector): vector; - native fun internal_div(`type`: u8, e1: &vector, e2: &vector): vector; + native fun internal_mul(type_: u8, e1: &vector, e2: &vector): vector; + native fun internal_div(type_: u8, e1: &vector, e2: &vector): vector; - native fun internal_hash_to(`type`: u8, m: &vector): vector; - native fun internal_multi_scalar_mul(`type`: u8, scalars: &vector, elements: &vector): vector; + native fun internal_hash_to(type_: u8, m: &vector): vector; + native fun internal_multi_scalar_mul(type_: u8, scalars: &vector, elements: &vector): vector; // 'type' represents the type of e1, and the rest are determined automatically from e1. - native fun internal_pairing(`type`:u8, e1: &vector, e2: &vector): vector; + native fun internal_pairing(type_: u8, e1: &vector, e2: &vector): vector; // Helper function for encoding a given u64 number as bytes in a given buffer. public(package) fun set_as_prefix(x: u64, big_endian: bool, buffer: &mut vector) { - let buffer_len = vector::length(buffer); + let buffer_len = buffer.length(); assert!(buffer_len > 7, EInvalidBufferLength); let x_as_bytes = bcs::to_bytes(&x); // little endian let mut i = 0; while (i < 8) { let position = if (big_endian) { buffer_len - i - 1 } else { i }; - *vector::borrow_mut(buffer, position) = *vector::borrow(&x_as_bytes, i); + *(&mut buffer[position]) = x_as_bytes[i]; i = i + 1; }; } diff --git a/crates/sui-framework/packages/sui-framework/sources/crypto/poseidon.move b/crates/sui-framework/packages/sui-framework/sources/crypto/poseidon.move index 760df1e5f4a31..1a6055c7a0f3f 100644 --- a/crates/sui-framework/packages/sui-framework/sources/crypto/poseidon.move +++ b/crates/sui-framework/packages/sui-framework/sources/crypto/poseidon.move @@ -4,7 +4,6 @@ /// Module which defines instances of the poseidon hash functions. module sui::poseidon { - use std::vector; use sui::bcs; /// Error if any of the inputs are larger than or equal to the BN254 field size. @@ -23,16 +22,16 @@ module sui::poseidon { /// Each element has to be a BN254 field element in canonical representation so it must be smaller than the BN254 /// scalar field size which is 21888242871839275222246405745257275088548364400416034343698204186575808495617. public fun poseidon_bn254(data: &vector): u256 { - let (mut i, mut b, l) = (0, vector[], vector::length(data)); + let (mut i, mut b, l) = (0, vector[], data.length()); assert!(l > 0, EEmptyInput); while (i < l) { - let field_element = vector::borrow(data, i); + let field_element = &data[i]; assert!(*field_element < BN254_MAX, ENonCanonicalInput); - vector::push_back(&mut b, bcs::to_bytes(vector::borrow(data, i))); + b.push_back(bcs::to_bytes(&data[i])); i = i + 1; }; let binary_output = poseidon_bn254_internal(&b); - bcs::peel_u256(&mut bcs::new(binary_output)) + bcs::new(binary_output).peel_u256() } /// @param data: Vector of BN254 field elements in little-endian representation. diff --git a/crates/sui-framework/packages/sui-framework/sources/crypto/zklogin_verified_id.move b/crates/sui-framework/packages/sui-framework/sources/crypto/zklogin_verified_id.move index b1ea8178d9255..8a5699e012e0c 100644 --- a/crates/sui-framework/packages/sui-framework/sources/crypto/zklogin_verified_id.move +++ b/crates/sui-framework/packages/sui-framework/sources/crypto/zklogin_verified_id.move @@ -4,9 +4,6 @@ #[allow(unused_const, unused_function)] module sui::zklogin_verified_id { use std::string::String; - use sui::object; - use sui::object::UID; - use sui::tx_context::TxContext; const EFunctionDisabled: u64 = 0; @@ -54,7 +51,7 @@ module sui::zklogin_verified_id { /// Delete a VerifiedID public fun delete(verified_id: VerifiedID) { let VerifiedID { id, owner: _, key_claim_name: _, key_claim_value: _, issuer: _, audience: _ } = verified_id; - object::delete(id); + id.delete(); } /// This function has been disabled. diff --git a/crates/sui-framework/packages/sui-framework/sources/crypto/zklogin_verified_issuer.move b/crates/sui-framework/packages/sui-framework/sources/crypto/zklogin_verified_issuer.move index 5ea79d88044cd..30f9c94d97a81 100644 --- a/crates/sui-framework/packages/sui-framework/sources/crypto/zklogin_verified_issuer.move +++ b/crates/sui-framework/packages/sui-framework/sources/crypto/zklogin_verified_issuer.move @@ -4,11 +4,6 @@ #[allow(unused_const)] module sui::zklogin_verified_issuer { use std::string::String; - use sui::transfer; - use sui::object; - use sui::object::UID; - use sui::tx_context::TxContext; - use sui::tx_context; /// Error if the proof consisting of the inputs provided to the verification function is invalid. const EInvalidInput: u64 = 0; @@ -40,7 +35,7 @@ module sui::zklogin_verified_issuer { /// Delete a VerifiedIssuer public fun delete(verified_issuer: VerifiedIssuer) { let VerifiedIssuer { id, owner: _, issuer: _ } = verified_issuer; - object::delete(id); + id.delete(); } /// Verify that the caller's address was created using zklogin with the given issuer. If so, a VerifiedIssuer object @@ -52,7 +47,7 @@ module sui::zklogin_verified_issuer { issuer: String, ctx: &mut TxContext, ) { - let sender = tx_context::sender(ctx); + let sender = ctx.sender(); assert!(check_zklogin_issuer(sender, address_seed, &issuer), EInvalidProof); transfer::transfer( VerifiedIssuer { @@ -70,7 +65,7 @@ module sui::zklogin_verified_issuer { address_seed: u256, issuer: &String, ): bool { - check_zklogin_issuer_internal(address, address_seed, std::string::bytes(issuer)) + check_zklogin_issuer_internal(address, address_seed, issuer.bytes()) } /// Returns true if `address` was created using zklogin with the given issuer and address seed. diff --git a/crates/sui-framework/packages/sui-framework/sources/deny_list.move b/crates/sui-framework/packages/sui-framework/sources/deny_list.move index dbb6b026c5b9b..ae886b2baaa4c 100644 --- a/crates/sui-framework/packages/sui-framework/sources/deny_list.move +++ b/crates/sui-framework/packages/sui-framework/sources/deny_list.move @@ -5,10 +5,6 @@ /// instances of certain core types from being used as inputs by specified addresses in the deny /// list. module sui::deny_list { - use sui::tx_context::TxContext; - use sui::object::{Self, UID}; - use sui::transfer; - use sui::tx_context; use sui::table::{Self, Table}; use sui::bag::{Self, Bag}; use sui::vec_set::{Self, VecSet}; @@ -52,7 +48,8 @@ module sui::deny_list { `type`: vector, addr: address, ) { - per_type_list_add(bag::borrow_mut(&mut deny_list.lists, per_type_index), `type`, addr) + let bag_entry: &mut PerTypeList = &mut deny_list.lists[per_type_index]; + bag_entry.per_type_list_add(`type`, addr) } fun per_type_list_add( @@ -60,18 +57,18 @@ module sui::deny_list { `type`: vector, addr: address, ) { - if (!table::contains(&list.denied_addresses, `type`)) { - table::add(&mut list.denied_addresses, `type`, vec_set::empty()); + if (!list.denied_addresses.contains(`type`)) { + list.denied_addresses.add(`type`, vec_set::empty()); }; - let denied_addresses = table::borrow_mut(&mut list.denied_addresses, `type`); - let already_denied = vec_set::contains(denied_addresses, &addr); + let denied_addresses = &mut list.denied_addresses[`type`]; + let already_denied = denied_addresses.contains(&addr); if (already_denied) return; - vec_set::insert(denied_addresses, addr); - if (!table::contains(&list.denied_count, addr)) { - table::add(&mut list.denied_count, addr, 0); + denied_addresses.insert(addr); + if (!list.denied_count.contains(addr)) { + list.denied_count.add(addr, 0); }; - let denied_count = table::borrow_mut(&mut list.denied_count, addr); + let denied_count = &mut list.denied_count[addr]; *denied_count = *denied_count + 1; } @@ -83,7 +80,7 @@ module sui::deny_list { `type`: vector, addr: address, ) { - per_type_list_remove(bag::borrow_mut(&mut deny_list.lists, per_type_index), `type`, addr) + per_type_list_remove(&mut deny_list.lists[per_type_index], `type`, addr) } fun per_type_list_remove( @@ -91,13 +88,13 @@ module sui::deny_list { `type`: vector, addr: address, ) { - let denied_addresses = table::borrow_mut(&mut list.denied_addresses, `type`); - assert!(vec_set::contains(denied_addresses, &addr), ENotDenied); - vec_set::remove(denied_addresses, &addr); - let denied_count = table::borrow_mut(&mut list.denied_count, addr); + let denied_addresses = &mut list.denied_addresses[`type`]; + assert!(denied_addresses.contains(&addr), ENotDenied); + denied_addresses.remove(&addr); + let denied_count = &mut list.denied_count[addr]; *denied_count = *denied_count - 1; if (*denied_count == 0) { - table::remove(&mut list.denied_count, addr); + list.denied_count.remove(addr); } } @@ -108,7 +105,7 @@ module sui::deny_list { `type`: vector, addr: address, ): bool { - per_type_list_contains(bag::borrow(&deny_list.lists, per_type_index), `type`, addr) + per_type_list_contains(&deny_list.lists[per_type_index], `type`, addr) } fun per_type_list_contains( @@ -116,25 +113,25 @@ module sui::deny_list { `type`: vector, addr: address, ): bool { - if (!table::contains(&list.denied_count, addr)) return false; + if (!list.denied_count.contains(addr)) return false; - let denied_count = table::borrow(&list.denied_count, addr); + let denied_count = &list.denied_count[addr]; if (*denied_count == 0) return false; - if (!table::contains(&list.denied_addresses, `type`)) return false; + if (!list.denied_addresses.contains(`type`)) return false; - let denied_addresses = table::borrow(&list.denied_addresses, `type`); - vec_set::contains(denied_addresses, &addr) + let denied_addresses = &list.denied_addresses[`type`]; + denied_addresses.contains(&addr) } #[allow(unused_function)] /// Creation of the deny list object is restricted to the system address /// via a system transaction. fun create(ctx: &mut TxContext) { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); let mut lists = bag::new(ctx); - bag::add(&mut lists, COIN_INDEX, per_type_list(ctx)); + lists.add(COIN_INDEX, per_type_list(ctx)); let deny_list_object = DenyList { id: object::sui_deny_list_object_id(), lists, @@ -160,7 +157,7 @@ module sui::deny_list { /// doesn't matter which object ID the list has in this kind of test. public fun new_for_testing(ctx: &mut TxContext): DenyList { let mut lists = bag::new(ctx); - bag::add(&mut lists, COIN_INDEX, per_type_list(ctx)); + lists.add(COIN_INDEX, per_type_list(ctx)); DenyList { id: object::new(ctx), lists, diff --git a/crates/sui-framework/packages/sui-framework/sources/display.move b/crates/sui-framework/packages/sui-framework/sources/display.move index 9f3472be89ccd..38f460e890fef 100644 --- a/crates/sui-framework/packages/sui-framework/sources/display.move +++ b/crates/sui-framework/packages/sui-framework/sources/display.move @@ -11,13 +11,9 @@ /// /// More entry functions might be added in the future depending on the use cases. module sui::display { - use sui::package::{from_package, Publisher}; - use sui::tx_context::{sender, TxContext}; + use sui::package::Publisher; use sui::vec_map::{Self, VecMap}; - use sui::object::{Self, ID, UID}; - use sui::transfer; use sui::event; - use std::vector; use std::string::String; /// For when T does not belong to the package `Publisher`. @@ -87,13 +83,13 @@ module sui::display { public fun new_with_fields( pub: &Publisher, fields: vector, values: vector, ctx: &mut TxContext ): Display { - let len = vector::length(&fields); - assert!(len == vector::length(&values), EVecLengthMismatch); + let len = fields.length(); + assert!(len == values.length(), EVecLengthMismatch); let mut i = 0; let mut display = new(pub, ctx); while (i < len) { - add_internal(&mut display, *vector::borrow(&fields, i), *vector::borrow(&values, i)); + display.add_internal(fields[i], values[i]); i = i + 1; }; @@ -105,7 +101,7 @@ module sui::display { #[allow(lint(self_transfer))] /// Create a new empty Display object and keep it. entry public fun create_and_keep(pub: &Publisher, ctx: &mut TxContext) { - transfer::public_transfer(new(pub, ctx), sender(ctx)) + transfer::public_transfer(new(pub, ctx), ctx.sender()) } /// Manually bump the version and emit an event with the updated version's contents. @@ -116,7 +112,7 @@ module sui::display { event::emit(VersionUpdated { version: display.version, fields: *&display.fields, - id: object::uid_to_inner(&display.id), + id: display.id.to_inner(), }) } @@ -124,19 +120,19 @@ module sui::display { /// Sets a custom `name` field with the `value`. entry public fun add(self: &mut Display, name: String, value: String) { - add_internal(self, name, value) + self.add_internal(name, value) } /// Sets multiple `fields` with `values`. entry public fun add_multiple( self: &mut Display, fields: vector, values: vector ) { - let len = vector::length(&fields); - assert!(len == vector::length(&values), EVecLengthMismatch); + let len = fields.length(); + assert!(len == values.length(), EVecLengthMismatch); let mut i = 0; while (i < len) { - add_internal(self, *vector::borrow(&fields, i), *vector::borrow(&values, i)); + self.add_internal(fields[i], values[i]); i = i + 1; }; } @@ -144,20 +140,20 @@ module sui::display { /// Change the value of the field. /// TODO (long run): version changes; entry public fun edit(self: &mut Display, name: String, value: String) { - let (_, _) = vec_map::remove(&mut self.fields, &name); - add_internal(self, name, value) + let (_, _) = self.fields.remove(&name); + self.add_internal(name, value) } /// Remove the key from the Display. entry public fun remove(self: &mut Display, name: String) { - vec_map::remove(&mut self.fields, &name); + self.fields.remove(&name); } // === Access fields === /// Authorization check; can be performed externally to implement protection rules for Display. public fun is_authorized(pub: &Publisher): bool { - from_package(pub) + pub.from_package() } /// Read the `version` field. @@ -177,7 +173,7 @@ module sui::display { let uid = object::new(ctx); event::emit(DisplayCreated { - id: object::uid_to_inner(&uid) + id: uid.to_inner() }); Display { @@ -189,16 +185,14 @@ module sui::display { /// Private method for inserting fields without security checks. fun add_internal(display: &mut Display, name: String, value: String) { - vec_map::insert(&mut display.fields, name, value) + display.fields.insert(name, value) } } #[test_only] module sui::display_tests { - use sui::object::UID; use sui::test_scenario as test; - use sui::transfer; - use std::string::{utf8, String}; + use std::string::String; use sui::package; use sui::display; @@ -221,13 +215,13 @@ module sui::display_tests { // create a new display object let mut display = display::new(&pub, test::ctx(&mut test)); - display::add(&mut display, utf8(b"name"), utf8(b"Capy {name}")); - display::add(&mut display, utf8(b"link"), utf8(b"https://capy.art/capy/{id}")); - display::add(&mut display, utf8(b"image"), utf8(b"https://api.capy.art/capy/{id}/svg")); - display::add(&mut display, utf8(b"description"), utf8(b"A Lovely Capy")); + display.add(b"name".to_string(), b"Capy {name}".to_string()); + display.add(b"link".to_string(), b"https://capy.art/capy/{id}".to_string()); + display.add(b"image".to_string(), b"https://api.capy.art/capy/{id}/svg".to_string()); + display.add(b"description".to_string(), b"A Lovely Capy".to_string()); - package::burn_publisher(pub); + pub.burn_publisher(); transfer::public_transfer(display, @0x2); - test::end(test); + test.end(); } } diff --git a/crates/sui-framework/packages/sui-framework/sources/dynamic_field.move b/crates/sui-framework/packages/sui-framework/sources/dynamic_field.move index d6a8af205061b..d56422b2e2677 100644 --- a/crates/sui-framework/packages/sui-framework/sources/dynamic_field.move +++ b/crates/sui-framework/packages/sui-framework/sources/dynamic_field.move @@ -9,8 +9,6 @@ /// This gives Sui programmers the flexibility to extend objects on-the-fly, and it also serves as a /// building block for core collection types module sui::dynamic_field { - use std::option::{Self, Option}; - use sui::object::{Self, ID, UID}; /* friend sui::dynamic_object_field; */ @@ -45,7 +43,7 @@ module sui::dynamic_field { name: Name, value: Value, ) { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); assert!(!has_child_object(object_addr, hash), EFieldAlreadyExists); let field = Field { @@ -64,7 +62,7 @@ module sui::dynamic_field { object: &UID, name: Name, ): &Value { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let field = borrow_child_object>(object, hash); &field.value @@ -78,7 +76,7 @@ module sui::dynamic_field { object: &mut UID, name: Name, ): &mut Value { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let field = borrow_child_object_mut>(object, hash); &mut field.value @@ -93,10 +91,10 @@ module sui::dynamic_field { object: &mut UID, name: Name, ): Value { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let Field { id, name: _, value } = remove_child_object>(object_addr, hash); - object::delete(id); + id.delete(); value } @@ -106,7 +104,7 @@ module sui::dynamic_field { object: &UID, name: Name, ): bool { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); has_child_object(object_addr, hash) } @@ -129,7 +127,7 @@ module sui::dynamic_field { object: &UID, name: Name, ): bool { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); has_child_object_with_ty>(object_addr, hash) } @@ -138,20 +136,20 @@ module sui::dynamic_field { object: &UID, name: Name, ): (&UID, address) { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let Field { id, name: _, value } = borrow_child_object>(object, hash); - (id, object::id_to_address(value)) + (id, value.to_address()) } public(package) fun field_info_mut( object: &mut UID, name: Name, ): (&mut UID, address) { - let object_addr = object::uid_to_address(object); + let object_addr = object.to_address(); let hash = hash_type_and_key(object_addr, name); let Field { id, name: _, value } = borrow_child_object_mut>(object, hash); - (id, object::id_to_address(value)) + (id, value.to_address()) } /// May abort with `EBCSSerializationFailure`. diff --git a/crates/sui-framework/packages/sui-framework/sources/dynamic_object_field.move b/crates/sui-framework/packages/sui-framework/sources/dynamic_object_field.move index 291a2872df7b7..07207b7af72b4 100644 --- a/crates/sui-framework/packages/sui-framework/sources/dynamic_object_field.move +++ b/crates/sui-framework/packages/sui-framework/sources/dynamic_object_field.move @@ -6,8 +6,6 @@ /// themselves. This allows for the objects to still exist within in storage, which may be important /// for external tools. The difference is otherwise not observable from within Move. module sui::dynamic_object_field { - use std::option::{Self, Option}; - use sui::object::{Self, UID, ID}; use sui::dynamic_field::{ Self as field, add_child_object, @@ -34,7 +32,7 @@ module sui::dynamic_object_field { let id = object::id(&value); field::add(object, key, id); let (field, _) = field::field_info>(object, key); - add_child_object(object::uid_to_address(field), value); + add_child_object(field.to_address(), value); } /// Immutably borrows the `object`s dynamic object field with the name specified by `name: Name`. @@ -74,7 +72,7 @@ module sui::dynamic_object_field { ): Value { let key = Wrapper { name }; let (field, value_id) = field::field_info>(object, key); - let value = remove_child_object(object::uid_to_address(field), value_id); + let value = remove_child_object(field.to_address(), value_id); field::remove, ID>(object, key); value } @@ -98,7 +96,7 @@ module sui::dynamic_object_field { let key = Wrapper { name }; if (!field::exists_with_type, ID>(object, key)) return false; let (field, value_id) = field::field_info>(object, key); - field::has_child_object_with_ty(object::uid_to_address(field), value_id) + field::has_child_object_with_ty(field.to_address(), value_id) } /// Returns the ID of the object associated with the dynamic object field @@ -109,7 +107,7 @@ module sui::dynamic_object_field { ): Option { let key = Wrapper { name }; if (!field::exists_with_type, ID>(object, key)) return option::none(); - let (_field, value_id) = field::field_info>(object, key); - option::some(object::id_from_address(value_id)) + let (_field, value_addr) = field::field_info>(object, key); + option::some(value_addr.to_id()) } } diff --git a/crates/sui-framework/packages/sui-framework/sources/hex.move b/crates/sui-framework/packages/sui-framework/sources/hex.move index e8e9f9f33000c..63b17bc48a7b2 100644 --- a/crates/sui-framework/packages/sui-framework/sources/hex.move +++ b/crates/sui-framework/packages/sui-framework/sources/hex.move @@ -3,7 +3,6 @@ /// HEX (Base16) encoding utility. module sui::hex { - use std::vector; const EInvalidHexLength: u64 = 0; const ENotValidHexCharacter: u64 = 1; @@ -15,13 +14,10 @@ module sui::hex { /// Encode `bytes` in lowercase hex public fun encode(bytes: vector): vector { - let (mut i, mut r, l) = (0, vector[], vector::length(&bytes)); + let (mut i, mut r, l) = (0, vector[], bytes.length()); let hex_vector = HEX; while (i < l) { - vector::append( - &mut r, - *vector::borrow(&hex_vector, (*vector::borrow(&bytes, i) as u64)) - ); + r.append(hex_vector[(bytes[i] as u64)]); i = i + 1; }; r @@ -34,12 +30,11 @@ module sui::hex { /// Aborts if the hex string does not have an even number of characters (as each hex character is 2 characters long) /// Aborts if the hex string contains non-valid hex characters (valid characters are 0 - 9, a - f, A - F) public fun decode(hex: vector): vector { - let (mut i, mut r, l) = (0, vector[], vector::length(&hex)); + let (mut i, mut r, l) = (0, vector[], hex.length()); assert!(l % 2 == 0, EInvalidHexLength); while (i < l) { - let decimal = (decode_byte(*vector::borrow(&hex, i)) * 16) + - decode_byte(*vector::borrow(&hex, i + 1)); - vector::push_back(&mut r, decimal); + let decimal = decode_byte(hex[i]) * 16 + decode_byte(hex[i + 1]); + r.push_back(decimal); i = i + 2; }; r diff --git a/crates/sui-framework/packages/sui-framework/sources/kiosk/kiosk.move b/crates/sui-framework/packages/sui-framework/sources/kiosk/kiosk.move index 6461bb14e26cd..4a6716c6d9c6c 100644 --- a/crates/sui-framework/packages/sui-framework/sources/kiosk/kiosk.move +++ b/crates/sui-framework/packages/sui-framework/sources/kiosk/kiosk.move @@ -81,10 +81,7 @@ /// /// See `transfer_policy` module for more details on how they function. module sui::kiosk { - use std::option::{Self, Option}; - use sui::tx_context::{TxContext, sender}; use sui::dynamic_object_field as dof; - use sui::object::{Self, UID, ID}; use sui::dynamic_field as df; use sui::transfer_policy::{ Self, @@ -96,6 +93,9 @@ module sui::kiosk { use sui::sui::SUI; use sui::event; + /// Allows calling `cap.kiosk()` to retrieve `for` field from `KioskOwnerCap`. + public use fun kiosk_owner_cap_for as KioskOwnerCap.kiosk; + // Gets access to: // - `place_internal` // - `lock_internal` @@ -237,7 +237,7 @@ module sui::kiosk { /// `KioskOwnerCap` and becomes the Owner, the `Kiosk` is shared. entry fun default(ctx: &mut TxContext) { let (kiosk, cap) = new(ctx); - sui::transfer::transfer(cap, sender(ctx)); + sui::transfer::transfer(cap, ctx.sender()); sui::transfer::share_object(kiosk); } @@ -246,7 +246,7 @@ module sui::kiosk { let kiosk = Kiosk { id: object::new(ctx), profits: balance::zero(), - owner: sender(ctx), + owner: ctx.sender(), item_count: 0, allow_extensions: false }; @@ -268,13 +268,13 @@ module sui::kiosk { let Kiosk { id, profits, owner: _, item_count, allow_extensions: _ } = self; let KioskOwnerCap { id: cap_id, `for` } = cap; - assert!(object::uid_to_inner(&id) == `for`, ENotOwner); + assert!(id.to_inner() == `for`, ENotOwner); assert!(item_count == 0, ENotEmpty); - object::delete(cap_id); - object::delete(id); + cap_id.delete(); + id.delete(); - coin::from_balance(profits, ctx) + profits.into_coin(ctx) } /// Change the `owner` field to the transaction sender. @@ -284,8 +284,8 @@ module sui::kiosk { public fun set_owner( self: &mut Kiosk, cap: &KioskOwnerCap, ctx: &TxContext ) { - assert!(has_access(self, cap), ENotOwner); - self.owner = sender(ctx); + assert!(self.has_access(cap), ENotOwner); + self.owner = ctx.sender(); } /// Update the `owner` field with a custom address. Can be used for @@ -293,7 +293,7 @@ module sui::kiosk { public fun set_owner_custom( self: &mut Kiosk, cap: &KioskOwnerCap, owner: address ) { - assert!(has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); self.owner = owner } @@ -304,8 +304,8 @@ module sui::kiosk { public fun place( self: &mut Kiosk, cap: &KioskOwnerCap, item: T ) { - assert!(has_access(self, cap), ENotOwner); - place_internal(self, item) + assert!(self.has_access(cap), ENotOwner); + self.place_internal(item) } /// Place an item to the `Kiosk` and issue a `Lock` for it. Once placed this @@ -317,8 +317,8 @@ module sui::kiosk { public fun lock( self: &mut Kiosk, cap: &KioskOwnerCap, _policy: &TransferPolicy, item: T ) { - assert!(has_access(self, cap), ENotOwner); - lock_internal(self, item) + assert!(self.has_access(cap), ENotOwner); + self.lock_internal(item) } /// Take any object from the Kiosk. @@ -326,10 +326,10 @@ module sui::kiosk { public fun take( self: &mut Kiosk, cap: &KioskOwnerCap, id: ID ): T { - assert!(has_access(self, cap), ENotOwner); - assert!(!is_locked(self, id), EItemLocked); - assert!(!is_listed_exclusively(self, id), EListedExclusively); - assert!(has_item(self, id), EItemNotFound); + assert!(self.has_access(cap), ENotOwner); + assert!(!self.is_locked(id), EItemLocked); + assert!(!self.is_listed_exclusively(id), EListedExclusively); + assert!(self.has_item(id), EItemNotFound); self.item_count = self.item_count - 1; df::remove_if_exists(&mut self.id, Listing { id, is_exclusive: false }); @@ -343,9 +343,9 @@ module sui::kiosk { public fun list( self: &mut Kiosk, cap: &KioskOwnerCap, id: ID, price: u64 ) { - assert!(has_access(self, cap), ENotOwner); - assert!(has_item_with_type(self, id), EItemNotFound); - assert!(!is_listed_exclusively(self, id), EListedExclusively); + assert!(self.has_access(cap), ENotOwner); + assert!(self.has_item_with_type(id), EItemNotFound); + assert!(!self.is_listed_exclusively(id), EListedExclusively); df::add(&mut self.id, Listing { id, is_exclusive: false }, price); event::emit(ItemListed { kiosk: object::id(self), id, price }) @@ -356,8 +356,8 @@ module sui::kiosk { self: &mut Kiosk, cap: &KioskOwnerCap, item: T, price: u64 ) { let id = object::id(&item); - place(self, cap, item); - list(self, cap, id, price) + self.place(cap, item); + self.list(cap, id, price) } /// Remove an existing listing from the `Kiosk` and keep the item in the @@ -365,10 +365,10 @@ module sui::kiosk { public fun delist( self: &mut Kiosk, cap: &KioskOwnerCap, id: ID ) { - assert!(has_access(self, cap), ENotOwner); - assert!(has_item_with_type(self, id), EItemNotFound); - assert!(!is_listed_exclusively(self, id), EListedExclusively); - assert!(is_listed(self, id), ENotListed); + assert!(self.has_access(cap), ENotOwner); + assert!(self.has_item_with_type(id), EItemNotFound); + assert!(!self.is_listed_exclusively(id), EListedExclusively); + assert!(self.is_listed(id), ENotListed); df::remove(&mut self.id, Listing { id, is_exclusive: false }); event::emit(ItemDelisted { kiosk: object::id(self), id }) @@ -388,7 +388,7 @@ module sui::kiosk { let inner = dof::remove(&mut self.id, Item { id }); self.item_count = self.item_count - 1; - assert!(price == coin::value(&payment), EIncorrectAmount); + assert!(price == payment.value(), EIncorrectAmount); df::remove_if_exists(&mut self.id, Lock { id }); coin::put(&mut self.profits, payment); @@ -404,9 +404,9 @@ module sui::kiosk { public fun list_with_purchase_cap( self: &mut Kiosk, cap: &KioskOwnerCap, id: ID, min_price: u64, ctx: &mut TxContext ): PurchaseCap { - assert!(has_access(self, cap), ENotOwner); - assert!(has_item_with_type(self, id), EItemNotFound); - assert!(!is_listed(self, id), EAlreadyListed); + assert!(self.has_access(cap), ENotOwner); + assert!(self.has_item_with_type(id), EItemNotFound); + assert!(!self.is_listed(id), EAlreadyListed); df::add(&mut self.id, Listing { id, is_exclusive: true }, min_price); @@ -424,10 +424,10 @@ module sui::kiosk { self: &mut Kiosk, purchase_cap: PurchaseCap, payment: Coin ): (T, TransferRequest) { let PurchaseCap { id, item_id, kiosk_id, min_price } = purchase_cap; - object::delete(id); + id.delete(); let id = item_id; - let paid = coin::value(&payment); + let paid = payment.value(); assert!(paid >= min_price, EIncorrectAmount); assert!(object::id(self) == kiosk_id, EWrongKiosk); @@ -450,21 +450,21 @@ module sui::kiosk { assert!(object::id(self) == kiosk_id, EWrongKiosk); df::remove(&mut self.id, Listing { id: item_id, is_exclusive: true }); - object::delete(id) + id.delete() } /// Withdraw profits from the Kiosk. public fun withdraw( self: &mut Kiosk, cap: &KioskOwnerCap, amount: Option, ctx: &mut TxContext ): Coin { - assert!(has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); - let amount = if (option::is_some(&amount)) { - let amt = option::destroy_some(amount); - assert!(amt <= balance::value(&self.profits), ENotEnough); + let amount = if (amount.is_some()) { + let amt = amount.destroy_some(); + assert!(amt <= self.profits.value(), ENotEnough); amt } else { - balance::value(&self.profits) + self.profits.value() }; coin::take(&mut self.profits, amount, ctx) @@ -475,7 +475,7 @@ module sui::kiosk { /// Internal: "lock" an item disabling the `take` action. public(package) fun lock_internal(self: &mut Kiosk, item: T) { df::add(&mut self.id, Lock { id: object::id(&item) }, true); - place_internal(self, item) + self.place_internal(item) } /// Internal: "place" an item to the Kiosk and increment the item count. @@ -511,7 +511,7 @@ module sui::kiosk { /// Check whether an `item` is listed (exclusively or non exclusively). public fun is_listed(self: &Kiosk, id: ID): bool { df::exists_(&self.id, Listing { id, is_exclusive: false }) - || is_listed_exclusively(self, id) + || self.is_listed_exclusively(id) } /// Check whether there's a `PurchaseCap` issued for an item. @@ -528,7 +528,7 @@ module sui::kiosk { public fun uid_mut_as_owner( self: &mut Kiosk, cap: &KioskOwnerCap ): &mut UID { - assert!(has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); &mut self.id } @@ -538,7 +538,7 @@ module sui::kiosk { public fun set_allow_extensions( self: &mut Kiosk, cap: &KioskOwnerCap, allow_extensions: bool ) { - assert!(has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); self.allow_extensions = allow_extensions; } @@ -570,36 +570,38 @@ module sui::kiosk { /// Get the amount of profits collected by selling items. public fun profits_amount(self: &Kiosk): u64 { - balance::value(&self.profits) + self.profits.value() } /// Get mutable access to `profits` - owner only action. public fun profits_mut(self: &mut Kiosk, cap: &KioskOwnerCap): &mut Balance { - assert!(has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); &mut self.profits } // === Item borrowing === + #[syntax(index)] /// Immutably borrow an item from the `Kiosk`. Any item can be `borrow`ed /// at any time. public fun borrow( self: &Kiosk, cap: &KioskOwnerCap, id: ID ): &T { assert!(object::id(self) == cap.`for`, ENotOwner); - assert!(has_item(self, id), EItemNotFound); + assert!(self.has_item(id), EItemNotFound); dof::borrow(&self.id, Item { id }) } + #[syntax(index)] /// Mutably borrow an item from the `Kiosk`. /// Item can be `borrow_mut`ed only if it's not `is_listed`. public fun borrow_mut( self: &mut Kiosk, cap: &KioskOwnerCap, id: ID ): &mut T { - assert!(has_access(self, cap), ENotOwner); - assert!(has_item(self, id), EItemNotFound); - assert!(!is_listed(self, id), EItemIsListed); + assert!(self.has_access(cap), ENotOwner); + assert!(self.has_item(id), EItemNotFound); + assert!(!self.is_listed(id), EItemIsListed); dof::borrow_mut(&mut self.id, Item { id }) } @@ -609,9 +611,9 @@ module sui::kiosk { public fun borrow_val( self: &mut Kiosk, cap: &KioskOwnerCap, id: ID ): (T, Borrow) { - assert!(has_access(self, cap), ENotOwner); - assert!(has_item(self, id), EItemNotFound); - assert!(!is_listed(self, id), EItemIsListed); + assert!(self.has_access(cap), ENotOwner); + assert!(self.has_item(id), EItemNotFound); + assert!(!self.is_listed(id), EItemIsListed); ( dof::remove(&mut self.id, Item { id }), diff --git a/crates/sui-framework/packages/sui-framework/sources/kiosk/kiosk_extension.move b/crates/sui-framework/packages/sui-framework/sources/kiosk/kiosk_extension.move index e167f8a7624e7..dd3ec9e2fe34c 100644 --- a/crates/sui-framework/packages/sui-framework/sources/kiosk/kiosk_extension.move +++ b/crates/sui-framework/packages/sui-framework/sources/kiosk/kiosk_extension.move @@ -41,9 +41,8 @@ module sui::kiosk_extension { use sui::bag::{Self, Bag}; use sui::dynamic_field as df; - use sui::tx_context::TxContext; use sui::transfer_policy::TransferPolicy; - use sui::kiosk::{Self, Kiosk, KioskOwnerCap}; + use sui::kiosk::{Kiosk, KioskOwnerCap}; /// Trying to add an extension while not being the owner of the Kiosk. const ENotOwner: u64 = 0; @@ -107,9 +106,9 @@ module sui::kiosk_extension { permissions: u128, ctx: &mut TxContext ) { - assert!(kiosk::has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); df::add( - kiosk::uid_mut_as_owner(self, cap), + self.uid_mut_as_owner(cap), ExtensionKey {}, Extension { storage: bag::new(ctx), @@ -126,7 +125,7 @@ module sui::kiosk_extension { self: &mut Kiosk, cap: &KioskOwnerCap, ) { - assert!(kiosk::has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); assert!(is_installed(self), EExtensionNotInstalled); extension_mut(self).is_enabled = false; } @@ -138,7 +137,7 @@ module sui::kiosk_extension { self: &mut Kiosk, cap: &KioskOwnerCap, ) { - assert!(kiosk::has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); assert!(is_installed(self), EExtensionNotInstalled); extension_mut(self).is_enabled = true; } @@ -148,16 +147,16 @@ module sui::kiosk_extension { public fun remove( self: &mut Kiosk, cap: &KioskOwnerCap ) { - assert!(kiosk::has_access(self, cap), ENotOwner); + assert!(self.has_access(cap), ENotOwner); assert!(is_installed(self), EExtensionNotInstalled); let Extension { storage, permissions: _, is_enabled: _, - } = df::remove(kiosk::uid_mut_as_owner(self, cap), ExtensionKey {}); + } = df::remove(self.uid_mut_as_owner(cap), ExtensionKey {}); - bag::destroy_empty(storage); + storage.destroy_empty(); } // === Storage === @@ -204,7 +203,7 @@ module sui::kiosk_extension { assert!(is_installed(self), EExtensionNotInstalled); assert!(can_place(self) || can_lock(self), EExtensionNotAllowed); - kiosk::place_internal(self, item) + self.place_internal(item) } /// Protected action: lock an item in the Kiosk. Can be performed by an @@ -215,14 +214,14 @@ module sui::kiosk_extension { assert!(is_installed(self), EExtensionNotInstalled); assert!(can_lock(self), EExtensionNotAllowed); - kiosk::lock_internal(self, item) + self.lock_internal(item) } // === Field Access === /// Check whether an extension of type `Ext` is installed. public fun is_installed(self: &Kiosk): bool { - df::exists_(kiosk::uid(self), ExtensionKey {}) + df::exists_(self.uid(), ExtensionKey {}) } /// Check whether an extension of type `Ext` is enabled. @@ -245,11 +244,11 @@ module sui::kiosk_extension { /// Internal: get a read-only access to the Extension. fun extension(self: &Kiosk): &Extension { - df::borrow(kiosk::uid(self), ExtensionKey {}) + df::borrow(self.uid(), ExtensionKey {}) } /// Internal: get a mutable access to the Extension. fun extension_mut(self: &mut Kiosk): &mut Extension { - df::borrow_mut(kiosk::uid_mut_internal(self), ExtensionKey {}) + df::borrow_mut(self.uid_mut_internal(), ExtensionKey {}) } } diff --git a/crates/sui-framework/packages/sui-framework/sources/kiosk/transfer_policy.move b/crates/sui-framework/packages/sui-framework/sources/kiosk/transfer_policy.move index 8f1bfcd51aa2a..075bfb5969e02 100644 --- a/crates/sui-framework/packages/sui-framework/sources/kiosk/transfer_policy.move +++ b/crates/sui-framework/packages/sui-framework/sources/kiosk/transfer_policy.move @@ -22,12 +22,8 @@ /// policies can be removed at any moment, and the change will affect all instances /// of the type at once. module sui::transfer_policy { - use std::vector; - use std::option::{Self, Option}; use std::type_name::{Self, TypeName}; use sui::package::{Self, Publisher}; - use sui::tx_context::{sender, TxContext}; - use sui::object::{Self, ID, UID}; use sui::vec_set::{Self, VecSet}; use sui::dynamic_field as df; use sui::balance::{Self, Balance}; @@ -122,7 +118,7 @@ module sui::transfer_policy { ): (TransferPolicy, TransferPolicyCap) { assert!(package::from_package(pub), 0); let id = object::new(ctx); - let policy_id = object::uid_to_inner(&id); + let policy_id = id.to_inner(); event::emit(TransferPolicyCreated { id: policy_id }); @@ -139,7 +135,7 @@ module sui::transfer_policy { entry fun default(pub: &Publisher, ctx: &mut TxContext) { let (policy, cap) = new(pub, ctx); sui::transfer::share_object(policy); - sui::transfer::transfer(cap, sender(ctx)); + sui::transfer::transfer(cap, ctx.sender()); } /// Withdraw some amount of profits from the `TransferPolicy`. If amount @@ -152,12 +148,12 @@ module sui::transfer_policy { ): Coin { assert!(object::id(self) == cap.policy_id, ENotOwner); - let amount = if (option::is_some(&amount)) { - let amt = option::destroy_some(amount); - assert!(amt <= balance::value(&self.balance), ENotEnough); + let amount = if (amount.is_some()) { + let amt = amount.destroy_some(); + assert!(amt <= self.balance.value(), ENotEnough); amt } else { - balance::value(&self.balance) + self.balance.value() }; coin::take(&mut self.balance, amount, ctx) @@ -173,10 +169,10 @@ module sui::transfer_policy { let TransferPolicyCap { id: cap_id, policy_id } = cap; let TransferPolicy { id, rules: _, balance } = self; - object::delete(id); - object::delete(cap_id); + id.delete(); + cap_id.delete(); event::emit(TransferPolicyDestroyed { id: policy_id }); - coin::from_balance(balance, ctx) + balance.into_coin(ctx) } /// Allow a `TransferRequest` for the type `T`. The call is protected @@ -189,14 +185,14 @@ module sui::transfer_policy { self: &TransferPolicy, request: TransferRequest ): (ID, u64, ID) { let TransferRequest { item, paid, from, receipts } = request; - let mut completed = vec_set::into_keys(receipts); - let mut total = vector::length(&completed); + let mut completed = receipts.into_keys(); + let mut total = completed.length(); - assert!(total == vec_set::size(&self.rules), EPolicyNotSatisfied); + assert!(total == self.rules.size(), EPolicyNotSatisfied); while (total > 0) { - let rule_type = vector::pop_back(&mut completed); - assert!(vec_set::contains(&self.rules, &rule_type), EIllegalRule); + let rule_type = completed.pop_back(); + assert!(self.rules.contains(&rule_type), EIllegalRule); total = total - 1; }; @@ -220,7 +216,7 @@ module sui::transfer_policy { assert!(object::id(policy) == cap.policy_id, ENotOwner); assert!(!has_rule(policy), ERuleAlreadySet); df::add(&mut policy.id, RuleKey {}, cfg); - vec_set::insert(&mut policy.rules, type_name::get()) + policy.rules.insert(type_name::get()) } /// Get the custom Config for the Rule (can be only one per "Rule" type). @@ -243,7 +239,7 @@ module sui::transfer_policy { public fun add_receipt( _: Rule, request: &mut TransferRequest ) { - vec_set::insert(&mut request.receipts, type_name::get()) + request.receipts.insert(type_name::get()) } /// Check whether a custom rule has been added to the `TransferPolicy`. @@ -257,7 +253,7 @@ module sui::transfer_policy { ) { assert!(object::id(policy) == cap.policy_id, ENotOwner); let _: Config = df::remove(&mut policy.id, RuleKey {}); - vec_set::remove(&mut policy.rules, &type_name::get()); + policy.rules.remove(&type_name::get()); } // === Fields access: TransferPolicy === @@ -296,7 +292,7 @@ module sui::transfer_policy { /// Create a new TransferPolicy for testing purposes. public fun new_for_testing(ctx: &mut TxContext): (TransferPolicy, TransferPolicyCap) { let id = object::new(ctx); - let policy_id = object::uid_to_inner(&id); + let policy_id = id.to_inner(); ( TransferPolicy { id, rules: vec_set::empty(), balance: balance::zero() }, diff --git a/crates/sui-framework/packages/sui-framework/sources/linked_table.move b/crates/sui-framework/packages/sui-framework/sources/linked_table.move index 66f7710441fc4..d7e91b1c78e1f 100644 --- a/crates/sui-framework/packages/sui-framework/sources/linked_table.move +++ b/crates/sui-framework/packages/sui-framework/sources/linked_table.move @@ -4,10 +4,7 @@ /// Similar to `sui::table` but the values are linked together, allowing for ordered insertion and /// removal module sui::linked_table { - use std::option::{Self, Option}; - use sui::object::{Self, UID}; use sui::dynamic_field as field; - use sui::tx_context::TxContext; // Attempted to destroy a non-empty table const ETableNotEmpty: u64 = 0; @@ -63,11 +60,11 @@ module sui::linked_table { k: K, value: V, ) { - let old_head = option::swap_or_fill(&mut table.head, k); - if (option::is_none(&table.tail)) option::fill(&mut table.tail, k); + let old_head = table.head.swap_or_fill(k); + if (table.tail.is_none()) table.tail.fill(k); let prev = option::none(); - let next = if (option::is_some(&old_head)) { - let old_head_k = option::destroy_some(old_head); + let next = if (old_head.is_some()) { + let old_head_k = old_head.destroy_some(); field::borrow_mut>(&mut table.id, old_head_k).prev = option::some(k); option::some(old_head_k) } else { @@ -86,10 +83,10 @@ module sui::linked_table { k: K, value: V, ) { - if (option::is_none(&table.head)) option::fill(&mut table.head, k); - let old_tail = option::swap_or_fill(&mut table.tail, k); - let prev = if (option::is_some(&old_tail)) { - let old_tail_k = option::destroy_some(old_tail); + if (table.head.is_none()) table.head.fill(k); + let old_tail = table.tail.swap_or_fill(k); + let prev = if (old_tail.is_some()) { + let old_tail_k = old_tail.destroy_some(); field::borrow_mut>(&mut table.id, old_tail_k).next = option::some(k); option::some(old_tail_k) } else { @@ -100,6 +97,7 @@ module sui::linked_table { table.size = table.size + 1; } + #[syntax(index)] /// Immutable borrows the value associated with the key in the table `table: &LinkedTable`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the table does not have an entry with /// that key `k: K`. @@ -107,6 +105,7 @@ module sui::linked_table { &field::borrow>(&table.id, k).value } + #[syntax(index)] /// Mutably borrows the value associated with the key in the table `table: &mut LinkedTable`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the table does not have an entry with /// that key `k: K`. @@ -140,31 +139,31 @@ module sui::linked_table { public fun remove(table: &mut LinkedTable, k: K): V { let Node { prev, next, value } = field::remove(&mut table.id, k); table.size = table.size - 1; - if (option::is_some(&prev)) { - field::borrow_mut>(&mut table.id, *option::borrow(&prev)).next = next + if (prev.is_some()) { + field::borrow_mut>(&mut table.id, *prev.borrow()).next = next }; - if (option::is_some(&next)) { - field::borrow_mut>(&mut table.id, *option::borrow(&next)).prev = prev + if (next.is_some()) { + field::borrow_mut>(&mut table.id, *next.borrow()).prev = prev }; - if (option::borrow(&table.head) == &k) table.head = next; - if (option::borrow(&table.tail) == &k) table.tail = prev; + if (table.head.borrow() == &k) table.head = next; + if (table.tail.borrow() == &k) table.tail = prev; value } /// Removes the front of the table `table: &mut LinkedTable` and returns the value. /// Aborts with `ETableIsEmpty` if the table is empty public fun pop_front(table: &mut LinkedTable): (K, V) { - assert!(option::is_some(&table.head), ETableIsEmpty); - let head = *option::borrow(&table.head); - (head, remove(table, head)) + assert!(table.head.is_some(), ETableIsEmpty); + let head = *table.head.borrow(); + (head, table.remove(head)) } /// Removes the back of the table `table: &mut LinkedTable` and returns the value. /// Aborts with `ETableIsEmpty` if the table is empty public fun pop_back(table: &mut LinkedTable): (K, V) { - assert!(option::is_some(&table.tail), ETableIsEmpty); - let tail = *option::borrow(&table.tail); - (tail, remove(table, tail)) + assert!(table.tail.is_some(), ETableIsEmpty); + let tail = *table.tail.borrow(); + (tail, table.remove(tail)) } /// Returns true iff there is a value associated with the key `k: K` in table @@ -188,13 +187,13 @@ module sui::linked_table { public fun destroy_empty(table: LinkedTable) { let LinkedTable { id, size, head: _, tail: _ } = table; assert!(size == 0, ETableNotEmpty); - object::delete(id) + id.delete() } /// Drop a possibly non-empty table. /// Usable only if the value type `V` has the `drop` ability public fun drop(table: LinkedTable) { let LinkedTable { id, size: _, head: _, tail: _ } = table; - object::delete(id) + id.delete() } } diff --git a/crates/sui-framework/packages/sui-framework/sources/object.move b/crates/sui-framework/packages/sui-framework/sources/object.move index 442712fe19ec8..95ebd4522e781 100644 --- a/crates/sui-framework/packages/sui-framework/sources/object.move +++ b/crates/sui-framework/packages/sui-framework/sources/object.move @@ -5,7 +5,6 @@ module sui::object { use std::bcs; use sui::address; - use sui::tx_context::{Self, TxContext}; /* friend sui::clock; */ /* friend sui::coin; */ @@ -16,6 +15,24 @@ module sui::object { /* friend sui::random; */ /* friend sui::deny_list; */ + /// Allows calling `.to_address` on an `ID` to get an `address`. + public use fun id_to_address as ID.to_address; + + /// Allows calling `.to_bytes` on an `ID` to get a `vector`. + public use fun id_to_bytes as ID.to_bytes; + + /// Allows calling `.as_inner` on a `UID` to get an `&ID`. + public use fun uid_as_inner as UID.as_inner; + + /// Allows calling `.to_inner` on a `UID` to get an `ID`. + public use fun uid_to_inner as UID.to_inner; + + /// Allows calling `.to_address` on a `UID` to get an `address`. + public use fun uid_to_address as UID.to_address; + + /// Allows calling `.to_bytes` on a `UID` to get a `vector`. + public use fun uid_to_bytes as UID.to_bytes; + /* #[test_only] */ /* friend sui::test_scenario; */ @@ -75,7 +92,7 @@ module sui::object { /// Make an `ID` from raw bytes. public fun id_from_bytes(bytes: vector): ID { - id_from_address(address::from_bytes(bytes)) + address::from_bytes(bytes).to_id() } /// Make an `ID` from an address. @@ -89,7 +106,7 @@ module sui::object { /// Create the `UID` for the singleton `SuiSystemState` object. /// This should only be called once from `sui_system`. fun sui_system_state(ctx: &TxContext): UID { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); UID { id: ID { bytes: SUI_SYSTEM_STATE_OBJECT_ID }, } @@ -153,7 +170,7 @@ module sui::object { /// This is the only way to create `UID`s. public fun new(ctx: &mut TxContext): UID { UID { - id: ID { bytes: tx_context::fresh_object_address(ctx) }, + id: ID { bytes: ctx.fresh_object_address() }, } } @@ -211,7 +228,7 @@ module sui::object { #[test_only] /// Return the most recent created object ID. public fun last_created(ctx: &TxContext): ID { - ID { bytes: tx_context::last_created_object_id(ctx) } + ID { bytes: ctx.last_created_object_id() } } } diff --git a/crates/sui-framework/packages/sui-framework/sources/object_bag.move b/crates/sui-framework/packages/sui-framework/sources/object_bag.move index 916ae9b26299d..2f01d8a4fc1a8 100644 --- a/crates/sui-framework/packages/sui-framework/sources/object_bag.move +++ b/crates/sui-framework/packages/sui-framework/sources/object_bag.move @@ -6,10 +6,7 @@ /// for the objects to still exist in storage, which may be important for external tools. /// The difference is otherwise not observable from within Move. module sui::object_bag { - use std::option::Option; - use sui::object::{Self, ID, UID}; use sui::dynamic_object_field as ofield; - use sui::tx_context::TxContext; // Attempted to destroy a non-empty bag const EBagNotEmpty: u64 = 0; @@ -37,6 +34,7 @@ module sui::object_bag { bag.size = bag.size + 1; } + #[syntax(index)] /// Immutably borrows the value associated with the key in the bag `bag: &ObjectBag`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the bag does not have an entry with /// that key `k: K`. @@ -46,6 +44,7 @@ module sui::object_bag { ofield::borrow(&bag.id, k) } + #[syntax(index)] /// Mutably borrows the value associated with the key in the bag `bag: &mut ObjectBag`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the bag does not have an entry with /// that key `k: K`. @@ -92,7 +91,7 @@ module sui::object_bag { public fun destroy_empty(bag: ObjectBag) { let ObjectBag { id, size } = bag; assert!(size == 0, EBagNotEmpty); - object::delete(id) + id.delete() } /// Returns the ID of the object associated with the key if the bag has an entry with key `k: K` diff --git a/crates/sui-framework/packages/sui-framework/sources/object_table.move b/crates/sui-framework/packages/sui-framework/sources/object_table.move index 982f7d170ec67..a6dc52aafb563 100644 --- a/crates/sui-framework/packages/sui-framework/sources/object_table.move +++ b/crates/sui-framework/packages/sui-framework/sources/object_table.move @@ -6,10 +6,7 @@ /// for the objects to still exist within in storage, which may be important for external tools. /// The difference is otherwise not observable from within Move. module sui::object_table { - use std::option::Option; - use sui::object::{Self, ID, UID}; use sui::dynamic_object_field as ofield; - use sui::tx_context::TxContext; // Attempted to destroy a non-empty table const ETableNotEmpty: u64 = 0; @@ -37,6 +34,7 @@ module sui::object_table { table.size = table.size + 1; } + #[syntax(index)] /// Immutable borrows the value associated with the key in the table `table: &ObjectTable`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the table does not have an entry with /// that key `k: K`. @@ -44,6 +42,7 @@ module sui::object_table { ofield::borrow(&table.id, k) } + #[syntax(index)] /// Mutably borrows the value associated with the key in the table `table: &mut ObjectTable`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the table does not have an entry with /// that key `k: K`. @@ -84,7 +83,7 @@ module sui::object_table { public fun destroy_empty(table: ObjectTable) { let ObjectTable { id, size } = table; assert!(size == 0, ETableNotEmpty); - object::delete(id) + id.delete() } /// Returns the ID of the object associated with the key if the table has an entry with key `k: K` diff --git a/crates/sui-framework/packages/sui-framework/sources/package.move b/crates/sui-framework/packages/sui-framework/sources/package.move index 50a17665d0722..706e94e8a3a71 100644 --- a/crates/sui-framework/packages/sui-framework/sources/package.move +++ b/crates/sui-framework/packages/sui-framework/sources/package.move @@ -5,8 +5,6 @@ /// - Creating proof-of-publish objects from one-time witnesses /// - Administering package upgrades through upgrade policies. module sui::package { - use sui::object::{Self, ID, UID}; - use sui::tx_context::{TxContext, sender}; use std::ascii::String; use std::type_name; use sui::types; @@ -93,12 +91,12 @@ module sui::package { public fun claim(otw: OTW, ctx: &mut TxContext): Publisher { assert!(types::is_one_time_witness(&otw), ENotOneTimeWitness); - let `type` = type_name::get_with_original_ids(); + let tyname = type_name::get_with_original_ids(); Publisher { id: object::new(ctx), - package: type_name::get_address(&`type`), - module_name: type_name::get_module(&`type`), + package: tyname.get_address(), + module_name: tyname.get_module(), } } @@ -107,29 +105,26 @@ module sui::package { /// Since this function can only be called in the module initializer, /// the sender is the publisher. public fun claim_and_keep(otw: OTW, ctx: &mut TxContext) { - sui::transfer::public_transfer(claim(otw, ctx), sender(ctx)) + sui::transfer::public_transfer(claim(otw, ctx), ctx.sender()) } /// Destroy a Publisher object effectively removing all privileges /// associated with it. public fun burn_publisher(self: Publisher) { let Publisher { id, package: _, module_name: _ } = self; - object::delete(id); + id.delete(); } /// Check whether type belongs to the same package as the publisher object. public fun from_package(self: &Publisher): bool { - let `type` = type_name::get_with_original_ids(); - - (type_name::get_address(&`type`) == self.package) + type_name::get_with_original_ids().get_address() == self.package } /// Check whether a type belongs to the same module as the publisher object. public fun from_module(self: &Publisher): bool { - let `type` = type_name::get_with_original_ids(); + let tyname = type_name::get_with_original_ids(); - (type_name::get_address(&`type`) == self.package) - && (type_name::get_module(&`type`) == self.module_name) + (tyname.get_address() == self.package) && (tyname.get_module() == self.module_name) } /// Read the name of the module. @@ -209,19 +204,19 @@ module sui::package { /// Restrict upgrades through this upgrade `cap` to just add code, or /// change dependencies. public entry fun only_additive_upgrades(cap: &mut UpgradeCap) { - restrict(cap, ADDITIVE) + cap.restrict(ADDITIVE) } /// Restrict upgrades through this upgrade `cap` to just change /// dependencies. public entry fun only_dep_upgrades(cap: &mut UpgradeCap) { - restrict(cap, DEP_ONLY) + cap.restrict(DEP_ONLY) } /// Discard the `UpgradeCap` to make a package immutable. public entry fun make_immutable(cap: UpgradeCap) { let UpgradeCap { id, package: _, version: _, policy: _ } = cap; - object::delete(id); + id.delete(); } /// Issue a ticket authorizing an upgrade to a particular new bytecode @@ -239,7 +234,7 @@ module sui::package { policy: u8, digest: vector ): UpgradeTicket { - let id_zero = object::id_from_address(@0x0); + let id_zero = @0x0.to_id(); assert!(cap.package != id_zero, EAlreadyAuthorized); assert!(policy >= cap.policy, ETooPermissive); @@ -263,7 +258,7 @@ module sui::package { let UpgradeReceipt { cap: cap_id, package } = receipt; assert!(object::id(cap) == cap_id, EWrongUpgradeCap); - assert!(object::id_to_address(&cap.package) == @0x0, ENotAuthorized); + assert!(cap.package.to_address() == @0x0, ENotAuthorized); cap.package = package; cap.version = cap.version + 1; @@ -272,12 +267,12 @@ module sui::package { #[test_only] /// Test-only function to claim a Publisher object bypassing OTW check. public fun test_claim(_: OTW, ctx: &mut TxContext): Publisher { - let `type` = type_name::get_with_original_ids(); + let tyname = type_name::get_with_original_ids(); Publisher { id: object::new(ctx), - package: type_name::get_address(&`type`), - module_name: type_name::get_module(&`type`), + package: tyname.get_address(), + module_name: tyname.get_module(), } } @@ -302,8 +297,8 @@ module sui::package { // Generate a fake package ID for the upgraded package by // hashing the existing package and cap ID. - let mut data = object::id_to_bytes(&cap); - std::vector::append(&mut data, object::id_to_bytes(&package)); + let mut data = cap.to_bytes(); + data.append(package.to_bytes()); let package = object::id_from_bytes(sui::hash::blake2b256(&data)); UpgradeReceipt { diff --git a/crates/sui-framework/packages/sui-framework/sources/pay.move b/crates/sui-framework/packages/sui-framework/sources/pay.move index 1e181d4838ee9..a13bab88c68c6 100644 --- a/crates/sui-framework/packages/sui-framework/sources/pay.move +++ b/crates/sui-framework/packages/sui-framework/sources/pay.move @@ -3,10 +3,7 @@ /// This module provides handy functionality for wallets and `sui::Coin` management. module sui::pay { - use sui::tx_context::{Self, TxContext}; - use sui::coin::{Self, Coin}; - use sui::transfer; - use std::vector; + use sui::coin::Coin; /// For when empty vector is supplied into join function. const ENoCoins: u64 = 0; @@ -14,15 +11,15 @@ module sui::pay { #[allow(lint(self_transfer))] /// Transfer `c` to the sender of the current transaction public fun keep(c: Coin, ctx: &TxContext) { - transfer::public_transfer(c, tx_context::sender(ctx)) + transfer::public_transfer(c, ctx.sender()) } /// Split coin `self` to two coins, one with balance `split_amount`, /// and the remaining balance is left is `self`. public entry fun split( - self: &mut Coin, split_amount: u64, ctx: &mut TxContext + coin: &mut Coin, split_amount: u64, ctx: &mut TxContext ) { - keep(coin::split(self, split_amount, ctx), ctx) + keep(coin.split(split_amount, ctx), ctx) } /// Split coin `self` into multiple coins, each with balance specified @@ -30,9 +27,9 @@ module sui::pay { public entry fun split_vec( self: &mut Coin, split_amounts: vector, ctx: &mut TxContext ) { - let (mut i, len) = (0, vector::length(&split_amounts)); + let (mut i, len) = (0, split_amounts.length()); while (i < len) { - split(self, *vector::borrow(&split_amounts, i), ctx); + split(self, split_amounts[i], ctx); i = i + 1; }; } @@ -42,7 +39,7 @@ module sui::pay { public entry fun split_and_transfer( c: &mut Coin, amount: u64, recipient: address, ctx: &mut TxContext ) { - transfer::public_transfer(coin::split(c, amount, ctx), recipient) + transfer::public_transfer(c.split(amount, ctx), recipient) } @@ -52,37 +49,38 @@ module sui::pay { public entry fun divide_and_keep( self: &mut Coin, n: u64, ctx: &mut TxContext ) { - let mut vec: vector> = coin::divide_into_n(self, n, ctx); - let (mut i, len) = (0, vector::length(&vec)); + let mut vec: vector> = self.divide_into_n(n, ctx); + let (mut i, len) = (0, vec.length()); while (i < len) { - transfer::public_transfer(vector::pop_back(&mut vec), tx_context::sender(ctx)); + transfer::public_transfer(vec.pop_back(), ctx.sender()); i = i + 1; }; - vector::destroy_empty(vec); + vec.destroy_empty(); } /// Join `coin` into `self`. Re-exports `coin::join` function. + /// Deprecated: you should call `coin.join(other)` directly. public entry fun join(self: &mut Coin, coin: Coin) { - coin::join(self, coin) + self.join(coin) } /// Join everything in `coins` with `self` public entry fun join_vec(self: &mut Coin, mut coins: vector>) { - let (mut i, len) = (0, vector::length(&coins)); + let (mut i, len) = (0, coins.length()); while (i < len) { - let coin = vector::pop_back(&mut coins); - coin::join(self, coin); + let coin = coins.pop_back(); + self.join(coin); i = i + 1 }; // safe because we've drained the vector - vector::destroy_empty(coins) + coins.destroy_empty() } /// Join a vector of `Coin` into a single object and transfer it to `receiver`. public entry fun join_vec_and_transfer(mut coins: vector>, receiver: address) { - assert!(vector::length(&coins) > 0, ENoCoins); + assert!(coins.length() > 0, ENoCoins); - let mut self = vector::pop_back(&mut coins); + let mut self = coins.pop_back(); join_vec(&mut self, coins); transfer::public_transfer(self, receiver) } diff --git a/crates/sui-framework/packages/sui-framework/sources/priority_queue.move b/crates/sui-framework/packages/sui-framework/sources/priority_queue.move index 983fe8667e02b..20061229bcec1 100644 --- a/crates/sui-framework/packages/sui-framework/sources/priority_queue.move +++ b/crates/sui-framework/packages/sui-framework/sources/priority_queue.move @@ -3,7 +3,6 @@ /// Priority queue implemented using a max heap. module sui::priority_queue { - use std::vector; /// For when heap is empty and there's no data to pop. const EPopFromEmptyHeap: u64 = 0; @@ -24,7 +23,7 @@ module sui::priority_queue { /// Create a new priority queue from the input entry vectors. public fun new(mut entries: vector>) : PriorityQueue { - let len = vector::length(&entries); + let len = entries.length(); let mut i = len / 2; // Max heapify from the first node that is a parent (node at len / 2). while (i > 0) { @@ -36,10 +35,10 @@ module sui::priority_queue { /// Pop the entry with the highest priority value. public fun pop_max(pq: &mut PriorityQueue) : (u64, T) { - let len = vector::length(&pq.entries); + let len = pq.entries.length(); assert!(len > 0, EPopFromEmptyHeap); // Swap the max element with the last element in the entries and remove the max element. - let Entry { priority, value } = vector::swap_remove(&mut pq.entries, 0); + let Entry { priority, value } = pq.entries.swap_remove(0); // Now the max heap property has been violated at the root node, but nowhere else // so we call max heapify on the root node. max_heapify_recursive(&mut pq.entries, len - 1, 0); @@ -48,8 +47,8 @@ module sui::priority_queue { /// Insert a new entry into the queue. public fun insert(pq: &mut PriorityQueue, priority: u64, value: T) { - vector::push_back(&mut pq.entries, Entry { priority, value}); - let index = vector::length(&pq.entries) - 1; + pq.entries.push_back(Entry { priority, value}); + let index = pq.entries.length() - 1; restore_heap_recursive(&mut pq.entries, index); } @@ -58,14 +57,14 @@ module sui::priority_queue { } public fun create_entries(mut p: vector, mut v: vector): vector> { - let len = vector::length(&p); - assert!(vector::length(&v) == len, 0); - let mut res = vector::empty(); + let len = p.length(); + assert!(v.length() == len, 0); + let mut res = vector[]; let mut i = 0; while (i < len) { - let priority = vector::remove(&mut p, 0); - let value = vector::remove(&mut v, 0); - vector::push_back(&mut res, Entry { priority, value }); + let priority = p.remove(0); + let value = v.remove(0); + res.push_back(Entry { priority, value }); i = i + 1; }; res @@ -80,8 +79,8 @@ module sui::priority_queue { // If new elem is greater than its parent, swap them and recursively // do the restoration upwards. - if (vector::borrow(v, i).priority > vector::borrow(v, parent).priority) { - vector::swap(v, i, parent); + if (*&v[i].priority > *&v[parent].priority) { + v.swap(i, parent); restore_heap_recursive(v, parent); } } @@ -100,16 +99,16 @@ module sui::priority_queue { let right = left + 1; let mut max = i; // Find the node with highest priority among node `i` and its two children. - if (left < len && vector::borrow(v, left).priority> vector::borrow(v, max).priority) { + if (left < len && *&v[left].priority > *&v[max].priority) { max = left; }; - if (right < len && vector::borrow(v, right).priority > vector::borrow(v, max).priority) { + if (right < len && *&v[right].priority > *&v[max].priority) { max = right; }; // If the parent node (node `i`) doesn't have the highest priority, we swap the parent with the // max priority node. if (max != i) { - vector::swap(v, max, i); + v.swap(max, i); // After the swap, we have restored the property at node `i` but now the max heap property // may be violated at node `max` since this node now has a new value. So we need to now // max heapify the subtree rooted at node `max`. @@ -120,8 +119,8 @@ module sui::priority_queue { public fun priorities(pq: &PriorityQueue): vector { let mut res = vector[]; let mut i = 0; - while (i < vector::length(&pq.entries)) { - vector::push_back(&mut res, vector::borrow(&pq.entries, i).priority); + while (i < pq.entries.length()) { + res.push_back(pq.entries[i].priority); i = i +1; }; res diff --git a/crates/sui-framework/packages/sui-framework/sources/random.move b/crates/sui-framework/packages/sui-framework/sources/random.move index e8f7b1313d0f0..1fdc104c394fa 100644 --- a/crates/sui-framework/packages/sui-framework/sources/random.move +++ b/crates/sui-framework/packages/sui-framework/sources/random.move @@ -4,12 +4,8 @@ /// This module provides functionality for generating secure randomness. module sui::random { use std::bcs; - use std::vector; - use sui::address::to_bytes; use sui::hmac::hmac_sha3_256; - use sui::object::{Self, UID}; use sui::transfer; - use sui::tx_context::{Self, TxContext, fresh_object_address}; use sui::versioned::{Self, Versioned}; // Sender is not @0x0 the system address. @@ -44,13 +40,13 @@ module sui::random { /// the Random object is first created. /// Can only be called by genesis or change_epoch transactions. fun create(ctx: &mut TxContext) { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); let version = CURRENT_VERSION; let inner = RandomInner { version, - epoch: tx_context::epoch(ctx), + epoch: ctx.epoch(), randomness_round: 0, random_bytes: vector[], }; @@ -101,13 +97,12 @@ module sui::random { ctx: &TxContext, ) { // Validator will make a special system call with sender set as 0x0. - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); + assert!(ctx.sender() == @0x0, ENotSystemAddress); // Randomness should only be incremented. - let epoch = tx_context::epoch(ctx); - let inner = load_inner_mut(self); - if (inner.randomness_round == 0 && inner.epoch == 0 && - vector::is_empty(&inner.random_bytes)) { + let epoch = ctx.epoch(); + let inner = self.load_inner_mut(); + if (inner.randomness_round == 0 && inner.epoch == 0 && inner.random_bytes.is_empty()) { // First update should be for round zero. assert!(new_round == 0, EInvalidRandomnessUpdate); } else { @@ -121,7 +116,7 @@ module sui::random { ); }; - inner.epoch = tx_context::epoch(ctx); + inner.epoch = ctx.epoch(); inner.randomness_round = new_round; inner.random_bytes = new_bytes; } @@ -133,7 +128,7 @@ module sui::random { new_bytes: vector, ctx: &TxContext, ) { - update_randomness_state(self, new_round, new_bytes, ctx); + self.update_randomness_state(new_round, new_bytes, ctx); } @@ -149,7 +144,7 @@ module sui::random { let inner = load_inner(r); let seed = hmac_sha3_256( &inner.random_bytes, - &to_bytes(fresh_object_address(ctx)) + &ctx.fresh_object_address().to_bytes() ); RandomGenerator { seed, counter: 0, buffer: vector[] } } diff --git a/crates/sui-framework/packages/sui-framework/sources/sui.move b/crates/sui-framework/packages/sui-framework/sources/sui.move index 74a4c7a0ed228..90c7daab59cdf 100644 --- a/crates/sui-framework/packages/sui-framework/sources/sui.move +++ b/crates/sui-framework/packages/sui-framework/sources/sui.move @@ -4,10 +4,7 @@ /// Coin is the token used to pay for gas in Sui. /// It has 9 decimals, and the smallest unit (10^-9) is called "mist". module sui::sui { - use std::option; - use sui::tx_context::{Self, TxContext}; - use sui::balance::{Self, Balance}; - use sui::transfer; + use sui::balance::Balance; use sui::coin; const EAlreadyMinted: u64 = 0; @@ -33,8 +30,8 @@ module sui::sui { /// Register the `SUI` Coin to acquire its `Supply`. /// This should be called only once during genesis creation. fun new(ctx: &mut TxContext): Balance { - assert!(tx_context::sender(ctx) == @0x0, ENotSystemAddress); - assert!(tx_context::epoch(ctx) == 0, EAlreadyMinted); + assert!(ctx.sender() == @0x0, ENotSystemAddress); + assert!(ctx.epoch() == 0, EAlreadyMinted); let (treasury, metadata) = coin::create_currency( SUI {}, @@ -47,9 +44,9 @@ module sui::sui { ctx ); transfer::public_freeze_object(metadata); - let mut supply = coin::treasury_into_supply(treasury); - let total_sui = balance::increase_supply(&mut supply, TOTAL_SUPPLY_MIST); - balance::destroy_supply(supply); + let mut supply = treasury.treasury_into_supply(); + let total_sui = supply.increase_supply(TOTAL_SUPPLY_MIST); + supply.destroy_supply(); total_sui } diff --git a/crates/sui-framework/packages/sui-framework/sources/table.move b/crates/sui-framework/packages/sui-framework/sources/table.move index ed201a620bc17..406af388c5a3f 100644 --- a/crates/sui-framework/packages/sui-framework/sources/table.move +++ b/crates/sui-framework/packages/sui-framework/sources/table.move @@ -17,9 +17,7 @@ /// assert!(&table1 != &table2, 0); /// ``` module sui::table { - use sui::object::{Self, UID}; use sui::dynamic_field as field; - use sui::tx_context::TxContext; // Attempted to destroy a non-empty table const ETableNotEmpty: u64 = 0; @@ -47,6 +45,7 @@ module sui::table { table.size = table.size + 1; } + #[syntax(index)] /// Immutable borrows the value associated with the key in the table `table: &Table`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the table does not have an entry with /// that key `k: K`. @@ -54,6 +53,7 @@ module sui::table { field::borrow(&table.id, k) } + #[syntax(index)] /// Mutably borrows the value associated with the key in the table `table: &mut Table`. /// Aborts with `sui::dynamic_field::EFieldDoesNotExist` if the table does not have an entry with /// that key `k: K`. @@ -90,13 +90,13 @@ module sui::table { public fun destroy_empty(table: Table) { let Table { id, size } = table; assert!(size == 0, ETableNotEmpty); - object::delete(id) + id.delete() } /// Drop a possibly non-empty table. /// Usable only if the value type `V` has the `drop` ability public fun drop(table: Table) { let Table { id, size: _ } = table; - object::delete(id) + id.delete() } } diff --git a/crates/sui-framework/packages/sui-framework/sources/table_vec.move b/crates/sui-framework/packages/sui-framework/sources/table_vec.move index 107e6475fc811..9ae8b9c1a2a50 100644 --- a/crates/sui-framework/packages/sui-framework/sources/table_vec.move +++ b/crates/sui-framework/packages/sui-framework/sources/table_vec.move @@ -4,7 +4,6 @@ /// A basic scalable vector library implemented using `Table`. module sui::table_vec { use sui::table::{Self, Table}; - use sui::tx_context::TxContext; public struct TableVec has store { /// The contents of the table vector. @@ -24,38 +23,40 @@ module sui::table_vec { /// Return a TableVec of size one containing element `e`. public fun singleton(e: Element, ctx: &mut TxContext): TableVec { let mut t = empty(ctx); - push_back(&mut t, e); + t.push_back(e); t } /// Return the length of the TableVec. public fun length(t: &TableVec): u64 { - table::length(&t.contents) + t.contents.length() } /// Return if the TableVec is empty or not. public fun is_empty(t: &TableVec): bool { - length(t) == 0 + t.length() == 0 } + #[syntax(index)] /// Acquire an immutable reference to the `i`th element of the TableVec `t`. /// Aborts if `i` is out of bounds. public fun borrow(t: &TableVec, i: u64): &Element { - assert!(length(t) > i, EIndexOutOfBound); - table::borrow(&t.contents, i) + assert!(t.length() > i, EIndexOutOfBound); + &t.contents[i] } /// Add element `e` to the end of the TableVec `t`. public fun push_back(t: &mut TableVec, e: Element) { - let key = length(t); - table::add(&mut t.contents, key, e); + let key = t.length(); + t.contents.add(key, e); } + #[syntax(index)] /// Return a mutable reference to the `i`th element in the TableVec `t`. /// Aborts if `i` is out of bounds. public fun borrow_mut(t: &mut TableVec, i: u64): &mut Element { - assert!(length(t) > i, EIndexOutOfBound); - table::borrow_mut(&mut t.contents, i) + assert!(t.length() > i, EIndexOutOfBound); + &mut t.contents[i] } /// Pop an element from the end of TableVec `t`. @@ -63,7 +64,7 @@ module sui::table_vec { public fun pop_back(t: &mut TableVec): Element { let length = length(t); assert!(length > 0, EIndexOutOfBound); - table::remove(&mut t.contents, length - 1) + t.contents.remove(length - 1) } /// Destroy the TableVec `t`. @@ -71,35 +72,59 @@ module sui::table_vec { public fun destroy_empty(t: TableVec) { assert!(length(&t) == 0, ETableNonEmpty); let TableVec { contents } = t; - table::destroy_empty(contents); + contents.destroy_empty(); } /// Drop a possibly non-empty TableVec `t`. /// Usable only if the value type `Element` has the `drop` ability public fun drop(t: TableVec) { let TableVec { contents } = t; - table::drop(contents) + contents.drop() } /// Swaps the elements at the `i`th and `j`th indices in the TableVec `t`. /// Aborts if `i` or `j` is out of bounds. public fun swap(t: &mut TableVec, i: u64, j: u64) { - assert!(length(t) > i, EIndexOutOfBound); - assert!(length(t) > j, EIndexOutOfBound); + assert!(t.length() > i, EIndexOutOfBound); + assert!(t.length() > j, EIndexOutOfBound); if (i == j) { return }; - let element_i = table::remove(&mut t.contents, i); - let element_j = table::remove(&mut t.contents, j); - table::add(&mut t.contents, j, element_i); - table::add(&mut t.contents, i, element_j); + let element_i = t.contents.remove(i); + let element_j = t.contents.remove(j); + t.contents.add(j, element_i); + t.contents.add(i, element_j); } /// Swap the `i`th element of the TableVec `t` with the last element and then pop the TableVec. /// This is O(1), but does not preserve ordering of elements in the TableVec. /// Aborts if `i` is out of bounds. public fun swap_remove(t: &mut TableVec, i: u64): Element { - assert!(length(t) > i, EIndexOutOfBound); - let last_idx = length(t) - 1; - swap(t, i, last_idx); - pop_back(t) + assert!(t.length() > i, EIndexOutOfBound); + let last_idx = t.length() - 1; + t.swap(i, last_idx); + t.pop_back() } + + #[test] + fun test_swap() { + let ctx = &mut sui::tx_context::dummy(); + let mut tv = singleton(0, ctx); + tv.push_back(1); + tv.push_back(2); + tv.push_back(3); + tv.push_back(4); + tv.swap(4,2); + tv.check_pop(2); + tv.check_pop(3); + tv.check_pop(4); + tv.check_pop(1); + tv.check_pop(0); + tv.drop() + } + + #[test_only] + fun check_pop(tv: &mut TableVec, expected_value: u64) { + let value = tv.pop_back(); + assert!(value == expected_value, value * 100 + expected_value); + } + } diff --git a/crates/sui-framework/packages/sui-framework/sources/test/test_random.move b/crates/sui-framework/packages/sui-framework/sources/test/test_random.move index f99cae46cc1fd..89a7ba66f7b3e 100644 --- a/crates/sui-framework/packages/sui-framework/sources/test/test_random.move +++ b/crates/sui-framework/packages/sui-framework/sources/test/test_random.move @@ -4,7 +4,6 @@ #[test_only] module sui::test_random { use std::hash; - use std::vector; // Internally, the pseudorandom generator uses a hash chain over Sha3-256 // which has an output length of 32 bytes. @@ -36,7 +35,7 @@ module sui::test_random { let (mut i, mut output) = (0, vector[]); while (i < quotient) { - vector::append(&mut output, next_digest(random)); + output.append(next_digest(random)); i = i + 1; }; @@ -44,7 +43,7 @@ module sui::test_random { if (remainder > 0) { let (mut i, digest) = (0, next_digest(random)); while (i < remainder) { - vector::push_back(&mut output, *vector::borrow(&digest, i)); + output.push_back(digest[i]); i = i + 1; }; }; @@ -57,7 +56,7 @@ module sui::test_random { let mut bytes = next_digest(random); let (mut value, mut i) = (0u256, 0u8); while (i < 32) { - let byte = (vector::pop_back(&mut bytes) as u256); + let byte = (bytes.pop_back() as u256); value = value + (byte << 8*i); i = i + 1; }; @@ -126,7 +125,7 @@ module sui::test_random { /// Use the given pseudorandom generator to generate a random `u8`. public fun next_u8(random: &mut Random): u8 { - vector::pop_back(&mut next_digest(random)) + next_digest(random).pop_back() } /// Use the given pseudo-random generator and a non-zero `upper_bound` to generate a diff --git a/crates/sui-framework/packages/sui-framework/sources/test/test_scenario.move b/crates/sui-framework/packages/sui-framework/sources/test/test_scenario.move index f17307dac18dc..346731d63f5cf 100644 --- a/crates/sui-framework/packages/sui-framework/sources/test/test_scenario.move +++ b/crates/sui-framework/packages/sui-framework/sources/test/test_scenario.move @@ -3,9 +3,6 @@ #[test_only] module sui::test_scenario { - use std::option::{Self, Option}; - use sui::object::{Self, ID, UID}; - use sui::tx_context::{Self, TxContext}; use sui::vec_map::VecMap; #[allow(unused_const)] @@ -105,8 +102,8 @@ module sui::test_scenario { // create a seed for new transaction digest to ensure that this tx has a different // digest (and consequently, different object ID's) than the previous tx scenario.txn_number = scenario.txn_number + 1; - let epoch = tx_context::epoch(&scenario.ctx); - let epoch_timestamp_ms = tx_context::epoch_timestamp_ms(&scenario.ctx); + let epoch = scenario.ctx.epoch(); + let epoch_timestamp_ms = scenario.ctx.epoch_timestamp_ms(); scenario.ctx = tx_context::new_from_hint( sender, scenario.txn_number, @@ -121,7 +118,7 @@ module sui::test_scenario { /// Advance the scenario to a new epoch and end the transaction /// See `next_tx` for further details public fun next_epoch(scenario: &mut Scenario, sender: address): TransactionEffects { - tx_context::increment_epoch_number(&mut scenario.ctx); + scenario.ctx.increment_epoch_number(); next_tx(scenario, sender) } @@ -133,7 +130,7 @@ module sui::test_scenario { delta_ms: u64, sender: address, ): TransactionEffects { - tx_context::increment_epoch_timestamp(&mut scenario.ctx, delta_ms); + scenario.ctx.increment_epoch_timestamp(delta_ms); next_epoch(scenario, sender) } @@ -160,7 +157,7 @@ module sui::test_scenario { /// Return the sender of the current tx in this `scenario` public fun sender(scenario: &Scenario): address { - tx_context::sender(&scenario.ctx) + scenario.ctx.sender() } /// Return the number of concluded transactions in this scenario. @@ -232,15 +229,15 @@ module sui::test_scenario { /// helper that returns true iff `most_recent_id_for_address` returns some public fun has_most_recent_for_address(account: address): bool { - option::is_some(&most_recent_id_for_address(account)) + most_recent_id_for_address(account).is_some() } /// Helper combining `take_from_address_by_id` and `most_recent_id_for_address` /// Aborts if there is no object of type `T` in the inventory of `account` public fun take_from_address(scenario: &Scenario, account: address): T { let id_opt = most_recent_id_for_address(account); - assert!(option::is_some(&id_opt), EEmptyInventory); - take_from_address_by_id(scenario, account, option::destroy_some(id_opt)) + assert!(id_opt.is_some(), EEmptyInventory); + take_from_address_by_id(scenario, account, id_opt.destroy_some()) } /// Return `t` to the inventory of the `account`. `transfer` can be used directly instead, @@ -269,7 +266,7 @@ module sui::test_scenario { /// helper that returns true iff `most_recent_id_for_sender` returns some public fun has_most_recent_for_sender(scenario: &Scenario): bool { - option::is_some(&most_recent_id_for_address(sender(scenario))) + most_recent_id_for_address(sender(scenario)).is_some() } /// helper for `take_from_address` that operates over the transaction sender @@ -303,15 +300,15 @@ module sui::test_scenario { /// helper that returns true iff `most_recent_immutable_id` returns some public fun has_most_recent_immutable(): bool { - option::is_some(&most_recent_immutable_id()) + most_recent_immutable_id().is_some() } /// Helper combining `take_immutable_by_id` and `most_recent_immutable_id` /// Aborts if there is no immutable object of type `T` in the global inventory public fun take_immutable(scenario: &Scenario): T { let id_opt = most_recent_immutable_id(); - assert!(option::is_some(&id_opt), EEmptyInventory); - take_immutable_by_id(scenario, option::destroy_some(id_opt)) + assert!(id_opt.is_some(), EEmptyInventory); + take_immutable_by_id(scenario, id_opt.destroy_some()) } /// Return `t` to the global inventory @@ -335,15 +332,15 @@ module sui::test_scenario { /// helper that returns true iff `most_recent_id_shared` returns some public fun has_most_recent_shared(): bool { - option::is_some(&most_recent_id_shared()) + most_recent_id_shared().is_some() } /// Helper combining `take_shared_by_id` and `most_recent_id_shared` /// Aborts if there is no shared object of type `T` in the global inventory public fun take_shared(scenario: &Scenario): T { let id_opt = most_recent_id_shared(); - assert!(option::is_some(&id_opt), EEmptyInventory); - take_shared_by_id(scenario, option::destroy_some(id_opt)) + assert!(id_opt.is_some(), EEmptyInventory); + take_shared_by_id(scenario, id_opt.destroy_some()) } /// Return `t` to the global inventory diff --git a/crates/sui-framework/packages/sui-framework/sources/test/test_utils.move b/crates/sui-framework/packages/sui-framework/sources/test/test_utils.move index 0baf932939258..4e0c56b4abf8c 100644 --- a/crates/sui-framework/packages/sui-framework/sources/test/test_utils.move +++ b/crates/sui-framework/packages/sui-framework/sources/test/test_utils.move @@ -19,7 +19,7 @@ module sui::test_utils { } public fun print(str: vector) { - std::debug::print(&std::ascii::string(str)) + std::debug::print(&str.to_ascii_string()) } public native fun destroy(x: T); diff --git a/crates/sui-framework/packages/sui-framework/sources/token.move b/crates/sui-framework/packages/sui-framework/sources/token.move index 5d8f528dd4df0..bdc1b63fac1e1 100644 --- a/crates/sui-framework/packages/sui-framework/sources/token.move +++ b/crates/sui-framework/packages/sui-framework/sources/token.move @@ -20,18 +20,13 @@ /// on the token. And hence it is highly suitable for applications that require /// control over the currency which a simple open-loop system can't provide. module sui::token { - use std::vector; - use std::string::{Self, String}; - use std::option::{Self, Option}; + use std::string::String; use std::type_name::{Self, TypeName}; - use sui::tx_context::{Self, TxContext}; - use sui::coin::{Self, Coin, TreasuryCap}; + use sui::coin::{Coin, TreasuryCap}; use sui::balance::{Self, Balance}; - use sui::object::{Self, ID, UID}; use sui::vec_map::{Self, VecMap}; use sui::vec_set::{Self, VecSet}; use sui::dynamic_field as df; - use sui::transfer; use sui::event; /// The action is not allowed (defined) in the policy. @@ -180,7 +175,7 @@ module sui::token { public fun transfer( t: Token, recipient: address, ctx: &mut TxContext ): ActionRequest { - let amount = balance::value(&t.balance); + let amount = t.balance.value(); transfer::transfer(t, recipient); new_request( @@ -200,11 +195,11 @@ module sui::token { /// request and join the spent balance with the `TokenPolicy.spent_balance`. public fun spend(t: Token, ctx: &mut TxContext): ActionRequest { let Token { id, balance } = t; - object::delete(id); + id.delete(); new_request( spend_action(), - balance::value(&balance), + balance.value(), option::none(), option::some(balance), ctx @@ -217,11 +212,11 @@ module sui::token { t: Token, ctx: &mut TxContext ): (Coin, ActionRequest) { let Token { id, balance } = t; - let amount = balance::value(&balance); - object::delete(id); + let amount = balance.value(); + id.delete(); ( - coin::from_balance(balance, ctx), + balance.into_coin(ctx), new_request( to_coin_action(), amount, @@ -237,10 +232,10 @@ module sui::token { public fun from_coin( coin: Coin, ctx: &mut TxContext ): (Token, ActionRequest) { - let amount = coin::value(&coin); + let amount = coin.value(); let token = Token { id: object::new(ctx), - balance: coin::into_balance(coin) + balance: coin.into_balance() }; ( @@ -260,8 +255,8 @@ module sui::token { /// Join two `Token`s into one, always available. public fun join(token: &mut Token, another: Token) { let Token { id, balance } = another; - balance::join(&mut token.balance, balance); - object::delete(id); + token.balance.join(balance); + id.delete(); } /// Split a `Token` with `amount`. @@ -269,10 +264,10 @@ module sui::token { public fun split( token: &mut Token, amount: u64, ctx: &mut TxContext ): Token { - assert!(balance::value(&token.balance) >= amount, EBalanceTooLow); + assert!(token.balance.value() >= amount, EBalanceTooLow); Token { id: object::new(ctx), - balance: balance::split(&mut token.balance, amount), + balance: token.balance.split(amount), } } @@ -288,15 +283,15 @@ module sui::token { /// Aborts if the `Token.balance` is not zero. public fun destroy_zero(token: Token) { let Token { id, balance } = token; - assert!(balance::value(&balance) == 0, ENotZero); - balance::destroy_zero(balance); - object::delete(id); + assert!(balance.value() == 0, ENotZero); + balance.destroy_zero(); + id.delete(); } #[allow(lint(self_transfer))] /// Transfer the `Token` to the transaction sender. public fun keep(token: Token, ctx: &mut TxContext) { - transfer::transfer(token, tx_context::sender(ctx)) + transfer::transfer(token, ctx.sender()) } // === Request Handling === @@ -315,7 +310,7 @@ module sui::token { amount, recipient, spent_balance, - sender: tx_context::sender(ctx), + sender: ctx.sender(), approvals: vec_set::empty(), } } @@ -335,8 +330,8 @@ module sui::token { request: ActionRequest, _ctx: &mut TxContext ): (String, u64, address, Option
) { - assert!(option::is_none(&request.spent_balance), ECantConsumeBalance); - assert!(vec_map::contains(&policy.rules, &request.name), EUnknownAction); + assert!(request.spent_balance.is_none(), ECantConsumeBalance); + assert!(policy.rules.contains(&request.name), EUnknownAction); let ActionRequest { name, approvals, @@ -344,15 +339,15 @@ module sui::token { amount, sender, recipient, } = request; - option::destroy_none(spent_balance); + spent_balance.destroy_none(); - let rules = &vec_set::into_keys(*vec_map::get(&policy.rules, &name)); - let rules_len = vector::length(rules); + let rules = &(*policy.rules.get(&name)).into_keys(); + let rules_len = rules.length(); let mut i = 0; while (i < rules_len) { - let rule = vector::borrow(rules, i); - assert!(vec_set::contains(&approvals, rule), ENotApproved); + let rule = &rules[i]; + assert!(approvals.contains(rule), ENotApproved); i = i + 1; }; @@ -372,13 +367,10 @@ module sui::token { mut request: ActionRequest, ctx: &mut TxContext ): (String, u64, address, Option
) { - assert!(vec_map::contains(&policy.rules, &request.name), EUnknownAction); - assert!(option::is_some(&request.spent_balance), EUseImmutableConfirm); + assert!(policy.rules.contains(&request.name), EUnknownAction); + assert!(request.spent_balance.is_some(), EUseImmutableConfirm); - balance::join( - &mut policy.spent_balance, - option::extract(&mut request.spent_balance) - ); + policy.spent_balance.join(request.spent_balance.extract()); confirm_request(policy, request, ctx) } @@ -395,13 +387,13 @@ module sui::token { request: ActionRequest, _ctx: &mut TxContext ): (String, u64, address, Option
) { - assert!(option::is_none(&request.spent_balance), ECantConsumeBalance); + assert!(request.spent_balance.is_none(), ECantConsumeBalance); let ActionRequest { name, amount, sender, recipient, approvals: _, spent_balance } = request; - option::destroy_none(spent_balance); + spent_balance.destroy_none(); (name, amount, sender, recipient) } @@ -422,13 +414,10 @@ module sui::token { spent_balance } = request; - if (option::is_some(&spent_balance)) { - balance::decrease_supply( - coin::supply_mut(treasury_cap), - option::destroy_some(spent_balance) - ); + if (spent_balance.is_some()) { + treasury_cap.supply_mut().decrease_supply(spent_balance.destroy_some()); } else { - option::destroy_none(spent_balance); + spent_balance.destroy_none(); }; (name, amount, sender, recipient) @@ -443,7 +432,7 @@ module sui::token { public fun add_approval( _t: W, request: &mut ActionRequest, _ctx: &mut TxContext ) { - vec_set::insert(&mut request.approvals, type_name::get()) + request.approvals.insert(type_name::get()) } /// Add a `Config` for a `Rule` in the `TokenPolicy`. Rule configuration is @@ -542,7 +531,7 @@ module sui::token { _ctx: &mut TxContext ) { assert!(object::id(self) == cap.`for`, ENotAuthorized); - vec_map::insert(&mut self.rules, action, vec_set::empty()); + self.rules.insert(action, vec_set::empty()); } /// Completely disallows an `action` on the `Token` by removing the record @@ -556,7 +545,7 @@ module sui::token { _ctx: &mut TxContext ) { assert!(object::id(self) == cap.`for`, ENotAuthorized); - vec_map::remove(&mut self.rules, &action); + self.rules.remove(&action); } /// Adds a Rule for an action with `name` in the `TokenPolicy`. @@ -569,14 +558,11 @@ module sui::token { ctx: &mut TxContext ) { assert!(object::id(self) == cap.`for`, ENotAuthorized); - if (!vec_map::contains(&self.rules, &action)) { + if (!self.rules.contains(&action)) { allow(self, cap, action, ctx); }; - vec_set::insert( - vec_map::get_mut(&mut self.rules, &action), - type_name::get() - ) + self.rules.get_mut(&action).insert(type_name::get()) } /// Removes a rule for an action with `name` in the `TokenPolicy`. Returns @@ -591,10 +577,7 @@ module sui::token { ) { assert!(object::id(self) == cap.`for`, ENotAuthorized); - vec_set::remove( - vec_map::get_mut(&mut self.rules, &action), - &type_name::get() - ) + self.rules.get_mut(&action).remove(&type_name::get()) } // === Protected: Treasury Management === @@ -603,15 +586,15 @@ module sui::token { public fun mint( cap: &mut TreasuryCap, amount: u64, ctx: &mut TxContext ): Token { - let balance = balance::increase_supply(coin::supply_mut(cap), amount); + let balance = cap.supply_mut().increase_supply(amount); Token { id: object::new(ctx), balance } } /// Burn a `Token` using the `TreasuryCap`. public fun burn(cap: &mut TreasuryCap, token: Token) { let Token { id, balance } = token; - balance::decrease_supply(coin::supply_mut(cap), balance); - object::delete(id); + cap.supply_mut().decrease_supply(balance); + id.delete(); } /// Flush the `TokenPolicy.spent_balance` into the `TreasuryCap`. This @@ -621,48 +604,60 @@ module sui::token { cap: &mut TreasuryCap, _ctx: &mut TxContext ): u64 { - let amount = balance::value(&self.spent_balance); - let balance = balance::split(&mut self.spent_balance, amount); - balance::decrease_supply(coin::supply_mut(cap), balance) + let amount = self.spent_balance.value(); + let balance = self.spent_balance.split(amount); + cap.supply_mut().decrease_supply(balance) } // === Getters: `TokenPolicy` and `Token` === /// Check whether an action is present in the rules VecMap. public fun is_allowed(self: &TokenPolicy, action: &String): bool { - vec_map::contains(&self.rules, action) + self.rules.contains(action) } /// Returns the rules required for a specific action. public fun rules( self: &TokenPolicy, action: &String ): VecSet { - *vec_map::get(&self.rules, action) + *self.rules.get(action) } /// Returns the `spent_balance` of the `TokenPolicy`. public fun spent_balance(self: &TokenPolicy): u64 { - balance::value(&self.spent_balance) + self.spent_balance.value() } /// Returns the `balance` of the `Token`. public fun value(t: &Token): u64 { - balance::value(&t.balance) + t.balance.value() } // === Action Names === /// Name of the Transfer action. - public fun transfer_action(): String { string::utf8(TRANSFER) } + public fun transfer_action(): String { + let transfer_str = TRANSFER; + transfer_str.to_string() + } /// Name of the `Spend` action. - public fun spend_action(): String { string::utf8(SPEND) } + public fun spend_action(): String { + let spend_str = SPEND; + spend_str.to_string() + } /// Name of the `ToCoin` action. - public fun to_coin_action(): String { string::utf8(TO_COIN) } + public fun to_coin_action(): String { + let to_coin_str = TO_COIN; + to_coin_str.to_string() + } /// Name of the `FromCoin` action. - public fun from_coin_action(): String { string::utf8(FROM_COIN) } + public fun from_coin_action(): String { + let from_coin_str = FROM_COIN; + from_coin_str.to_string() + } // === Action Request Fields == @@ -687,8 +682,8 @@ module sui::token { /// Burned balance of the `ActionRequest`. public fun spent(self: &ActionRequest): Option { - if (option::is_some(&self.spent_balance)) { - option::some(balance::value(option::borrow(&self.spent_balance))) + if (self.spent_balance.is_some()) { + option::some(self.spent_balance.borrow().value()) } else { option::none() } @@ -730,9 +725,9 @@ module sui::token { ) { let TokenPolicyCap { id: cap_id, `for`: _ } = cap; let TokenPolicy { id, rules: _, spent_balance } = policy; - balance::destroy_for_testing(spent_balance); - object::delete(cap_id); - object::delete(id); + spent_balance.destroy_for_testing(); + cap_id.delete(); + id.delete(); } #[test_only] @@ -744,7 +739,7 @@ module sui::token { #[test_only] public fun burn_for_testing(token: Token) { let Token { id, balance } = token; - balance::destroy_for_testing(balance); - object::delete(id); + balance.destroy_for_testing(); + id.delete(); } } diff --git a/crates/sui-framework/packages/sui-framework/sources/transfer.move b/crates/sui-framework/packages/sui-framework/sources/transfer.move index 84c0f47ab9264..6843fb9897d41 100644 --- a/crates/sui-framework/packages/sui-framework/sources/transfer.move +++ b/crates/sui-framework/packages/sui-framework/sources/transfer.move @@ -4,7 +4,6 @@ #[allow(unused_const)] module sui::transfer { - use sui::object::{Self, ID, UID}; /* #[test_only] */ /* friend sui::test_scenario; */ @@ -110,7 +109,7 @@ module sui::transfer { id, version, } = to_receive; - receive_impl(object::uid_to_address(parent), id, version) + receive_impl(parent.to_address(), id, version) } /// Given mutable (i.e., locked) access to the `parent` and a `Receiving` argument @@ -122,7 +121,7 @@ module sui::transfer { id, version, } = to_receive; - receive_impl(object::uid_to_address(parent), id, version) + receive_impl(parent.to_address(), id, version) } /// Return the object ID that the given `Receiving` argument references. @@ -136,5 +135,5 @@ module sui::transfer { public(package) native fun transfer_impl(obj: T, recipient: address); - native fun receive_impl(parent: address, to_receive: object::ID, version: u64): T; + native fun receive_impl(parent: address, to_receive: ID, version: u64): T; } diff --git a/crates/sui-framework/packages/sui-framework/sources/tx_context.move b/crates/sui-framework/packages/sui-framework/sources/tx_context.move index 7ef243c1c117c..56111acecdc51 100644 --- a/crates/sui-framework/packages/sui-framework/sources/tx_context.move +++ b/crates/sui-framework/packages/sui-framework/sources/tx_context.move @@ -3,9 +3,6 @@ module sui::tx_context { - #[test_only] - use std::vector; - #[test_only] /// Number of bytes in an tx hash (which will be the transaction digest) const TX_HASH_LENGTH: u64 = 32; @@ -88,7 +85,7 @@ module sui::tx_context { epoch_timestamp_ms: u64, ids_created: u64, ): TxContext { - assert!(vector::length(&tx_hash) == TX_HASH_LENGTH, EBadTxHashLength); + assert!(tx_hash.length() == TX_HASH_LENGTH, EBadTxHashLength); TxContext { sender, tx_hash, epoch, epoch_timestamp_ms, ids_created } } @@ -116,7 +113,7 @@ module sui::tx_context { /// These hashes are guaranteed to be unique given a unique `hint: u64` fun dummy_tx_hash_with_hint(hint: u64): vector { let mut tx_hash = std::bcs::to_bytes(&hint); - while (vector::length(&tx_hash) < TX_HASH_LENGTH) vector::push_back(&mut tx_hash, 0); + while (tx_hash.length() < TX_HASH_LENGTH) tx_hash.push_back(0); tx_hash } diff --git a/crates/sui-framework/packages/sui-framework/sources/url.move b/crates/sui-framework/packages/sui-framework/sources/url.move index eff256af7ed05..e4bfb272bf551 100644 --- a/crates/sui-framework/packages/sui-framework/sources/url.move +++ b/crates/sui-framework/packages/sui-framework/sources/url.move @@ -3,7 +3,7 @@ /// URL: standard Uniform Resource Locator string module sui::url { - use std::ascii::{Self, String}; + use std::ascii::String; /// Standard Uniform Resource Locator (URL) string. public struct Url has store, copy, drop { @@ -19,7 +19,7 @@ module sui::url { /// Create a `Url` with no validation from bytes /// Note: this will abort if `bytes` is not valid ASCII public fun new_unsafe_from_bytes(bytes: vector): Url { - let url = ascii::string(bytes); + let url = bytes.to_ascii_string(); Url { url } } diff --git a/crates/sui-framework/packages/sui-framework/sources/vec_map.move b/crates/sui-framework/packages/sui-framework/sources/vec_map.move index 3f88f46383175..43cb6c8a4f7b0 100644 --- a/crates/sui-framework/packages/sui-framework/sources/vec_map.move +++ b/crates/sui-framework/packages/sui-framework/sources/vec_map.move @@ -2,8 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 module sui::vec_map { - use std::option::{Self, Option}; - use std::vector; /// This key already exists in the map const EKeyAlreadyExists: u64 = 0; @@ -38,43 +36,45 @@ module sui::vec_map { /// Create an empty `VecMap` public fun empty(): VecMap { - VecMap { contents: vector::empty() } + VecMap { contents: vector[] } } /// Insert the entry `key` |-> `value` into `self`. /// Aborts if `key` is already bound in `self`. public fun insert(self: &mut VecMap, key: K, value: V) { - assert!(!contains(self, &key), EKeyAlreadyExists); - vector::push_back(&mut self.contents, Entry { key, value }) + assert!(!self.contains(&key), EKeyAlreadyExists); + self.contents.push_back(Entry { key, value }) } /// Remove the entry `key` |-> `value` from self. Aborts if `key` is not bound in `self`. public fun remove(self: &mut VecMap, key: &K): (K, V) { - let idx = get_idx(self, key); - let Entry { key, value } = vector::remove(&mut self.contents, idx); + let idx = self.get_idx(key); + let Entry { key, value } = self.contents.remove(idx); (key, value) } /// Pop the most recently inserted entry from the map. Aborts if the map is empty. public fun pop(self: &mut VecMap): (K, V) { - assert!(!vector::is_empty(&self.contents), EMapEmpty); - let Entry { key, value } = vector::pop_back(&mut self.contents); + assert!(!self.contents.is_empty(), EMapEmpty); + let Entry { key, value } = self.contents.pop_back(); (key, value) } + #[syntax(index)] /// Get a mutable reference to the value bound to `key` in `self`. /// Aborts if `key` is not bound in `self`. public fun get_mut(self: &mut VecMap, key: &K): &mut V { - let idx = get_idx(self, key); - let entry = vector::borrow_mut(&mut self.contents, idx); + let idx = self.get_idx(key); + let entry = &mut self.contents[idx]; &mut entry.value } + #[syntax(index)] /// Get a reference to the value bound to `key` in `self`. /// Aborts if `key` is not bound in `self`. public fun get(self: &VecMap, key: &K): &V { - let idx = get_idx(self, key); - let entry = vector::borrow(&self.contents, idx); + let idx = self.get_idx(key); + let entry = &self.contents[idx]; &entry.value } @@ -82,7 +82,7 @@ module sui::vec_map { /// Return Some(V) if the value exists, None otherwise. /// Only works for a "copyable" value as references cannot be stored in `vector`. public fun try_get(self: &VecMap, key: &K): Option { - if (contains(self, key)) { + if (self.contains(key)) { option::some(*get(self, key)) } else { option::none() @@ -91,24 +91,24 @@ module sui::vec_map { /// Return true if `self` contains an entry for `key`, false otherwise public fun contains(self: &VecMap, key: &K): bool { - option::is_some(&get_idx_opt(self, key)) + get_idx_opt(self, key).is_some() } /// Return the number of entries in `self` public fun size(self: &VecMap): u64 { - vector::length(&self.contents) + self.contents.length() } /// Return true if `self` has 0 elements, false otherwise public fun is_empty(self: &VecMap): bool { - size(self) == 0 + self.size() == 0 } /// Destroy an empty map. Aborts if `self` is not empty public fun destroy_empty(self: VecMap) { let VecMap { contents } = self; - assert!(vector::is_empty(&contents), EMapNotEmpty); - vector::destroy_empty(contents) + assert!(contents.is_empty(), EMapNotEmpty); + contents.destroy_empty() } /// Unpack `self` into vectors of its keys and values. @@ -116,18 +116,18 @@ module sui::vec_map { public fun into_keys_values(self: VecMap): (vector, vector) { let VecMap { mut contents } = self; // reverse the vector so the output keys and values will appear in insertion order - vector::reverse(&mut contents); + contents.reverse(); let mut i = 0; - let n = vector::length(&contents); - let mut keys = vector::empty(); - let mut values = vector::empty(); + let n = contents.length(); + let mut keys = vector[]; + let mut values = vector[]; while (i < n) { - let Entry { key, value } = vector::pop_back(&mut contents); - vector::push_back(&mut keys, key); - vector::push_back(&mut values, value); + let Entry { key, value } = contents.pop_back(); + keys.push_back(key); + values.push_back(value); i = i + 1; }; - vector::destroy_empty(contents); + contents.destroy_empty(); (keys, values) } @@ -135,11 +135,11 @@ module sui::vec_map { /// Do not assume any particular ordering. public fun keys(self: &VecMap): vector { let mut i = 0; - let n = vector::length(&self.contents); - let mut keys = vector::empty(); + let n = self.contents.length(); + let mut keys = vector[]; while (i < n) { - let entry = vector::borrow(&self.contents, i); - vector::push_back(&mut keys, entry.key); + let entry = self.contents.borrow(i); + keys.push_back(entry.key); i = i + 1; }; keys @@ -151,7 +151,7 @@ module sui::vec_map { let mut i = 0; let n = size(self); while (i < n) { - if (&vector::borrow(&self.contents, i).key == key) { + if (&self.contents[i].key == key) { return option::some(i) }; i = i + 1; @@ -162,9 +162,9 @@ module sui::vec_map { /// Find the index of `key` in `self`. Aborts if `key` is not in `self`. /// Note that map entries are stored in insertion order, *not* sorted by key. public fun get_idx(self: &VecMap, key: &K): u64 { - let idx_opt = get_idx_opt(self, key); - assert!(option::is_some(&idx_opt), EKeyDoesNotExist); - option::destroy_some(idx_opt) + let idx_opt = self.get_idx_opt(key); + assert!(idx_opt.is_some(), EKeyDoesNotExist); + idx_opt.destroy_some() } /// Return a reference to the `idx`th entry of `self`. This gives direct access into the backing array of the map--use with caution. @@ -172,7 +172,7 @@ module sui::vec_map { /// Aborts if `idx` is greater than or equal to `size(self)` public fun get_entry_by_idx(self: &VecMap, idx: u64): (&K, &V) { assert!(idx < size(self), EIndexOutOfBounds); - let entry = vector::borrow(&self.contents, idx); + let entry = &self.contents[idx]; (&entry.key, &entry.value) } @@ -181,7 +181,7 @@ module sui::vec_map { /// Aborts if `idx` is greater than or equal to `size(self)` public fun get_entry_by_idx_mut(self: &mut VecMap, idx: u64): (&K, &mut V) { assert!(idx < size(self), EIndexOutOfBounds); - let entry = vector::borrow_mut(&mut self.contents, idx); + let entry = &mut self.contents[idx]; (&entry.key, &mut entry.value) } @@ -189,7 +189,7 @@ module sui::vec_map { /// Aborts if `idx` is greater than or equal to `size(self)` public fun remove_entry_by_idx(self: &mut VecMap, idx: u64): (K, V) { assert!(idx < size(self), EIndexOutOfBounds); - let Entry { key, value } = vector::remove(&mut self.contents, idx); + let Entry { key, value } = self.contents.remove(idx); (key, value) } } diff --git a/crates/sui-framework/packages/sui-framework/sources/vec_set.move b/crates/sui-framework/packages/sui-framework/sources/vec_set.move index e47104cbb8a63..611eb7a228bfd 100644 --- a/crates/sui-framework/packages/sui-framework/sources/vec_set.move +++ b/crates/sui-framework/packages/sui-framework/sources/vec_set.move @@ -2,8 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 module sui::vec_set { - use std::option::{Self, Option}; - use std::vector; /// This key already exists in the map const EKeyAlreadyExists: u64 = 0; @@ -22,35 +20,35 @@ module sui::vec_set { /// Create an empty `VecSet` public fun empty(): VecSet { - VecSet { contents: vector::empty() } + VecSet { contents: vector[] } } /// Create a singleton `VecSet` that only contains one element. public fun singleton(key: K): VecSet { - VecSet { contents: vector::singleton(key) } + VecSet { contents: vector[key] } } /// Insert a `key` into self. /// Aborts if `key` is already present in `self`. public fun insert(self: &mut VecSet, key: K) { - assert!(!contains(self, &key), EKeyAlreadyExists); - vector::push_back(&mut self.contents, key) + assert!(!self.contains(&key), EKeyAlreadyExists); + self.contents.push_back(key) } /// Remove the entry `key` from self. Aborts if `key` is not present in `self`. public fun remove(self: &mut VecSet, key: &K) { let idx = get_idx(self, key); - vector::remove(&mut self.contents, idx); + self.contents.remove(idx); } /// Return true if `self` contains an entry for `key`, false otherwise public fun contains(self: &VecSet, key: &K): bool { - option::is_some(&get_idx_opt(self, key)) + get_idx_opt(self, key).is_some() } /// Return the number of entries in `self` public fun size(self: &VecSet): u64 { - vector::length(&self.contents) + self.contents.length() } /// Return true if `self` has 0 elements, false otherwise @@ -80,7 +78,7 @@ module sui::vec_set { let mut i = 0; let n = size(self); while (i < n) { - if (vector::borrow(&self.contents, i) == key) { + if (&self.contents[i] == key) { return option::some(i) }; i = i + 1; @@ -92,7 +90,7 @@ module sui::vec_set { /// Note that map entries are stored in insertion order, *not* sorted. fun get_idx(self: &VecSet, key: &K): u64 { let idx_opt = get_idx_opt(self, key); - assert!(option::is_some(&idx_opt), EKeyDoesNotExist); - option::destroy_some(idx_opt) + assert!(idx_opt.is_some(), EKeyDoesNotExist); + idx_opt.destroy_some() } } diff --git a/crates/sui-framework/packages/sui-framework/sources/versioned.move b/crates/sui-framework/packages/sui-framework/sources/versioned.move index 06d95e117be8c..ae916fcdef8b0 100644 --- a/crates/sui-framework/packages/sui-framework/sources/versioned.move +++ b/crates/sui-framework/packages/sui-framework/sources/versioned.move @@ -2,9 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 module sui::versioned { - use sui::object::{UID, ID}; - use sui::tx_context::TxContext; - use sui::object; use sui::dynamic_field; /// Failed to upgrade the inner object due to invalid capability or new version. @@ -80,7 +77,7 @@ module sui::versioned { public fun destroy(self: Versioned): T { let Versioned { mut id, version } = self; let ret = dynamic_field::remove(&mut id, version); - object::delete(id); + id.delete(); ret } } diff --git a/crates/sui-framework/packages/sui-system/Move.lock b/crates/sui-framework/packages/sui-system/Move.lock index cec30ec285c6d..af204d00c7990 100644 --- a/crates/sui-framework/packages/sui-system/Move.lock +++ b/crates/sui-framework/packages/sui-system/Move.lock @@ -1,8 +1,8 @@ # @generated by Move, please check-in and do not edit manually. [move] -version = 0 -manifest_digest = "67260FCD7E87294C58A3477C87DFEB182EC8E91FF1AEF97234D0FBF5C43BB7DC" +version = 1 +manifest_digest = "68AEB9354EE1D616F6D2293EC721FE3D7E810FEC4FE34197676ECFA3DA72CAE3" deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600" dependencies = [ @@ -23,6 +23,6 @@ dependencies = [ ] [move.toolchain-version] -compiler-version = "1.16.0" +compiler-version = "1.22.0" edition = "legacy" flavor = "sui" diff --git a/crates/sui-swarm-config/tests/snapshots/snapshot_tests__populated_genesis_snapshot_matches-2.snap b/crates/sui-swarm-config/tests/snapshots/snapshot_tests__populated_genesis_snapshot_matches-2.snap index bc9e0f928078c..28d527e4f6c31 100644 --- a/crates/sui-swarm-config/tests/snapshots/snapshot_tests__populated_genesis_snapshot_matches-2.snap +++ b/crates/sui-swarm-config/tests/snapshots/snapshot_tests__populated_genesis_snapshot_matches-2.snap @@ -240,13 +240,13 @@ validators: next_epoch_worker_address: ~ extra_fields: id: - id: "0xa9f999c274f17d24e0057edeb88894c39ecc940f7c9e8d18675dc9653969acbb" + id: "0x3257c39e87e755fd5b03b18232b78258d5d0515723c736865211808486b1b419" size: 0 voting_power: 10000 - operation_cap_id: "0xca8c970a8fedbd4ae4c63a1ca1b1727da366dd226dd8ed705b38fc3e4fd06220" + operation_cap_id: "0xf81a5571116e01722e97ae9747350d833cdfebc8eb8a93ada708025426652d93" gas_price: 1000 staking_pool: - id: "0x9307d36ffe6f1d2e464cfd8eab70d1b08921e4b92f91a56162de04986bafa29c" + id: "0xfddffe284fae43ee13b38d349e38a37466e4a08aa4baf33757649d018757af39" activation_epoch: 0 deactivation_epoch: ~ sui_balance: 20000000000000000 @@ -254,14 +254,14 @@ validators: value: 0 pool_token_balance: 20000000000000000 exchange_rates: - id: "0x58f8d636c53a4b2db3fa2d574f74871b57e0b4ad250ae86003445415958bff2e" + id: "0x6cb4fbe42943ee5b151a3fbf2f598b4b488318d102fa8b61c10c37a79c545d50" size: 1 pending_stake: 0 pending_total_sui_withdraw: 0 pending_pool_token_withdraw: 0 extra_fields: id: - id: "0x36c7f4f2341c877d364b1e2cadf2648d9e0f94b3a4f8b4b9436ad154ba1c3f3e" + id: "0x24f419be038bbb2a5c7035f0f0cb007ff36832c4cecf07d23f446fd7f37459b1" size: 0 commission_rate: 200 next_epoch_stake: 20000000000000000 @@ -269,27 +269,27 @@ validators: next_epoch_commission_rate: 200 extra_fields: id: - id: "0x6cb66e43d989f3fd40698eb62e30516987c14547280df5f86c1da117c786bbac" + id: "0x491f1c32136a11ed7c5a1357af8f4de5a8b036d0085c1a20139c488d092c7b5a" size: 0 pending_active_validators: contents: - id: "0x6e7c85d942ab8b061d3aeef2a56a28bebddca976b377250ae23c2649c2895958" + id: "0x0fa914b6b5dfce464b301b62d954d4b96c0b7334a6623243ddced29c501e4761" size: 0 pending_removals: [] staking_pool_mappings: - id: "0x2a74db60f793076b97e6ecdeee75083b0162db0e6a0e3235f27b167baf4f30c5" + id: "0x94e3779ae22112f40df8f71376a5290794eb79dd972e2cb113d5311e2d5cf94d" size: 1 inactive_validators: - id: "0xb3957d2d4a6e4d791443df3075a600e200122b253a68fdde14287dde45eb0630" + id: "0x2253a380a7255e2406e642d3cef9abc88b433c4153e7bbbcf7b123049974b147" size: 0 validator_candidates: - id: "0xfad28014e7a694f0bb767a2671753a0e7ad2c621308a7d76c64319c7231b4b04" + id: "0xc2f1bba1f93a4db8f3b1d1240d460b34bc8e44c7375b332d89e108b08baa84a2" size: 0 at_risk_validators: contents: [] extra_fields: id: - id: "0x3329992e4c7e662c4a506c6932f43fa1e77d1d824f714c743ef20fae93c0deec" + id: "0xe56c345d2ddf88ada7949750bc1926823dadbf96f18ccea372e92157d6865a63" size: 0 storage_fund: total_object_storage_rebates: @@ -306,7 +306,7 @@ parameters: validator_low_stake_grace_period: 7 extra_fields: id: - id: "0xd155c63702b25f43a3f4d627c96e9aab289babe6a02017ee4b653e4ab9d986ea" + id: "0x0323b9a322f595f80c7aa4502619eae6e2014bbcdd9b2bd67af427d01ecef998" size: 0 reference_gas_price: 1000 validator_report_records: @@ -320,7 +320,7 @@ stake_subsidy: stake_subsidy_decrease_rate: 1000 extra_fields: id: - id: "0x6f0852619f90112f1710b806b94ef52163e90ae73c4eb220db2ae920d358c880" + id: "0x0aaa40a984efa073c06b50a1ce9d1f9c2d2ef091ca1e81e3ea65b3847f918094" size: 0 safe_mode: false safe_mode_storage_rewards: @@ -332,6 +332,6 @@ safe_mode_non_refundable_storage_fee: 0 epoch_start_timestamp_ms: 10 extra_fields: id: - id: "0x1f215129bcd8dd79e6c5200ad35f5c2cf7344730d589398135e2e34fb409af36" + id: "0xf6810ae1ab20d518b9267e653fc407da9ce05779a74fa14957ba4aeaca8a8b4a" size: 0 diff --git a/crates/sui-transactional-test-runner/src/test_adapter.rs b/crates/sui-transactional-test-runner/src/test_adapter.rs index 5e149618afcdf..aae43ddb96994 100644 --- a/crates/sui-transactional-test-runner/src/test_adapter.rs +++ b/crates/sui-transactional-test-runner/src/test_adapter.rs @@ -19,7 +19,7 @@ use move_command_line_common::{ address::ParsedAddress, files::verify_and_create_named_address_mapping, }; use move_compiler::{ - editions::Edition, + editions::{Edition, Flavor}, shared::{NumberFormat, NumericalAddress, PackageConfig, PackagePaths}, Flags, FullyCompiledProgram, }; @@ -1865,6 +1865,7 @@ pub static PRE_COMPILED: Lazy = Lazy::new(|| { }; let config = PackageConfig { edition: Edition::E2024_BETA, + flavor: Flavor::Sui, ..Default::default() }; let fully_compiled_res = move_compiler::construct_pre_compiled_lib( diff --git a/external-crates/move/crates/move-model/src/model.rs b/external-crates/move/crates/move-model/src/model.rs index 746f9791e7ec1..e08e5cf57d888 100644 --- a/external-crates/move/crates/move-model/src/model.rs +++ b/external-crates/move/crates/move-model/src/model.rs @@ -718,12 +718,9 @@ impl GlobalEnv { /// TODO: move-compiler should use FileId as well so we don't need this here. There is already /// a todo in their code to remove the current use of `&'static str` for file names in Loc. pub fn to_loc(&self, loc: &MoveIrLoc) -> Loc { - let file_id = self.get_file_id(loc.file_hash()).unwrap_or_else(|| { - panic!( - "Unable to find source file '{}' in the environment", - loc.file_hash() - ) - }); + let Some(file_id) = self.get_file_id(loc.file_hash()) else { + return self.unknown_loc(); + }; Loc { file_id, span: Span::new(loc.start(), loc.end()),