Skip to content

Commit

Permalink
refactor: embrace Rust 2018 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad authored and doitian committed Dec 11, 2018
1 parent 880d0c7 commit 313b2ea
Show file tree
Hide file tree
Showing 138 changed files with 372 additions and 595 deletions.
2 changes: 1 addition & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[cargo-new]
name = "Nervos Core Dev"
email = "[email protected]"

edition = "2018"
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ name = "ckb"
version = "0.1.0"
license = "MIT"
authors = ["Nervos Core Dev <[email protected]>"]
edition = "2018"
build = "build.rs"

[dependencies]
clap = { version = "2" }
serde = "1.0"
serde_derive = "1.0"
log = "0.4"
crossbeam-channel = "0.3"
channel = { package= "crossbeam-channel", version = "0.3" }
config-tool = { package= "config", version = "0.9" }
ckb-util = { path = "util" }
ckb-core = { path = "core" }
ckb-chain = { path = "chain" }
Expand All @@ -33,7 +35,6 @@ dir = { path = "util/dir" }
ctrlc = { version = "3.1", features = ["termination"] }
lazy_static = "1.0"
ckb-sync = { path = "sync"}
config = "0.9"
serde_json = "1.0"
crypto = { path = "util/crypto"}
ckb-instrument = { path = "util/instrument", features = ["progress_bar"] }
Expand Down
1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "ckb-benches"
version = "0.1.0"
license = "MIT"
authors = ["Nervos Core Dev <[email protected]>"]
edition = "2018"

[dependencies]

Expand Down
6 changes: 1 addition & 5 deletions benches/benches/cuckoo.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#[macro_use]
extern crate criterion;
extern crate ckb_pow;

use ckb_pow::Cuckoo;
use criterion::Criterion;
use criterion::{criterion_group, criterion_main, Criterion};

