Skip to content

Commit

Permalink
proto: move box_grpc_svc to proto crate (#3711)
Browse files Browse the repository at this point in the history
  • Loading branch information
avahowell authored and TalDerei committed Feb 8, 2024
1 parent 92a73e7 commit 3c1adbc
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/bin/pcli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ parallel = [

[dependencies]
# Workspace dependencies
penumbra-proto = { path = "../../proto", features = ["rpc"] }
penumbra-proto = { path = "../../proto", features = ["rpc", "box-grpc"] }
penumbra-tct = { path = "../../crypto/tct" }
penumbra-num = { path = "../../core/num", default-features = false }
penumbra-asset = { path = "../../core/asset", default-features = false }
Expand Down
3 changes: 1 addition & 2 deletions crates/bin/pcli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ use anyhow::{Context, Result};
use clap::Parser;
use futures::StreamExt;

use box_grpc_svc::BoxGrpcService;
use command::*;
use config::PcliConfig;
use opt::Opt;
use penumbra_proto::box_grpc_svc::BoxGrpcService;
use penumbra_proto::{
custody::v1alpha1::custody_protocol_service_client::CustodyProtocolServiceClient,
view::v1alpha1::view_protocol_service_client::ViewProtocolServiceClient,
};
use penumbra_view::ViewClient;

mod box_grpc_svc;
mod command;
mod config;
mod dex_utils;
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pcli/src/opt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{
box_grpc_svc,
config::{CustodyConfig, PcliConfig},
terminal::ActualTerminal,
App, Command,
Expand All @@ -9,6 +8,7 @@ use camino::Utf8PathBuf;
use clap::Parser;
use directories::ProjectDirs;
use penumbra_custody::soft_kms::SoftKms;
use penumbra_proto::box_grpc_svc;
use penumbra_proto::{
custody::v1alpha1::{
custody_protocol_service_client::CustodyProtocolServiceClient,
Expand Down
3 changes: 3 additions & 0 deletions crates/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ decaf377-rdsa = { version = "0.7" }
bytes = { version = "1", features = ["serde"] }
prost = "0.12.3"
tonic = { version = "0.10", optional = true }
tower = { version = "0.4", features = ["full"], optional = true }
http-body = { version = "0.4.5", optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
hex = "0.4"
Expand Down Expand Up @@ -39,4 +41,5 @@ anyhow = "1"

[features]
rpc = ["dep:tonic", "ibc-proto/client"]
box-grpc = ["dep:http-body", "dep:tonic", "dep:tower"]
cnidarium = ["dep:cnidarium"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use tonic::{
use tower::{util::BoxCloneService, Service, ServiceBuilder};

/// A type-erased gRPC service.
pub(crate) type BoxGrpcService =
pub type BoxGrpcService =
BoxCloneService<grpc::Request<ReqBody>, grpc::Response<RspBody>, BoxError>;

pub(crate) type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;

/// A type-erased gRPC response [`Body`].
pub(crate) type RspBody = UnsyncBoxBody<Bytes, BoxError>;
pub type RspBody = UnsyncBoxBody<Bytes, BoxError>;

/// Connects to the provided tonic [`Endpoint`], returning a [`BoxGrpcService`].
pub(crate) async fn connect(ep: Endpoint) -> anyhow::Result<BoxGrpcService> {
pub async fn connect(ep: Endpoint) -> anyhow::Result<BoxGrpcService> {
let conn = ep.connect().await?;
let svc = ServiceBuilder::new()
.map_response(|rsp: grpc::Response<transport::Body>| rsp.map(box_rsp_body))
Expand All @@ -28,7 +28,7 @@ pub(crate) async fn connect(ep: Endpoint) -> anyhow::Result<BoxGrpcService> {

/// Constructs a [`BoxGrpcService`] by erasing the type of an `S`-typed local
/// (in-process) service instance.
pub(crate) fn local<S, B>(svc: S) -> BoxGrpcService
pub fn local<S, B>(svc: S) -> BoxGrpcService
where
S: Service<grpc::Request<ReqBody>, Response = grpc::Response<B>>,
S: Clone + Send + Sync + 'static,
Expand Down
3 changes: 3 additions & 0 deletions crates/proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub use prost::{Message, Name};
/// Helper methods used for shaping the JSON (and other Serde) formats derived from the protos.
pub mod serializers;

#[cfg(feature = "box-grpc")]
pub mod box_grpc_svc;

/// Helper trait for using Protobuf messages as ABCI events.
pub mod event;
mod protobuf;
Expand Down

0 comments on commit 3c1adbc

Please sign in to comment.