Skip to content

Commit

Permalink
nym_poc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
idky137 committed Jul 26, 2024
1 parent 79d080f commit 1f3dd06
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 58 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

10 changes: 9 additions & 1 deletion zingo-proxyd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ path = "src/lib.rs"

[features]
# NOTE: Deprecated
nym_poc = []
nym_poc = ["zingo-netutils", "zcash_client_backend"]

[dependencies]
# Zinglib and LibRustZcash:
#
# Only used in original nym_poc code, to be removed with creation of nym enhanced zingolib build.
#
# Not to be used in production code as zingo-rpc will become a dep of zingolib and zingo-proxy now builds its onw CompactTxStreamer.
zingo-netutils = { git = "https://github.com/zingolabs/zingolib.git", branch = "nym_integration", optional = true }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", branch = "nym_integration", features = ["lightwalletd-tonic"], optional = true }

zingo-rpc = { path = "../zingo-rpc" }

# NymSdk
Expand Down
11 changes: 7 additions & 4 deletions zingo-proxyd/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ use std::{
Arc,
},
};
use zingo_rpc::{
jsonrpc::connector::test_node_and_return_uri, primitives::client::ProxyClient,
proto::service::compact_tx_streamer_server::CompactTxStreamerServer,
};
use zingo_rpc::{jsonrpc::connector::test_node_and_return_uri, primitives::client::ProxyClient};

#[cfg(not(feature = "nym_poc"))]
use zingo_rpc::proto::service::compact_tx_streamer_server::CompactTxStreamerServer;

#[cfg(feature = "nym_poc")]
use zcash_client_backend::proto::service::compact_tx_streamer_server::CompactTxStreamerServer;

/// Configuration data for gRPC server.
pub struct ProxyServer(pub ProxyClient);
Expand Down
10 changes: 9 additions & 1 deletion zingo-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ repository = { workspace = true }

[features]
# NOTE: Deprecated
nym_poc = []
nym_poc = ["zingo-netutils", "zcash_client_backend"]

[dependencies]
# Zinglib and LibRustZcash:
#
# Only used in original nym_poc code, to be removed with creation of nym enhanced zingolib build.
#
# Not to be used in production code as zingo-rpc will become a dep of zingolib and zingo-proxy now builds its onw CompactTxStreamer.
zingo-netutils = { git = "https://github.com/zingolabs/zingolib.git", branch = "nym_integration", optional = true }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", branch = "nym_integration", features = ["lightwalletd-tonic"], optional = true }

# NymSdk
nym-sdk = { workspace = true }
nym-sphinx-addressing = { workspace = true }
Expand Down
11 changes: 7 additions & 4 deletions zingo-rpc/src/rpc/nymservice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
use prost::Message;

use crate::{
primitives::client::ProxyClient, proto::service::compact_tx_streamer_server::CompactTxStreamer,
queue::request::ZingoProxyRequest,
};
use crate::{primitives::client::ProxyClient, queue::request::ZingoProxyRequest};

#[cfg(not(feature = "nym_poc"))]
use crate::proto::service::compact_tx_streamer_server::CompactTxStreamer;

#[cfg(feature = "nym_poc")]
use zcash_client_backend::proto::service::compact_tx_streamer_server::CompactTxStreamer;

impl ProxyClient {
/// Processes gRPC requests coming from the nym server.
Expand Down
56 changes: 44 additions & 12 deletions zingo-rpc/src/rpc/nymwalletservice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,52 @@ use std::env;
use tonic::{async_trait, Request, Response, Status};

use crate::{
define_grpc_passthrough,
primitives::{NymClient, ProxyClient},
proto::{
compact_formats::{CompactBlock, CompactTx},
service::{
compact_tx_streamer_server::CompactTxStreamer, Address, AddressList, Balance, BlockId,
BlockRange, ChainSpec, Duration, Empty, Exclude, GetAddressUtxosArg,
GetAddressUtxosReply, GetAddressUtxosReplyList, GetSubtreeRootsArg, LightdInfo,
PingResponse, RawTransaction, SendResponse, SubtreeRoot, TransparentAddressBlockFilter,
TreeState, TxFilter,
},
},
primitives::client::{NymClient, ProxyClient},
walletrpc::utils::{deserialize_response, serialize_request, write_nym_request_data},
};
use zcash_client_backend::proto::{
compact_formats::{CompactBlock, CompactTx},
service::{
compact_tx_streamer_server::CompactTxStreamer, Address, AddressList, Balance, BlockId,
BlockRange, ChainSpec, Duration, Empty, Exclude, GetAddressUtxosArg, GetAddressUtxosReply,
GetAddressUtxosReplyList, GetSubtreeRootsArg, LightdInfo, PingResponse, RawTransaction,
SendResponse, SubtreeRoot, TransparentAddressBlockFilter, TreeState, TxFilter,
},
};

macro_rules! define_grpc_passthrough {
(fn
$name:ident(
&$self:ident$(,$($arg:ident: $argty:ty,)*)?
) -> $ret:ty
) => {
#[must_use]
#[allow(clippy::type_complexity, clippy::type_repetition_in_bounds)]
fn $name<'life0, 'async_trait>(&'life0 $self$($(, $arg: $argty)*)?) ->
::core::pin::Pin<Box<
dyn ::core::future::Future<
Output = ::core::result::Result<
::tonic::Response<$ret>,
::tonic::Status
>
> + ::core::marker::Send + 'async_trait
>>
where
'life0: 'async_trait,
Self: 'async_trait,
{
println!("@zingoproxyd: Received call of {}.", stringify!($name));
Box::pin(async {
::zingo_netutils::GrpcConnector::new($self.lightwalletd_uri.clone())
.get_client()
.await
.expect("Proxy server failed to create client")
.$name($($($arg),*)?)
.await
})
}
};
}

#[async_trait]
impl CompactTxStreamer for ProxyClient {
Expand Down
36 changes: 0 additions & 36 deletions zingo-rpc/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,5 @@
//! Utility functions for Zingo-RPC.
/// Passes unimplemented RPCs on to Lightwalletd.
#[macro_export]
macro_rules! define_grpc_passthrough {
(fn
$name:ident(
&$self:ident$(,$($arg:ident: $argty:ty,)*)?
) -> $ret:ty
) => {
#[must_use]
#[allow(clippy::type_complexity, clippy::type_repetition_in_bounds)]
fn $name<'life0, 'async_trait>(&'life0 $self$($(, $arg: $argty)*)?) ->
::core::pin::Pin<Box<
dyn ::core::future::Future<
Output = ::core::result::Result<
::tonic::Response<$ret>,
::tonic::Status
>
> + ::core::marker::Send + 'async_trait
>>
where
'life0: 'async_trait,
Self: 'async_trait,
{
println!("@zingoproxyd: Received call of {}.", stringify!($name));
Box::pin(async {
::zingo_netutils::GrpcConnector::new($self.lightwalletd_uri.clone())
.get_client()
.await
.expect("Proxy server failed to create client")
.$name($($($arg),*)?)
.await
})
}
};
}

/// Zingo-Proxy build info.
pub struct BuildInfo {
/// Git commit hash.
Expand Down

0 comments on commit 1f3dd06

Please sign in to comment.