This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adrian Brink
committed
Jun 16, 2017
1 parent
2ec9939
commit 167d771
Showing
7 changed files
with
1,004 additions
and
1,052 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.*" |
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,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(); | ||
} | ||
} |
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 |
---|---|---|
@@ -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 | ||
} | ||
} |
Oops, something went wrong.