osmosis-labs / osmosis-rust

Rust libraries for osmosis
Apache License 2.0
59 stars 52 forks source link

How to decode Any #100

Closed Philipp-Sc closed 9 months ago

Philipp-Sc commented 10 months ago

Hi,

I work on cosmos-rust-package a simple package to query cosmos blockchains.

I am in the process of updating it to the recent cosmos-rust and osmosis-std. Regarding the cosmos-sdk-proto I can now simply use any.to_msg().ok(), to decode the any types.

I tried the same for the osmosis types, getting the following error:

error[E0277]: the trait bound `RemoveSuperfluidAssetsProposal: Name` is not satisfied
   --> src/api/custom/types/gov/proposal_ext.rs:261:67
    |
261 |                 ProposalContent::RemoveSuperfluidAssetsProposal(any.to_msg().ok())
    |                                                                   ^^^^^^ the trait `Name` is not implemented for `RemoveSuperfluidAssetsProposal`
    |
    = help: the following other types implement trait `Name`:

the solution I had before:

let decoded = osmosis_std::types::osmosis::superfluid::v1beta1::RemoveSuperfluidAssetsProposal::decode(&*any.value).ok();

now also does not work anymore.

Any ideas what I am missing?

Thanks in advance.

Philipp-Sc commented 9 months ago

I found the issue.

osmosis_rust uses prost v0.11.9, any.to_msg() is not yet supported for osmosis-std.

To ensure osmosis_std works alongside cosmos-rust the following works:

Cargo.toml
osmosis_prost = { version ="0.11.9", package = "prost" }

and then the following works:

osmosis_prost::Message::decode(&any.value[..]).ok()