-
Notifications
You must be signed in to change notification settings - Fork 344
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
untagged enum causes F64Load vm gatekeeper's error #1443
Comments
I came up against this too after following the nested example in the It works if you remove |
You can use cfg macro to fix this, one for building wasm and one for generating schema #[cfg(not(target_arch = "wasm32"))]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
enum Simple {
A(String),
}
#[cfg(target_arch = "wasm32")]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
enum Simple {
A(String),
} |
Its an old issue, but I think this feature is very needed in CW, and can make contracts much nicer to look at and work with. |
I'm not sure about the state of untagged support. Would be great to test this heaviliy in serde_json_wasm. But float support is on the agenda for this year, avoiding all of those issues. |
Reading this issue, I see: "In this implementation, our main goal is to support json messages coming from cosmwasm. Communicating go modules should use protobuf encoding." The interesting point is that (1) there are nice libraries (from Osmosis) to generate protobuf sdk types (for StargateMsg) and (2) the proposed JSON doesn't work at all in CosmWasm. If the main point of this ibc-go PR is to for easier support from CosmWasm contracts, then someone (like @Art3miX who flagged this) should talk with them so they modify their format to produce something that is CosmWasm compatible. And also ask about their process, so they check this actually works on the Rust side. In particular, the existence of a unique |
Hi @ethanfrey, I've opened that PR in ibc-go, and we've been in communication with @Art3miX. I was aware that the rust implementation was not optimal but wasn't aware that it would panic in wasmvm. We're in communication and will update that example once we come to a good resolution |
Hey Ethan, Thank you for your suggestion, unfortunately tags also uses floats, so that doesn't work: #[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "@type")]
pub enum CosmosMessages {
#[serde(rename = "/cosmos.gov.v1beta1.MsgSubmitProposal")]
MsgSubmitProposalV1 {
content: Box<CosmosMessages>,
initial_deposit: Vec<Coin>,
proposer: String,
},
#[serde(rename = "/cosmos.gov.v1beta1.TextProposal")]
TextProposal {
title: String,
description: String,
},
} I gave the ibc-go as an example of a use case for #[cw_serde]
#[serde(untagged)]
pub enum AcceptedReceiveNftMsgs {
Cw721 (Cw721ReceiveMsg)
Ics721 (Ics721ReceiveMsg)
Other (OtherReceiveMsg)
}
#[cw_serde]
pub enum ExecuteMsg {
ReceiveNft (AcceptedReceiveNftMsgs)
}
// contract.rs
match msg {
ExecuteMsg::ReceiveNft (AcceptedReceiveNftMsgs::Other (other)) => handle_other_receive(other),
ExecuteMsg::ReceiveNft (receiveMsg) => handle_receive(receiveMsg)
} The alternative is to use something like this: pub enum ExecuteMsg {
ReceiveNft (cw721::Cw721ReceiveMsg),
ReceiveNftIcs721 (ics721::Ics721ReceiveMsg),
ReceiveNftOther (other::OtherReceiveMsg)
} |
For the interchain accounts feature we discussed, we only need serialization to work (and deserialization is not a priority). The tags don't work only if you use deserialize. So, this suggestion actually works! We didn't go with a more cosmwasm friendly json format because we simply wanted to import the sdk's JSONCodec methods rather than implementing our own. (I did actually write a cosmwasm friendly json encoder/decoder but the team and I have agreed that using the sdk's codec makes more sense). I think relying on the sdk and expecting cosmwasm to produce the same format is acceptable as long as there is a simple solution like @Art3miX posted. Since we don't need deserialization at the moment, I think this is enough for our feature. |
Thank you two for working this out. I agree float support (or better untagged) is a nice longer-term goal, but glad this is not blocking your work. |
Float support is done in #1845 to be released with CosmWasm 1.5. |
When introducing
#[serde(untagged)]
to a contract, it causes:Even with simple enum like:
so even with
serde_json_wasm
supportsuntagged
it's currently not working with cosmwasm contract.The text was updated successfully, but these errors were encountered: