-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from chainwayxyz/proto-design
Add initial gRPC support with new RPC interfaces
- Loading branch information
Showing
18 changed files
with
2,924 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::{env, path::Path, process::Command}; | ||
|
||
fn trim_ascii_end(s: &str) -> &str { | ||
let trimmed_len = s | ||
.as_bytes() | ||
.iter() | ||
.rposition(|&b| !b.is_ascii_whitespace()) | ||
.map_or(0, |pos| pos + 1); | ||
&s[..trimmed_len] | ||
} | ||
|
||
fn compile_protobuf() { | ||
// Try to set PROTOC env var if on *nix. | ||
if let Ok(output) = Command::new("which").args(["protoc"]).output() { | ||
// Skip compilation, if command failed. | ||
if !output.status.success() { | ||
return; | ||
} | ||
|
||
// Set env var. | ||
let path = String::from_utf8_lossy(&output.stdout); | ||
env::set_var("PROTOC", trim_ascii_end(&path)); | ||
} | ||
|
||
// Skip compilation if env var is not set. | ||
if env::var("PROTOC").is_err() { | ||
return; | ||
}; | ||
|
||
let proto_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/rpc/"); | ||
let protos = &["clementine.proto"]; | ||
|
||
let proto_files: Vec<String> = protos | ||
.iter() | ||
.map(|proto| proto_root.join(proto).to_str().unwrap().to_owned()) | ||
.collect(); | ||
|
||
// Tell Cargo that if a proto file changes, rerun this build script. | ||
for pf in &proto_files { | ||
println!("cargo:rerun-if-changed={}", pf); | ||
} | ||
|
||
// Compile server and client code from proto files | ||
tonic_build::configure() | ||
.build_server(true) | ||
.build_client(true) | ||
.out_dir("./src/rpc") | ||
.compile_protos(&proto_files, &[proto_root.to_str().unwrap()]) | ||
.unwrap(); | ||
} | ||
|
||
fn main() { | ||
compile_protobuf(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use super::clementine::{ | ||
clementine_aggregator_server::ClementineAggregator, DepositParams, Empty, RawSignedMoveTx, | ||
}; | ||
use crate::aggregator::Aggregator; | ||
use tonic::{async_trait, Request, Response, Status}; | ||
|
||
#[async_trait] | ||
impl ClementineAggregator for Aggregator { | ||
#[tracing::instrument(skip(self), err(level = tracing::Level::ERROR), ret(level = tracing::Level::TRACE))] | ||
async fn setup(&self, _request: Request<Empty>) -> Result<Response<Empty>, Status> { | ||
todo!() | ||
} | ||
|
||
#[tracing::instrument(skip(self), err(level = tracing::Level::ERROR), ret(level = tracing::Level::TRACE))] | ||
async fn new_deposit( | ||
&self, | ||
_request: Request<DepositParams>, | ||
) -> Result<Response<RawSignedMoveTx>, Status> { | ||
todo!() | ||
} | ||
} |
Oops, something went wrong.