Skip to content

Commit

Permalink
feat: remove all pack/unpack used
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Jul 10, 2024
1 parent ed102b7 commit 2617762
Show file tree
Hide file tree
Showing 215 changed files with 2,733 additions and 2,301 deletions.
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
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).into())
.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.clone().into())
.output_data(data.into())
.build()
})
.collect();

let genesis_block = BlockBuilder::default()
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
.compact_target(difficulty_to_compact(U256::from(1000u64)).into())
.dao(dao)
.transaction(tx)
.transactions(transactions)
Expand Down Expand Up @@ -208,7 +208,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>().into())
.build();
let block = raw_block.as_builder().header(header).build().into_view();

Expand Down
10 changes: 5 additions & 5 deletions benches/benches/benchmarks/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ 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())
.code_hash(DEFAULT_CODE_HASH.into())
.args(Bytes::from(PUBKEY_HASH.as_bytes()).into())
.hash_type(ScriptHashType::Type.into())
.build()
}
Expand All @@ -43,7 +43,7 @@ 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())
.index(0u32.into())
.build();

CellDep::new_builder()
Expand All @@ -54,11 +54,11 @@ fn cell_dep(genesis: &BlockView) -> CellDep {

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
70 changes: 35 additions & 35 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).into())
.lock(always_success_script.clone())
.build(),
)
.output_data(data.pack())
.output_data(data.into())
.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)).into())
.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.into())
.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.into())
.lock(always_success_script.clone())
.build(),
)
.output_data(Bytes::new().pack())
.output_data(Bytes::new().into())
.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.into())
.timestamp(timestamp.into())
.compact_target(epoch.compact_target().into())
.epoch(epoch.number_with_fraction(number).into())
.nonce(random::<u128>().into())
.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().into())
.build();
(cell, data)
};
Expand All @@ -219,12 +219,12 @@ 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().into())
.build();

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

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).into())
.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).into())
.output_data(data.into())
.build()
})
.collect();

let genesis_block = BlockBuilder::default()
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
.compact_target(difficulty_to_compact(U256::from(1000u64)).into())
.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.into())
.lock(secp_script.clone())
.build(),
)
.output_data(Bytes::new().pack())
.output_data(Bytes::new().into())
.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.into())
.timestamp(timestamp.into())
.compact_target(epoch.compact_target().into())
.epoch(epoch.number_with_fraction(number).into())
.nonce(random::<u128>().into())
.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).into())
.lock(lock)
.build(),
)
.output_data(data.pack())
.output_data(data.into())
.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).into())
.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).into())
.output_data(data.into())
.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])).into())
.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).into()).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
Loading

0 comments on commit 2617762

Please sign in to comment.