Skip to content

Commit

Permalink
Merge pull request #24 from TheWaWaR/ckb-0.17
Browse files Browse the repository at this point in the history
 feat: Mock transaction support in ckb-sdk
  • Loading branch information
doitian authored Jul 26, 2019
2 parents 668104b + 0c11f9d commit 6cf87a7
Show file tree
Hide file tree
Showing 42 changed files with 1,956 additions and 2,081 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: rust
rust: 1.34.2
rust: 1.36.0
dist: xenial
sudo: true
cache:
Expand Down Expand Up @@ -91,7 +91,7 @@ matrix:
if: 'tag IS present AND env(GITHUB_TOKEN) IS present'
language: ruby
addons: { apt: { packages: [] } }
env: REL_PKG=x86_64-unknown-linux-gnu.tar.gz BUILDER_IMAGE=nervos/ckb-docker-builder:xenial-rust-1.34.2
env: REL_PKG=x86_64-unknown-linux-gnu.tar.gz BUILDER_IMAGE=nervos/ckb-docker-builder:xenial-rust-1.36.0
before_install: skip
before_cache: skip
cache:
Expand All @@ -107,7 +107,7 @@ matrix:
if: 'tag IS present AND env(GITHUB_TOKEN) IS present'
language: ruby
addons: { apt: { packages: [] } }
env: REL_PKG=x86_64-unknown-centos-gnu.tar.gz BUILDER_IMAGE=nervos/ckb-docker-builder:centos-7-rust-1.34.2
env: REL_PKG=x86_64-unknown-centos-gnu.tar.gz BUILDER_IMAGE=nervos/ckb-docker-builder:centos-7-rust-1.36.0
before_install: skip
before_cache: skip
cache:
Expand Down
145 changes: 86 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
name = "ckb-cli"
version = "0.17.0"
license = "MIT"
authors = ["Linfeng Qian <[email protected]>"]
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"

[dependencies]
numext-fixed-hash = "~0.1"
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "develop", features = ["secp", "bech32"] }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-core = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-util = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17", features = ["secp", "bech32"] }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-core = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-util = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-sdk = { path = "ckb-sdk" }
ckb-index = { path = "ckb-index" }

jsonrpc-client-core = "0.5.0"
secp256k1 = {version = "0.12.2" }
Expand All @@ -25,6 +26,7 @@ clap = "2.33.0"
serde = { version = "1.0", features = ["rc"] }
serde_derive = "1.0"
serde_json = "1.0"
serde_yaml = "0.8.9"
yaml-rust = "0.4.3"
dtoa = "0.4"
ansi_term = "^0.11.0"
Expand All @@ -44,7 +46,7 @@ tui = "0.6.0"
termion = "1.5"

[build-dependencies]
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-build-info = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }

[workspace]
members = ["ckb-sdk"]
members = ["ckb-sdk", "ckb-index"]
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- template: devtools/azure/windows-dependencies.yml
parameters:
rustup_toolchain: '1.34.2-x86_64-pc-windows-msvc'
rustup_toolchain: '1.36.0-x86_64-pc-windows-msvc'
- script: make test
displayName: Run unit tests
env:
Expand All @@ -34,7 +34,7 @@ jobs:
steps:
- template: devtools/azure/windows-dependencies.yml
parameters:
rustup_toolchain: '1.34.2-x86_64-pc-windows-msvc'
rustup_toolchain: '1.36.0-x86_64-pc-windows-msvc'
- script: make prod
displayName: Build
- powershell: |
Expand Down
18 changes: 18 additions & 0 deletions ckb-index/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "ckb-index"
version = "0.17.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"

[dependencies]
serde = { version = "1.0", features = ["rc"] }
serde_derive = "1.0"
numext-fixed-hash = "~0.1"
bincode = "1.1.4"
log = "0.4.6"
rocksdb = { version = "0.12.2", default-features = false }
failure = "0.1.5"

ckb-core = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-sdk = { path = "../ckb-sdk" }
41 changes: 41 additions & 0 deletions ckb-index/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::io;

use failure::Fail;

use crate::index::IndexError;

#[derive(Debug, Fail)]
pub enum Error {
#[fail(display = "Rocksdb error: {}", _0)]
Rocksdb(rocksdb::Error),
#[fail(display = "IO error: {}", _0)]
Io(io::Error),
#[fail(display = "Index DB error: {}", _0)]
Index(IndexError),
#[fail(display = "Other error: {}", _0)]
Other(String),
}

impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::Io(err)
}
}

impl From<rocksdb::Error> for Error {
fn from(err: rocksdb::Error) -> Error {
Error::Rocksdb(err)
}
}

impl From<IndexError> for Error {
fn from(err: IndexError) -> Error {
Error::Index(err)
}
}

