Skip to content

Commit

Permalink
[move-2024] Method syntax for sui-framework (#16754)
Browse files Browse the repository at this point in the history
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 <tmn@mystenlabs.com>
  • Loading branch information
2 people authored and leecchh committed Mar 27, 2024
1 parent e524bd4 commit 809c81a
Show file tree
Hide file tree
Showing 87 changed files with 1,339 additions and 1,363 deletions.
30 changes: 26 additions & 4 deletions crates/sui-framework/docs/deepbook/clob_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3830,8 +3830,19 @@ The latter is the corresponding depth list

<b>if</b> (price_low &lt; price_low_) price_low = price_low_;
<b>if</b> (price_high &gt; price_high_) price_high = price_high_;
price_low = <a href="critbit.md#0xdee9_critbit_find_closest_key">critbit::find_closest_key</a>(&pool.bids, price_low);
price_high = <a href="critbit.md#0xdee9_critbit_find_closest_key">critbit::find_closest_key</a>(&pool.bids, price_high);
<b>let</b> closest_low = <a href="critbit.md#0xdee9_critbit_find_closest_key">critbit::find_closest_key</a>(&pool.bids, price_low);
<b>let</b> closest_high = <a href="critbit.md#0xdee9_critbit_find_closest_key">critbit::find_closest_key</a>(&pool.bids, price_high);
<b>if</b> (price_low &lt;= closest_low){
price_low = closest_low;
} <b>else</b> {
(price_low, _) = <a href="critbit.md#0xdee9_critbit_next_leaf">critbit::next_leaf</a>(&pool.bids, closest_low);
};
<b>if</b> (price_high &gt;= closest_high){
price_high = closest_high;
} <b>else</b> {
(price_high, _) = <a href="critbit.md#0xdee9_critbit_previous_leaf">critbit::previous_leaf</a>(&pool.bids, closest_high);
};

<b>while</b> (price_low &lt;= price_high) {
<b>let</b> depth = <a href="clob_v2.md#0xdee9_clob_v2_get_level2_book_status">get_level2_book_status</a>(
&pool.bids,
Expand Down Expand Up @@ -3892,8 +3903,19 @@ The latter is the corresponding depth list
<b>if</b> (price_low &lt; price_low_) price_low = price_low_;
<b>let</b> (price_high_, _) = <a href="critbit.md#0xdee9_critbit_max_leaf">critbit::max_leaf</a>(&pool.asks);
<b>if</b> (price_high &gt; price_high_) price_high = price_high_;
price_low = <a href="critbit.md#0xdee9_critbit_find_closest_key">critbit::find_closest_key</a>(&pool.asks, price_low);
price_high = <a href="critbit.md#0xdee9_critbit_find_closest_key">critbit::find_closest_key</a>(&pool.asks, price_high);
<b>let</b> closest_low = <a href="critbit.md#0xdee9_critbit_find_closest_key">critbit::find_closest_key</a>(&pool.asks, price_low);
<b>let</b> closest_high = <a href="critbit.md#0xdee9_critbit_find_closest_key">critbit::find_closest_key</a>(&pool.asks, price_high);
<b>if</b> (price_low &lt;= closest_low){
price_low = closest_low;
} <b>else</b> {
(price_low, _) = <a href="critbit.md#0xdee9_critbit_next_leaf">critbit::next_leaf</a>(&pool.bids, closest_low);
};
<b>if</b> (price_high &gt;= closest_high){
price_high = closest_high;
} <b>else</b> {
(price_high, _) = <a href="critbit.md#0xdee9_critbit_previous_leaf">critbit::previous_leaf</a>(&pool.bids, closest_high);
};

<b>while</b> (price_low &lt;= price_high) {
<b>let</b> depth = <a href="clob_v2.md#0xdee9_clob_v2_get_level2_book_status">get_level2_book_status</a>(
&pool.asks,
Expand Down
14 changes: 7 additions & 7 deletions crates/sui-framework/docs/sui-framework/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Convert <code>a</code> to a hex-encoded ASCII string


<pre><code><b>public</b> <b>fun</b> <a href="../sui-framework/address.md#0x2_address_to_ascii_string">to_ascii_string</a>(a: <b>address</b>): <a href="../move-stdlib/ascii.md#0x1_ascii_String">ascii::String</a> {
<a href="../move-stdlib/ascii.md#0x1_ascii_string">ascii::string</a>(<a href="../sui-framework/hex.md#0x2_hex_encode">hex::encode</a>(<a href="../sui-framework/address.md#0x2_address_to_bytes">to_bytes</a>(a)))
<a href="../sui-framework/hex.md#0x2_hex_encode">hex::encode</a>(<a href="../sui-framework/address.md#0x2_address_to_bytes">to_bytes</a>(a)).<a href="../sui-framework/address.md#0x2_address_to_ascii_string">to_ascii_string</a>()
}
</code></pre>

Expand All @@ -186,7 +186,7 @@ Convert <code>a</code> to a hex-encoded ASCII string

## Function `to_string`

Convert <code>a</code> to a hex-encoded ASCII string
Convert <code>a</code> to a hex-encoded string


<pre><code><b>public</b> <b>fun</b> <a href="../sui-framework/address.md#0x2_address_to_string">to_string</a>(a: <b>address</b>): <a href="../move-stdlib/string.md#0x1_string_String">string::String</a>
Expand All @@ -199,7 +199,7 @@ Convert <code>a</code> to a hex-encoded ASCII string


<pre><code><b>public</b> <b>fun</b> <a href="../sui-framework/address.md#0x2_address_to_string">to_string</a>(a: <b>address</b>): <a href="../move-stdlib/string.md#0x1_string_String">string::String</a> {
<a href="../move-stdlib/string.md#0x1_string_from_ascii">string::from_ascii</a>(<a href="../sui-framework/address.md#0x2_address_to_ascii_string">to_ascii_string</a>(a))
<a href="../sui-framework/address.md#0x2_address_to_ascii_string">to_ascii_string</a>(a).<a href="../sui-framework/address.md#0x2_address_to_string">to_string</a>()
}
</code></pre>

Expand Down Expand Up @@ -229,13 +229,13 @@ or if an invalid character is encountered.


<pre><code><b>public</b> <b>fun</b> <a href="../sui-framework/address.md#0x2_address_from_ascii_bytes">from_ascii_bytes</a>(bytes: &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;): <b>address</b> {
<b>assert</b>!(<a href="../move-stdlib/vector.md#0x1_vector_length">vector::length</a>(bytes) == 64, <a href="../sui-framework/address.md#0x2_address_EAddressParseError">EAddressParseError</a>);
<b>assert</b>!(bytes.<a href="../sui-framework/address.md#0x2_address_length">length</a>() == 64, <a href="../sui-framework/address.md#0x2_address_EAddressParseError">EAddressParseError</a>);
<b>let</b> <b>mut</b> hex_bytes = <a href="../move-stdlib/vector.md#0x1_vector">vector</a>[];
<b>let</b> <b>mut</b> i = 0;
<b>while</b> (i &lt; 64) {
<b>let</b> hi = <a href="../sui-framework/address.md#0x2_address_hex_char_value">hex_char_value</a>(*<a href="../move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, i));
<b>let</b> lo = <a href="../sui-framework/address.md#0x2_address_hex_char_value">hex_char_value</a>(*<a href="../move-stdlib/vector.md#0x1_vector_borrow">vector::borrow</a>(bytes, i + 1));
<a href="../move-stdlib/vector.md#0x1_vector_push_back">vector::push_back</a>(&<b>mut</b> hex_bytes, (hi &lt;&lt; 4) | lo);
<b>let</b> hi = <a href="../sui-framework/address.md#0x2_address_hex_char_value">hex_char_value</a>(bytes[i]);
<b>let</b> lo = <a href="../sui-framework/address.md#0x2_address_hex_char_value">hex_char_value</a>(bytes[i+1]);
hex_bytes.push_back((hi &lt;&lt; 4) | lo);
i = i + 2;
};
<a href="../sui-framework/address.md#0x2_address_from_bytes">from_bytes</a>(hex_bytes)
Expand Down
Loading

0 comments on commit 809c81a

Please sign in to comment.