-
Notifications
You must be signed in to change notification settings - Fork 125
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
Add additional derive macros to Prost generated types #409
Comments
What's generating the type URLs? |
I'm assuming they're just being scraped from the .proto files. Likely whatever template they're using to generate the code includes those extra derives |
I mainly ask because I've been very much interested in getting that upstreamed to Prost: tokio-rs/prost#858 |
Ah yes I see that would be pretty convenient. Perhaps you can comment more on this, but I've wondered why cosmrs redefines many of the types in cosmos-idk-proto. Adding these extra derives IMO would mean that a new version of cosmrs could directly use the types from cosmos-sdk-proto rather than redefining them. |
CosmRS defines "domain types" which wrap the protos and enforce various invariants, similar to how A similar pattern is used in |
Ah gotcha! I see how that could be useful. So currently I'm maintaining a crate called cosm-utils which consists of 80% boilerplate that could be completely removed if we were able to get these |
I see that cosmos_sdk_proto has a pub trait Request {
type Response: TypeUrl + MessageExt
} This would be massively powerful. Adding a macro to make these for us wouldn't be too difficult either. What do you think? |
@ewoolsey FWIW I'd like to move to a trait like this in the next release: tokio-rs/prost#896 |
Awesome yeah I just saw that PR go up. That looks like a perfect solution. Any thoughts on a Request style trait that provides a Response associated type? |
What's the use case? |
@tony-iqlusion It allows you to build queries automatically. Essentially you could write a single function like this (coded from my head please ignore errors): impl Client {
pub async fn query<T: Request>(&self, msg: T) -> Result<<T as Request>::Response> {
let res = self.query(msg)?;
let response: <T as Request>::Response = serde_json::from_bytes(res.value)?;
Ok(response)
}
} You could do something similar with execute message as well, imagine a message like pub struct MsgStoreCodeResponse {
code_id: u32
}
impl TryFrom<Vec<Events>> for MsgStoreCodeResponse {
...
} |
That's what |
Yes that's true for tonic and gRPC, but not true for other clients(tendermint_rpc, http, websocket, etc.) |
We don't even support gRPC yet. That seems like the logical place to start. (Note: it's already implemented downstream in Ocular) |
Yeah I also have support for it in the library I'm maintaining for my work. It's currently very cumbersome to maintain manually, hence the request for this trait which would make that work a breeze. |
I have similar need where I'd like to get JSON version of What's the best way for now to do that? |
See #83 for JSON-related discussion |
In #432 we migrated to the new It should eventually get first-class support in |
This is fantastic news! Thanks for the hard work. I'll look into migrating over to this soon. |
If you take a look at osmosis-std You'll see they have derived some additional traits on many of their types, which allow you get access to type urls, and request responses automatically. This is super powerful, because then you can automatically generate utility functions to send/receive messages using a client. This is what the generated code looks like:
The macros are already built so they could simply be used in this crate almost without changes.
The text was updated successfully, but these errors were encountered: