From 7da8337000b5dbe34f34e783e5d1d67eae15dbc8 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Tue, 26 Nov 2024 11:30:24 +0900 Subject: [PATCH] fix to use u32 for option --- precompile/binaries/minlib/cosmos.mv | Bin 3771 -> 3863 bytes precompile/binaries/stdlib/cosmos.mv | Bin 3771 -> 3863 bytes .../modules/initia_stdlib/sources/cosmos.move | 78 ++++++++++----- .../initia_stdlib/sources/minitswap.move | 3 +- .../tests/ibc_transfer_tests_helpers.move | 10 +- .../minitia_stdlib/sources/address.move | 2 +- .../minitia_stdlib/sources/cosmos.move | 92 +++++++++++------- .../tests/ibc_transfer_tests_helpers.move | 10 +- 8 files changed, 130 insertions(+), 65 deletions(-) diff --git a/precompile/binaries/minlib/cosmos.mv b/precompile/binaries/minlib/cosmos.mv index 4e4bf0060b4878ac425c773ab1860b75f4553746..02aab079fe6f866920ccc1fdba3c40e72544093f 100644 GIT binary patch delta 560 zcmXAmJ8u&~6ov1-^Vspude^hT;NaK-1t~&8LRg6jA-rE9BmsgkZ;X)~N(5QbQb0=) zZ4r=gfkKxC$wCyg{Dc(n6A%?G6?g3B)17n9oEhnUuWi*^pCQbz`D360~AhwWbl_hQe135&w8u97q5Ej zS-UZKr+%R;t!Ler&$?N!v%zL(qcKUlQC9AA- pRjQ(dnItGU9E!rqG>%lPW^JT7sGX(>1m24UM?T`lsh0QS`hVv%NSgov delta 498 zcmXAlyKfUg5XQfmz1iElJ)eChAr5g&5DWxOTX8jbG9?kag{$!3n0P_W^o=DaT#-1!5Y?a|7Cl2i_gRa zGG{&fJqJufUv!QQD7p{{NG^%q?G>wxuO>`Pm`~M&1s#R3kE+VWLP<;YUCQP90LWb% z98~>!uX-a?adRm6SNABBTO*`L+U6~d#YQVsZjT4v*&ld!Qt2NYGUNykj|Az_vB1a2 z1D~7>d|ExF^Es(VqhM*uUYU>sLkH!s9F-H1%^dkExtjivvgVM@Ncs{vosh{UC_6M9 z1y}ijX8M=k)Y+{{kveU1WQ@^XS7>Ls&7-wmWIwpa@-t6bayh%aYt0+(zLRg%eI1`R s-JSHSnX1N#_L66Bd{nPwlFPKutnS+umPZJ>U5|o;r5NUB`8RL<2VlTEH2?qr diff --git a/precompile/binaries/stdlib/cosmos.mv b/precompile/binaries/stdlib/cosmos.mv index 4e4bf0060b4878ac425c773ab1860b75f4553746..02aab079fe6f866920ccc1fdba3c40e72544093f 100644 GIT binary patch delta 560 zcmXAmJ8u&~6ov1-^Vspude^hT;NaK-1t~&8LRg6jA-rE9BmsgkZ;X)~N(5QbQb0=) zZ4r=gfkKxC$wCyg{Dc(n6A%?G6?g3B)17n9oEhnUuWi*^pCQbz`D360~AhwWbl_hQe135&w8u97q5Ej zS-UZKr+%R;t!Ler&$?N!v%zL(qcKUlQC9AA- pRjQ(dnItGU9E!rqG>%lPW^JT7sGX(>1m24UM?T`lsh0QS`hVv%NSgov delta 498 zcmXAlyKfUg5XQfmz1iElJ)eChAr5g&5DWxOTX8jbG9?kag{$!3n0P_W^o=DaT#-1!5Y?a|7Cl2i_gRa zGG{&fJqJufUv!QQD7p{{NG^%q?G>wxuO>`Pm`~M&1s#R3kE+VWLP<;YUCQP90LWb% z98~>!uX-a?adRm6SNABBTO*`L+U6~d#YQVsZjT4v*&ld!Qt2NYGUNykj|Az_vB1a2 z1D~7>d|ExF^Es(VqhM*uUYU>sLkH!s9F-H1%^dkExtjivvgVM@Ncs{vosh{UC_6M9 z1y}ijX8M=k)Y+{{kveU1WQ@^XS7>Ls&7-wmWIwpa@-t6bayh%aYt0+(zLRg%eI1`R s-JSHSnX1N#_L66Bd{nPwlFPKutnS+umPZJ>U5|o;r5NUB`8RL<2VlTEH2?qr diff --git a/precompile/modules/initia_stdlib/sources/cosmos.move b/precompile/modules/initia_stdlib/sources/cosmos.move index 68c1dac3..d6752384 100644 --- a/precompile/modules/initia_stdlib/sources/cosmos.move +++ b/precompile/modules/initia_stdlib/sources/cosmos.move @@ -19,25 +19,49 @@ module initia_std::cosmos { const EINVALID_CALLBACK_ID: u64 = 1; const EINVALID_CALLBACK_FID: u64 = 2; - struct VoteRequest has copy, drop { + public entry fun stargate(sender: &signer, data: vector) { + stargate_internal(signer::address_of(sender), data, disallow_failure()) + } + + /// Stargate message with options + /// + /// Options: + /// - allow_failure() + /// - disallow_failure() + /// - allow_failure_with_callback(id: u64, fid: String) + /// - disallow_failure_with_callback(id: u64, fid: String) + /// + /// The callback function should be defined with the following signature: + /// ```rust + /// public fun callback(id: u64, success: bool); + /// public fun callback(sender: &signer, id: u64, success: bool); + /// ``` + /// + public fun stargate_with_options( + sender: &signer, data: vector, options: Options + ) { + stargate_internal(signer::address_of(sender), data, options) + } + + struct VoteRequestV2 has copy, drop { _type_: String, proposal_id: u64, voter: String, - option: u64, + option: u32, metadata: String } - public entry fun stargate_vote( + public entry fun stargate_vote_v2( sender: &signer, proposal_id: u64, voter: String, - option: u64, + option: u32, metadata: String ) { stargate( sender, json::marshal( - &VoteRequest { + &VoteRequestV2 { _type_: string::utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter, @@ -48,28 +72,30 @@ module initia_std::cosmos { ); } - public entry fun stargate(sender: &signer, data: vector) { - stargate_internal(signer::address_of(sender), data, disallow_failure()) + #[deprecated] + struct VoteRequest has copy, drop { + _type_: String, + proposal_id: u64, + voter: String, + option: u64, + metadata: String } - /// Stargate message with options - /// - /// Options: - /// - allow_failure() - /// - disallow_failure() - /// - allow_failure_with_callback(id: u64, fid: String) - /// - disallow_failure_with_callback(id: u64, fid: String) - /// - /// The callback function should be defined with the following signature: - /// ```rust - /// public fun callback(id: u64, success: bool); - /// public fun callback(sender: &signer, id: u64, success: bool); - /// ``` - /// - public fun stargate_with_options( - sender: &signer, data: vector, options: Options + #[deprecated] + public entry fun stargate_vote( + sender: &signer, + proposal_id: u64, + voter: String, + option: u64, + metadata: String ) { - stargate_internal(signer::address_of(sender), data, options) + stargate_vote_v2( + sender, + proposal_id, + voter, + option as u32, + metadata + ) } struct ExecuteRequest has copy, drop { @@ -525,11 +551,11 @@ module initia_std::cosmos { let msg = json::marshal_to_string( - &VoteRequest { + &VoteRequestV2 { _type_: utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter: voter, - option, + option: option as u32, metadata: metadata } ); diff --git a/precompile/modules/initia_stdlib/sources/minitswap.move b/precompile/modules/initia_stdlib/sources/minitswap.move index 64bd12d4..687c03fb 100644 --- a/precompile/modules/initia_stdlib/sources/minitswap.move +++ b/precompile/modules/initia_stdlib/sources/minitswap.move @@ -2464,7 +2464,8 @@ module initia_std::minitswap { vector::append(&mut hex_input, table_key::encode_u256(0x60)); // start position of denom: padded(0x60) vector::append(&mut hex_input, table_key::encode_u256((amount as u256))); vector::append( - &mut hex_input, table_key::encode_u256((0x60 + 32 + denom_bytes_len as u256)) + &mut hex_input, + table_key::encode_u256((0x60 + 32 + denom_bytes_len as u256)) ); // start position of receiver vector::append( &mut hex_input, diff --git a/precompile/modules/initia_stdlib/tests/ibc_transfer_tests_helpers.move b/precompile/modules/initia_stdlib/tests/ibc_transfer_tests_helpers.move index cef30126..8a1b22cb 100644 --- a/precompile/modules/initia_stdlib/tests/ibc_transfer_tests_helpers.move +++ b/precompile/modules/initia_stdlib/tests/ibc_transfer_tests_helpers.move @@ -43,7 +43,10 @@ module cafe::ibc_transfer_tests_helpers { struct OnTimeoutResponse has key {} public fun store_on_callback_request( - sender: address, amount: u64, expected_result: bool, id: u64 + sender: address, + amount: u64, + expected_result: bool, + id: u64 ) { let chain_signer = create_signer_for_test(@std); move_to( @@ -71,7 +74,10 @@ module cafe::ibc_transfer_tests_helpers { } public fun store_on_ack_request( - id: u64, expected_result: bool, sender: address, amount: u64 + id: u64, + expected_result: bool, + sender: address, + amount: u64 ) { let chain_signer = create_signer_for_test(@std); move_to( diff --git a/precompile/modules/minitia_stdlib/sources/address.move b/precompile/modules/minitia_stdlib/sources/address.move index 3b371687..9c3274dd 100644 --- a/precompile/modules/minitia_stdlib/sources/address.move +++ b/precompile/modules/minitia_stdlib/sources/address.move @@ -82,7 +82,7 @@ module minitia_std::address { assert!(addr == from_sdk(addr_sdk), 0) } - // hex string <> address + // hex string <> address native public fun to_string(addr: address): String; native public fun from_string(addr_str: String): address; diff --git a/precompile/modules/minitia_stdlib/sources/cosmos.move b/precompile/modules/minitia_stdlib/sources/cosmos.move index 62d44bd5..0f1bbf31 100644 --- a/precompile/modules/minitia_stdlib/sources/cosmos.move +++ b/precompile/modules/minitia_stdlib/sources/cosmos.move @@ -19,35 +19,6 @@ module minitia_std::cosmos { const EINVALID_CALLBACK_ID: u64 = 1; const EINVALID_CALLBACK_FID: u64 = 2; - struct VoteRequest has copy, drop { - _type_: String, - proposal_id: u64, - voter: String, - option: u64, - metadata: String - } - - public entry fun stargate_vote( - sender: &signer, - proposal_id: u64, - voter: String, - option: u64, - metadata: String - ) { - stargate( - sender, - json::marshal( - &VoteRequest { - _type_: string::utf8(b"/cosmos.gov.v1.MsgVote"), - proposal_id, - voter, - option, - metadata - } - ) - ); - } - public entry fun stargate(sender: &signer, data: vector) { stargate_internal(signer::address_of(sender), data, disallow_failure()) } @@ -82,6 +53,61 @@ module minitia_std::cosmos { args: vector // base64 encoded } + struct VoteRequestV2 has copy, drop { + _type_: String, + proposal_id: u64, + voter: String, + option: u32, + metadata: String + } + + public entry fun stargate_vote_v2( + sender: &signer, + proposal_id: u64, + voter: String, + option: u32, + metadata: String + ) { + stargate( + sender, + json::marshal( + &VoteRequestV2 { + _type_: string::utf8(b"/cosmos.gov.v1.MsgVote"), + proposal_id, + voter, + option, + metadata + } + ) + ); + } + + #[deprecated] + struct VoteRequest has copy, drop { + _type_: String, + proposal_id: u64, + voter: String, + option: u64, + metadata: String + } + + #[deprecated] + public entry fun stargate_vote( + sender: &signer, + proposal_id: u64, + voter: String, + option: u64, + metadata: String + ) { + stargate_vote_v2( + sender, + proposal_id, + voter, + option as u32, + metadata + ) + } + public entry fun move_execute( sender: &signer, module_address: address, @@ -525,11 +551,11 @@ module minitia_std::cosmos { let msg = json::marshal_to_string( - &VoteRequest { + &VoteRequestV2 { _type_: utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter: voter, - option, + option: option as u32, metadata: metadata } ); @@ -547,11 +573,11 @@ module minitia_std::cosmos { let metadata = utf8(b"metadata"); let msg = json::marshal_to_string( - &VoteRequest { + &VoteRequestV2 { _type_: utf8(b"/cosmos.gov.v1.MsgVote"), proposal_id, voter: voter, - option, + option: option as u32, metadata: metadata } ); diff --git a/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests_helpers.move b/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests_helpers.move index cef30126..8a1b22cb 100644 --- a/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests_helpers.move +++ b/precompile/modules/minitia_stdlib/tests/ibc_transfer_tests_helpers.move @@ -43,7 +43,10 @@ module cafe::ibc_transfer_tests_helpers { struct OnTimeoutResponse has key {} public fun store_on_callback_request( - sender: address, amount: u64, expected_result: bool, id: u64 + sender: address, + amount: u64, + expected_result: bool, + id: u64 ) { let chain_signer = create_signer_for_test(@std); move_to( @@ -71,7 +74,10 @@ module cafe::ibc_transfer_tests_helpers { } public fun store_on_ack_request( - id: u64, expected_result: bool, sender: address, amount: u64 + id: u64, + expected_result: bool, + sender: address, + amount: u64 ) { let chain_signer = create_signer_for_test(@std); move_to(