Skip to content

Commit

Permalink
Merge pull request #557 from eval-exec/exec/data2
Browse files Browse the repository at this point in the history
Upgrade ckb dependencies to `v0.111.0`
  • Loading branch information
doitian authored Sep 14, 2023
2 parents 31c858e + 2554ebb commit f043bf1
Show file tree
Hide file tree
Showing 21 changed files with 886 additions and 288 deletions.
455 changes: 252 additions & 203 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[package]
name = "ckb-cli"
version = "1.4.0"
version = "1.5.0"
license = "MIT"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2021"
description = "ckb command line interface"

[dependencies]
ckb-jsonrpc-types = "=0.108.0"
ckb-hash = "=0.108.0"
ckb-crypto = { version = "=0.108.0", features = ["secp"] }
ckb-build-info = "=0.108.0"
ckb-types = "=0.108.0"
ckb-util = "=0.108.0"
ckb-error = "=0.108.0"
ckb-script = "=0.108.0"
ckb-chain-spec = "=0.108.0"
ckb-mock-tx-types = "=0.108.0"
ckb-sdk = "2.5.0"
ckb-jsonrpc-types = "=0.111.0"
ckb-hash = "=0.111.0"
ckb-crypto = { version = "=0.111.0", features = ["secp"] }
ckb-build-info = "=0.111.0"
ckb-types = "=0.111.0"
ckb-util = "=0.111.0"
ckb-error = "=0.111.0"
ckb-script = "=0.111.0"
ckb-chain-spec = "=0.111.0"
ckb-mock-tx-types = "=0.111.0"
ckb-sdk = "3.0.0"
ckb-signer = { path = "ckb-signer", version = "0.4.0" }
plugin-protocol = { path = "plugin-protocol", package = "ckb-cli-plugin-protocol", version = "=1.3.0" }
jsonrpc-core-client = "18"
Expand Down Expand Up @@ -73,7 +73,7 @@ termion = "1.5"
rand = "0.7"

[build-dependencies]
ckb-build-info = "=0.108.0"
ckb-build-info = "=0.111.0"

