diff --git a/Cargo.lock b/Cargo.lock index 62c28fe5cd..c5c361a389 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5519,6 +5519,7 @@ dependencies = [ "decaf377-rdsa", "futures", "hex", + "http-body", "ibc-proto", "ibc-types", "ics23", @@ -5531,6 +5532,7 @@ dependencies = [ "subtle-encoding", "tendermint", "tonic", + "tower", "tracing", ] diff --git a/crates/bin/pcli/Cargo.toml b/crates/bin/pcli/Cargo.toml index f9eaa7e0b0..a98f786696 100644 --- a/crates/bin/pcli/Cargo.toml +++ b/crates/bin/pcli/Cargo.toml @@ -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 } diff --git a/crates/bin/pcli/src/main.rs b/crates/bin/pcli/src/main.rs index 562973997c..98a2de3d16 100644 --- a/crates/bin/pcli/src/main.rs +++ b/crates/bin/pcli/src/main.rs @@ -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; diff --git a/crates/bin/pcli/src/opt.rs b/crates/bin/pcli/src/opt.rs index 41adc64e07..58f68877ec 100644 --- a/crates/bin/pcli/src/opt.rs +++ b/crates/bin/pcli/src/opt.rs @@ -1,5 +1,4 @@ use crate::{ - box_grpc_svc, config::{CustodyConfig, PcliConfig}, terminal::ActualTerminal, App, Command, @@ -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, diff --git a/crates/proto/Cargo.toml b/crates/proto/Cargo.toml index 04bfefe42b..90bcda1eb6 100644 --- a/crates/proto/Cargo.toml +++ b/crates/proto/Cargo.toml @@ -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" @@ -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"] diff --git a/crates/bin/pcli/src/box_grpc_svc.rs b/crates/proto/src/box_grpc_svc.rs similarity index 83% rename from crates/bin/pcli/src/box_grpc_svc.rs rename to crates/proto/src/box_grpc_svc.rs index f90df97e25..1ce117449f 100644 --- a/crates/bin/pcli/src/box_grpc_svc.rs +++ b/crates/proto/src/box_grpc_svc.rs @@ -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::Response, BoxError>; -pub(crate) type BoxError = Box; +pub type BoxError = Box; /// A type-erased gRPC response [`Body`]. -pub(crate) type RspBody = UnsyncBoxBody; +pub type RspBody = UnsyncBoxBody; /// Connects to the provided tonic [`Endpoint`], returning a [`BoxGrpcService`]. -pub(crate) async fn connect(ep: Endpoint) -> anyhow::Result { +pub async fn connect(ep: Endpoint) -> anyhow::Result { let conn = ep.connect().await?; let svc = ServiceBuilder::new() .map_response(|rsp: grpc::Response| rsp.map(box_rsp_body)) @@ -28,7 +28,7 @@ pub(crate) async fn connect(ep: Endpoint) -> anyhow::Result { /// Constructs a [`BoxGrpcService`] by erasing the type of an `S`-typed local /// (in-process) service instance. -pub(crate) fn local(svc: S) -> BoxGrpcService +pub fn local(svc: S) -> BoxGrpcService where S: Service, Response = grpc::Response>, S: Clone + Send + Sync + 'static, diff --git a/crates/proto/src/lib.rs b/crates/proto/src/lib.rs index 3255ec028f..8383207921 100644 --- a/crates/proto/src/lib.rs +++ b/crates/proto/src/lib.rs @@ -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;