From dd272c7a4c6350165aa54336d7d34613803d0507 Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Mon, 13 May 2024 19:39:46 +0900 Subject: [PATCH] fix duplicate mutable references (#44) --- Cargo.toml | 58 +++++++------- .../pack/sources/TableTestData.move | 28 +++---- crates/natives/src/table.rs | 9 ++- precompile/binaries/minlib/collection.mv | Bin 4317 -> 4313 bytes precompile/binaries/minlib/dex.mv | Bin 12014 -> 12150 bytes precompile/binaries/minlib/multisig.mv | Bin 4494 -> 4490 bytes .../binaries/minlib/primary_fungible_store.mv | Bin 3199 -> 3195 bytes precompile/binaries/minlib/table.mv | Bin 2072 -> 2031 bytes precompile/binaries/stdlib/collection.mv | Bin 4317 -> 4313 bytes precompile/binaries/stdlib/dex.mv | Bin 12144 -> 12150 bytes precompile/binaries/stdlib/multisig.mv | Bin 4494 -> 4490 bytes .../binaries/stdlib/primary_fungible_store.mv | Bin 3199 -> 3195 bytes precompile/binaries/stdlib/stableswap.mv | Bin 8268 -> 8264 bytes precompile/binaries/stdlib/staking.mv | Bin 10956 -> 10955 bytes precompile/binaries/stdlib/table.mv | Bin 2072 -> 2031 bytes precompile/binaries/stdlib/vip.mv | Bin 10046 -> 10057 bytes precompile/binaries/stdlib/vip_vesting.mv | Bin 7644 -> 7846 bytes .../modules/initia_stdlib/sources/dex.move | 12 +-- .../sources/fa/primary_fungible_store.move | 4 +- .../initia_stdlib/sources/multisig.move | 4 +- .../initia_stdlib/sources/stableswap.move | 4 +- .../initia_stdlib/sources/staking.move | 12 ++- .../modules/initia_stdlib/sources/table.move | 56 +++++++------ .../sources/token/collection.move | 4 +- .../initia_stdlib/sources/vip/vesting.move | 75 ++++++++++-------- .../initia_stdlib/sources/vip/vip.move | 16 ++-- .../modules/minitia_stdlib/sources/dex.move | 24 ++++-- .../sources/fa/primary_fungible_store.move | 4 +- .../minitia_stdlib/sources/multisig.move | 4 +- .../modules/minitia_stdlib/sources/table.move | 56 +++++++------ .../sources/token/collection.move | 4 +- .../modules/tests/sources/TableTestData.move | 24 +++--- .../modules/tests/sources/TableUnitTests.move | 18 ++--- 33 files changed, 224 insertions(+), 192 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2398c9e5..5517c982 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,35 +106,35 @@ triomphe = "0.1.9" # Note: the BEGIN and END comments below are required for external tooling. Do not remove. # BEGIN MOVE DEPENDENCIES -# move-abigen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-bytecode-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-errmapgen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-ir-compiler = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-prover-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-stackless-bytecode-interpreter = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# move-transactional-test-runner = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# read-write-set = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -# read-write-set-dynamic = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-binary-format = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-bytecode-verifier = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-cli = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-command-line-common = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-compiler = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-core-types = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-docgen = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-model = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-package = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-prover = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-prover-boogie-backend = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-prover-bytecode-pipeline = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-resource-viewer = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-stackless-bytecode = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-stdlib = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-symbol-pool = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-unit-test = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-vm-runtime = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-vm-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } -move-vm-types = { git = "https://github.com/initia-labs/move.git", rev = "f9e116fbfd9c4c5eaa4b39ee5da83715f0c99367" } +# move-abigen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-bytecode-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-errmapgen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-ir-compiler = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-prover-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-stackless-bytecode-interpreter = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# move-transactional-test-runner = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# read-write-set = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +# read-write-set-dynamic = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-binary-format = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-bytecode-verifier = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-cli = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-command-line-common = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-compiler = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-core-types = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-docgen = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-model = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-package = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-prover = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-prover-boogie-backend = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-prover-bytecode-pipeline = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-resource-viewer = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-stackless-bytecode = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-stdlib = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-symbol-pool = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-unit-test = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-vm-runtime = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-vm-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } +move-vm-types = { git = "https://github.com/initia-labs/move.git", rev = "2b55388a528d222ae93b24672e15424d445d7b9e" } # END MOVE DEPENDENCIES diff --git a/crates/e2e-move-tests/src/tests/table.data/pack/sources/TableTestData.move b/crates/e2e-move-tests/src/tests/table.data/pack/sources/TableTestData.move index d3daba79..682ebc90 100644 --- a/crates/e2e-move-tests/src/tests/table.data/pack/sources/TableTestData.move +++ b/crates/e2e-move-tests/src/tests/table.data/pack/sources/TableTestData.move @@ -49,8 +49,8 @@ module 0x2::TableTestData { let keys = vector::empty(); let vals = vector::empty(); - while(T::prepare(&mut iter)) { - let (key, value) = T::next(&mut iter); + while(T::prepare(iter)) { + let (key, value) = T::next(iter); vector::push_back(&mut keys, key); vector::push_back(&mut vals, *value); @@ -83,27 +83,27 @@ module 0x2::TableTestData { let i = 1; while(i < 11) { - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == i, 101); assert!(value == &i, 101); i = i + 1; }; - assert!(!T::prepare(&mut iter), 101); + assert!(!T::prepare(iter), 101); let iter = T::iter(t_ref, option::some(2), option::some(5), 1); let i = 2; while(i < 5) { - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == i, 102); assert!(value == &i, 102); i = i + 1; }; - assert!(!T::prepare(&mut iter), 102); + assert!(!T::prepare(iter), 102); } public entry fun iterate_descending(acc: address) acquires S { @@ -113,26 +113,26 @@ module 0x2::TableTestData { let i = 10; while(i > 0) { - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == i, 101); assert!(value == &i, 101); i = i - 1; }; - assert!(!T::prepare(&mut iter), 101); + assert!(!T::prepare(iter), 101); let iter = T::iter(t_ref, option::some(2), option::some(5), 2); let i = 4; while(i > 1) { - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == i, 102); assert!(value == &i, 102); i = i - 1; }; - assert!(!T::prepare(&mut iter), 102); + assert!(!T::prepare(iter), 102); } } diff --git a/crates/natives/src/table.rs b/crates/natives/src/table.rs index e4f4ce46..0275e68e 100644 --- a/crates/natives/src/table.rs +++ b/crates/natives/src/table.rs @@ -620,7 +620,7 @@ fn native_new_table_iter( order, }); - Ok(smallvec![Value::u64(context_iterator_id as u64)]) + Ok(smallvec![Value::iter_reference(context_iterator_id as u64)]) } /// Check the `next_key` exist or not and store @@ -683,9 +683,10 @@ fn native_next_box( let table_context = context.extensions().get::(); let mut iterators = table_context.iterators.borrow_mut(); let iterator = iterators.get_mut(iterator_id).unwrap(); - let (key, value) = iterator.next.take().ok_or_else(|| { - partial_extension_error("next_box called without prepare_box") - })?; + let (key, value) = iterator + .next + .take() + .ok_or_else(|| partial_extension_error("next_box called without prepare_box"))?; iterator.next = None; diff --git a/precompile/binaries/minlib/collection.mv b/precompile/binaries/minlib/collection.mv index b8034094a29039f6148c8526e66427284cb2f458..85dc856e7f18655ff0bc3238f9bfca2601240b5a 100644 GIT binary patch delta 173 zcmcbscvEqLl=2*A_6=;y*g3B8DzJUytrGaa_nw98zHl7RUXcSlynhv>_@{5Q^=ITX zR$yXg;P5jxojjG%meG9kWySp0z$5_fk{^u# delta 170 zcmcbqcvo?Pl=5O`_U&xT*g5X5s|$-yp4)d{IfUO`ZIEx zDljoKaQK;;O`ghV%V@FrGGhYcWD{luVQv8?P6kd!MhbyfvF4o4F%CKF{IW>!s39%gQ47BirfBo7-8Cocy#CpVjj5W9;Bs|+^>6CWc3 QBcu7`cl;4R(p_K@024OV diff --git a/precompile/binaries/minlib/dex.mv b/precompile/binaries/minlib/dex.mv index 7b3fe819781f5fd3b6605ee95fd8d1caf1f564fd..a9dd6325095a410fd4dbe94634734460454b656a 100644 GIT binary patch delta 1024 zcmYLIZ){Ul6u;-)ckg@ezT5V__EpTr*5}sJvaNGN&7Np*TO3;r-6rYASSed^1*%(% ztaHkQp+*vdV&pEw#1DXip!g4KLWq7b`bFXwV`5@VO#Bx=7)kgbYBa{%j^MdDzxyZW z{LVS|+9ROb%=vnd(cAj16a|Qp4Soh5cnWKUZETRor69t?Vth^Naa? z?tF1>VK!eWmP>AN-Yu0YZhm&QyjYm2ezC^E5E9=ve6q%|do`(c9}n^n=REAkcE4tc zD~&zU;(Ft8iHFyI$)*_A?5IjLTV$K!u~0kVx*vIl+U7$Z^MO>wV?o_B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BH{Q&z^4vwq*3T$8bTNnj?3Y=l)Ix4c4k*7&)6%X&4jn)>7dgk0r z%nV#%<`zJTE!>Kmk%2AH%9@dZGs4!6fg{q1n~8;m!`E2{LT@k-SI^(-SuY)-Sg)N-4A22H=iW~Ow>gY92h!*LjwpNHAH)A zL5P^)y5MnB2q&%Zom0mk*cVnTw8bu;X<{#SL$ALWvJ@K?EH4R0EpCm)Ejw zl5R52T_>KlTq|ei9nUVA-vYU1*Zp000(k;lro79WS`iP_w6+lPPI;`WR4D-Q* zD*UV^(*%n}=^AKKJV3D8y0nn8< AB>(^b delta 391 zcmXYrIa9(=6ouc-d)f1pK@&p^0*?SeLBx$6_Z3&H{3p&>@E3IQ7qHNl%EH#tv9O`D zwXwBu9DH$XzB}j4z31F-dt~1@iB~MY%R@zZj3lLDBpVq;?m+8DneiO`66w=z?X#EE z1&owRGQ|g}QUerROD7Pndm<>LVNlLyHit;d&m+>F6%k&WlR#0{V}F+$VnM(}*({1- z&enV>%-QxS5_U`xB)lsp5ZUv2F4^}N5jpUe5IGEEac4P!dN{Vii{Oar2#zTre6q^h zrz_mVGltH2TII%BEqv$Pr3iQVD$dlomM%1|v(0cf*9z%JCphzM&N0(4CoR*q=#*=_ zG1p;^WiZ!@n<|8h{o*AkS2 kd({IPyr>T6hnfngmWE7F)~=vDc+k24jo?T3IGJ(z3+b*nJpcdz diff --git a/precompile/binaries/stdlib/stableswap.mv b/precompile/binaries/stdlib/stableswap.mv index 819a85660bd81d9b5b2183043ee745576432b169..8b5877fdbdb89f8498b66e7d3daa88df612b3abe 100644 GIT binary patch delta 404 zcmWNJy-!n77>CdAJ?Gw@_MEF!+6!&Cw=GFi!17^e)20g-#Sc&v@LNP(9H=56DjEh2 z1G+e9UI#a0qKi)E&c=-x=)UoH zsOxR-U!8hYdSGAne-6Cg?_1aLa3Ufp?DE89M{avSio}gt8QQyf1Q4`Rsfy&SV-lKH zs}*6_aGa!a*J~%C^~R|tgk1CIguFd3g}$>8LFl^+ryTt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@v-v8I!03f#J3)ZmmK}*o*U;P${t6 zVvIaWpED3cdff=@j?c$+NMA6_&e^gpFAx)8^9*VP#?g;9nxuKd6!u57sHQJs2}1f3 zOtgeu2M8x!8rQe?Z-iXj@O=e|34LF64Fs#)rdWCPL%sv~(z}kGr`HJVgG%HfJIqU= zVPXU~BHP0o!2Zbif&)SU%e=I}?7ZXPVOeIah?Q{Fi)}##?M8YX9dsy>h+-~m+3`$^ zI${^Xr41}_sY94@(OM|e<6;zx1%sD3kbLkQgO_>r zZ17z3-QXooEG6qGE=cRogH0^V>`9DXDr`NII7Yd_A*#Z5oT?5;haE~Ls+d!_b>=wN z&(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, *value) } @@ -523,8 +523,8 @@ module initia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, PairByDenomResponse { coin_a: coin::metadata_to_denom(object::address_to_object(value.coin_a)), @@ -576,8 +576,8 @@ module initia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (coin_a != key.coin_a || coin_b != key.coin_b) break; if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, *value) diff --git a/precompile/modules/initia_stdlib/sources/fa/primary_fungible_store.move b/precompile/modules/initia_stdlib/sources/fa/primary_fungible_store.move index ae006618..b059591a 100644 --- a/precompile/modules/initia_stdlib/sources/fa/primary_fungible_store.move +++ b/precompile/modules/initia_stdlib/sources/fa/primary_fungible_store.move @@ -198,8 +198,8 @@ module initia_std::primary_fungible_store { let metadata_vec: vector> = vector[]; let balance_vec: vector = vector[]; - while (table::prepare(&mut iter) && vector::length(&balance_vec) < (limit as u64)) { - let (metadata_addr, store_addr) = table::next(&mut iter); + while (table::prepare(iter) && vector::length(&balance_vec) < (limit as u64)) { + let (metadata_addr, store_addr) = table::next(iter); let metadata = object::address_to_object(metadata_addr); let store = object::address_to_object(*store_addr); diff --git a/precompile/modules/initia_stdlib/sources/multisig.move b/precompile/modules/initia_stdlib/sources/multisig.move index f653bc09..95d8f358 100644 --- a/precompile/modules/initia_stdlib/sources/multisig.move +++ b/precompile/modules/initia_stdlib/sources/multisig.move @@ -159,8 +159,8 @@ module initia_std::multisig { let multisig_wallet = borrow_global(multisig_addr); let iter = table::iter(&multisig_wallet.proposals, option::none(), start_after, 2); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut iter)) { - let (proposal_id, proposal) = table::next(&mut iter); + while (vector::length(&res) < (limit as u64) && table::prepare(iter)) { + let (proposal_id, proposal) = table::next(iter); vector::push_back(&mut res, proposal_to_proposal_response(multisig_wallet, multisig_addr, proposal_id, proposal)); }; diff --git a/precompile/modules/initia_stdlib/sources/stableswap.move b/precompile/modules/initia_stdlib/sources/stableswap.move index a1023b60..0275e3c3 100644 --- a/precompile/modules/initia_stdlib/sources/stableswap.move +++ b/precompile/modules/initia_stdlib/sources/stableswap.move @@ -208,8 +208,8 @@ module initia_std::stableswap { 2, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pools_iter)) { - let (key, _) = table::next(&mut pools_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pools_iter)) { + let (key, _) = table::next(pools_iter); let pool_response = get_pool(object::address_to_object(key)); vector::push_back(&mut res, pool_response) }; diff --git a/precompile/modules/initia_stdlib/sources/staking.move b/precompile/modules/initia_stdlib/sources/staking.move index 6d7c9595..ec16cf55 100644 --- a/precompile/modules/initia_stdlib/sources/staking.move +++ b/precompile/modules/initia_stdlib/sources/staking.move @@ -341,10 +341,10 @@ module initia_std::staking { 2, ); - let prepare = table::prepare(&mut delegations_iter); + let prepare = table::prepare(delegations_iter); let res: vector = vector[]; while (vector::length(&res) < (limit as u64) && prepare) { - let (validator, delegation) = table::next(&mut delegations_iter); + let (validator, delegation) = table::next(delegations_iter); let state = table::borrow(staking_states, validator); let reward = calculate_reward(delegation, state); vector::push_back( @@ -356,7 +356,7 @@ module initia_std::staking { unclaimed_reward: reward, }, ); - prepare = table::prepare(&mut delegations_iter); + prepare = table::prepare(delegations_iter); }; res @@ -431,10 +431,8 @@ module initia_std::staking { ); let res: vector = vector[]; - while (vector::length(&res) < (limit as u64) && table::prepare( - &mut unbondings_iter - )) { - let (_, unbonding) = table::next(&mut unbondings_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(unbondings_iter)) { + let (_, unbonding) = table::next(unbondings_iter); let unbonding_amount = get_unbonding_amount_from_unbonding(unbonding); vector::push_back( &mut res, diff --git a/precompile/modules/initia_stdlib/sources/table.move b/precompile/modules/initia_stdlib/sources/table.move index 2b4be13c..25ed256b 100644 --- a/precompile/modules/initia_stdlib/sources/table.move +++ b/precompile/modules/initia_stdlib/sources/table.move @@ -23,11 +23,6 @@ module initia_std::table { iterator_id: u64, } - /// Type of mutable table iterators - struct TableIterMut has drop { - iterator_id: u64, - } - /// Create a new Table. public fun new(): Table { let handle = new_table_handle(); @@ -151,7 +146,7 @@ module initia_std::table { start: Option, /* inclusive */ end: Option, /* exclusive */ order: u8 /* 1: Ascending, 2: Descending */, - ): TableIter { + ): &TableIter { let start_bytes: vector = if (option::is_some(&start)) { bcs::to_bytes(&option::extract(&mut start)) } else { @@ -164,17 +159,14 @@ module initia_std::table { vector::empty() }; - let iterator_id = new_table_iter>(table, start_bytes, end_bytes, order); - TableIter { - iterator_id, - } + new_table_iter>(table, start_bytes, end_bytes, order) } - public fun prepare(table_iter: &mut TableIter): bool { + public fun prepare(table_iter: &TableIter): bool { prepare_box>(table_iter) } - public fun next(table_iter: &mut TableIter): (K, &V) { + public fun next(table_iter: &TableIter): (K, &V) { let (key, box) = next_box>(table_iter); (key, &box.val) } @@ -201,7 +193,7 @@ module initia_std::table { start: Option, /* inclusive */ end: Option, /* exclusive */ order: u8 /* 1: Ascending, 2: Descending */, - ): TableIterMut { + ): &mut TableIter { let start_bytes: vector = if (option::is_some(&start)) { bcs::to_bytes(&option::extract(&mut start)) } else { @@ -214,17 +206,14 @@ module initia_std::table { vector::empty() }; - let iterator_id = new_table_iter_mut>(table, start_bytes, end_bytes, order); - TableIterMut { - iterator_id, - } + new_table_iter_mut>(table, start_bytes, end_bytes, order) } - public fun prepare_mut(table_iter: &mut TableIterMut): bool { + public fun prepare_mut(table_iter: &mut TableIter): bool { prepare_box_mut>(table_iter) } - public fun next_mut(table_iter: &mut TableIterMut): (K, &mut V) { + public fun next_mut(table_iter: &mut TableIter): (K, &mut V) { let (key, box) = next_box_mut>(table_iter); (key, &mut box.val) } @@ -260,22 +249,22 @@ module initia_std::table { start: vector, end: vector, order: u8 - ): u64; + ): &TableIter; native fun new_table_iter_mut( table: &mut Table, start: vector, end: vector, order: u8 - ): u64; + ): &mut TableIter; - native fun next_box(table_iter: &mut TableIter): (K, &mut Box); + native fun next_box(table_iter: &TableIter): (K, &Box); - native fun prepare_box(table_iter: &mut TableIter): bool; + native fun prepare_box(table_iter: &TableIter): bool; - native fun next_box_mut(table_iter: &mut TableIterMut): (K, &mut Box); + native fun next_box_mut(table_iter: &mut TableIter): (K, &mut Box); - native fun prepare_box_mut(table_iter: &mut TableIterMut): bool; + native fun prepare_box_mut(table_iter: &mut TableIter): bool; // ====================================================================================================== // Tests @@ -311,4 +300,21 @@ module initia_std::table { move_to(&account, TableHolder{ t }); } + + #[test(account = @0x1)] + fun test_iterator(account: &signer) { + let t = new(); + add(&mut t, 1, 1); + add(&mut t, 2, 2); + + let iter = iter(&t, option::none(), option::none(), 1); + let iter2 = iter(&t, option::none(), option::none(), 1); + assert!(iter.iterator_id == 0, 1); + assert!(iter2.iterator_id == 1, 1); + prepare(iter); + let (key, value) = next(iter); + assert!(key == 1 && *value == 1, 1); + + move_to(account, TableHolder { t }); + } } diff --git a/precompile/modules/initia_stdlib/sources/token/collection.move b/precompile/modules/initia_stdlib/sources/token/collection.move index 100d315f..8bf13ca2 100644 --- a/precompile/modules/initia_stdlib/sources/token/collection.move +++ b/precompile/modules/initia_stdlib/sources/token/collection.move @@ -396,8 +396,8 @@ module initia_std::collection { let res: vector = vector[]; - while (table::prepare(&mut nfts_iter) && vector::length(&res) < (limit as u64)) { - let (token_id, nft) = table::next(&mut nfts_iter); + while (table::prepare(nfts_iter) && vector::length(&res) < (limit as u64)) { + let (token_id, nft) = table::next(nfts_iter); vector::push_back( &mut res, diff --git a/precompile/modules/initia_stdlib/sources/vip/vesting.move b/precompile/modules/initia_stdlib/sources/vip/vesting.move index e430a1b1..786c0c8e 100644 --- a/precompile/modules/initia_stdlib/sources/vip/vesting.move +++ b/precompile/modules/initia_stdlib/sources/vip/vesting.move @@ -180,19 +180,6 @@ module initia_std::vip_vesting { table::add(&mut vesting_store.vestings, table_key::encode_u64(stage), vesting); } - fun finalize_vesting( - account_addr: address, - bridge_id: u64, - stage: u64, - ) acquires VestingStore { - let vesting_store_addr = get_vesting_store_address(account_addr, bridge_id); - let vesting_store = borrow_global_mut>(vesting_store_addr); - assert!(table::contains(&vesting_store.claimed_stages, table_key::encode_u64(stage)), error::unavailable(EVESTING_NOT_CLAIMED)); - - let vesting = table::remove(&mut vesting_store.vestings, table_key::encode_u64(stage)); - table::add(&mut vesting_store.vestings_finalized, table_key::encode_u64(stage), vesting); - } - fun create_vesting_store_address(account: address, bridge_id: u64): address { let seed = generate_vesting_store_seed(bridge_id); object::create_object_address(account, seed) @@ -276,10 +263,10 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.claimed_stages, option::none(), option::none(), 2); - if (!table::prepare, bool>(&mut iter)) { + if (!table::prepare, bool>(iter)) { return 0 }; - let (key, _) = table::next, bool>(&mut iter); + let (key, _) = table::next, bool>(iter); table_key::decode_u64(key) } @@ -290,16 +277,18 @@ module initia_std::vip_vesting { l2_score: u64, ) : (u64, vector) acquires VestingStore { let vested_reward = 0u64; + + let finalized_vestings = vector::empty(); let vesting_changes = vector::empty(); let vesting_store_addr = get_vesting_store_address(account_addr, bridge_id); let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter_mut(&mut vesting_store.vestings, option::none(), option::none(), 1); loop { - if (!table::prepare_mut, UserVesting>(&mut iter)) { + if (!table::prepare_mut, UserVesting>(iter)) { break }; - let (_, value) = table::next_mut, UserVesting>(&mut iter); + let (_, value) = table::next_mut, UserVesting>(iter); // move vesting if end stage is over or the left reward is empty if ( stage > value.end_stage || value.remaining_reward == 0) { @@ -311,7 +300,8 @@ module initia_std::vip_vesting { remaining_reward: value.remaining_reward, } ); - finalize_vesting(account_addr, bridge_id, value.start_stage); + + vector::push_back(&mut finalized_vestings, value.start_stage); continue }; @@ -327,6 +317,14 @@ module initia_std::vip_vesting { }); }; + // cleanup finalized vestings + vector::for_each_ref(&finalized_vestings, |stage| { + assert!(table::contains(&vesting_store.claimed_stages, table_key::encode_u64(*stage)), error::unavailable(EVESTING_NOT_CLAIMED)); + + let vesting = table::remove(&mut vesting_store.vestings, table_key::encode_u64(*stage)); + table::add(&mut vesting_store.vestings_finalized, table_key::encode_u64(*stage), vesting); + }); + (vested_reward, vesting_changes) } @@ -336,16 +334,18 @@ module initia_std::vip_vesting { stage: u64, ) : (u64, vector) acquires VestingStore { let vested_reward = 0u64; + + let finalized_vestings = vector::empty(); let vesting_changes = vector::empty(); let vesting_store_addr = get_vesting_store_address(account_addr, bridge_id); let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter_mut(&mut vesting_store.vestings, option::none(), option::none(), 1); loop { - if (!table::prepare_mut, OperatorVesting>(&mut iter)) { + if (!table::prepare_mut, OperatorVesting>(iter)) { break }; - let (_, value) = table::next_mut, OperatorVesting>(&mut iter); + let (_, value) = table::next_mut, OperatorVesting>(iter); // move vesting if end stage is over or the left reward is empty if ( stage > value.end_stage || value.remaining_reward == 0) { @@ -357,7 +357,8 @@ module initia_std::vip_vesting { remaining_reward: value.remaining_reward, } ); - finalize_vesting(account_addr, bridge_id, value.start_stage); + + vector::push_back(&mut finalized_vestings, value.start_stage); continue }; @@ -373,6 +374,14 @@ module initia_std::vip_vesting { }); }; + // cleanup finalized vestings + vector::for_each_ref(&finalized_vestings, |stage| { + assert!(table::contains(&vesting_store.claimed_stages, table_key::encode_u64(*stage)), error::unavailable(EVESTING_NOT_CLAIMED)); + + let vesting = table::remove(&mut vesting_store.vestings, table_key::encode_u64(*stage)); + table::add(&mut vesting_store.vestings_finalized, table_key::encode_u64(*stage), vesting); + }); + (vested_reward, vesting_changes) } @@ -688,11 +697,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.claimed_stages, option::none(), option::none(), 1); loop { - if (!table::prepare, bool>(&mut iter)) { + if (!table::prepare, bool>(iter)) { break }; - let (key, _) = table::next, bool>(&mut iter); + let (key, _) = table::next, bool>(iter); vector::push_back(&mut claimed_stages, table_key::decode_u64(key)); }; claimed_stages @@ -723,11 +732,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.vestings, option::none(), option::some(table_key::encode_u64(stage + 1)), 1); loop { - if (!table::prepare, UserVesting>(&mut iter)) { + if (!table::prepare, UserVesting>(iter)) { break }; - let (_, value) = table::next, UserVesting>(&mut iter); + let (_, value) = table::next, UserVesting>(iter); locked_reward = locked_reward + value.remaining_reward; }; @@ -741,11 +750,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter_mut(&mut vesting_store.vestings, option::none(), option::some(table_key::encode_u64(stage)), 1); loop { - if (!table::prepare_mut, UserVesting>(&mut iter)) { + if (!table::prepare_mut, UserVesting>(iter)) { break }; - let (_, value) = table::next_mut, UserVesting>(&mut iter); + let (_, value) = table::next_mut, UserVesting>(iter); let vest_amount = calculate_user_vest(value, l2_score); vested_reward = vested_reward + vest_amount; @@ -796,11 +805,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.claimed_stages, option::none(), option::none(), 1); loop { - if (!table::prepare, bool>(&mut iter)) { + if (!table::prepare, bool>(iter)) { break }; - let (key, _) = table::next, bool>(&mut iter); + let (key, _) = table::next, bool>(iter); vector::push_back(&mut claimed_stages, table_key::decode_u64(key)); }; claimed_stages @@ -831,11 +840,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter(&mut vesting_store.vestings, option::none(), option::some(table_key::encode_u64(stage + 1)), 1); loop { - if (!table::prepare, OperatorVesting>(&mut iter)) { + if (!table::prepare, OperatorVesting>(iter)) { break }; - let (_, value) = table::next, OperatorVesting>(&mut iter); + let (_, value) = table::next, OperatorVesting>(iter); locked_reward = locked_reward + value.remaining_reward; }; @@ -849,11 +858,11 @@ module initia_std::vip_vesting { let vesting_store = borrow_global_mut>(vesting_store_addr); let iter = table::iter_mut(&mut vesting_store.vestings, option::none(), option::some(table_key::encode_u64(stage)), 1); loop { - if (!table::prepare_mut, OperatorVesting>(&mut iter)) { + if (!table::prepare_mut, OperatorVesting>(iter)) { break }; - let (_, value) = table::next_mut, OperatorVesting>(&mut iter); + let (_, value) = table::next_mut, OperatorVesting>(iter); let vest_amount = calculate_operator_vest(value); vested_reward = vested_reward + vest_amount; diff --git a/precompile/modules/initia_stdlib/sources/vip/vip.move b/precompile/modules/initia_stdlib/sources/vip/vip.move index 19c9733f..99906055 100644 --- a/precompile/modules/initia_stdlib/sources/vip/vip.move +++ b/precompile/modules/initia_stdlib/sources/vip/vip.move @@ -408,11 +408,11 @@ module initia_std::vip { let index = 0; let iter = table::iter(&module_store.bridges, option::none(), option::none(), 1); loop { - if (!table::prepare, Bridge>(&mut iter)){ + if (!table::prepare, Bridge>(iter)){ break }; - let (bridge_id_vec, bridge) = table::next, Bridge>(&mut iter); + let (bridge_id_vec, bridge) = table::next, Bridge>(iter); let bridge_id = table_key::decode_u64(bridge_id_vec); let balance_reward = split_reward_with_share( balance_shares, @@ -552,10 +552,10 @@ module initia_std::vip { let iter = table::iter(&module_store.bridges, option::none(), option::none(), 1); loop { - if (!table::prepare, Bridge>(&mut iter)){ + if (!table::prepare, Bridge>(iter)){ break }; - let (bridge_id_vec, bridge) = table::next, Bridge>(&mut iter); + let (bridge_id_vec, bridge) = table::next, Bridge>(iter); let bridge_id = table_key::decode_u64(bridge_id_vec); let bridge_balance = primary_fungible_store::balance(bridge.bridge_addr, vip_reward::reward_metadata()); @@ -582,10 +582,10 @@ module initia_std::vip { let iter = table::iter(&module_store.bridges, option::none(), option::none(), 1); loop { - if (!table::prepare, Bridge>(&mut iter)){ + if (!table::prepare, Bridge>(iter)){ break }; - let (bridge_id_vec, bridge) = table::next, Bridge>(&mut iter); + let (bridge_id_vec, bridge) = table::next, Bridge>(iter); let bridge_id = table_key::decode_u64(bridge_id_vec); let bridge_balance = primary_fungible_store::balance(bridge.bridge_addr, vip_reward::reward_metadata()); @@ -1078,11 +1078,11 @@ module initia_std::vip { let iter = table::iter(&module_store.stage_data, option::none(), option::none(), 2); loop { - if (!table::prepare, StageData>(&mut iter)) { + if (!table::prepare, StageData>(iter)) { break }; - let (key, value) = table::next, StageData>(&mut iter); + let (key, value) = table::next, StageData>(iter); if (table::contains(&value.snapshots, table_key::encode_u64(bridge_id))) { return table_key::decode_u64(key) + 1 }; diff --git a/precompile/modules/minitia_stdlib/sources/dex.move b/precompile/modules/minitia_stdlib/sources/dex.move index 8abff336..dcc5c3d5 100644 --- a/precompile/modules/minitia_stdlib/sources/dex.move +++ b/precompile/modules/minitia_stdlib/sources/dex.move @@ -204,8 +204,12 @@ module minitia_std::dex { /// All start_after must be provided or not const ESTART_AFTER: u64 = 17; + // Cannot create pair with the same coin type const ESAME_COIN_TYPE: u64 = 19; + /// Zero amount in the swap simulation is not allowed + const EZERO_AMOUNT_IN: u64 = 20; + // Constants const MAX_LIMIT: u8 = 30; @@ -463,8 +467,8 @@ module minitia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, *value) } @@ -519,8 +523,8 @@ module minitia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, PairByDenomResponse { coin_a: coin::metadata_to_denom(object::address_to_object(value.coin_a)), @@ -572,8 +576,8 @@ module minitia_std::dex { 1, ); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut pairs_iter)) { - let (key, value) = table::next(&mut pairs_iter); + while (vector::length(&res) < (limit as u64) && table::prepare(pairs_iter)) { + let (key, value) = table::next(pairs_iter); if (coin_a != key.coin_a || coin_b != key.coin_b) break; if (&key != option::borrow(&start_after)) { vector::push_back(&mut res, *value) @@ -1359,9 +1363,17 @@ module minitia_std::dex { amount_in: u64, swap_fee_rate: Decimal128, ): (u64, u64) { + assert!(amount_in > 0, error::invalid_argument(EZERO_AMOUNT_IN)); + let one = decimal128::one(); let exp = decimal128::from_ratio(decimal128::val(&weight_in), decimal128::val(&weight_out)); + + // avoid zero fee amount to prevent fee bypass attack let fee_amount = decimal128::mul_u64(&swap_fee_rate, amount_in); + if (fee_amount == 0) { + fee_amount = 1; + }; + let adjusted_amount_in = amount_in - fee_amount; let base = decimal128::from_ratio_u64(pool_amount_in, pool_amount_in + adjusted_amount_in); let sub_amount = pow(&base, &exp); diff --git a/precompile/modules/minitia_stdlib/sources/fa/primary_fungible_store.move b/precompile/modules/minitia_stdlib/sources/fa/primary_fungible_store.move index a6843b14..a428065c 100644 --- a/precompile/modules/minitia_stdlib/sources/fa/primary_fungible_store.move +++ b/precompile/modules/minitia_stdlib/sources/fa/primary_fungible_store.move @@ -198,8 +198,8 @@ module minitia_std::primary_fungible_store { let metadata_vec: vector> = vector[]; let balance_vec: vector = vector[]; - while (table::prepare(&mut iter) && vector::length(&balance_vec) < (limit as u64)) { - let (metadata_addr, store_addr) = table::next(&mut iter); + while (table::prepare(iter) && vector::length(&balance_vec) < (limit as u64)) { + let (metadata_addr, store_addr) = table::next(iter); let metadata = object::address_to_object(metadata_addr); let store = object::address_to_object(*store_addr); diff --git a/precompile/modules/minitia_stdlib/sources/multisig.move b/precompile/modules/minitia_stdlib/sources/multisig.move index e2bca6cf..8fb29ff2 100644 --- a/precompile/modules/minitia_stdlib/sources/multisig.move +++ b/precompile/modules/minitia_stdlib/sources/multisig.move @@ -159,8 +159,8 @@ module minitia_std::multisig { let multisig_wallet = borrow_global(multisig_addr); let iter = table::iter(&multisig_wallet.proposals, option::none(), start_after, 2); - while (vector::length(&res) < (limit as u64) && table::prepare(&mut iter)) { - let (proposal_id, proposal) = table::next(&mut iter); + while (vector::length(&res) < (limit as u64) && table::prepare(iter)) { + let (proposal_id, proposal) = table::next(iter); vector::push_back(&mut res, proposal_to_proposal_response(multisig_wallet, multisig_addr, proposal_id, proposal)); }; diff --git a/precompile/modules/minitia_stdlib/sources/table.move b/precompile/modules/minitia_stdlib/sources/table.move index 4b516733..398b561f 100644 --- a/precompile/modules/minitia_stdlib/sources/table.move +++ b/precompile/modules/minitia_stdlib/sources/table.move @@ -23,11 +23,6 @@ module minitia_std::table { iterator_id: u64, } - /// Type of mutable table iterators - struct TableIterMut has drop { - iterator_id: u64, - } - /// Create a new Table. public fun new(): Table { let handle = new_table_handle(); @@ -151,7 +146,7 @@ module minitia_std::table { start: Option, /* inclusive */ end: Option, /* exclusive */ order: u8 /* 1: Ascending, 2: Descending */, - ): TableIter { + ): &TableIter { let start_bytes: vector = if (option::is_some(&start)) { bcs::to_bytes(&option::extract(&mut start)) } else { @@ -164,17 +159,14 @@ module minitia_std::table { vector::empty() }; - let iterator_id = new_table_iter>(table, start_bytes, end_bytes, order); - TableIter { - iterator_id, - } + new_table_iter>(table, start_bytes, end_bytes, order) } - public fun prepare(table_iter: &mut TableIter): bool { + public fun prepare(table_iter: &TableIter): bool { prepare_box>(table_iter) } - public fun next(table_iter: &mut TableIter): (K, &V) { + public fun next(table_iter: &TableIter): (K, &V) { let (key, box) = next_box>(table_iter); (key, &box.val) } @@ -201,7 +193,7 @@ module minitia_std::table { start: Option, /* inclusive */ end: Option, /* exclusive */ order: u8 /* 1: Ascending, 2: Descending */, - ): TableIterMut { + ): &mut TableIter { let start_bytes: vector = if (option::is_some(&start)) { bcs::to_bytes(&option::extract(&mut start)) } else { @@ -214,17 +206,14 @@ module minitia_std::table { vector::empty() }; - let iterator_id = new_table_iter_mut>(table, start_bytes, end_bytes, order); - TableIterMut { - iterator_id, - } + new_table_iter_mut>(table, start_bytes, end_bytes, order) } - public fun prepare_mut(table_iter: &mut TableIterMut): bool { + public fun prepare_mut(table_iter: &mut TableIter): bool { prepare_box_mut>(table_iter) } - public fun next_mut(table_iter: &mut TableIterMut): (K, &mut V) { + public fun next_mut(table_iter: &mut TableIter): (K, &mut V) { let (key, box) = next_box_mut>(table_iter); (key, &mut box.val) } @@ -260,22 +249,22 @@ module minitia_std::table { start: vector, end: vector, order: u8 - ): u64; + ): &TableIter; native fun new_table_iter_mut( table: &mut Table, start: vector, end: vector, order: u8 - ): u64; + ): &mut TableIter; - native fun next_box(table_iter: &mut TableIter): (K, &mut Box); + native fun next_box(table_iter: &TableIter): (K, &Box); - native fun prepare_box(table_iter: &mut TableIter): bool; + native fun prepare_box(table_iter: &TableIter): bool; - native fun next_box_mut(table_iter: &mut TableIterMut): (K, &mut Box); + native fun next_box_mut(table_iter: &mut TableIter): (K, &mut Box); - native fun prepare_box_mut(table_iter: &mut TableIterMut): bool; + native fun prepare_box_mut(table_iter: &mut TableIter): bool; // ====================================================================================================== // Tests @@ -311,4 +300,21 @@ module minitia_std::table { move_to(&account, TableHolder{ t }); } + + #[test(account = @0x1)] + fun test_iterator(account: &signer) { + let t = new(); + add(&mut t, 1, 1); + add(&mut t, 2, 2); + + let iter = iter(&t, option::none(), option::none(), 1); + let iter2 = iter(&t, option::none(), option::none(), 1); + assert!(iter.iterator_id == 0, 1); + assert!(iter2.iterator_id == 1, 1); + prepare(iter); + let (key, value) = next(iter); + assert!(key == 1 && *value == 1, 1); + + move_to(account, TableHolder { t }); + } } diff --git a/precompile/modules/minitia_stdlib/sources/token/collection.move b/precompile/modules/minitia_stdlib/sources/token/collection.move index 23acc0aa..dfef1719 100644 --- a/precompile/modules/minitia_stdlib/sources/token/collection.move +++ b/precompile/modules/minitia_stdlib/sources/token/collection.move @@ -396,8 +396,8 @@ module minitia_std::collection { let res: vector = vector[]; - while (table::prepare(&mut nfts_iter) && vector::length(&res) < (limit as u64)) { - let (token_id, nft) = table::next(&mut nfts_iter); + while (table::prepare(nfts_iter) && vector::length(&res) < (limit as u64)) { + let (token_id, nft) = table::next(nfts_iter); vector::push_back( &mut res, diff --git a/precompile/modules/tests/sources/TableTestData.move b/precompile/modules/tests/sources/TableTestData.move index d91f58c8..6e0971bf 100644 --- a/precompile/modules/tests/sources/TableTestData.move +++ b/precompile/modules/tests/sources/TableTestData.move @@ -31,27 +31,27 @@ module TestAccount::TableTestData { let i = 1; while(i < 11) { - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == i, 101); assert!(value == &i, 101); i = i + 1; }; - assert!(!T::prepare(&mut iter), 101); + assert!(!T::prepare(iter), 101); let iter = T::iter(t_ref, option::some(2), option::some(5), 1); let i = 2; while(i < 5) { - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == i, 102); assert!(value == &i, 102); i = i + 1; }; - assert!(!T::prepare(&mut iter), 102); + assert!(!T::prepare(iter), 102); } public entry fun iterate_descending(acc: address) acquires S { let t_ref = &borrow_global>(acc).t; @@ -60,26 +60,26 @@ module TestAccount::TableTestData { let i = 10; while(i > 0) { - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == i, 101); assert!(value == &i, 101); i = i - 1; }; - assert!(!T::prepare(&mut iter), 101); + assert!(!T::prepare(iter), 101); let iter = T::iter(t_ref, option::some(2), option::some(5), 2); let i = 4; while(i > 1) { - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == i, 102); assert!(value == &i, 102); i = i - 1; }; - assert!(!T::prepare(&mut iter), 102); + assert!(!T::prepare(iter), 102); } } diff --git a/precompile/modules/tests/sources/TableUnitTests.move b/precompile/modules/tests/sources/TableUnitTests.move index 431821bb..f388f970 100644 --- a/precompile/modules/tests/sources/TableUnitTests.move +++ b/precompile/modules/tests/sources/TableUnitTests.move @@ -276,27 +276,27 @@ module TestAccount::TableUnitTests { let iter = T::iter(&t, option::some(1), option::some(5), 1); - assert!(T::prepare(&mut iter), 101); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 101); + let (key, value) = T::next(iter); assert!(key == 1, 101); assert!(value == &1, 101); - assert!(T::prepare(&mut iter), 102); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 102); + let (key, value) = T::next(iter); assert!(key == 2, 102); assert!(value == &2, 102); - assert!(T::prepare(&mut iter), 103); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 103); + let (key, value) = T::next(iter); assert!(key == 3, 103); assert!(value == &3, 103); - assert!(T::prepare(&mut iter), 104); - let (key, value) = T::next(&mut iter); + assert!(T::prepare(iter), 104); + let (key, value) = T::next(iter); assert!(key == 4, 104); assert!(value == &4, 104); - assert!(!T::prepare(&mut iter), 105); + assert!(!T::prepare(iter), 105); // clear T::remove(&mut t, 1);