impl From<String> for Error {
fn from(err: String) -> Error {
Error::Other(err)
}
}
2 changes: 1 addition & 1 deletion ckb-sdk/src/index/key.rs → ckb-index/src/index/key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::types::{BlockDeltaInfo, CellIndex, HashType, HeaderInfo, LiveCellInfo, TxInfo};
use crate::{Address, NetworkType};
use ckb_core::{header::Header, script::Script, transaction::CellOutPoint};
use ckb_sdk::{Address, NetworkType};
use numext_fixed_hash::H256;
use serde_derive::{Deserialize, Serialize};

Expand Down
3 changes: 2 additions & 1 deletion ckb-sdk/src/index/mod.rs → ckb-index/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use std::fmt;
use std::io;

use ckb_core::{block::Block, header::Header, script::Script, transaction::CellOutPoint};
use ckb_sdk::{Address, GenesisInfo, NetworkType};
use numext_fixed_hash::H256;
use rocksdb::{ColumnFamily, DB};

use crate::{Address, GenesisInfo, KVReader, KVTxn, NetworkType, RocksReader, RocksTxn};
use crate::{KVReader, KVTxn, RocksReader, RocksTxn};
pub use key::{Key, KeyMetrics, KeyType};
pub use types::{CellIndex, HashType, LiveCellInfo, TxInfo};

Expand Down
3 changes: 2 additions & 1 deletion ckb-sdk/src/index/types.rs → ckb-index/src/index/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use numext_fixed_hash::H256;
use serde_derive::{Deserialize, Serialize};

use super::key::{Key, KeyType};
use crate::{Address, KVReader, KVTxn};
use crate::{KVReader, KVTxn};
use ckb_sdk::Address;

const KEEP_RECENT_HEADERS: u64 = 10_000;
const KEEP_RECENT_BLOCKS: u64 = 200;
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions ckb-index/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod error;
mod index;
mod kvdb;
mod util;

pub use error::Error;
pub use index::{
CellIndex, HashType, IndexDatabase, IndexError, Key as IndexKey, KeyMetrics as IndexKeyMetrics,
KeyType as IndexKeyType, LiveCellInfo, TxInfo,
};
pub use kvdb::{KVReader, KVTxn, RocksReader, RocksTxn};
pub use util::{with_index_db, with_rocksdb};

const ROCKSDB_COL_INDEX_DB: &str = "index-db";
16 changes: 2 additions & 14 deletions ckb-sdk/src/util.rs → ckb-index/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use std::time::{Duration, Instant};
use numext_fixed_hash::H256;
use rocksdb::{ColumnFamily, Options, DB};

use crate::{
Error, ROCKSDB_COL_CELL, ROCKSDB_COL_CELL_ALIAS, ROCKSDB_COL_CELL_INPUT, ROCKSDB_COL_INDEX_DB,
ROCKSDB_COL_SCRIPT, ROCKSDB_COL_TX,
};
use crate::{Error, ROCKSDB_COL_INDEX_DB};

pub fn with_rocksdb<P, T, F>(path: P, timeout: Option<Duration>, func: F) -> Result<T, Error>
where
Expand All @@ -22,16 +19,7 @@ where
options.create_if_missing(true);
options.create_missing_column_families(true);
options.set_keep_log_file_num(32);
let columns = vec![
// TODO: remove this later
"key",
ROCKSDB_COL_CELL,
ROCKSDB_COL_CELL_ALIAS,
ROCKSDB_COL_CELL_INPUT,
ROCKSDB_COL_SCRIPT,
ROCKSDB_COL_TX,
ROCKSDB_COL_INDEX_DB,
];
let columns = vec![ROCKSDB_COL_INDEX_DB];
loop {
match DB::open_cf(&options, &path, &columns) {
Ok(db) => break func(&db),
Expand Down
15 changes: 6 additions & 9 deletions ckb-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ckb-sdk"
version = "0.17.0"
authors = ["Linfeng Qian <[email protected]>"]
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"

Expand All @@ -12,12 +12,9 @@ serde_json = "1.0"
numext-fixed-hash = "~0.1"
bech32 = "0.6.0"
bytes = { version="0.4", features = ["serde"] }
bincode = "1.1.4"
log = "0.4.6"
# fs2 = "0.4.3"
jsonrpc-client-core = "0.5.0"
jsonrpc-client-http = "0.5.0"
rocksdb = { version = "0.12.2", default-features = false }
secp256k1 = {version = "0.12.2" }
faster-hex = "0.3"
fnv = "1.0.3"
Expand All @@ -31,8 +28,8 @@ uuid = { version = "0.7.4", features = ["v4"] }
chrono = "0.4.6"
failure = "0.1.5"

ckb-core = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "develop" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "develop", features = ["secp", "bech32"] }
ckb-core = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-script = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-jsonrpc-types = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-hash = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17" }
ckb-crypto = { git = "https://github.com/nervosnetwork/ckb", branch = "rc/v0.17", features = ["secp", "bech32"] }
Loading

0 comments on commit 6cf87a7

Please sign in to comment.