Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Impl from into for gen type #4512

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DEFAULT_GOAL:=help
SHELL = /bin/sh
MOLC := moleculec
MOLC_VERSION := 0.7.5
MOLC_VERSION := 0.8.0
VERBOSE := $(if ${CI},--verbose,)
CLIPPY_OPTS := -D warnings -D clippy::clone_on_ref_ptr -D clippy::redundant_clone -D clippy::enum_glob_use -D clippy::fallible_impl_from \
-A clippy::mutable_key_type -A clippy::upper_case_acronyms -A clippy::needless_return
Expand Down
14 changes: 7 additions & 7 deletions benches/benches/benchmarks/overall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const SIZES: &[usize] = &[2usize];

fn block_assembler_config() -> BlockAssemblerConfig {
let (_, _, secp_script) = secp_cell();
let args = JsonBytes::from_bytes(secp_script.args().unpack());
let args = JsonBytes::from_bytes(secp_script.args().into());
let hash_type = ScriptHashType::try_from(secp_script.hash_type()).expect("checked data");

BlockAssemblerConfig {
code_hash: secp_script.code_hash().unpack(),
code_hash: secp_script.code_hash().into(),
hash_type: hash_type.into(),
args,
message: Default::default(),
Expand Down Expand Up @@ -92,21 +92,21 @@ pub fn setup_chain(txs_size: usize) -> (Shared, ChainController) {
.map(|i| {
let data = Bytes::from(i.to_le_bytes().to_vec());
let output = CellOutput::new_builder()
.capacity(capacity_bytes!(50_000).pack())
.capacity(capacity_bytes!(50_000))
.lock(secp_script.clone())
.build();
TransactionBuilder::default()
.input(CellInput::new(OutPoint::null(), 0))
.output(output.clone())
.output(output)
.output_data(data.pack())
.output_data(data.pack())
.output_data(&data)
.output_data(&data)
.build()
})
.collect();

let genesis_block = BlockBuilder::default()
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
.compact_target(difficulty_to_compact(U256::from(1000u64)))
.dao(dao)
.transaction(tx)
.transactions(transactions)
Expand Down Expand Up @@ -207,7 +207,7 @@ fn bench(c: &mut Criterion) {
let raw_header = raw_block.header().raw();
let header = Header::new_builder()
.raw(raw_header)
.nonce(random::<u128>().pack())
.nonce(random::<u128>())
.build();
let block = raw_block.as_builder().header(header).build().into_view();

Expand Down
17 changes: 7 additions & 10 deletions benches/benches/benchmarks/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,29 @@ const DEFAULT_CODE_HASH: H256 =

fn script() -> Script {
Script::new_builder()
.code_hash(DEFAULT_CODE_HASH.pack())
.args(Bytes::from(PUBKEY_HASH.as_bytes()).pack())
.hash_type(ScriptHashType::Type.into())
.code_hash(DEFAULT_CODE_HASH)
.args(Bytes::from(PUBKEY_HASH.as_bytes()))
.hash_type(ScriptHashType::Type)
.build()
}

fn cell_dep(genesis: &BlockView) -> CellDep {
let tx_hash = genesis.transaction(1).unwrap().hash();
let out_point = OutPoint::new_builder()
.tx_hash(tx_hash)
.index(0u32.pack())
.build();
let out_point = OutPoint::new_builder().tx_hash(tx_hash).index(0u32).build();

CellDep::new_builder()
.out_point(out_point)
.dep_type(DepType::DepGroup.into())
.dep_type(DepType::DepGroup)
.build()
}

fn block_assembler_config() -> BlockAssemblerConfig {
let secp_script = script();
let args = JsonBytes::from_bytes(secp_script.args().unpack());
let args = JsonBytes::from_bytes(secp_script.args().into());
let hash_type = ScriptHashType::try_from(secp_script.hash_type()).expect("checked data");

BlockAssemblerConfig {
code_hash: secp_script.code_hash().unpack(),
code_hash: secp_script.code_hash().into(),
hash_type: hash_type.into(),
args,
message: Default::default(),
Expand Down
72 changes: 36 additions & 36 deletions benches/benches/benchmarks/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ pub fn new_always_success_chain(txs_size: usize, chains_num: usize) -> Chains {
.input(CellInput::new(OutPoint::null(), 0))
.output(
CellOutput::new_builder()
.capacity(capacity_bytes!(50_000).pack())
.capacity(capacity_bytes!(50_000))
.lock(always_success_script.clone())
.build(),
)
.output_data(data.pack())
.output_data(data)
.build()
})
.collect();

let genesis_block = BlockBuilder::default()
.dao(dao)
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
.compact_target(difficulty_to_compact(U256::from(1000u64)))
.transaction(tx)
.transactions(transactions)
.build();
Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn create_always_success_tx() -> TransactionView {
.witness(script.clone().into_witness())
.input(CellInput::new(OutPoint::null(), 0))
.output(always_success_cell.clone())
.output_data(always_success_cell_data.pack())
.output_data(always_success_cell_data)
.build()
}

Expand All @@ -110,11 +110,11 @@ pub fn create_always_success_cellbase(shared: &Shared, parent: &HeaderView) -> T
builder
.output(
CellOutput::new_builder()
.capacity(capacity.pack())
.capacity(capacity)
.lock(always_success_script.clone())
.build(),
)
.output_data(Bytes::new().pack())
.output_data(Bytes::new())
.build()
}
}
Expand Down Expand Up @@ -185,11 +185,11 @@ pub fn gen_always_success_block(
.transactions(transactions)
.proposals(proposals)
.parent_hash(p_block.hash())
.number(number.pack())
.timestamp(timestamp.pack())
.compact_target(epoch.compact_target().pack())
.epoch(epoch.number_with_fraction(number).pack())
.nonce(random::<u128>().pack())
.number(number)
.timestamp(timestamp)
.compact_target(epoch.compact_target())
.epoch(epoch.number_with_fraction(number))
.nonce(random::<u128>())
.dao(dao)
.build();

Expand All @@ -208,7 +208,7 @@ lazy_static! {
let data: Bytes = raw_data.to_vec().into();

let cell = CellOutput::new_builder()
.capacity(Capacity::bytes(data.len()).unwrap().pack())
.capacity(Capacity::bytes(data.len()).unwrap())
.build();
(cell, data)
};
Expand All @@ -219,13 +219,13 @@ lazy_static! {
let data: Bytes = raw_data.to_vec().into();

let cell = CellOutput::new_builder()
.capacity(Capacity::bytes(data.len()).unwrap().pack())
.capacity(Capacity::bytes(data.len()).unwrap())
.build();

let script = Script::new_builder()
.code_hash(CellOutput::calc_data_hash(&data))
.args(Bytes::from(PUBKEY_HASH.as_bytes()).pack())
.hash_type(ScriptHashType::Data.into())
.args(Bytes::from(PUBKEY_HASH.as_bytes()))
.hash_type(ScriptHashType::Data)
.build();

(cell, data, script)
Expand All @@ -244,7 +244,7 @@ pub fn create_secp_tx() -> TransactionView {
let (ref secp_data_cell, ref secp_data_cell_data) = secp_data_cell();
let (ref secp_cell, ref secp_cell_data, ref script) = secp_cell();
let outputs = vec![secp_data_cell.clone(), secp_cell.clone()];
let outputs_data = vec![secp_data_cell_data.pack(), secp_cell_data.pack()];
let outputs_data = vec![secp_data_cell_data.into(), secp_cell_data.into()];
TransactionBuilder::default()
.witness(script.clone().into_witness())
.input(CellInput::new(OutPoint::null(), 0))
Expand All @@ -263,21 +263,21 @@ pub fn new_secp_chain(txs_size: usize, chains_num: usize) -> Chains {
.map(|i| {
let data = Bytes::from(i.to_le_bytes().to_vec());
let output = CellOutput::new_builder()
.capacity(capacity_bytes!(50_000).pack())
.capacity(capacity_bytes!(50_000))
.lock(secp_script.clone())
.build();
TransactionBuilder::default()
.input(CellInput::new(OutPoint::null(), 0))
.output(output.clone())
.output(output)
.output_data(data.pack())
.output_data(data.pack())
.output_data(&data)
.output_data(&data)
.build()
})
.collect();

let genesis_block = BlockBuilder::default()
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
.compact_target(difficulty_to_compact(U256::from(1000u64)))
.dao(dao)
.transaction(tx)
.transactions(transactions)
Expand Down Expand Up @@ -318,11 +318,11 @@ pub fn create_secp_cellbase(shared: &Shared, parent: &HeaderView) -> Transaction
builder
.output(
CellOutput::new_builder()
.capacity(capacity.pack())
.capacity(capacity)
.lock(secp_script.clone())
.build(),
)
.output_data(Bytes::new().pack())
.output_data(Bytes::new())
.build()
}
}
Expand Down Expand Up @@ -395,11 +395,11 @@ pub fn gen_secp_block(
.transactions(transactions)
.proposals(proposals)
.parent_hash(p_block.hash())
.number(number.pack())
.timestamp(timestamp.pack())
.compact_target(epoch.compact_target().pack())
.epoch(epoch.number_with_fraction(number).pack())
.nonce(random::<u128>().pack())
.number(number)
.timestamp(timestamp)
.compact_target(epoch.compact_target())
.epoch(epoch.number_with_fraction(number))
.nonce(random::<u128>())
.dao(dao)
.build();

Expand All @@ -412,11 +412,11 @@ fn create_transaction(parent_hash: &Byte32, lock: Script, dep: OutPoint) -> Tran
TransactionBuilder::default()
.output(
CellOutput::new_builder()
.capacity(capacity_bytes!(50_000).pack())
.capacity(capacity_bytes!(50_000))
.lock(lock)
.build(),
)
.output_data(data.pack())
.output_data(data)
.input(CellInput::new(OutPoint::new(parent_hash.to_owned(), 0), 0))
.cell_dep(CellDep::new_builder().out_point(dep).build())
.build()
Expand All @@ -431,7 +431,7 @@ pub fn create_2out_transaction(

let cell_inputs = inputs.into_iter().map(|pts| CellInput::new(pts, 0));
let cell_output = CellOutput::new_builder()
.capacity(capacity_bytes!(50_000).pack())
.capacity(capacity_bytes!(50_000))
.lock(lock)
.build();

Expand All @@ -440,15 +440,15 @@ pub fn create_2out_transaction(
let raw = TransactionBuilder::default()
.output(cell_output.clone())
.output(cell_output)
.output_data(data.pack())
.output_data(data.pack())
.output_data(&data)
.output_data(&data)
.inputs(cell_inputs)
.cell_deps(cell_deps)
.build();

let privkey: Privkey = PRIVKEY.into();
let witness: WitnessArgs = WitnessArgs::new_builder()
.lock(Some(Bytes::from(vec![0u8; 65])).pack())
.lock(Some(Bytes::from(vec![0u8; 65])))
.build();
let witness_len: u64 = witness.as_bytes().len() as u64;
let non_sig_witnesses = vec![Bytes::new(); inputs_count - 1];
Expand All @@ -470,10 +470,10 @@ pub fn create_2out_transaction(
.expect("sign tx")
.serialize()
.into();
let witness = witness.as_builder().lock(Some(sig).pack()).build();
let witness = witness.as_builder().lock(Some(sig)).build();

let mut witnesses = vec![witness.as_bytes().pack()];
witnesses.extend(non_sig_witnesses.into_iter().map(|w| w.pack()));
let mut witnesses = vec![witness.as_bytes().into()];
witnesses.extend(non_sig_witnesses.into_iter().map(|w| w.into()));

raw.as_advanced_builder().set_witnesses(witnesses).build()
}
Expand Down
5 changes: 2 additions & 3 deletions block-filter/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ckb_store::{ChainDB, ChainStore};
use ckb_types::{
core::HeaderView,
packed::{Byte32, CellOutput, OutPoint},
prelude::*,
utilities::{build_filter_data, FilterDataProvider},
};

Expand All @@ -26,7 +25,7 @@ impl<'a> FilterDataProvider for WrappedChainDB<'a> {
fn cell(&self, out_point: &OutPoint) -> Option<CellOutput> {
self.inner
.get_transaction(&out_point.tx_hash())
.and_then(|(tx, _)| tx.outputs().get(out_point.index().unpack()))
.and_then(|(tx, _)| tx.outputs().get(out_point.index().into()))
}
}

Expand Down Expand Up @@ -153,7 +152,7 @@ impl BlockFilter {
db_transaction
.insert_block_filter(
&header.hash(),
&filter_data.pack(),
&filter_data.as_slice().into(),
&parent_block_filter_hash,
)
.expect("insert_block_filter should be ok");
Expand Down
4 changes: 2 additions & 2 deletions chain/src/init_load_unverified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ckb_stop_handler::has_received_stop_signal;
use ckb_store::ChainStore;
use ckb_types::core::{BlockNumber, BlockView};
use ckb_types::packed;
use ckb_types::prelude::{Entity, FromSliceShouldBeOk, Pack, Reader};
use ckb_types::prelude::{Entity, FromSliceShouldBeOk, Reader};
use std::cmp;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
Expand All @@ -34,7 +34,7 @@ impl InitLoadUnverified {
}

fn find_unverified_block_hashes(&self, check_unverified_number: u64) -> Vec<packed::Byte32> {
let pack_number: packed::Uint64 = check_unverified_number.pack();
let pack_number: packed::Uint64 = check_unverified_number.into();
let prefix = pack_number.as_slice();

// If a block has `COLUMN_NUMBER_HASH` but not `BlockExt`,
Expand Down
9 changes: 4 additions & 5 deletions chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub mod verify;
pub use chain_controller::ChainController;
use ckb_logger::{error, info};
use ckb_store::{ChainDB, ChainStore};
use ckb_types::prelude::{Pack, Unpack};
use ckb_types::{BlockNumberAndHash, H256};
pub use init::start_chain_services;

Expand Down Expand Up @@ -89,11 +88,11 @@ impl From<LonelyBlock> for LonelyBlockHash {
switch,
verify_callback,
} = val;
let block_hash_h256: H256 = block.hash().unpack();
let block_hash_h256: H256 = block.hash().into();
let block_number: BlockNumber = block.number();
let parent_hash_h256: H256 = block.parent_hash().unpack();
let block_hash = block_hash_h256.pack();
let parent_hash = parent_hash_h256.pack();
let parent_hash_h256: H256 = block.parent_hash().into();
let block_hash = block_hash_h256.into();
let parent_hash = parent_hash_h256.into();

let epoch_number: EpochNumber = block.epoch().number();

Expand Down
Loading
Loading