[workspace]
members = ["ckb-signer", "plugin-protocol"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ci: fmt clippy test security-audit check-crates check-licenses
git diff --exit-code Cargo.lock

integration:
bash devtools/ci/integration.sh v0.108.0
bash devtools/ci/integration.sh v0.111.0-rc8

prod: ## Build binary with release profile.
cargo build --release
Expand Down
8 changes: 4 additions & 4 deletions ckb-signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ thiserror = "1.0.30"
parking_lot = "0.11"
anyhow = "1.0.63"

ckb-types = "=0.108.0"
ckb-hash = "=0.108.0"
ckb-crypto = { version = "=0.108.0", features = ["secp"] }
ckb-sdk = "2.5.0"
ckb-types = "=0.111.0"
ckb-hash = "=0.111.0"
ckb-crypto = { version = "=0.111.0", features = ["secp"] }
ckb-sdk = "3.0.0"
14 changes: 6 additions & 8 deletions ckb-signer/src/keystore/passphrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,15 @@ impl ScryptParams {
}
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub enum ScryptType {
#[default]
Standard,
Light,
Custom { log_n: u8, p: u32 },
}

impl Default for ScryptType {
fn default() -> ScryptType {
ScryptType::Standard
}
Custom {
log_n: u8,
p: u32,
},
}

// Example:
Expand Down
4 changes: 2 additions & 2 deletions plugin-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description = "ckb-cli plugin protocol"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ckb-types = "=0.108.0"
ckb-jsonrpc-types = "=0.108.0"
ckb-types = "=0.111.0"
ckb-jsonrpc-types = "=0.111.0"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.67.1
1.71.1
2 changes: 1 addition & 1 deletion src/plugin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ impl Drop for PluginProcess {
}

impl PluginProcess {
#[allow(clippy::zero_ptr, clippy::drop_copy)]
#[allow(clippy::zero_ptr, dropping_copy_types)]
pub fn start(
plugin: Plugin,
config: PluginConfig,
Expand Down
11 changes: 10 additions & 1 deletion src/subcommands/deploy/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn build_tx<T: ChangeInfo>(

let mut cell_collector = DefaultCellCollector::new(ckb_rpc);
if let Some(pending_tx) = pending_tx.as_ref() {
let mut ckb_client = CkbRpcClient::new(ckb_rpc);
let ckb_client = CkbRpcClient::new(ckb_rpc);
let tip_num = ckb_client.get_tip_block_number().unwrap().value();
cell_collector.apply_tx(pending_tx.clone(), tip_num)?;
}
Expand Down Expand Up @@ -187,4 +187,13 @@ impl TransactionDependencyProvider for TxDepProviderWrapper {
.get_header(block_hash)
.or_else(|_| self.inner.get_header(block_hash))
}

fn get_block_extension(
&self,
_block_hash: &Byte32,
) -> std::result::Result<Option<packed::Bytes>, TransactionDependencyError> {
Err(TransactionDependencyError::NotFound(
"get_block_extension not supported".to_string(),
))
}
}
2 changes: 2 additions & 0 deletions src/subcommands/mock_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl<'a> CliSubCommand for MockTxSubCommand<'a> {
inputs: vec![mock_input],
cell_deps: vec![mock_cell_dep],
header_deps: vec![HeaderBuilder::default().build()],
extensions: vec![],
};
let tx = TransactionBuilder::default()
.input(input)
Expand Down Expand Up @@ -368,6 +369,7 @@ impl<'a> CliSubCommand for MockTxSubCommand<'a> {
inputs: mock_inputs,
cell_deps: mock_cell_deps,
header_deps: mock_header_deps,
extensions: vec![],
},
tx: src_tx,
};
Expand Down
123 changes: 115 additions & 8 deletions src/subcommands/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::time::Duration;

use super::{CliSubCommand, Output};
use crate::utils::arg_parser::{
ArgParser, DurationParser, FeeRateStaticsTargetParser, FilePathParser, FixedHashParser,
ArgParser, DurationParser, FeeRateStatisticsTargetParser, FilePathParser, FixedHashParser,
FromStrParser, HexParser,
};
use crate::utils::rpc::{
Expand Down Expand Up @@ -177,12 +177,48 @@ impl<'a> RpcSubCommand<'a> {
App::new("get_fee_rate_statics")
.arg(
Arg::with_name("target")
.long("target")
.takes_value(true)
.validator(|input| FromStrParser::<u64>::default().validate(input))
.about("Specify the number (1 - 101) of confirmed blocks to be counted. If the number is even, automatically add one. Default is 21.")
.long("target")
.takes_value(true)
.validator(|input| FromStrParser::<u64>::default().validate(input))
.about("[Deprecated! please use get_fee_rate_statistics] Specify the number (1 - 101) of confirmed blocks to be counted. If the number is even, automatically add one. Default is 21.")
)
.about("estimate_cycles run a transaction and return the execution consumed cycles."),
.about("[Deprecated! please use get_fee_rate_statistics] Returns the fee_rate statistics of confirmed blocks on the chain."),
App::new("get_fee_rate_statistics")
.arg(
Arg::with_name("target")
.long("target")
.takes_value(true)
.validator(|input| FromStrParser::<u64>::default().validate(input))
.about("Specify the number (1 - 101) of confirmed blocks to be counted. If the number is even, automatically add one. Default is 21.")
)
.about("Returns the fee_rate statistics of confirmed blocks on the chain."),
App::new("get_deployments_info").about("Returns the information about all deployments"),
App::new("get_transaction_and_witness_proof")
.arg(
Arg::with_name("tx-hash")
.long("tx-hash")
.takes_value(true)
.multiple(true)
.validator(|input| FixedHashParser::<H256>::default().validate(input))
.about("Transaction hashes")
)
.arg(
Arg::with_name("block-hash")
.long("block-hash")
.takes_value(true)
.validator(|input| FixedHashParser::<H256>::default().validate(input))
.about("Looks for transactions in the block with this hash")
).about("Returns a Merkle proof that transactions and witnesses are included in a block"),
App::new("verify_transaction_and_witness_proof")
.arg(
Arg::with_name("json-path")
.long("json-path")
.takes_value(true)
.required(true)
.validator(|input| FilePathParser::new(true).validate(input))
.about("File path of proof which is a `TransactionAndWitnessProof` (JSON format)")
)
.about("Verifies that a proof points to transactions in a block, returning the transaction hashes it commits to"),
// [Net]
App::new("get_banned_addresses").about("Get all banned IPs/Subnets"),
App::new("get_peers").about("Get connected peers"),
Expand Down Expand Up @@ -756,7 +792,7 @@ impl<'a> CliSubCommand for RpcSubCommand<'a> {
("get_fee_rate_statics", Some(m)) => {
let is_raw_data = is_raw_data || m.is_present("raw-data");
let target: Option<u64> =
FeeRateStaticsTargetParser {}.from_matches_opt(m, "target")?;
FeeRateStatisticsTargetParser {}.from_matches_opt(m, "target")?;

if is_raw_data {
let resp = self
Expand All @@ -765,7 +801,78 @@ impl<'a> CliSubCommand for RpcSubCommand<'a> {
.map_err(|err| err.to_string())?;
Ok(Output::new_output(resp))
} else {
let resp = self.rpc_client.get_fee_rate_statics(target)?;
let resp = self.rpc_client.get_fee_rate_statistics(target)?;
Ok(Output::new_output(resp))
}
}
("get_fee_rate_statistics", Some(m)) => {
let is_raw_data = is_raw_data || m.is_present("raw-data");
let target: Option<u64> =
FeeRateStatisticsTargetParser {}.from_matches_opt(m, "target")?;

if is_raw_data {
let resp = self
.raw_rpc_client
.get_fee_rate_statics(target.map(|v| v.into()))
.map_err(|err| err.to_string())?;
Ok(Output::new_output(resp))
} else {
let resp = self.rpc_client.get_fee_rate_statistics(target)?;
Ok(Output::new_output(resp))
}
}
("get_deployments_info", Some(m)) => {
let is_raw_data = is_raw_data || m.is_present("raw-data");

if is_raw_data {
let resp = self
.raw_rpc_client
.get_deployments_info()
.map_err(|err| err.to_string())?;
Ok(Output::new_output(resp))
} else {
let resp = self.rpc_client.get_deployments_info()?;
Ok(Output::new_output(resp))
}
}
("get_transaction_and_witness_proof", Some(m)) => {
let is_raw_data = is_raw_data || m.is_present("raw-data");
let tx_hashes: Vec<H256> =
FixedHashParser::<H256>::default().from_matches_vec(m, "tx-hash")?;
let block_hash: Option<H256> =
FixedHashParser::<H256>::default().from_matches_opt(m, "block-hash")?;

if is_raw_data {
let resp = self
.raw_rpc_client
.get_transaction_and_witness_proof(tx_hashes, block_hash)
.map_err(|err| err.to_string())?;
Ok(Output::new_output(resp))
} else {
let resp = self
.rpc_client
.get_transaction_and_witness_proof(tx_hashes, block_hash)?;
Ok(Output::new_output(resp))
}
}
("verify_transaction_and_witness_proof", Some(m)) => {
let is_raw_data = is_raw_data || m.is_present("raw-data");

let json_path: PathBuf = FilePathParser::new(true).from_matches(m, "json-path")?;
let content = fs::read_to_string(json_path).map_err(|err| err.to_string())?;

let tx_and_witness_proof: rpc_types::TransactionAndWitnessProof =
serde_json::from_str(&content).map_err(|err| err.to_string())?;
if is_raw_data {
let resp = self
.raw_rpc_client
.verify_transaction_and_witness_proof(tx_and_witness_proof)
.map_err(|err| err.to_string())?;
Ok(Output::new_output(resp))
} else {
let resp = self
.rpc_client
.verify_transaction_and_witness_proof(tx_and_witness_proof.into())?;
Ok(Output::new_output(resp))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/arg_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ impl ArgParser<Vec<u8>> for HexParser {
}
}

pub struct FeeRateStaticsTargetParser;
pub struct FeeRateStatisticsTargetParser;

impl ArgParser<u64> for FeeRateStaticsTargetParser {
impl ArgParser<u64> for FeeRateStatisticsTargetParser {
fn parse(&self, input: &str) -> Result<u64, String> {
let target = FromStrParser::<u64>::default().parse(input)?;
if target == 0 || target > 101 {
Expand Down
9 changes: 2 additions & 7 deletions src/utils/json_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macro_rules! colorize {
}

/// The set of available colors for the various JSON components.
#[derive(Clone)]
#[derive(Clone, Default)]
pub enum Color {
#[allow(dead_code)]
Black,
Expand All @@ -43,15 +43,10 @@ pub enum Color {
Yellow,

/// Default color
#[default]
Plain,
}

impl Default for Color {
fn default() -> Self {
Color::Plain
}
}

#[derive(Default)]
pub struct ColorizerBuilder {
null: Color,
Expand Down
26 changes: 23 additions & 3 deletions src/utils/mock_tx_helper.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use ckb_chain_spec::consensus::ConsensusBuilder;
use std::collections::{HashMap, HashSet};
use std::convert::TryInto;
use std::sync::Arc;

use ckb_error::OtherError;
use ckb_hash::new_blake2b;
use ckb_jsonrpc_types as rpc_types;
use ckb_mock_tx_types::{MockResourceLoader, MockTransaction, Resource};
use ckb_script::TransactionScriptsVerifier;
use ckb_script::{TransactionScriptsVerifier, TxVerifyEnv};
use ckb_sdk::constants::{MIN_SECP_CELL_CAPACITY, SIGHASH_TYPE_HASH};
use ckb_types::core::hardfork::{HardForks, CKB2021, CKB2023};
use ckb_types::core::HeaderBuilder;
use ckb_types::{
bytes::Bytes,
core::{cell::resolve_transaction, Capacity, Cycle, ScriptHashType},
Expand Down Expand Up @@ -152,7 +156,9 @@ impl<'a> MockTransactionHelper<'a> {
.collect::<HashMap<_, _>>();
let mut insert_dep = |hash_type, code_hash: &Byte32| -> Result<(), String> {
match (hash_type, code_hash) {
(ScriptHashType::Data, data_hash) | (ScriptHashType::Data1, data_hash) => {
(ScriptHashType::Data, data_hash)
| (ScriptHashType::Data1, data_hash)
| (ScriptHashType::Data2, data_hash) => {
let dep = data_deps.get(data_hash).cloned().ok_or_else(|| {
format!("Can not find data hash in mock deps: {}", data_hash)
})?;
Expand Down Expand Up @@ -316,7 +322,21 @@ impl<'a> MockTransactionHelper<'a> {
.map_err(|err| format!("Resolve transaction error: {:?}", err))?
};

let mut verifier = TransactionScriptsVerifier::new(&rtx, &resource);
let consensus = ConsensusBuilder::default()
.hardfork_switch(HardForks {
ckb2021: CKB2021::new_dev_default(),
ckb2023: CKB2023::new_dev_default(),
})
.build();
let tip = HeaderBuilder::default().number(0.pack()).build();
let tx_verify_env = TxVerifyEnv::new_submit(&tip);

let mut verifier = TransactionScriptsVerifier::new(
Arc::new(rtx),
resource,
Arc::new(consensus),
Arc::new(tx_verify_env),
);
verifier.set_debug_printer(|script_hash, message| {
println!("script: {:x}, debug: {}", script_hash, message);
});
Expand Down
Loading

0 comments on commit f043bf1

Please sign in to comment.