const TESTSET: [([u8; 80], [u32; 6]); 3] = [
(
Expand Down
2 changes: 0 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate build_info;

fn main() {
// Don't rebuild even if nothing changed
println!("cargo:rerun-if-changed=build.rs");
Expand Down
4 changes: 3 additions & 1 deletion chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "ckb-chain"
version = "0.1.0"
license = "MIT"
authors = ["Nervos Core Dev <[email protected]>"]
edition = "2018"

[dependencies]
serde = "1.0"
Expand All @@ -21,7 +22,8 @@ numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heap
numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] }
lru-cache = { git = "https://github.com/nervosnetwork/lru-cache" }
fnv = "1.0.3"
crossbeam-channel = "0.3"
channel = { package= "crossbeam-channel", version = "0.3" }


[dev-dependencies]
env_logger = "0.6"
Expand Down
6 changes: 3 additions & 3 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use channel::{self, Receiver, Sender};
use crate::error::ProcessBlockError;
use channel::{self, select, Receiver, Sender};
use ckb_chain_spec::consensus::Consensus;
use ckb_core::block::Block;
use ckb_core::extras::BlockExt;
Expand All @@ -11,8 +12,7 @@ use ckb_shared::index::ChainIndex;
use ckb_shared::shared::{ChainProvider, Shared, TipHeader};
use ckb_time::now_ms;
use ckb_verification::{BlockVerifier, Verifier};
use error::ProcessBlockError;
use log;
use log::{self, debug, error, log_enabled};
use numext_fixed_hash::H256;
use numext_fixed_uint::U256;
use std::cmp;
Expand Down
19 changes: 0 additions & 19 deletions chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,5 @@
//! - [Chain](chain::chain::Chain) represent a struct which
//! implement `ChainProvider`
extern crate ckb_chain_spec;
extern crate ckb_core;
extern crate ckb_db;
extern crate ckb_notify;
extern crate ckb_shared;
extern crate ckb_time;
extern crate ckb_verification;
extern crate numext_fixed_hash;
extern crate numext_fixed_uint;
#[macro_use]
extern crate log;
#[macro_use]
extern crate crossbeam_channel as channel;

#[cfg(test)]
extern crate rand;
#[cfg(test)]
extern crate tempfile;

pub mod chain;
pub mod error;
3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "ckb-core"
version = "0.1.0"
license = "MIT"
authors = ["Nervos Core Dev <[email protected]>"]
edition = "2018"

[dependencies]
serde = "1.0"
Expand All @@ -14,7 +15,7 @@ hash = {path = "../util/hash"}
crypto = {path = "../util/crypto"}
ckb-time = { path = "../util/time" }
bit-vec = "0.5.0"
crossbeam-channel = "0.3"
channel = { package= "crossbeam-channel", version = "0.3" }
rayon = "1.0"
ckb-util = { path = "../util" }
fnv = "1.0.3"
Expand Down
7 changes: 4 additions & 3 deletions core/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::header::{Header, HeaderBuilder};
use crate::transaction::{ProposalShortId, Transaction};
use crate::uncle::{uncles_hash, UncleBlock};
use fnv::FnvHashSet;
use header::{Header, HeaderBuilder};
use merkle_root::merkle_root;
use numext_fixed_hash::H256;
use transaction::{ProposalShortId, Transaction};
use uncle::{uncles_hash, UncleBlock};
use serde_derive::{Deserialize, Serialize};

#[derive(Clone, Serialize, Deserialize, Eq, Default, Debug)]
pub struct Block {
Expand Down
2 changes: 1 addition & 1 deletion core/src/cell.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::transaction::{CellOutput, OutPoint, Transaction};
use numext_fixed_hash::H256;
use std::collections::HashSet;
use std::iter::Chain;
use std::slice;
use transaction::{CellOutput, OutPoint, Transaction};

#[derive(Clone, PartialEq, Debug)]
pub enum CellStatus {
Expand Down
1 change: 1 addition & 0 deletions core/src/extras.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use numext_fixed_hash::H256;
use numext_fixed_uint::U256;
use serde_derive::{Deserialize, Serialize};

#[derive(Clone, Serialize, Deserialize, PartialEq, Default, Debug)]
pub struct BlockExt {
Expand Down
3 changes: 2 additions & 1 deletion core/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use bincode::{deserialize, serialize};
use hash::sha3_256;
use numext_fixed_hash::H256;
use numext_fixed_uint::U256;
use serde_derive::{Deserialize, Serialize};

pub use BlockNumber;
pub use crate::BlockNumber;

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug, Default)]
pub struct Seal {
Expand Down
15 changes: 1 addition & 14 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
//!
//! This Library provides the essential types for building ckb.
extern crate bincode;
extern crate ckb_util;
extern crate crypto;
extern crate hash;
extern crate numext_fixed_hash;
#[macro_use]
extern crate serde_derive;
extern crate bit_vec;
extern crate crossbeam_channel as channel;
extern crate fnv;
extern crate merkle_root;
extern crate numext_fixed_uint;

pub mod block;
pub mod cell;
pub mod chain;
Expand All @@ -28,7 +15,7 @@ pub mod transaction;
pub mod transaction_meta;
pub mod uncle;

pub use error::Error;
pub use crate::error::Error;

pub type PublicKey = numext_fixed_hash::H512;
pub type BlockNumber = u64;
Expand Down
1 change: 1 addition & 0 deletions core/src/script.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use hash::sha3_256;
use numext_fixed_hash::H256;
use serde_derive::{Deserialize, Serialize};
use std::io::Write;

// TODO: when flatbuffer work is done, remove Serialize/Deserialize here and
Expand Down
8 changes: 4 additions & 4 deletions core/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//! Transaction using Cell.
//! It is similar to Bitcoin Tx <https://en.bitcoin.it/wiki/Protocol_documentation#tx/>
use crate::script::Script;
use crate::BlockNumber;
pub use crate::Capacity;
use bincode::{deserialize, serialize};
use ckb_util::u64_to_bytes;
use hash::sha3_256;
use header::BlockNumber;
use numext_fixed_hash::H256;
use script::Script;
use serde_derive::{Deserialize, Serialize};
use std::mem;
use std::ops::{Deref, DerefMut};

pub const VERSION: u32 = 0;

pub use Capacity;

#[derive(Clone, Serialize, Deserialize, Eq, PartialEq, Hash, Debug)]
pub struct OutPoint {
// Hash of Transaction
Expand Down
1 change: 1 addition & 0 deletions core/src/transaction_meta.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bit_vec::BitVec;
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
#[serde(remote = "BitVec")]
Expand Down
9 changes: 5 additions & 4 deletions core/src/uncle.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::block::Block;
use crate::header::Header;
use crate::transaction::{ProposalShortId, Transaction};
use crate::BlockNumber;
use bincode::serialize;
use block::Block;
use hash::sha3_256;
use header::Header;
use numext_fixed_hash::H256;
use transaction::{ProposalShortId, Transaction};
use BlockNumber;
use serde_derive::{Deserialize, Serialize};

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Default, Debug)]
pub struct UncleBlock {
Expand Down
1 change: 1 addition & 0 deletions db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "ckb-db"
version = "0.1.0"
license = "MIT"
authors = ["Nervos Core Dev <[email protected]>"]
edition = "2018"

[dependencies]
bincode = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions db/src/diskdb.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use batch::{Batch, Col, Operation};
use kvdb::{ErrorKind, KeyValueDB, Result};
use crate::batch::{Batch, Col, Operation};
use crate::kvdb::{ErrorKind, KeyValueDB, Result};
use rocksdb::{ColumnFamily, Options, WriteBatch, DB};
use std::ops::Range;
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion db/src/kvdb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use batch::{Batch, Col};
use crate::batch::{Batch, Col};
use bincode::Error as BcError;
use rocksdb::Error as RdbError;
use std::error::Error as StdError;
Expand Down
8 changes: 0 additions & 8 deletions db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
//! This Library contains the `KeyValueDB` traits
//! which provides key-value store interface
extern crate bincode;
extern crate ckb_util;
extern crate fnv;
extern crate rocksdb;

pub mod batch;
pub mod diskdb;
pub mod kvdb;
pub mod memorydb;

#[cfg(test)]
extern crate tempfile;
4 changes: 2 additions & 2 deletions db/src/memorydb.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use batch::{Batch, Col, Operation};
use crate::batch::{Batch, Col, Operation};
use crate::kvdb::{ErrorKind, KeyValueDB, Result};
use ckb_util::RwLock;
use fnv::FnvHashMap;
use kvdb::{ErrorKind, KeyValueDB, Result};
use std::ops::Range;

pub type MemoryKey = Vec<u8>;
Expand Down
3 changes: 2 additions & 1 deletion miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "ckb-miner"
version = "0.1.0"
license = "MIT"
authors = ["Nervos Core Dev <[email protected]>"]
edition = "2018"

[dependencies]
log = "0.4"
Expand All @@ -18,7 +19,7 @@ flatbuffers = "0.5.0"
rand = "0.6"
serde = "1.0"
serde_derive = "1.0"
crossbeam-channel = "0.3"
channel = { package= "crossbeam-channel", version = "0.3" }
fnv = "1.0.3"
jsonrpc = { git = "https://github.com/quake/rust-jsonrpc" }
serde_json = "1.0"
5 changes: 3 additions & 2 deletions miner/src/agent.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use channel::{self, Receiver, Sender};
use crate::types::BlockTemplate;
use channel::{self, select, Receiver, Sender};
use ckb_core::block::{Block, BlockBuilder};
use ckb_core::header::{Header, HeaderBuilder};
use ckb_core::service::{Request, DEFAULT_CHANNEL_SIZE};
Expand All @@ -11,11 +12,11 @@ use ckb_shared::index::ChainIndex;
use ckb_shared::shared::{ChainProvider, Shared};
use ckb_time::now_ms;
use fnv::{FnvHashMap, FnvHashSet};
use log::error;
use numext_fixed_hash::H256;
use std::cmp;
use std::sync::Arc;
use std::thread::{self, JoinHandle};
use types::BlockTemplate;

const MINER_AGENT_SUBSCRIBER: &str = "miner_agent";

Expand Down
4 changes: 3 additions & 1 deletion miner/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::types::{BlockTemplate, Config, Shared};
use channel::Sender;
use ckb_core::block::Block;
use ckb_util::RwLockUpgradableReadGuard;
use jsonrpc::client::Client as JsonRpcClient;
use log::{debug, error, info};
use numext_fixed_hash::H256;
use serde_json::json;
use std::{thread, time};
use types::{BlockTemplate, Config, Shared};

#[derive(Clone)]
pub struct Client {
Expand Down
28 changes: 4 additions & 24 deletions miner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
extern crate ckb_core;
extern crate ckb_notify;
extern crate ckb_pool;
extern crate ckb_pow;
extern crate ckb_shared;
extern crate ckb_time;
extern crate ckb_util;
extern crate fnv;
extern crate jsonrpc;
extern crate numext_fixed_hash;
extern crate rand;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate crossbeam_channel as channel;

mod agent;
mod client;
mod miner;
mod types;

pub use agent::{Agent, AgentController, AgentReceivers};
pub use client::Client;
pub use miner::Miner;
pub use types::{BlockTemplate, Config, Shared};
pub use crate::agent::{Agent, AgentController, AgentReceivers};
pub use crate::client::Client;
pub use crate::miner::Miner;
pub use crate::types::{BlockTemplate, Config, Shared};
Loading

0 comments on commit 313b2ea

Please sign in to comment.