Skip to content

Commit

Permalink
feat: jsonrpc API modules
Browse files Browse the repository at this point in the history
1. jsonrpc API modules
2. fork original jsonrpc-macros, make change to support 2018-edition trait syntax
3. listen_addr -> listen_address
4. now, if `pow_engine is Clicker, jsonrpc load test module automatically, without conditional compilation.
  • Loading branch information
zhangsoledad committed Dec 21, 2018
1 parent bdf323f commit f87d9a1
Show file tree
Hide file tree
Showing 17 changed files with 409 additions and 417 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ hash = { path = "util/hash"}
faster-hex = "0.1"
build-info = { path = "util/build-info" }

[features]
integration_test = ["ckb-rpc/integration_test"]

[dev-dependencies]
tempfile = "3.0"

Expand Down
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
test:
cargo test --all -- --nocapture

build-integration-test:
cargo build --all --features integration_test --no-default-features

doc:
cargo doc --all --no-deps

Expand All @@ -22,10 +19,10 @@ fmt:
clippy:
cargo clippy --all -- -D warnings -D clippy::clone_on_ref_ptr -D clippy::enum_glob_use

ci: fmt clippy test build-integration-test
ci: fmt clippy test
git diff --exit-code Cargo.lock

ci-quick: test build-integration-test
ci-quick: test
git diff --exit-code Cargo.lock

info:
Expand All @@ -47,6 +44,6 @@ security-audit:
docker: build
docker build -f docker/hub/Dockerfile -t nervos/ckb:latest .

.PHONY: build build-integration-test docker
.PHONY: build docker
.PHONY: fmt test clippy proto doc doc-deps check stats
.PHONY: ci ci-quick info security-audit
10 changes: 9 additions & 1 deletion nodes_template/default.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"__comments__": {
"rpc modules": [
"List of API modules",
["Net", "Pool", "Miner", "Chain"]
]
},

"data_dir": "default",
"ckb": {
"chain": "spec/dev.json"
Expand All @@ -19,7 +26,8 @@
"nodes_file": "nodes.json"
},
"rpc": {
"listen_addr": "0.0.0.0:8114"
"listen_address": "0.0.0.0:8114",
"modules": ["Net", "Pool", "Miner", "Chain"]
},
"sync": {
"verification_level": "Full",
Expand Down
9 changes: 4 additions & 5 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "ckb-rpc"
version = "0.3.0-pre"
license = "MIT"
authors = ["Nervos Core Dev <dev@nervos.org>"]
edition = "2018"

[dependencies]
numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] }
Expand All @@ -15,20 +16,18 @@ ckb-pool = { path = "../pool" }
ckb-chain = { path = "../chain" }
ckb-miner = { path = "../miner" }
ckb-protocol = { path = "../protocol" }
ckb-pow = { path = "../pow", optional = true }
ckb-pow = { path = "../pow"}
jsonrpc-core = "9.0"
jsonrpc-macros = "9.0"
jsonrpc-macros = { git = "https://github.com/nervosnetwork/jsonrpc.git", branch = "2018-edition" }
jsonrpc-http-server = "9.0"
jsonrpc-server-utils = "9.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
log = "0.4"
flatbuffers = "0.5.0"
num_cpus = "1.0"

[dev-dependencies]
ckb-db = { path = "../db" }
ckb-verification = { path = "../verification" }

[features]
integration_test = ["ckb-pow"]
31 changes: 31 additions & 0 deletions rpc/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use serde_derive::Deserialize;

const NET: &str = "Net";
const CHAIN: &str = "Chain";
const MINER: &str = "Miner";
const POOL: &str = "Pool";

#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct Config {
pub listen_address: String,
pub threads: Option<usize>,
pub modules: Vec<String>,
}

impl Config {
pub(crate) fn net_enable(&self) -> bool {
self.modules.iter().any(|m| m == NET)
}

pub(crate) fn chain_enable(&self) -> bool {
self.modules.iter().any(|m| m == CHAIN)
}

pub(crate) fn miner_enable(&self) -> bool {
self.modules.iter().any(|m| m == MINER)
}

pub(crate) fn pool_enable(&self) -> bool {
self.modules.iter().any(|m| m == POOL)
}
}
101 changes: 0 additions & 101 deletions rpc/src/integration_test.rs

This file was deleted.

39 changes: 4 additions & 35 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
extern crate flatbuffers;
extern crate jsonrpc_core;
extern crate numext_fixed_hash;
#[macro_use]
extern crate jsonrpc_macros;
extern crate jsonrpc_http_server;
extern crate jsonrpc_server_utils;
#[macro_use]
extern crate log;
extern crate ckb_chain;
extern crate ckb_core;
#[cfg(test)]
extern crate ckb_db;
extern crate ckb_miner;
extern crate ckb_network;
extern crate ckb_pool;
extern crate ckb_protocol;
extern crate ckb_shared;
extern crate ckb_sync;
#[cfg(test)]
extern crate ckb_verification;
#[macro_use]
extern crate serde_derive;
#[cfg(feature = "integration_test")]
extern crate ckb_pow;

mod config;
mod module;
mod server;
mod types;

pub use types::Config;

#[cfg(feature = "integration_test")]
mod integration_test;

#[cfg(feature = "integration_test")]
pub use integration_test::RpcServer;
#[cfg(not(feature = "integration_test"))]
pub use server::RpcServer;
pub use crate::config::Config;
pub use crate::server::RpcServer;

0 comments on commit f87d9a1

Please sign in to comment.