Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use u32 for the stargate vote option #169

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified precompile/binaries/minlib/cosmos.mv
Binary file not shown.
Binary file modified precompile/binaries/stdlib/cosmos.mv
Binary file not shown.
82 changes: 54 additions & 28 deletions precompile/modules/initia_stdlib/sources/cosmos.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) {
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<u8>, options: Options
) {
stargate_internal(signer::address_of(sender), data, options)
}
beer-1 marked this conversation as resolved.
Show resolved Hide resolved

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,
Expand All @@ -48,28 +72,30 @@ module initia_std::cosmos {
);
}

public entry fun stargate(sender: &signer, data: vector<u8>) {
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<u8>, 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
)
beer-1 marked this conversation as resolved.
Show resolved Hide resolved
}

struct ExecuteRequest has copy, drop {
Expand Down Expand Up @@ -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
}
);
Expand All @@ -547,11 +573,11 @@ module initia_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
}
);
Expand Down
3 changes: 2 additions & 1 deletion precompile/modules/initia_stdlib/sources/minitswap.move
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OnCallbackRequest>(
Expand Down Expand Up @@ -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<OnAckRequest>(
Expand Down
2 changes: 1 addition & 1 deletion precompile/modules/minitia_stdlib/sources/address.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
92 changes: 59 additions & 33 deletions precompile/modules/minitia_stdlib/sources/cosmos.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) {
stargate_internal(signer::address_of(sender), data, disallow_failure())
}
Expand Down Expand Up @@ -82,6 +53,61 @@ module minitia_std::cosmos {
args: vector<String> // 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,
Expand Down Expand Up @@ -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
}
);
Expand All @@ -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
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OnCallbackRequest>(
Expand Down Expand Up @@ -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<OnAckRequest>(
Expand Down
Loading