Comments (19)
See #83 for JSON-related discussion
from cosmos-rust.
What's generating the type URLs?
from cosmos-rust.
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
from cosmos-rust.
I mainly ask because I've been very much interested in getting that upstreamed to Prost: tokio-rs/prost#858
from cosmos-rust.
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.
from cosmos-rust.
CosmRS defines "domain types" which wrap the protos and enforce various invariants, similar to how gogoproto
is used in the upstream Cosmos SDK. It also has custom logic to handle field evolution between versions, as well as custom serializations for various types.
A similar pattern is used in tendermint-rs
and ibc-rs
(as well as various other Cosmos-related projects like Penumbra).
from cosmos-rust.
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 response
and type_url
traits on all of the proto types. It would make maintaining it so much easier.
from cosmos-rust.
I see that cosmos_sdk_proto has a TypeUrl
trait. Is there any chance we could get a Request
trait that looks something like this?
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?
from cosmos-rust.
@ewoolsey FWIW I'd like to move to a trait like this in the next release: tokio-rs/prost#896
from cosmos-rust.
@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?
from cosmos-rust.
What's the use case?
from cosmos-rust.
@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 MsgStoreCode
, the Response could be
pub struct MsgStoreCodeResponse {
code_id: u32
}
impl TryFrom<Vec<Events>> for MsgStoreCodeResponse {
...
}
from cosmos-rust.
That's what tonic
already does with gRPC endpoints
from cosmos-rust.
That's what tonic already does with gRPC endpoints
Yes that's true for tonic and gRPC, but not true for other clients(tendermint_rpc, http, websocket, etc.)
from cosmos-rust.
We don't even support gRPC yet. That seems like the logical place to start.
(Note: it's already implemented downstream in Ocular)
from cosmos-rust.
(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.
from cosmos-rust.
I have similar need where I'd like to get JSON version of cosmrs::bank::MsgSend
and other proto related structs and having serde derives on those would make my life way easier.
What's the best way for now to do that?
from cosmos-rust.
In #432 we migrated to the new prost::Name
trait.
It should eventually get first-class support in prost-build
: tokio-rs/prost#926
from cosmos-rust.
In #432 we migrated to the new
prost::Name
trait.It should eventually get first-class support in
prost-build
: tokio-rs/prost#926
This is fantastic news! Thanks for the hard work. I'll look into migrating over to this soon.
from cosmos-rust.
Related Issues (20)
- TallyParams Undocumented Decimal Type HOT 2
- Enable cosmrs support `no_std` HOT 5
- Maybe Can Use only one crate `cosmos-sdk-proto` or `ibc-proto-rs` HOT 6
- Sync versions with tendermint-rs?
- wasm-bindgen issue when using cosmrs in CosmWasm HOT 10
- Type URLs for x/authz messages not present HOT 4
- gov/v1 HOT 2
- Does this crate only supports gRPC for querying contracts states? HOT 4
- proto build fails because of deprecated buf template HOT 1
- Update crypto lib HOT 2
- Error: failed to load state at height 0; version mismatch on immutable IAVL tree; version does not exist. Version has either been pruned, or is for a future block height (latest height: 0): invalid request HOT 1
- 405 Method Not Allowed HOT 2
- Update ibc-go types HOT 1
- Error with user entered invalid UTF8 for protobuf structs.
- bug: cargo run ends in an error
- proto-build: bump COSMOS_SDK_REV to v0.47 or higher HOT 3
- Querying `minimum_gas_price` HOT 3
- How to output the private key and print it to the terminal? HOT 2
- Abandon `cosmos-sdk-proto` in favor of `ibc-proto`? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cosmos-rust.