Skip to content

Commit

Permalink
Add Stride proto-derived struct used for ICS31 QueryResponse (#43)
Browse files Browse the repository at this point in the history
* Add Stride proto-derived struct used for ICS31 QueryResponse

* Add module for Stride interchainquery
  • Loading branch information
ljoss17 authored Dec 15, 2022
1 parent 40ef04d commit 7d695f4
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 2 deletions.
40 changes: 40 additions & 0 deletions definitions/stride/interchainquery/v1/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";
package stride.interchainquery.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "google/api/annotations.proto";
import "tendermint/crypto/proof.proto";

option go_package = "github.com/Stride-Labs/stride/v3/x/interchainquery/types";

// Msg defines the interchainquery Msg service.
service Msg {
// SubmitQueryResponse defines a method for submit query responses.
rpc SubmitQueryResponse(MsgSubmitQueryResponse)
returns (MsgSubmitQueryResponseResponse) {
option (google.api.http) = {
post : "/interchainquery/tx/v1beta1/submitquery"
body : "*"
};
};
}

// MsgSubmitQueryResponse represents a message type to fulfil a query request.
message MsgSubmitQueryResponse {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = true;

string chain_id = 1 [ (gogoproto.moretags) = "yaml:\"chain_id\"" ];
string query_id = 2 [ (gogoproto.moretags) = "yaml:\"query_id\"" ];
bytes result = 3 [ (gogoproto.moretags) = "yaml:\"result\"" ];
tendermint.crypto.ProofOps proof_ops = 4
[ (gogoproto.moretags) = "yaml:\"proof_ops\"" ];
int64 height = 5 [ (gogoproto.moretags) = "yaml:\"height\"" ];
string from_address = 6 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

// MsgSubmitQueryResponseResponse defines the MsgSubmitQueryResponse response
// type.
message MsgSubmitQueryResponseResponse {}
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ pub mod ics23 {
include_proto!("ics23.rs");
}

pub mod stride {
pub mod interchainquery {
pub mod v1 {
include_proto!("stride.interchainquery.v1.rs");
}
}
}

pub(crate) mod base64 {
use alloc::string::String;
use alloc::vec::Vec;
Expand Down
273 changes: 273 additions & 0 deletions src/prost/stride.interchainquery.v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
/// MsgSubmitQueryResponse represents a message type to fulfil a query request.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MsgSubmitQueryResponse {
#[prost(string, tag="1")]
pub chain_id: ::prost::alloc::string::String,
#[prost(string, tag="2")]
pub query_id: ::prost::alloc::string::String,
#[prost(bytes="vec", tag="3")]
pub result: ::prost::alloc::vec::Vec<u8>,
#[prost(message, optional, tag="4")]
pub proof_ops: ::core::option::Option<::tendermint_proto::crypto::ProofOps>,
#[prost(int64, tag="5")]
pub height: i64,
#[prost(string, tag="6")]
pub from_address: ::prost::alloc::string::String,
}
/// MsgSubmitQueryResponseResponse defines the MsgSubmitQueryResponse response
/// type.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MsgSubmitQueryResponseResponse {
}
/// Generated client implementations.
#[cfg(feature = "client")]
pub mod msg_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
/// Msg defines the interchainquery Msg service.
#[derive(Debug, Clone)]
pub struct MsgClient<T> {
inner: tonic::client::Grpc<T>,
}
impl MsgClient<tonic::transport::Channel> {
/// Attempt to create a new client by connecting to a given endpoint.
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
where
D: std::convert::TryInto<tonic::transport::Endpoint>,
D::Error: Into<StdError>,
{
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
Ok(Self::new(conn))
}
}
impl<T> MsgClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T::Error: Into<StdError>,
T::ResponseBody: Body<Data = Bytes> + Send + 'static,
<T::ResponseBody as Body>::Error: Into<StdError> + Send,
{
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Self { inner }
}
pub fn with_origin(inner: T, origin: Uri) -> Self {
let inner = tonic::client::Grpc::with_origin(inner, origin);
Self { inner }
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> MsgClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T::ResponseBody: Default,
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
>>::Error: Into<StdError> + Send + Sync,
{
MsgClient::new(InterceptedService::new(inner, interceptor))
}
/// Compress requests with the given encoding.
///
/// This requires the server to support it otherwise it might respond with an
/// error.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.send_compressed(encoding);
self
}
/// Enable decompressing responses.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// SubmitQueryResponse defines a method for submit query responses.
pub async fn submit_query_response(
&mut self,
request: impl tonic::IntoRequest<super::MsgSubmitQueryResponse>,
) -> Result<
tonic::Response<super::MsgSubmitQueryResponseResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/stride.interchainquery.v1.Msg/SubmitQueryResponse",
);
self.inner.unary(request.into_request(), path, codec).await
}
}
}
/// Generated server implementations.
#[cfg(feature = "server")]
pub mod msg_server {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
///Generated trait containing gRPC methods that should be implemented for use with MsgServer.
#[async_trait]
pub trait Msg: Send + Sync + 'static {
/// SubmitQueryResponse defines a method for submit query responses.
async fn submit_query_response(
&self,
request: tonic::Request<super::MsgSubmitQueryResponse>,
) -> Result<
tonic::Response<super::MsgSubmitQueryResponseResponse>,
tonic::Status,
>;
}
/// Msg defines the interchainquery Msg service.
#[derive(Debug)]
pub struct MsgServer<T: Msg> {
inner: _Inner<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
}
struct _Inner<T>(Arc<T>);
impl<T: Msg> MsgServer<T> {
pub fn new(inner: T) -> Self {
Self::from_arc(Arc::new(inner))
}
pub fn from_arc(inner: Arc<T>) -> Self {
let inner = _Inner(inner);
Self {
inner,
accept_compression_encodings: Default::default(),
send_compression_encodings: Default::default(),
}
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> InterceptedService<Self, F>
where
F: tonic::service::Interceptor,
{
InterceptedService::new(Self::new(inner), interceptor)
}
/// Enable decompressing requests with the given encoding.
#[must_use]
pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.accept_compression_encodings.enable(encoding);
self
}
/// Compress responses with the given encoding, if the client supports it.
#[must_use]
pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
self.send_compression_encodings.enable(encoding);
self
}
}
impl<T, B> tonic::codegen::Service<http::Request<B>> for MsgServer<T>
where
T: Msg,
B: Body + Send + 'static,
B::Error: Into<StdError> + Send + 'static,
{
type Response = http::Response<tonic::body::BoxBody>;
type Error = std::convert::Infallible;
type Future = BoxFuture<Self::Response, Self::Error>;
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
let inner = self.inner.clone();
match req.uri().path() {
"/stride.interchainquery.v1.Msg/SubmitQueryResponse" => {
#[allow(non_camel_case_types)]
struct SubmitQueryResponseSvc<T: Msg>(pub Arc<T>);
impl<
T: Msg,
> tonic::server::UnaryService<super::MsgSubmitQueryResponse>
for SubmitQueryResponseSvc<T> {
type Response = super::MsgSubmitQueryResponseResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::MsgSubmitQueryResponse>,
) -> Self::Future {
let inner = self.0.clone();
let fut = async move {
(*inner).submit_query_response(request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = SubmitQueryResponseSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
Ok(
http::Response::builder()
.status(200)
.header("grpc-status", "12")
.header("content-type", "application/grpc")
.body(empty_body())
.unwrap(),
)
})
}
}
}
}
impl<T: Msg> Clone for MsgServer<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self {
inner,
accept_compression_encodings: self.accept_compression_encodings,
send_compression_encodings: self.send_compression_encodings,
}
}
}
impl<T: Msg> Clone for _Inner<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}
impl<T: Msg> tonic::server::NamedService for MsgServer<T> {
const NAME: &'static str = "stride.interchainquery.v1.Msg";
}
}
6 changes: 4 additions & 2 deletions tools/proto-compiler/src/cmd/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl CompileCmd {

// Paths
let proto_paths = [
format!("{}/../proto/definitions/mock", root),
format!("{}/../../definitions/mock", root),
format!("{}/../../definitions/interchainquery/v1", root),

This comment has been minimized.

Copy link
@romac

romac Jan 17, 2023

Member

This should read

format!("{}/../../definitions/stride/interchainquery/v1", root),
format!("{}/ibc", ibc_dir.display()),
format!("{}/cosmos/auth", sdk_dir.display()),
format!("{}/cosmos/gov", sdk_dir.display()),
Expand All @@ -50,7 +51,8 @@ impl CompileCmd {
let proto_includes_paths = [
format!("{}", sdk_dir.display()),
format!("{}", ibc_dir.display()),
format!("{}/../proto/definitions/mock", root),
format!("{}/../../definitions/mock", root),
format!("{}/../../definitions/interchainquery/v1", root),

This comment has been minimized.

Copy link
@romac

romac Jan 17, 2023

Member

This should read

format!("{}/../../definitions/stride/interchainquery/v1", root),
];

// List available proto files
Expand Down

0 comments on commit 7d695f4

Please sign in to comment.