Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Working GRPC implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Brink committed Jun 16, 2017
1 parent 2ec9939 commit 167d771
Show file tree
Hide file tree
Showing 7 changed files with 1,004 additions and 1,052 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ version = "0.1.0"
authors = ["Adrian Brink <[email protected]>"]

[dependencies]
futures = "0.1"
futures-cpupool = "0.1"
grpc = "0.*"
protobuf = "1.*"
tls-api = "0.*"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ cargo install protobuf
cargo install grpc-compiler
```
```bash
protoc --rust_out src/ src/types.proto
protoc --rust-grpc_out src/ src/types.proto
protoc --rust_out src/ types.proto
protoc --rust-grpc_out src/ types.proto
```
96 changes: 96 additions & 0 deletions src/bin/dummy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
extern crate grpc;
extern crate rust_abci;


use rust_abci::new_server;
use rust_abci::types::*;
use rust_abci::types_grpc::*;

use std::thread;


struct DummyApp;

unsafe impl Sync for DummyApp {}

unsafe impl Send for DummyApp {}

impl ABCIApplication for DummyApp {
fn echo(&self, o: ::grpc::RequestOptions, p: RequestEcho) -> ::grpc::SingleResponse<ResponseEcho> {
println!("Echo");
let response = ResponseEcho::new();
::grpc::SingleResponse::completed(response)
}

fn flush(&self, o: ::grpc::RequestOptions, p: RequestFlush) -> ::grpc::SingleResponse<ResponseFlush> {
println!("Flush");
let response = ResponseFlush::new();
::grpc::SingleResponse::completed(response)
}

fn info(&self, o: ::grpc::RequestOptions, p: RequestInfo) -> ::grpc::SingleResponse<ResponseInfo> {
println!("Info");
let response = ResponseInfo::new();
::grpc::SingleResponse::completed(response)
}

fn set_option(&self, o: ::grpc::RequestOptions, p: RequestSetOption) -> ::grpc::SingleResponse<ResponseSetOption> {
println!("SetOption");
let response = ResponseSetOption::new();
::grpc::SingleResponse::completed(response)
}

fn deliver_tx(&self, o: ::grpc::RequestOptions, p: RequestDeliverTx) -> ::grpc::SingleResponse<ResponseDeliverTx> {
println!("DeliverTx");
let response = ResponseDeliverTx::new();
::grpc::SingleResponse::completed(response)
}

fn check_tx(&self, o: ::grpc::RequestOptions, p: RequestCheckTx) -> ::grpc::SingleResponse<ResponseCheckTx> {
println!("CheckTx");
let response = ResponseCheckTx::new();
::grpc::SingleResponse::completed(response)
}

fn query(&self, o: ::grpc::RequestOptions, p: RequestQuery) -> ::grpc::SingleResponse<ResponseQuery> {
println!("Query");
let response = ResponseQuery::new();
::grpc::SingleResponse::completed(response)
}

fn commit(&self, o: ::grpc::RequestOptions, p: RequestCommit) -> ::grpc::SingleResponse<ResponseCommit> {
println!("Commit");
let response = ResponseCommit::new();
::grpc::SingleResponse::completed(response)
}

fn init_chain(&self, o: ::grpc::RequestOptions, p: RequestInitChain) -> ::grpc::SingleResponse<ResponseInitChain> {
println!("InitChain");
let response = ResponseInitChain::new();
::grpc::SingleResponse::completed(response)
}

fn begin_block(&self, o: ::grpc::RequestOptions, p: RequestBeginBlock) -> ::grpc::SingleResponse<ResponseBeginBlock> {
println!("BeginBlock");
let response = ResponseBeginBlock::new();
::grpc::SingleResponse::completed(response)
}

fn end_block(&self, o: ::grpc::RequestOptions, p: RequestEndBlock) -> ::grpc::SingleResponse<ResponseEndBlock> {
println!("EndBlock");
let response = ResponseEndBlock::new();
::grpc::SingleResponse::completed(response)
}
}


fn main() {
let listen_addr = "0.0.0.0:46658";
let connection_type = "grpc";

let _server = new_server(listen_addr, connection_type, DummyApp);

loop {
thread::park();
}
}
30 changes: 26 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
extern crate futures;
extern crate futures_cpupool;
extern crate grpc;
extern crate protobuf;
extern crate tls_api;


pub mod types;
pub mod types_grpc;


use futures_cpupool::CpuPool;
use types_grpc::{ABCIApplication, ABCIApplicationServer};


// Container trait so that we can return either a GRPC or SOCKET server
pub trait Service {}

impl Service for ABCIApplicationServer {}


pub fn new_server<H: ABCIApplication + 'static + Sync + Send + 'static>(listen_addr: &str, connection_type: &str, app: H) -> Option<Box<Service>> {
match connection_type {
"grpc" => Some(Box::new(ABCIApplicationServer::new_pool(listen_addr, Default::default(), app, CpuPool::new(4)))),
"socket" => None,
_ => None
}
}
Loading

0 comments on commit 167d771

Please sign in to comment.