-
Notifications
You must be signed in to change notification settings - Fork 30
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
[Research] prost on osmosis proto #63
Comments
Working examaple // >> Msg definition
/// MsgCreateDenom is the sdk.Msg type for allowing an account to create
/// a new denom. It requires a sender address and a subdenomination.
/// The (sender_address, sub_denomination) pair must be unique and cannot be
/// re-used. The resulting denom created is `factory/{creator
/// address}/{subdenom}`. The resultant denom's admin is originally set to be the
/// creator, but this can be changed later. The token denom does not indicate the
/// current admin.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MsgCreateDenom {
#[prost(string, tag = "1")]
pub sender: ::prost::alloc::string::String,
/// subdenom can be up to 44 "alphanumeric" characters long.
#[prost(string, tag = "2")]
pub subdenom: ::prost::alloc::string::String,
}
// >> Extention for conversion
// maybe deriving / code gen `impl From<prost::Message> for CosmosMsg::Stargate` instead
pub trait MessageExt: prost::Message {
/// Serialize this protobuf message as a byte vector.
fn to_bytes(&self) -> Result<cosmwasm_std::Binary, ContractError>;
}
impl<M> MessageExt for M
where
M: prost::Message,
{
fn to_binary(&self) -> Result<cosmwasm_std::Binary, From<Box<dyn Error>>> {
let mut bytes = Vec::new();
prost::Message::encode(self, &mut bytes)?
Ok(cosmwasm_std::Binary(bytes))
}
}
let msg = CosmosMsg::Stargate {
type_url: "/osmosis.tokenfactory.v1beta1.MsgCreateDenom".to_string(),
value: MsgCreateDenom {
sender: contract_addr,
subdenom,
}
.to_binary()?,
} |
I've had issues getting prost types deployed on the chains as they depend on floats (which aren't supported by the wasmvm because of indeterminism). When I tried something similar to this, it worked on the tests but not the real chains. @iboss-ptk is there something I'm missing here? Are you using any specific compilation flags? |
@nicolaslara I have tested it on LocalOsmosis, it does not complain anything about nondeterminism and there is no specific compiler flags. Do you have the code, I might miss something and cause problems later so I would like to see it. Here is my working example https://github.com/iboss-ptk/osmosis-cosmwasm-stargate-example |
I had tried something similar on Juno, but I'll try a version of your working example to see what my issue was. If this all works, I can use it to build a simple API for https://github.com/osmosis-labs/bindings |
Reviewed this now. The non-determinism issue I mentioned was not related to this. That happened because I was also using serde_json as a workaround when the StargateQuery didn't work (I tried this a few months ago, so didn't remember the details). And the reason the StargateQuery was failing on juno is because (duh) StargateQueries are disabled on juno 🤦. I just didn't see the proper error until now because CosmWasm/cosmwasm#1299 didn't exist when I tried this last time. Anyway. This all seems to work :) Now the fun part (of making protos easy to use for cosmwasm devs) starts. Thanks for all the good work @iboss-ptk ! |
Thanks for your kind words @nicolaslara ! |
Generate rust types from osmosis proto to create
StargateMsg
for cosmwasm to call osmosis specific stuffsStargateMsg
The text was updated successfully, but these errors were encountered: