Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jsonrpc #26

Merged
merged 41 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
797218b
added jsonrpc.rs
idky137 May 17, 2024
0514f54
added doc comments
idky137 May 17, 2024
4605127
jsonrpc builds
idky137 May 17, 2024
35bd4c7
move jsonrpc into modules
idky137 May 17, 2024
0d3075e
renamed HexSerializedBlock to ProxySerializedBlock
idky137 May 17, 2024
8bc6702
get_lightd_info implemented - working on testnet, not in tests
idky137 May 20, 2024
cd37ea6
get_lightd_info implemented - working on testnet, not in tests
idky137 May 20, 2024
ee402a0
connects to zebra or zcash, doesnt run unless one is running.. fix this
idky137 May 22, 2024
930b985
added startup connection checker
idky137 May 23, 2024
261d638
removed commented code
idky137 May 23, 2024
a4d24df
added welcome image
idky137 May 23, 2024
b9185f1
added welcome image
idky137 May 23, 2024
336040a
small fixes
idky137 May 24, 2024
be59ed8
small fixes
idky137 May 24, 2024
31998da
implemented send_transaction and get_best_block
idky137 May 29, 2024
551c4ba
implemented get_taddress_txids
idky137 Jun 3, 2024
dfdd17c
started implementing get_block_range - parser required first
idky137 Jun 4, 2024
cfa1d21
updated todos
idky137 Jun 5, 2024
b1b09d3
removed extern crate
idky137 Jun 5, 2024
9c73ccd
fixed merge conflicts
idky137 Jun 6, 2024
f4d6e28
started adding block parser
idky137 Jun 6, 2024
af5cc8a
added block and transaction structs
idky137 Jun 6, 2024
c070337
added comment to show untested code
idky137 Jun 6, 2024
d56984e
added BuildInfo struct and updated get_build_info
idky137 Jun 7, 2024
bd0c4c0
added gRPC server health check
idky137 Jun 7, 2024
fd3257b
added parse_from_slice
idky137 Jun 10, 2024
c6a3174
added block_height and block_hash getter logic
idky137 Jun 11, 2024
77f057d
builds, get_block_range not returning correct response
idky137 Jun 12, 2024
b72ecc6
builds, compact block returned inccorrect
idky137 Jun 13, 2024
f78ac42
fixed txid conversion, get_block_range no works
idky137 Jun 13, 2024
0e612aa
fixed block range inversion bug, possible bug with sapling spend / ou…
idky137 Jun 13, 2024
9498f72
get_block_range running, more testing needed..
idky137 Jun 14, 2024
f2d5234
added more tests, get_tree_state fails on sync_full_batch
idky137 Jun 14, 2024
84ef335
all tests pass
idky137 Jun 14, 2024
6c35b78
added mempool_manager test
idky137 Jun 17, 2024
5c1d8b5
get_mempool_stream implemented
idky137 Jun 17, 2024
4e91fff
converted errors to thiserror
idky137 Jun 17, 2024
917072e
removed unwraps in PR production code
idky137 Jun 18, 2024
5460808
added 30s timeout to streaming rpcs
idky137 Jun 18, 2024
420d32d
applied clippy changes
idky137 Jun 18, 2024
cba31b9
nym poc fixes and readme updated
idky137 Jun 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,643 changes: 1,461 additions & 182 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ nym-bin-common = { git = "https://github.com/nymtech/nym", branch = "master" }
nym-sphinx-anonymous-replies = { git = "https://github.com/nymtech/nym", branch = "master" }

http = "0.2.4"
tokio = { version = "1", features = ["full"] }
tokio = { version = "1.37.0", features = ["full"] }
tonic = "0.10.2"
prost = "0.12"
bytes = "1.1"
http-body = "0.4.4"


hyper = { version = "0.14.28", features = ["full"] }
hyper-rustls = { version = "0.23", features = ["http2"] }
tower = { version = "0.4.13" }
tokio-rustls = "0.23"
rustls-pemfile = "1.0.0"

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ shardtree = "0.3"
json = "0.12.4"
log = "0.4.17"
itertools = "0.10.5"
serde_json = "1.0.107"
serde_json = "1.0.117"
hex = "0.4"
76 changes: 55 additions & 21 deletions integration-tests/tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ use zingoproxy_testutils::{drop_test_manager, TestManager};

use zingo_netutils::GrpcConnector;

mod proxy {
mod wallet {
use super::*;

#[tokio::test]
async fn connect_to_lwd_get_info() {
async fn connect_to_node_get_info() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;

println!(
"Attempting to connect to GRPC server at URI: {}",
"@zingoproxytest: Attempting to connect to GRPC server at URI: {}.",
test_manager.get_proxy_uri()
);

let mut client = GrpcConnector::new(test_manager.get_proxy_uri())
.get_client()
.await
.expect("Failed to create GRPC client");

let lightd_info = client
.get_lightd_info(zcash_client_backend::proto::service::Empty {})
.await
.expect("Failed to retrieve lightd info from GRPC server");

println!("{:#?}", lightd_info.into_inner());

println!(
"@zingoproxytest: Lightd_info response:\n{:#?}.",
lightd_info.into_inner()
);
drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
Expand All @@ -43,7 +43,7 @@ mod proxy {
}

#[tokio::test]
async fn send_over_proxy() {
async fn send_and_sync_shielded() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
Expand All @@ -52,10 +52,7 @@ mod proxy {
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();

println!(
"zingo_client balance: {:#?}",
zingo_client.do_balance().await
);
// std::thread::sleep(std::time::Duration::from_secs(10));

zingo_client
.do_send(vec![(
Expand All @@ -65,29 +62,66 @@ mod proxy {
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);

println!(
"zingo_client balance: {:#?}",
zingo_client.do_balance().await
);
assert_eq!(balance.sapling_balance.unwrap(), 250_000);
drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
online,
)
.await;
}

assert_eq!(
zingo_client.do_balance().await.sapling_balance.unwrap(),
250_000
);
#[tokio::test]
async fn send_and_sync_transparent() {
let online = Arc::new(AtomicBool::new(true));
let (test_manager, regtest_handler, _proxy_handler) =
TestManager::launch(online.clone()).await;
let zingo_client = test_manager.build_lightclient().await;

test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "transparent"),
250_000,
None,
)])
.await
.unwrap();
zingo_client
.do_send(vec![(
&zingolib::get_base_address!(zingo_client, "transparent"),
250_000,
None,
)])
.await
.unwrap();
test_manager.regtest_manager.generate_n_blocks(1).unwrap();
zingo_client.do_sync(false).await.unwrap();
let balance = zingo_client.do_balance().await;
println!("@zingoproxytest: zingo_client balance: \n{:#?}.", balance);

assert_eq!(balance.transparent_balance.unwrap(), 500_000);
drop_test_manager(
Some(test_manager.temp_conf_dir.path().to_path_buf()),
regtest_handler,
online,
)
.await;
}

// TODO: Add test for get_mempool_stream: lightclient::start_mempool_monitor.
// #[tokio::test]
// async fn mempool_monitor() {}
}

mod nym {
// TODO: Build nym encanhed zingolib version using zingo-rpc::walletrpc::service.
// TODO: Build nym enhanced zingolib version using zingo-rpc::walletrpc::service.
}

mod darkside {
Expand Down
11 changes: 5 additions & 6 deletions zingo-proxyd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ tonic = { workspace = true }
prost = { workspace = true }
bytes = { workspace = true }
http-body = { workspace = true }

tower = { workspace = true }
hyper-rustls = { workspace = true, features = ["http2"] }
hyper = { workspace = true, features = ["full"] }
tokio-rustls = { workspace = true }
rustls-pemfile = { workspace = true }

tokio-socks = "0.5"
ctrlc = "3.2.1"
tower = { version = "0.4" }
hyper-rustls = { version = "0.23", features = ["http2"] }
tokio-rustls = "0.23"
hyper = { version = "0.14", features = ["full"] }
webpki-roots = "0.21.0"
rustls-pemfile = "1.0.0"

3 changes: 2 additions & 1 deletion zingo-proxyd/src/bin/zingoproxyd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ async fn main() {
let online = Arc::new(AtomicBool::new(true));
let online_ctrlc = online.clone();
ctrlc::set_handler(move || {
println!("Received Ctrl+C, exiting.");
println!("@zingoproxyd: Received Ctrl+C, exiting.");
online_ctrlc.store(false, Ordering::SeqCst);
process::exit(0);
})
.expect("Error setting Ctrl-C handler");

nym_bin_common::logging::setup_logging();

#[allow(unused_mut)]
let mut proxy_port: u16 = 8080;
#[cfg(feature = "nym_poc")]
{
Expand Down
21 changes: 17 additions & 4 deletions zingo-proxyd/src/nym_server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! Nym-gRPC server implementation.
//!
//! TODO: - Add NymServerError error type and rewrite functions to return <Result<(), NymServerError>>, propagating internal errors. Include NymClientError from zingo-rpc::nym::utils.
//! - Update NymServer to handle all service RPCs (currently only accepts send_command). [Return "Not Yet Implemented" for unimplemented RPC's?]
//! - Update NymServer to handle multiple requests, from multiple clients, simultaniously. [Combine with zingoproxyd "queue" logic when implemented?]

use std::sync::{
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -46,17 +50,26 @@ impl NymServer {
.unwrap();

//print request for testing
println!("request received: {:?}", &request_vu8[..]);
println!("request length: {}", &request_vu8[..].len());
println!(
"@zingoproxyd[nym]: request received: {:?}",
&request_vu8[..]
);
println!(
"@zingoproxyd[nym]: request length: {}",
&request_vu8[..].len()
);

let request = RawTransaction::decode(&request_vu8[..]).unwrap();
let response = NymClient::nym_send_transaction(&request).await.unwrap();
let mut response_vu8 = Vec::new();
response.encode(&mut response_vu8).unwrap();

//print response for testing
println!("response sent: {:?}", &response_vu8[..]);
println!("response length: {}", &response_vu8[..].len());
println!("@zingoproxyd[nym]: response sent: {:?}", &response_vu8[..]);
println!(
"@zingoproxyd[nym]: response length: {}",
&response_vu8[..].len()
);

let return_recipient = AnonymousSenderTag::try_from_base58_string(
request_in[0].sender_tag.unwrap().to_base58_string(),
Expand Down
Loading
Loading