From f380b4a1edb6de6326d9cb9116e7c824358ba87b Mon Sep 17 00:00:00 2001 From: ALPAC-4 <81249838+ALPAC-4@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:45:23 +0900 Subject: [PATCH] fix: change `async_callback.id` to number type (#170) * fix: use u32 for async callback id to make json marshal result to number type * chore: make precompile --- precompile/binaries/stdlib/minitswap.mv | Bin 21441 -> 21531 bytes .../sources/ibctesting/ibctesting.move | 6 ++-- .../initia_stdlib/sources/minitswap.move | 29 ++++++++++++++---- .../tests/ibc_transfer_tests.move | 6 ++-- .../sources/ibctesting/ibctesting.move | 6 ++-- .../tests/ibc_transfer_tests.move | 6 ++-- 6 files changed, 35 insertions(+), 18 deletions(-) diff --git a/precompile/binaries/stdlib/minitswap.mv b/precompile/binaries/stdlib/minitswap.mv index a79ed333aaa66a7b8c8162edbaa72051c8f528d5..a835ec55040fab7ac7986a3280db512901fdea4a 100644 GIT binary patch delta 3402 zcmZ`*37AvW6~6y@OK#q~S(#ym$z&$UybQB2%rL+Z6lMdVtVOJJ(fYX*MMbF#DrgOe z8v-Ic!37mj*%VQTpnx0Jy42R%+G>?*rM0cr+ReSK+H+sv`?UQ`a?f_p`OmrM+$3-R zW~|$So(;9{xFI1N1<_62@4?tXYr^JJ?p|1nBG1P|&!^wZ%KbeV`(V%06yMVSX~@|) zd4sKb>ANoXm!+H17B3=FYSlk2p) zN=vseF>Z$t*upmJURLQf5E&2wX7 z7;NqawDm!tUch(=nJgD1_aN7xlkY{H-rWaJYY!u@OL+vUQ9wNgX!OT1xQW?*w6t2eLvXxJjevt{@nW4JE&In=lDDSmhUv7`=pk z1mG{DIGzpWuW=M7HDAF5eb84iNqZf@;ss|nd9%G zA<3%vD~@A^zu|c9vHcFdtBrpTrem$gc)li~eK>)c@ehpUk>Q`noJf+}@?Ovf@jgz` zAs^s-oF?%RX0w+31Pux1iGSf#z4>p<(f1Gk!SP%meTtsb^_jw-;S6wx2Ye366;~`K zjv|Q5XdaKa^4;LFRa{P7D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pzZ%yCM|8ne5;xci*gB1@2O@N%X(HZtmQ$yFy?c&#vOWrFFtC?yr;VB$=t2 zat8lIi$1>0)MQ5Lluolv+D~PwGb4&U9H7y-cc$BueKDQ_YcY(Ugq4sw=@N zH|5Mv-3VQ!la;uB(yz*-GKpd@dkG>h_T;c*QtOD|+_A1`7pWRgr2C4^#bkRBE|@e} z8!Vh>goK-&GspcEP7_j01BZV9Lm;Fv0q#EP;o#@yLVBf zv<8b2E*$C(*A4cu@{5B;xoT(_b>Y!NJ5e7dr+$QdsD_)XgR9XHEmKXWhe~a{N>his z%}r&^_Pr@DAAW_h!A;;*;0>(wqfH}$XayHd@ADgqGeP`g&Xn=Q^kX=F;Y+VFv}Q0} zo;PDPF|%jZLCowwd%CG_;lZY)O$T3xT-ZM+z^HKEoXw~!(;+9KA$S<-L7Z ze#xOHmk zY$-yl>veTPeS diff --git a/precompile/modules/initia_stdlib/sources/ibctesting/ibctesting.move b/precompile/modules/initia_stdlib/sources/ibctesting/ibctesting.move index 2f0e6d95..47c5a28a 100644 --- a/precompile/modules/initia_stdlib/sources/ibctesting/ibctesting.move +++ b/precompile/modules/initia_stdlib/sources/ibctesting/ibctesting.move @@ -205,7 +205,7 @@ module initia_std::ibctesting { check_dispatch_type_compatibility_for_testing( &dispatchable_ibc_timeout_function_info(), &function_info ); - dispatchable_ibc_timeout(async_callback.id, &function_info); + dispatchable_ibc_timeout((async_callback.id as u64), &function_info); } else if (option::is_some(&result.async_callback)) { let async_callback = option::destroy_some(result.async_callback); let function_info = @@ -218,7 +218,7 @@ module initia_std::ibctesting { &dispatchable_ibc_ack_function_info(), &function_info ); dispatchable_ibc_ack( - async_callback.id, result.success, &function_info + (async_callback.id as u64), result.success, &function_info ); }; } @@ -401,7 +401,7 @@ module initia_std::ibctesting { } struct MoveAsyncCallback has copy, drop, store { - id: u64, + id: u32, module_address: address, module_name: String } diff --git a/precompile/modules/initia_stdlib/sources/minitswap.move b/precompile/modules/initia_stdlib/sources/minitswap.move index 687c03fb..2ed18e7f 100644 --- a/precompile/modules/initia_stdlib/sources/minitswap.move +++ b/precompile/modules/initia_stdlib/sources/minitswap.move @@ -2315,17 +2315,34 @@ module initia_std::minitswap { evm: Option } + struct IBCMemoV2 has copy, drop { + _move_: MemoMoveV2, + wasm: Option, + evm: Option + } + struct MemoMove has copy, drop { message: Option, async_callback: MemoAsyncCallback } + struct MemoMoveV2 has copy, drop { + message: Option, + async_callback: MemoAsyncCallbackV2 + } + struct MemoAsyncCallback has copy, drop { id: u64, module_address: address, module_name: String } + struct MemoAsyncCallbackV2 has copy, drop { + id: u32, // Use u32 instead of u64 to keep it as number type after json marshal. + module_address: address, + module_name: String + } + struct MemoMoveMessage has copy, drop { module_address: String, module_name: String, @@ -2381,11 +2398,11 @@ module initia_std::minitswap { op_denom: String, amount: u64 ): (String, String) { - let memo = IBCMemo { - _move_: MemoMove { + let memo = IBCMemoV2 { + _move_: MemoMoveV2 { message: option::none(), - async_callback: MemoAsyncCallback { - id: batch_index, + async_callback: MemoAsyncCallbackV2 { + id: (batch_index as u32), module_address: @initia_std, module_name: string::utf8(b"minitswap") } @@ -3419,7 +3436,7 @@ module initia_std::minitswap { assert!( memo == string::utf8( - b"{\"evm\":null,\"move\":{\"async_callback\":{\"id\":\"1\",\"module_address\":\"0x1\",\"module_name\":\"minitswap\"},\"message\":{\"args\":[\"CG9wX2Rlbm9t\",\"QEIPAAAAAAA=\",\"CHJlY2VpdmVy\"],\"function_name\":\"minitswap_hook\",\"module_address\":\"0x1\",\"module_name\":\"minitswap_hook\",\"type_args\":[]}},\"wasm\":null}" + b"{\"evm\":null,\"move\":{\"async_callback\":{\"id\":1,\"module_address\":\"0x1\",\"module_name\":\"minitswap\"},\"message\":{\"args\":[\"CG9wX2Rlbm9t\",\"QEIPAAAAAAA=\",\"CHJlY2VpdmVy\"],\"function_name\":\"minitswap_hook\",\"module_address\":\"0x1\",\"module_name\":\"minitswap_hook\",\"type_args\":[]}},\"wasm\":null}" ), 1 ); @@ -3438,7 +3455,7 @@ module initia_std::minitswap { assert!( memo == string::utf8( - b"{\"evm\":null,\"move\":{\"async_callback\":{\"id\":\"1\",\"module_address\":\"0x1\",\"module_name\":\"minitswap\"},\"message\":null},\"wasm\":{\"message\":{\"contracts\":\"cosmwasm_contract_addr\",\"funds\":[{\"amount\":\"1000000\",\"denom\":\"op_denom\"}],\"msg\":{\"minitswap_hook\":{\"receiver\":\"receiver\"}}}}}" + b"{\"evm\":null,\"move\":{\"async_callback\":{\"id\":1,\"module_address\":\"0x1\",\"module_name\":\"minitswap\"},\"message\":null},\"wasm\":{\"message\":{\"contracts\":\"cosmwasm_contract_addr\",\"funds\":[{\"amount\":\"1000000\",\"denom\":\"op_denom\"}],\"msg\":{\"minitswap_hook\":{\"receiver\":\"receiver\"}}}}}" ), 3 ); diff --git a/precompile/modules/initia_stdlib/tests/ibc_transfer_tests.move b/precompile/modules/initia_stdlib/tests/ibc_transfer_tests.move index 69481bdd..c1a822a5 100644 --- a/precompile/modules/initia_stdlib/tests/ibc_transfer_tests.move +++ b/precompile/modules/initia_stdlib/tests/ibc_transfer_tests.move @@ -285,7 +285,7 @@ module cafe::ibc_transfer_tests { }, timeout_timestamp: 0u64, // timeout timestamp is not used in this test memo: string::utf8( - b"{\"move\":{\"async_callback\":{\"id\": \"103\", \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" + b"{\"move\":{\"async_callback\":{\"id\": 103, \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" ) }; @@ -362,7 +362,7 @@ module cafe::ibc_transfer_tests { }, timeout_timestamp: 0u64, // timeout timestamp is not used in this test memo: string::utf8( - b"{\"move\":{\"async_callback\":{\"id\": \"103\", \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" + b"{\"move\":{\"async_callback\":{\"id\": 103, \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" ) }; @@ -441,7 +441,7 @@ module cafe::ibc_transfer_tests { }, timeout_timestamp: 0u64, // timeout timestamp is not used in this test memo: string::utf8( - b"{\"move\":{\"async_callback\":{\"id\": \"103\", \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" + b"{\"move\":{\"async_callback\":{\"id\": 103, \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" ) }; diff --git a/precompile/modules/minitia_stdlib/sources/ibctesting/ibctesting.move b/precompile/modules/minitia_stdlib/sources/ibctesting/ibctesting.move index 826d6045..b18e9e40 100644 --- a/precompile/modules/minitia_stdlib/sources/ibctesting/ibctesting.move +++ b/precompile/modules/minitia_stdlib/sources/ibctesting/ibctesting.move @@ -205,7 +205,7 @@ module minitia_std::ibctesting { check_dispatch_type_compatibility_for_testing( &dispatchable_ibc_timeout_function_info(), &function_info ); - dispatchable_ibc_timeout(async_callback.id, &function_info); + dispatchable_ibc_timeout((async_callback.id as u64), &function_info); } else if (option::is_some(&result.async_callback)) { let async_callback = option::destroy_some(result.async_callback); let function_info = @@ -218,7 +218,7 @@ module minitia_std::ibctesting { &dispatchable_ibc_ack_function_info(), &function_info ); dispatchable_ibc_ack( - async_callback.id, result.success, &function_info + (async_callback.id as u64), result.success, &function_info ); }; } @@ -401,7 +401,7 @@ module minitia_std::ibctesting { } struct MoveAsyncCallback has copy, drop, store { - id: u64, + id: u32, module_address: address, module_name: String } diff --git a/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests.move b/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests.move index 69481bdd..c1a822a5 100644 --- a/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests.move +++ b/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests.move @@ -285,7 +285,7 @@ module cafe::ibc_transfer_tests { }, timeout_timestamp: 0u64, // timeout timestamp is not used in this test memo: string::utf8( - b"{\"move\":{\"async_callback\":{\"id\": \"103\", \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" + b"{\"move\":{\"async_callback\":{\"id\": 103, \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" ) }; @@ -362,7 +362,7 @@ module cafe::ibc_transfer_tests { }, timeout_timestamp: 0u64, // timeout timestamp is not used in this test memo: string::utf8( - b"{\"move\":{\"async_callback\":{\"id\": \"103\", \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" + b"{\"move\":{\"async_callback\":{\"id\": 103, \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" ) }; @@ -441,7 +441,7 @@ module cafe::ibc_transfer_tests { }, timeout_timestamp: 0u64, // timeout timestamp is not used in this test memo: string::utf8( - b"{\"move\":{\"async_callback\":{\"id\": \"103\", \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" + b"{\"move\":{\"async_callback\":{\"id\": 103, \"module_address\": \"0xcafe\", \"module_name\": \"ibc_transfer_tests_helpers\"}}}" ) };