Skip to content

Commit

Permalink
Merge pull request #403 from TheWaWaR/update-ckb-to-v0.43
Browse files Browse the repository at this point in the history
chore: update ckb to 0.43
  • Loading branch information
doitian authored Jun 21, 2021
2 parents b15eb93 + 108f089 commit 75ec8e4
Show file tree
Hide file tree
Showing 35 changed files with 248 additions and 375 deletions.
189 changes: 81 additions & 108 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[package]
name = "ckb-cli"
version = "0.42.1"
version = "0.43.0"
license = "MIT"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
description = "ckb command line interface"

[dependencies]
ckb-jsonrpc-types = "=0.42.0"
ckb-hash = "=0.42.0"
ckb-crypto = { version = "=0.42.0", features = ["secp"] }
ckb-build-info = "=0.42.0"
ckb-types = "=0.42.0"
ckb-util = "=0.42.0"
ckb-resource = "=0.42.0"
ckb-dao-utils = "=0.42.0"
ckb-chain-spec = "=0.42.0"
ckb-sdk = { path = "ckb-sdk", version = "=0.42.1" }
ckb-index = { path = "ckb-index", version = "=0.42.1" }
plugin-protocol = { path = "plugin-protocol", package = "ckb-cli-plugin-protocol", version = "=0.42.1" }
ckb-jsonrpc-types = "=0.43.0"
ckb-hash = "=0.43.0"
ckb-crypto = { version = "=0.43.0", features = ["secp"] }
ckb-build-info = "=0.43.0"
ckb-types = "=0.43.0"
ckb-util = "=0.43.0"
ckb-resource = "=0.43.0"
ckb-dao-utils = "=0.43.0"
ckb-chain-spec = "=0.43.0"
ckb-sdk = { path = "ckb-sdk", version = "=0.43.0" }
ckb-index = { path = "ckb-index", version = "=0.43.0" }
plugin-protocol = { path = "plugin-protocol", package = "ckb-cli-plugin-protocol", version = "=0.43.0" }
jsonrpc-core-client = "17"
jsonrpc-core = "17"
jsonrpc-derive = "17"
Expand All @@ -30,7 +30,7 @@ env_logger = "0.6"
crossbeam-channel = "0.3"
clap = "=3.0.0-beta.1"
clap_generate = "=3.0.0-beta.1"
serde = { version = "1.0", features = ["rc"] }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
serde_yaml = "0.8.9"
Expand Down Expand Up @@ -61,7 +61,7 @@ tui = "0.6.0"
termion = "1.5"

[build-dependencies]
ckb-build-info = "=0.42.0"
ckb-build-info = "=0.43.0"

[workspace]
members = ["ckb-sdk", "ckb-index", "ckb-sdk-types", "plugin-protocol"]
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
CLIPPY_OPTS := -A clippy::mutable_key_type
# -D clippy::fallible_impl_from
CLIPPY_OPTS := -D warnings -D clippy::clone_on_ref_ptr -D clippy::enum_glob_use \
-A clippy::mutable_key_type -A clippy::upper_case_acronyms

fmt:
cargo fmt --all -- --check
cd test && cargo fmt --all -- --check

clippy:
RUSTFLAGS='-F warnings' cargo clippy --all --tests -- ${CLIPPY_OPTS}
cp -f Cargo.lock test/Cargo.lock && cd test && RUSTFLAGS='-F warnings' cargo clippy --all -- ${CLIPPY_OPTS}
cargo clippy --all --all-targets --all-features -- ${CLIPPY_OPTS}
cp -f Cargo.lock test/Cargo.lock && cd test && cargo clippy --all -- ${CLIPPY_OPTS}

test:
RUSTFLAGS='-F warnings' RUST_BACKTRACE=full cargo test --all
RUST_BACKTRACE=full cargo test --all

ci: fmt clippy test security-audit
git diff --exit-code Cargo.lock
Expand Down
8 changes: 4 additions & 4 deletions ckb-index/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "ckb-index"
version = "0.42.1"
version = "0.43.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
description = "ckb-cli index database"

[dependencies]
serde = { version = "1.0", features = ["rc"] }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
bincode = "1.1.4"
log = "0.4.6"
failure = "0.1.5"
ckb-types = "=0.42.0"
ckb-sdk = { path = "../ckb-sdk", version = "=0.42.1" }
ckb-types = "=0.43.0"
ckb-sdk = { path = "../ckb-sdk", version = "=0.43.0" }
rocksdb = { package = "ckb-rocksdb", version = "=0.15.1", features = ["snappy"] }
12 changes: 6 additions & 6 deletions ckb-index/src/index/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,15 @@ impl Key {
}
}

impl Into<Vec<u8>> for &Key {
fn into(self) -> Vec<u8> {
self.to_bytes()
impl From<&Key> for Vec<u8> {
fn from(key: &Key) -> Vec<u8> {
key.to_bytes()
}
}

impl Into<Vec<u8>> for Key {
fn into(self) -> Vec<u8> {
(&self).into()
impl From<Key> for Vec<u8> {
fn from(key: Key) -> Vec<u8> {
From::from(&key)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ckb-index/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'a> IndexDatabase<'a> {
reader
.get(&Key::BlockDelta(last_header.number()).to_bytes())
.map(|bytes| bincode::deserialize(&bytes).unwrap())
.ok_or_else(|| IndexError::LongFork)?
.ok_or(IndexError::LongFork)?
};
let mut txn = RocksTxn::new(self.db, self.cf);
last_block_delta.rollback(&mut txn);
Expand Down
16 changes: 8 additions & 8 deletions ckb-sdk-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "ckb-sdk-types"
version = "0.42.1"
version = "0.43.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
description = "ckb-cli sdk common types"

[dependencies]
serde = { version = "1.0", features = ["rc"] }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"

ckb-types = "=0.42.0"
ckb-traits = "=0.42.0"
ckb-jsonrpc-types = "=0.42.0"
ckb-hash = "=0.42.0"
ckb-error = "=0.42.0"
ckb-types = "=0.43.0"
ckb-traits = "=0.43.0"
ckb-jsonrpc-types = "=0.43.0"
ckb-hash = "=0.43.0"
ckb-error = "=0.43.0"

[dev-dependencies]
ckb-crypto = { version = "=0.42.0", features = ["secp"] }
ckb-crypto = { version = "=0.43.0", features = ["secp"] }
20 changes: 10 additions & 10 deletions ckb-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "ckb-sdk"
version = "0.42.1"
version = "0.43.0"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
description = "ckb-cli sdk"

[dependencies]
serde = { version = "1.0", features = ["rc"] }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
bech32 = "0.6.0"
Expand All @@ -30,11 +30,11 @@ tokio = { version = "1" }
bytes = "1"
futures = "0.3"

ckb-types = "=0.42.0"
ckb-error = "=0.42.0"
ckb-script = "=0.42.0"
ckb-jsonrpc-types = "=0.42.0"
ckb-hash = "=0.42.0"
ckb-resource = "=0.42.0"
ckb-crypto = { version = "=0.42.0", features = ["secp"] }
ckb-sdk-types = { path = "../ckb-sdk-types", version="=0.42.1" }
ckb-types = "=0.43.0"
ckb-error = "=0.43.0"
ckb-script = "=0.43.0"
ckb-jsonrpc-types = "=0.43.0"
ckb-hash = "=0.43.0"
ckb-resource = "=0.43.0"
ckb-crypto = { version = "=0.43.0", features = ["secp"] }
ckb-sdk-types = { path = "../ckb-sdk-types", version="=0.43.0" }
16 changes: 3 additions & 13 deletions ckb-sdk/src/rpc/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ckb_jsonrpc_types::{
BannedAddr, Block, BlockNumber, BlockReward, BlockTemplate, BlockView, CellWithStatus,
ChainInfo, Consensus, Cycle, EpochNumber, EpochView, ExtraLoggerConfig, HeaderView, JsonBytes,
LocalNode, MainLoggerConfig, OutPoint, RawTxPool, RemoteNode, Script, Timestamp, Transaction,
BannedAddr, Block, BlockNumber, BlockTemplate, BlockView, CellWithStatus, ChainInfo, Consensus,
Cycle, EpochNumber, EpochView, ExtraLoggerConfig, HeaderView, JsonBytes, LocalNode,
MainLoggerConfig, OutPoint, RawTxPool, RemoteNode, Script, Timestamp, Transaction,
TransactionProof, TransactionWithStatus, TxPoolInfo, Uint64, Version,
};

Expand Down Expand Up @@ -70,7 +70,6 @@ jsonrpc!(pub struct RawHttpRpcClient {
pub fn get_block(&mut self, hash: H256) -> Option<BlockView>;
pub fn get_block_by_number(&mut self, number: BlockNumber) -> Option<BlockView>;
pub fn get_block_hash(&mut self, number: BlockNumber) -> Option<H256>;
pub fn get_cellbase_output_capacity_details(&mut self, hash: H256) -> Option<BlockReward>;
pub fn get_current_epoch(&mut self) -> EpochView;
pub fn get_epoch_by_number(&mut self, number: EpochNumber) -> Option<EpochView>;
pub fn get_header(&mut self, hash: H256) -> Option<HeaderView>;
Expand Down Expand Up @@ -171,15 +170,6 @@ impl HttpRpcClient {
.map(|opt| opt.map(Into::into))
.map_err(|err| err.to_string())
}
pub fn get_cellbase_output_capacity_details(
&mut self,
hash: H256,
) -> Result<Option<types::BlockReward>, String> {
self.client
.get_cellbase_output_capacity_details(hash)
.map(|opt| opt.map(Into::into))
.map_err(|err| err.to_string())
}
pub fn get_current_epoch(&mut self) -> Result<types::EpochView, String> {
self.client
.get_current_epoch()
Expand Down
10 changes: 5 additions & 5 deletions ckb-sdk/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ mod types;
pub use client::{HttpRpcClient, RawHttpRpcClient};
pub use primitive::{Capacity, EpochNumberWithFraction, Since, Timestamp};
pub use types::{
Alert, AlertMessage, BannedAddr, Block, BlockReward, BlockView, Byte32, CellDep, CellInput,
CellOutput, ChainInfo, DepType, EpochView, Header, HeaderView, JsonBytes, LocalNode,
MerkleProof, NodeAddress, OutPoint, ProposalShortId, RemoteNode, Script, ScriptHashType,
Transaction, TransactionProof, TransactionView, TransactionWithStatus, TxPoolInfo, TxStatus,
Uint128, UncleBlock, UncleBlockView,
Alert, AlertMessage, BannedAddr, Block, BlockView, Byte32, CellDep, CellInput, CellOutput,
ChainInfo, DepType, EpochView, Header, HeaderView, JsonBytes, LocalNode, MerkleProof,
NodeAddress, OutPoint, ProposalShortId, RemoteNode, Script, ScriptHashType, Transaction,
TransactionProof, TransactionView, TransactionWithStatus, TxPoolInfo, TxStatus, Uint128,
UncleBlock, UncleBlockView,
};
31 changes: 0 additions & 31 deletions ckb-sdk/src/rpc/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,37 +568,6 @@ impl From<rpc_types::EpochView> for EpochView {
}
}

#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
pub struct BlockReward {
pub total: Capacity,
pub primary: Capacity,
pub secondary: Capacity,
pub tx_fee: Capacity,
pub proposal_reward: Capacity,
}
impl From<rpc_types::BlockReward> for BlockReward {
fn from(json: rpc_types::BlockReward) -> BlockReward {
BlockReward {
total: json.total.into(),
primary: json.primary.into(),
secondary: json.secondary.into(),
tx_fee: json.tx_fee.into(),
proposal_reward: json.proposal_reward.into(),
}
}
}
impl From<BlockReward> for core::BlockReward {
fn from(json: BlockReward) -> Self {
Self {
total: core::Capacity::shannons(json.total.0),
primary: core::Capacity::shannons(json.primary.0),
secondary: core::Capacity::shannons(json.secondary.0),
tx_fee: core::Capacity::shannons(json.tx_fee.0),
proposal_reward: core::Capacity::shannons(json.proposal_reward.0),
}
}
}

#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
pub struct TransactionProof {
/// Block hash
Expand Down
21 changes: 11 additions & 10 deletions ckb-sdk/src/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl From<&AddressPayload> for Script {
}

impl From<Script> for AddressPayload {
#[allow(clippy::fallible_impl_from)]
fn from(lock: Script) -> AddressPayload {
let hash_type: ScriptHashType = lock.hash_type().try_into().expect("Invalid hash_type");
let code_hash = lock.code_hash();
Expand Down Expand Up @@ -311,34 +312,34 @@ mod old_addr {
pub enum AddressFormat {
// SECP256K1 algorithm PK
#[allow(dead_code)]
SP2K,
Sp2k,
// SECP256R1 algorithm PK
#[allow(dead_code)]
SP2R,
Sp2r,
// SECP256K1 + blake160 blake160(pk)
P2PH,
P2ph,
// Alias of SP2K PK
#[allow(dead_code)]
P2PK,
P2pk,
}

impl Default for AddressFormat {
fn default() -> AddressFormat {
AddressFormat::P2PH
AddressFormat::P2ph
}
}

impl AddressFormat {
pub fn from_bytes(format: &[u8]) -> Result<AddressFormat, String> {
match format {
P2PH_MARK => Ok(AddressFormat::P2PH),
P2PH_MARK => Ok(AddressFormat::P2ph),
_ => Err(format!("Unsupported address format data: {:?}", format)),
}
}

pub fn to_bytes(self) -> Result<Vec<u8>, String> {
match self {
AddressFormat::P2PH => Ok(P2PH_MARK.to_vec()),
AddressFormat::P2ph => Ok(P2PH_MARK.to_vec()),
_ => Err(format!("Unsupported address format: {:?}", self)),
}
}
Expand All @@ -352,7 +353,7 @@ mod old_addr {

impl Address {
pub fn new_default(hash: H160) -> Address {
let format = AddressFormat::P2PH;
let format = AddressFormat::P2ph;
Address { format, hash }
}

Expand All @@ -369,7 +370,7 @@ mod old_addr {
}

pub fn from_pubkey(format: AddressFormat, pubkey: &Pubkey) -> Result<Address, String> {
if format != AddressFormat::P2PH {
if format != AddressFormat::P2ph {
return Err("Only support P2PH for now".to_owned());
}
// Serialize pubkey as compressed format
Expand All @@ -379,7 +380,7 @@ mod old_addr {
}

pub fn from_lock_arg(bytes: &[u8]) -> Result<Address, String> {
let format = AddressFormat::P2PH;
let format = AddressFormat::P2ph;
let hash = H160::from_slice(bytes).map_err(|err| err.to_string())?;
Ok(Address { format, hash })
}
Expand Down
8 changes: 4 additions & 4 deletions ckb-sdk/src/wallet/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ macro_rules! impl_array_newtype {
fn from(data: &'a [$ty]) -> $thing {
assert_eq!(data.len(), $len);
let mut ret = [0; $len];
ret.copy_from_slice(&data[..]);
ret.copy_from_slice(data);
$thing(ret)
}
}
Expand Down Expand Up @@ -316,9 +316,9 @@ impl From<Vec<ChildNumber>> for DerivationPath {
}
}

impl Into<Vec<ChildNumber>> for DerivationPath {
fn into(self) -> Vec<ChildNumber> {
self.0
impl From<DerivationPath> for Vec<ChildNumber> {
fn from(dpath: DerivationPath) -> Vec<ChildNumber> {
dpath.0
}
}

Expand Down
2 changes: 1 addition & 1 deletion ckb-sdk/src/wallet/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::KeyStoreError;
#[derive(Debug, Fail)]
pub enum Error {
#[fail(display = "BIP32 error: {}", _0)]
BIP32(Bip32Error),
Bip32(Bip32Error),

#[fail(display = "KeyStore error: {}", _0)]
KeyStore(KeyStoreError),
Expand Down
Loading

0 comments on commit 75ec8e4

Please sign in to comment.