diff --git a/Cargo.lock b/Cargo.lock index 128d1ef557..323e455d59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1025,7 +1025,6 @@ dependencies = [ "ckb-store", "ckb-sync", "ckb-tx-pool", - "ckb-types", "ckb-verification", "ckb-verification-traits", ] diff --git a/Makefile b/Makefile index 8013f6c8a3..4ec58d1283 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/benches/benches/benchmarks/overall.rs b/benches/benches/benchmarks/overall.rs index 2f966e0318..6a1f6a86c1 100644 --- a/benches/benches/benchmarks/overall.rs +++ b/benches/benches/benchmarks/overall.rs @@ -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(), @@ -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) @@ -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::().pack()) + .nonce(random::().into()) .build(); let block = raw_block.as_builder().header(header).build().into_view(); diff --git a/benches/benches/benchmarks/resolve.rs b/benches/benches/benchmarks/resolve.rs index 29ce56bc8c..77fed91658 100644 --- a/benches/benches/benchmarks/resolve.rs +++ b/benches/benches/benchmarks/resolve.rs @@ -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() } @@ -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() @@ -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(), diff --git a/benches/benches/benchmarks/util.rs b/benches/benches/benchmarks/util.rs index 8c21dddc3b..78608f4c80 100644 --- a/benches/benches/benchmarks/util.rs +++ b/benches/benches/benchmarks/util.rs @@ -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(); @@ -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() } @@ -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() } } @@ -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::().pack()) + .number(number.into()) + .timestamp(timestamp.into()) + .compact_target(epoch.compact_target().into()) + .epoch(epoch.number_with_fraction(number).into()) + .nonce(random::().into()) .dao(dao) .build(); @@ -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) }; @@ -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(); @@ -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)) @@ -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) @@ -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() } } @@ -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::().pack()) + .number(number.into()) + .timestamp(timestamp.into()) + .compact_target(epoch.compact_target().into()) + .epoch(epoch.number_with_fraction(number).into()) + .nonce(random::().into()) .dao(dao) .build(); @@ -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() @@ -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(); @@ -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]; @@ -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() } diff --git a/block-filter/src/filter.rs b/block-filter/src/filter.rs index 3c8a217557..4b00522e49 100644 --- a/block-filter/src/filter.rs +++ b/block-filter/src/filter.rs @@ -6,7 +6,6 @@ use ckb_store::{ChainDB, ChainStore}; use ckb_types::{ core::HeaderView, packed::{Byte32, CellOutput, OutPoint}, - prelude::*, utilities::{build_filter_data, FilterDataProvider}, }; @@ -26,7 +25,7 @@ impl<'a> FilterDataProvider for WrappedChainDB<'a> { fn cell(&self, out_point: &OutPoint) -> Option { 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())) } } @@ -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"); diff --git a/chain/src/tests/basic.rs b/chain/src/tests/basic.rs index e8ad1bf182..dbcf254c90 100644 --- a/chain/src/tests/basic.rs +++ b/chain/src/tests/basic.rs @@ -10,7 +10,6 @@ use ckb_test_chain_utils::{ create_transaction, create_transaction_with_out_point, dao_data, MockChain, MockStore, }; use ckb_types::core::error::OutPointError; -use ckb_types::prelude::*; use ckb_types::{ bytes::Bytes, core::{ @@ -22,6 +21,7 @@ use ckb_types::{ utilities::{compact_to_difficulty, difficulty_to_compact}, U256, }; +use ckb_types::{packed, prelude::*}; use ckb_verification_traits::Switch; use std::sync::Arc; @@ -66,11 +66,13 @@ fn test_genesis_transaction_spend() { .input(CellInput::new(OutPoint::null(), 0)) .outputs(vec![ CellOutputBuilder::default() - .capacity(capacity_bytes!(100_000_000).pack()) + .capacity(capacity_bytes!(100_000_000).into()) .build(); 100 ]) - .outputs_data(vec![Bytes::new(); 100].pack()) + .outputs_data(Into::::into( + vec![Bytes::new(); 100].as_slice(), + )) .build(); let always_success_tx = create_always_success_tx(); @@ -83,7 +85,7 @@ fn test_genesis_transaction_spend() { let genesis_block = BlockBuilder::default() .transaction(tx) .transaction(always_success_tx) - .compact_target(difficulty_to_compact(U256::from(1000u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) .dao(dao) .build(); @@ -376,12 +378,14 @@ fn test_genesis_transaction_fetch() { .input(CellInput::new(OutPoint::null(), 0)) .outputs(vec![ CellOutputBuilder::default() - .capacity(capacity_bytes!(100_000_000).pack()) + .capacity(capacity_bytes!(100_000_000).into()) .lock(Script::default()) .build(); 100 ]) - .outputs_data(vec![Bytes::new(); 100].pack()) + .outputs_data(Into::::into( + vec![Bytes::new(); 100].as_slice(), + )) .build(); let dao = genesis_dao_data(vec![&tx]).unwrap(); @@ -389,7 +393,7 @@ fn test_genesis_transaction_fetch() { let genesis_block = BlockBuilder::default() .dao(dao) .transaction(tx) - .compact_target(difficulty_to_compact(U256::from(1000u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) .build(); let consensus = ConsensusBuilder::default() @@ -521,10 +525,10 @@ fn prepare_context_chain( let new_block = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .timestamp((parent.timestamp() + timestep).pack()) - .compact_target(epoch.compact_target().pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .timestamp((parent.timestamp() + timestep).into()) + .compact_target(epoch.compact_target().into()) .transactions(transactions) .dao(dao) .build(); @@ -561,10 +565,10 @@ fn prepare_context_chain( let new_block = BlockBuilder::default() .parent_hash(parent.hash()) .uncles(uncles) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .timestamp((parent.timestamp() + timestep).pack()) - .compact_target(epoch.compact_target().pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .timestamp((parent.timestamp() + timestep).into()) + .compact_target(epoch.compact_target().into()) .transactions(transactions) .dao(dao) .build(); @@ -587,7 +591,7 @@ fn test_epoch_hash_rate_dampening() { .build(); let dao = genesis_dao_data(vec![&cellbase]).unwrap(); let genesis_block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(1000u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) .transaction(cellbase) .dao(dao) .build(); @@ -680,7 +684,7 @@ fn test_orphan_rate_estimation_overflow() { let dao = genesis_dao_data(vec![&cellbase]).unwrap(); let genesis_block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(1000u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) .transaction(cellbase) .dao(dao) .build(); @@ -734,7 +738,7 @@ fn test_next_epoch_ext() { .build(); let dao = genesis_dao_data(vec![&cellbase]).unwrap(); let genesis_block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(1000u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) .transaction(cellbase) .dao(dao) .build(); diff --git a/chain/src/tests/block_assembler.rs b/chain/src/tests/block_assembler.rs index d5f34c3188..42caff5c32 100644 --- a/chain/src/tests/block_assembler.rs +++ b/chain/src/tests/block_assembler.rs @@ -99,18 +99,18 @@ fn gen_block(parent_header: &HeaderView, nonce: u128, epoch: &EpochExt) -> Block let dao = genesis_dao_data(vec![&cellbase]).unwrap(); let header = HeaderBuilder::default() .parent_hash(parent_header.hash()) - .timestamp((parent_header.timestamp() + 10).pack()) - .number(number.pack()) - .epoch(epoch.number_with_fraction(number).pack()) - .compact_target(epoch.compact_target().pack()) - .nonce(nonce.pack()) + .timestamp((parent_header.timestamp() + 10).into()) + .number(number.into()) + .epoch(epoch.number_with_fraction(number).into()) + .compact_target(epoch.compact_target().into()) + .nonce(nonce.into()) .dao(dao) .build(); BlockBuilder::default() .header(header) .transaction(cellbase) - .proposal([1; 10].pack()) + .proposal([1; 10].into()) .build_unchecked() } @@ -119,7 +119,7 @@ fn create_cellbase(number: BlockNumber, epoch: &EpochExt) -> TransactionView { .input(CellInput::new_cellbase_input(number)) .output( CellOutput::new_builder() - .capacity(epoch.block_reward(number).unwrap().pack()) + .capacity(epoch.block_reward(number).unwrap().into()) .build(), ) .output_data(Default::default()) @@ -229,7 +229,7 @@ fn test_prepare_uncles() { .unwrap() .unwrap() } - assert_eq!(block_template.uncles[0].hash, block0_0.hash().unpack()); + assert_eq!(block_template.uncles[0].hash, block0_0.hash().into()); let epoch = shared .consensus() @@ -253,7 +253,7 @@ fn test_prepare_uncles() { .unwrap() } // block number 4, epoch 0, uncles should retained - assert_eq!(block_template.uncles[0].hash, block0_0.hash().unpack()); + assert_eq!(block_template.uncles[0].hash, block0_0.hash().into()); let epoch = shared .consensus() @@ -376,12 +376,12 @@ fn build_tx(parent_tx: &TransactionView, inputs: &[u32], outputs_len: usize) -> (0..outputs_len) .map(|_| { CellOutputBuilder::default() - .capacity(per_output_capacity.pack()) + .capacity(per_output_capacity.into()) .build() }) .collect::>(), ) - .outputs_data((0..outputs_len).map(|_| Bytes::new().pack())) + .outputs_data((0..outputs_len).map(|_| Bytes::new().into())) .build() } diff --git a/chain/src/tests/cell.rs b/chain/src/tests/cell.rs index 3d9c2fd5b9..74efb94358 100644 --- a/chain/src/tests/cell.rs +++ b/chain/src/tests/cell.rs @@ -37,10 +37,10 @@ pub(crate) fn create_cellbase( builder .output( CellOutputBuilder::default() - .capacity(capacity.pack()) + .capacity(capacity.into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build() } } @@ -66,10 +66,10 @@ pub(crate) fn gen_block( let block = BlockBuilder::default() .parent_hash(parent_header.hash()) - .timestamp((parent_header.timestamp() + 20_000).pack()) - .number(number.pack()) - .compact_target(epoch.compact_target().pack()) - .epoch(epoch.number_with_fraction(number).pack()) + .timestamp((parent_header.timestamp() + 20_000).into()) + .number(number.into()) + .compact_target(epoch.compact_target().into()) + .epoch(epoch.number_with_fraction(number).into()) .transactions(txs) .build(); @@ -83,16 +83,16 @@ pub(crate) fn create_transaction(parent: &TransactionView, index: u32) -> Transa .get(0) .expect("get output index 0") .capacity() - .unpack(); + .into(); TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().pack()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) .build(), ) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build() } @@ -104,11 +104,11 @@ fn test_block_cells_update() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -116,7 +116,7 @@ fn test_block_cells_update() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); diff --git a/chain/src/tests/delay_verify.rs b/chain/src/tests/delay_verify.rs index 77ed3780b7..b616d29a1f 100644 --- a/chain/src/tests/delay_verify.rs +++ b/chain/src/tests/delay_verify.rs @@ -6,7 +6,6 @@ use ckb_test_chain_utils::{ create_transaction_with_out_point, dao_data, MockChain, MockStore, }; use ckb_types::core::error::OutPointError; -use ckb_types::prelude::*; use ckb_types::{core::BlockBuilder, packed::OutPoint}; use ckb_verification_traits::Switch; use std::sync::Arc; @@ -287,9 +286,9 @@ fn test_full_dead_transaction() { let block = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transaction(cellbase_tx) .build(); @@ -327,9 +326,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transactions(transactions) .proposals(vec![tx1.proposal_short_id()]) @@ -348,9 +347,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transactions(transactions) .build() @@ -365,9 +364,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transactions(transactions) .build() @@ -407,9 +406,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transactions(transactions) .proposals(vec![tx2.proposal_short_id(), tx3.proposal_short_id()]) @@ -429,9 +428,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transactions(transactions) .build() @@ -448,9 +447,9 @@ fn test_full_dead_transaction() { BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transactions(transactions) .build() @@ -479,9 +478,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .proposals(vec![tx2.proposal_short_id(), tx3.proposal_short_id()]) .transactions(transactions) @@ -501,9 +500,9 @@ fn test_full_dead_transaction() { ); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transactions(transactions) .build() @@ -520,9 +519,9 @@ fn test_full_dead_transaction() { BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target((compact_target - 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target((compact_target - 1).into()) .dao(dao) .transactions(transactions) .build() diff --git a/chain/src/tests/dep_cell.rs b/chain/src/tests/dep_cell.rs index cac812d6ae..c95c858777 100644 --- a/chain/src/tests/dep_cell.rs +++ b/chain/src/tests/dep_cell.rs @@ -31,7 +31,7 @@ pub(crate) fn build_tx( .iter() .map(|index| { let output = inputs.0.output(*index as usize).expect("output index"); - let cap: Capacity = output.capacity().unpack(); + let cap: Capacity = output.capacity().into(); cap }) .try_fold(Capacity::zero(), Capacity::safe_add) @@ -45,13 +45,13 @@ pub(crate) fn build_tx( (0..outputs_len) .map(|_| { CellOutputBuilder::default() - .capacity(per_output_capacity.pack()) + .capacity(per_output_capacity.into()) .lock(always_success_script.clone()) .build() }) .collect::>(), ) - .outputs_data((0..outputs_len).map(|_| Bytes::new().pack())) + .outputs_data((0..outputs_len).map(|_| Bytes::new().into())) .cell_deps(cell_deps.1.iter().map(|index| { CellDep::new_builder() .out_point(OutPoint::new(cell_deps.0.hash(), *index)) @@ -79,18 +79,18 @@ fn test_package_txs_with_deps() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -98,7 +98,7 @@ fn test_package_txs_with_deps() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); @@ -211,25 +211,25 @@ fn test_package_txs_with_deps_unstable_sort() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) - .output_data(Bytes::new().pack()) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) + .output_data(Bytes::new().into()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -237,7 +237,7 @@ fn test_package_txs_with_deps_unstable_sort() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); @@ -355,25 +355,25 @@ fn test_package_txs_with_deps2() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) - .output_data(Bytes::new().pack()) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) + .output_data(Bytes::new().into()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -381,7 +381,7 @@ fn test_package_txs_with_deps2() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); @@ -492,18 +492,18 @@ fn test_package_txs_with_deps_priority() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -511,7 +511,7 @@ fn test_package_txs_with_deps_priority() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); diff --git a/chain/src/tests/find_fork.rs b/chain/src/tests/find_fork.rs index eb1f4208a8..811fda08df 100644 --- a/chain/src/tests/find_fork.rs +++ b/chain/src/tests/find_fork.rs @@ -6,9 +6,7 @@ use ckb_systemtime::unix_time_as_millis; use ckb_test_chain_utils::{MockChain, MockStore}; use ckb_types::{ core::{BlockBuilder, BlockExt, BlockView}, - packed, - prelude::Pack, - U256, + packed, U256, }; use ckb_verification_traits::Switch; use std::collections::HashSet; @@ -354,10 +352,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block1 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .compact_target(parent.compact_target().pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .nonce(1u128.pack()) + .number((parent.number() + 1).into()) + .compact_target(parent.compact_target().into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .nonce(1u128.into()) .uncle(uncle) .build(); chain_service @@ -373,10 +371,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block2 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .compact_target(parent.compact_target().pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .nonce(2u128.pack()) + .number((parent.number() + 1).into()) + .compact_target(parent.compact_target().into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .nonce(2u128.into()) .build(); parent = new_block2.clone(); chain_service @@ -389,10 +387,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block3 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .compact_target(parent.compact_target().pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .nonce(2u128.pack()) + .number((parent.number() + 1).into()) + .compact_target(parent.compact_target().into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .nonce(2u128.into()) .build(); chain_service .process_block(Arc::new(new_block3), Switch::DISABLE_ALL) @@ -407,10 +405,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block4 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .compact_target(parent.compact_target().pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .nonce(1u128.pack()) + .number((parent.number() + 1).into()) + .compact_target(parent.compact_target().into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .nonce(1u128.into()) .build(); chain_service .process_block(Arc::new(new_block4.clone()), Switch::DISABLE_ALL) @@ -424,10 +422,10 @@ fn repeatedly_switch_fork() { .epoch(); let new_block5 = BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .compact_target(parent.compact_target().pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .nonce(1u128.pack()) + .number((parent.number() + 1).into()) + .compact_target(parent.compact_target().into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .nonce(1u128.into()) .build(); chain_service .process_block(Arc::new(new_block5), Switch::DISABLE_ALL) diff --git a/chain/src/tests/load_code_with_snapshot.rs b/chain/src/tests/load_code_with_snapshot.rs index 42db84283d..b8d1128c33 100644 --- a/chain/src/tests/load_code_with_snapshot.rs +++ b/chain/src/tests/load_code_with_snapshot.rs @@ -27,9 +27,9 @@ pub(crate) fn create_load_is_even_script_tx() -> TransactionView { .witness(load_is_even_script.clone().into_witness()) .input(CellInput::new(OutPoint::null(), 0)) .output(load_is_even_cell.clone()) - .output_data(load_is_even_data.pack()) + .output_data(load_is_even_data.into()) .output(is_even_lib_cell.clone()) - .output_data(is_even_lib_data.pack()) + .output_data(is_even_lib_data.into()) .build() } @@ -41,15 +41,15 @@ pub(crate) fn create_call_load_is_even_tx(parent: &TransactionView, index: u32) .get(0) .expect("get output index 0") .capacity() - .unpack(); + .into(); TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().pack()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) .cell_dep(CellDep::new_builder().out_point(is_even_lib).build()) .cell_dep(CellDep::new_builder().out_point(load_is_even).build()) @@ -69,7 +69,7 @@ fn test_load_code() { let mut vec = Vec::with_capacity(40); vec.extend_from_slice(&number.to_le_bytes()); vec.extend_from_slice(&data_hash); - vec.pack() + vec.as_slice().into() }; let lock_script = Script::new_builder() @@ -82,11 +82,11 @@ fn test_load_code() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(lock_script) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&load_is_even_script_tx, &issue_tx]).unwrap(); @@ -94,7 +94,7 @@ fn test_load_code() { let genesis_block = BlockBuilder::default() .transaction(load_is_even_script_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); @@ -130,7 +130,7 @@ fn test_load_code_with_snapshot() { let mut vec = Vec::with_capacity(40); vec.extend_from_slice(&number.to_le_bytes()); vec.extend_from_slice(&data_hash); - vec.pack() + vec.as_slice().into() }; let lock_script = Script::new_builder() @@ -143,11 +143,11 @@ fn test_load_code_with_snapshot() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(lock_script) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&load_is_even_script_tx, &issue_tx]).unwrap(); @@ -155,7 +155,7 @@ fn test_load_code_with_snapshot() { let genesis_block = BlockBuilder::default() .transaction(load_is_even_script_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); @@ -209,7 +209,7 @@ fn _test_load_code_with_snapshot_after_hardfork(script_type: ScriptHashType) { let mut vec = Vec::with_capacity(40); vec.extend_from_slice(&number.to_le_bytes()); vec.extend_from_slice(&data_hash); - vec.pack() + vec.as_slice().into() }; let lock_script = Script::new_builder() @@ -222,11 +222,11 @@ fn _test_load_code_with_snapshot_after_hardfork(script_type: ScriptHashType) { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(lock_script) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&load_is_even_script_tx, &issue_tx]).unwrap(); @@ -234,7 +234,7 @@ fn _test_load_code_with_snapshot_after_hardfork(script_type: ScriptHashType) { let genesis_block = BlockBuilder::default() .transaction(load_is_even_script_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); diff --git a/chain/src/tests/load_input_cell_data.rs b/chain/src/tests/load_input_cell_data.rs index 236a952325..67e15590b2 100644 --- a/chain/src/tests/load_input_cell_data.rs +++ b/chain/src/tests/load_input_cell_data.rs @@ -30,16 +30,16 @@ pub(crate) fn create_load_input_one_byte_transaction( .get(0) .expect("get output index 0") .capacity() - .unpack(); + .into(); TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().pack()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) .lock(load_input_one_byte_script.clone()) .build(), ) - .output_data(Bytes::from(b"1".to_vec()).pack()) + .output_data(Bytes::from(b"1".to_vec()).into()) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) .cell_dep( CellDep::new_builder() @@ -59,11 +59,11 @@ fn test_load_input_one_byte_cell() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(load_input_one_byte_script.clone()) .build(), ) - .output_data(Bytes::from(b"1".to_vec()).pack()) + .output_data(Bytes::from(b"1".to_vec()).into()) .build(); let dao = genesis_dao_data(vec![&load_input_one_byte_cell_tx, &issue_tx]).unwrap(); @@ -71,7 +71,7 @@ fn test_load_input_one_byte_cell() { let genesis_block = BlockBuilder::default() .transaction(load_input_one_byte_cell_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); diff --git a/chain/src/tests/load_input_data_hash_cell.rs b/chain/src/tests/load_input_data_hash_cell.rs index b753c1d91f..f445dd2d19 100644 --- a/chain/src/tests/load_input_data_hash_cell.rs +++ b/chain/src/tests/load_input_data_hash_cell.rs @@ -30,16 +30,16 @@ pub(crate) fn create_load_input_data_hash_transaction( .get(0) .expect("get output index 0") .capacity() - .unpack(); + .into(); TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().pack()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) .lock(load_input_data_hash_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) .cell_dep( CellDep::new_builder() @@ -59,11 +59,11 @@ fn test_load_input_data_hash_cell() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(load_input_data_hash_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&load_input_data_hash_cell_tx, &issue_tx]).unwrap(); @@ -71,7 +71,7 @@ fn test_load_input_data_hash_cell() { let genesis_block = BlockBuilder::default() .transaction(load_input_data_hash_cell_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); diff --git a/chain/src/tests/non_contextual_block_txs_verify.rs b/chain/src/tests/non_contextual_block_txs_verify.rs index b8317363a3..8565a1712d 100644 --- a/chain/src/tests/non_contextual_block_txs_verify.rs +++ b/chain/src/tests/non_contextual_block_txs_verify.rs @@ -42,11 +42,11 @@ pub(crate) fn create_cellbase( builder .output( CellOutputBuilder::default() - .capacity(capacity.pack()) + .capacity(capacity.into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build() } } @@ -72,10 +72,10 @@ pub(crate) fn gen_block( let block = BlockBuilder::default() .parent_hash(parent_header.hash()) - .timestamp((parent_header.timestamp() + 20_000).pack()) - .number(number.pack()) - .compact_target(epoch.compact_target().pack()) - .epoch(epoch.number_with_fraction(number).pack()) + .timestamp((parent_header.timestamp() + 20_000).into()) + .number(number.into()) + .compact_target(epoch.compact_target().into()) + .epoch(epoch.number_with_fraction(number).into()) .transactions(txs) .build(); @@ -96,12 +96,12 @@ pub(crate) fn create_transaction( .get(0) .expect("get output index 0") .capacity() - .unpack(); + .into(); let mut builder = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().pack()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) .lock(always_success_script.clone()) .build(), ) @@ -113,7 +113,7 @@ pub(crate) fn create_transaction( ); if !missing_output_data { - builder = builder.output_data(Bytes::new().pack()) + builder = builder.output_data(Bytes::new().into()) } builder.build() } @@ -127,11 +127,11 @@ fn non_contextual_block_txs_verify() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &issue_tx]).unwrap(); @@ -139,7 +139,7 @@ fn non_contextual_block_txs_verify() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(issue_tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); diff --git a/chain/src/tests/reward.rs b/chain/src/tests/reward.rs index 73de141c86..7add2e3a09 100644 --- a/chain/src/tests/reward.rs +++ b/chain/src/tests/reward.rs @@ -47,11 +47,11 @@ pub(crate) fn create_cellbase( builder .output( CellOutputBuilder::default() - .capacity(reward.unwrap_or(capacity).pack()) + .capacity(reward.unwrap_or(capacity).into()) .lock(reward_lock) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build() } } @@ -91,10 +91,10 @@ pub(crate) fn gen_block( let block = BlockBuilder::default() .parent_hash(parent_header.hash()) - .timestamp((parent_header.timestamp() + 20_000).pack()) - .number(number.pack()) - .compact_target(epoch.compact_target().pack()) - .epoch(epoch.number_with_fraction(number).pack()) + .timestamp((parent_header.timestamp() + 20_000).into()) + .number(number.into()) + .compact_target(epoch.compact_target().into()) + .epoch(epoch.number_with_fraction(number).into()) .dao(dao) .transactions(txs) .uncles(uncles) @@ -115,16 +115,16 @@ pub(crate) fn create_transaction(parent: &TransactionView, index: u32) -> Transa .get(0) .expect("get output index 0") .capacity() - .unpack(); + .into(); TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(input_cap.safe_sub(TX_FEE).unwrap().pack()) + .capacity(input_cap.safe_sub(TX_FEE).unwrap().into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .input(CellInput::new(OutPoint::new(parent.hash(), index), 0)) .cell_dep( CellDep::new_builder() @@ -142,11 +142,11 @@ fn finalize_reward() { .input(CellInput::new(OutPoint::null(), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(5_000).pack()) + .capacity(capacity_bytes!(5_000).into()) .lock(always_success_script.clone()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let dao = genesis_dao_data(vec![&always_success_tx, &tx]).unwrap(); @@ -154,7 +154,7 @@ fn finalize_reward() { let genesis_block = BlockBuilder::default() .transaction(always_success_tx) .transaction(tx.clone()) - .compact_target(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .dao(dao) .build(); @@ -176,7 +176,7 @@ fn finalize_reward() { let ids: Vec<_> = txs.iter().map(TransactionView::proposal_short_id).collect(); let mut blocks = Vec::with_capacity(24); - let bob_args: packed::Bytes = Bytes::from(b"b0b".to_vec()).pack(); + let bob_args: packed::Bytes = Bytes::from(b"b0b".to_vec()).into(); let bob = ScriptBuilder::default() .args(bob_args) @@ -184,7 +184,7 @@ fn finalize_reward() { .hash_type(ScriptHashType::Data.into()) .build(); - let alice_args: packed::Bytes = Bytes::from(b"a11ce".to_vec()).pack(); + let alice_args: packed::Bytes = Bytes::from(b"a11ce".to_vec()).into(); let alice = ScriptBuilder::default() .args(alice_args) .code_hash(always_success_script.code_hash()) diff --git a/chain/src/tests/util.rs b/chain/src/tests/util.rs index 0d42b0def6..4f7fe4cf47 100644 --- a/chain/src/tests/util.rs +++ b/chain/src/tests/util.rs @@ -42,18 +42,18 @@ pub(crate) fn start_chain_with_tx_pool_config( .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(DIFF_TWO.pack()) + .compact_target(DIFF_TWO.into()) .transaction(tx) .transactions(transactions) .build(); diff --git a/ckb-bin/src/subcommand/init.rs b/ckb-bin/src/subcommand/init.rs index 2cdcc13b26..36a076c91d 100644 --- a/ckb-bin/src/subcommand/init.rs +++ b/ckb-bin/src/subcommand/init.rs @@ -10,7 +10,7 @@ use ckb_resource::{ Resource, TemplateContext, AVAILABLE_SPECS, CKB_CONFIG_FILE_NAME, DB_OPTIONS_FILE_NAME, MINER_CONFIG_FILE_NAME, SPEC_DEV_FILE_NAME, }; -use ckb_types::{prelude::*, H256}; +use ckb_types::H256; const DEFAULT_LOCK_SCRIPT_HASH_TYPE: &str = "type"; const SECP256K1_BLAKE160_SIGHASH_ALL_ARG_LEN: usize = 20 * 2 + 2; // 42 = 20 x 2 + prefix 0x @@ -79,7 +79,7 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> { .build_consensus() .expect("Build consensus failed") .get_secp_type_script_hash() - .unpack(); + .into(); format!("{hash:#x}") }); diff --git a/ckb-bin/src/subcommand/list_hashes.rs b/ckb-bin/src/subcommand/list_hashes.rs index 62e431c10b..cdff023aad 100644 --- a/ckb-bin/src/subcommand/list_hashes.rs +++ b/ckb-bin/src/subcommand/list_hashes.rs @@ -1,7 +1,7 @@ use ckb_app_config::{cli, CKBAppConfig, ExitCode}; use ckb_chain_spec::ChainSpec; use ckb_resource::{Resource, AVAILABLE_SPECS}; -use ckb_types::{packed::CellOutput, prelude::*, H256}; +use ckb_types::{packed::CellOutput, H256}; use ckb_util::LinkedHashMap; use clap::ArgMatches; use serde::{Deserialize, Serialize}; @@ -39,7 +39,7 @@ impl TryFrom for SpecHashes { let hash_option = spec.genesis.hash.take(); let consensus = spec.build_consensus().map_err(to_config_error)?; if let Some(hash) = hash_option { - let genesis_hash: H256 = consensus.genesis_hash().unpack(); + let genesis_hash: H256 = consensus.genesis_hash().into(); if hash != genesis_hash { eprintln!( "Genesis hash unmatched in {} chainspec config file:\n\ @@ -69,14 +69,14 @@ impl TryFrom for SpecHashes { ) .enumerate() .map(|(index_minus_one, (resource, (output, data)))| { - let data_hash: H256 = CellOutput::calc_data_hash(&data.raw_data()).unpack(); + let data_hash: H256 = CellOutput::calc_data_hash(&data.raw_data()).into(); let type_hash: Option = output .type_() .to_opt() - .map(|script| script.calc_script_hash().unpack()); + .map(|script| script.calc_script_hash().into()); SystemCell { path: resource.to_string(), - tx_hash: cellbase.hash().unpack(), + tx_hash: cellbase.hash().into(), index: index_minus_one + 1, data_hash, type_hash, @@ -95,15 +95,15 @@ impl TryFrom for SpecHashes { .iter() .map(|res| res.to_string()) .collect::>(), - tx_hash: dep_group_tx.hash().unpack(), + tx_hash: dep_group_tx.hash().into(), index, }) .collect::>(); Ok(SpecHashes { - spec_hash: spec.hash.unpack(), - genesis: consensus.genesis_hash().unpack(), - cellbase: cellbase.hash().unpack(), + spec_hash: spec.hash.into(), + genesis: consensus.genesis_hash().into(), + cellbase: cellbase.hash().into(), system_cells: cells_hashes, dep_groups, }) diff --git a/miner/src/miner.rs b/miner/src/miner.rs index 436ea53ca4..d600e760a4 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -116,8 +116,7 @@ impl Miner { let parent_hash = work.block.header().into_view().parent_hash(); if !self.legacy_work.contains(&parent_hash) { let pow_hash = work.block.header().calc_pow_hash(); - let (target, _) = - compact_to_target(work.block.header().raw().compact_target().unpack()); + let (target, _) = compact_to_target(work.block.header().raw().compact_target().into()); self.notify_workers(WorkerMessage::NewWork { pow_hash, work, @@ -131,7 +130,7 @@ impl Miner { let raw_header = work.block.header().raw(); let header = Header::new_builder() .raw(raw_header) - .nonce(nonce.pack()) + .nonce(nonce.into()) .build(); let block = work .block diff --git a/network/src/protocols/discovery/protocol.rs b/network/src/protocols/discovery/protocol.rs index 0950e48784..c5f16f025c 100644 --- a/network/src/protocols/discovery/protocol.rs +++ b/network/src/protocols/discovery/protocol.rs @@ -32,8 +32,8 @@ impl DiscoveryMessage { listen_port, required_flags, } => { - let version = version.pack(); - let count = count.pack(); + let version = version.into(); + let count = count.into(); let listen_port = packed::PortOpt::new_builder() .set(listen_port.map(|port| { let port_le = port.to_le_bytes(); @@ -43,7 +43,7 @@ impl DiscoveryMessage { .build() })) .build(); - let required_flags = required_flags.bits().pack(); + let required_flags = required_flags.bits().into(); let get_node = packed::GetNodes2::new_builder() .listen_port(listen_port) .count(count) @@ -70,7 +70,7 @@ impl DiscoveryMessage { ) } let bytes_vec = packed::BytesVec::new_builder().set(vec_addrs).build(); - let flags = item.flags.bits().pack(); + let flags = item.flags.bits().into(); let node = packed::Node2::new_builder() .addresses(bytes_vec) .flags(flags) @@ -118,7 +118,7 @@ impl DiscoveryMessage { let get_nodes2 = packed::GetNodes2::from_compatible_slice(reader.as_slice()).ok()?; let reader = get_nodes2.as_reader(); - Flags::from_bits_truncate(reader.required_flags().unpack()) + Flags::from_bits_truncate(reader.required_flags().into()) } else { Flags::COMPATIBILITY }; @@ -146,7 +146,7 @@ impl DiscoveryMessage { let node2 = packed::Node2::from_compatible_slice(node_reader.as_slice()).ok()?; let reader = node2.as_reader(); - Flags::from_bits_truncate(reader.flags().unpack()) + Flags::from_bits_truncate(reader.flags().into()) } else { Flags::COMPATIBILITY }; diff --git a/network/src/protocols/identify/mod.rs b/network/src/protocols/identify/mod.rs index 8f2448050d..0c3a0bb8f7 100644 --- a/network/src/protocols/identify/mod.rs +++ b/network/src/protocols/identify/mod.rs @@ -588,9 +588,9 @@ impl Identify { fn new(name: String, flags: Flags, client_version: String) -> Self { Identify { encode_data: packed::Identify::new_builder() - .name(name.as_str().pack()) - .flag(flags.bits().pack()) - .client_version(client_version.as_str().pack()) + .name(name.as_str().into()) + .flag(flags.bits().into()) + .client_version(client_version.as_str().into()) .build() .as_bytes(), name, @@ -613,7 +613,7 @@ impl Identify { return None; } - let flag: u64 = reader.flag().unpack(); + let flag: u64 = reader.flag().into(); if flag == 0 { return None; } diff --git a/pow/src/eaglesong.rs b/pow/src/eaglesong.rs index f7bb88be27..456f131945 100644 --- a/pow/src/eaglesong.rs +++ b/pow/src/eaglesong.rs @@ -9,12 +9,11 @@ pub struct EaglesongPowEngine; impl PowEngine for EaglesongPowEngine { fn verify(&self, header: &Header) -> bool { - let input = - crate::pow_message(&header.as_reader().calc_pow_hash(), header.nonce().unpack()); + let input = crate::pow_message(&header.as_reader().calc_pow_hash(), header.nonce().into()); let mut output = [0u8; 32]; eaglesong(&input, &mut output); - let (block_target, overflow) = compact_to_target(header.raw().compact_target().unpack()); + let (block_target, overflow) = compact_to_target(header.raw().compact_target().into()); if block_target.is_zero() || overflow { debug!( @@ -43,7 +42,7 @@ impl PowEngine for EaglesongPowEngine { ); debug!( "PowEngine::verify error: nonce {:#x}", - header.nonce().unpack() + Into::::into(header.nonce()) ); debug!( "PowEngine::verify error: pow input: 0x{:x}", diff --git a/pow/src/eaglesong_blake2b.rs b/pow/src/eaglesong_blake2b.rs index 0b87aed9ad..fbfbbd6df5 100644 --- a/pow/src/eaglesong_blake2b.rs +++ b/pow/src/eaglesong_blake2b.rs @@ -10,15 +10,14 @@ pub struct EaglesongBlake2bPowEngine; impl PowEngine for EaglesongBlake2bPowEngine { fn verify(&self, header: &Header) -> bool { - let input = - crate::pow_message(&header.as_reader().calc_pow_hash(), header.nonce().unpack()); + let input = crate::pow_message(&header.as_reader().calc_pow_hash(), header.nonce().into()); let output = { let mut output_tmp = [0u8; 32]; eaglesong(&input, &mut output_tmp); blake2b_256(output_tmp) }; - let (block_target, overflow) = compact_to_target(header.raw().compact_target().unpack()); + let (block_target, overflow) = compact_to_target(header.raw().compact_target().into()); if block_target.is_zero() || overflow { debug!( @@ -51,7 +50,7 @@ impl PowEngine for EaglesongBlake2bPowEngine { ); debug!( "PowEngine::verify error: nonce {:#x}", - header.nonce().unpack() + Into::::into(header.nonce()) ); debug!( "PowEngine::verify error: pow input: 0x{:x}", diff --git a/pow/src/tests.rs b/pow/src/tests.rs index ad4f27ca26..fafeabd3dd 100644 --- a/pow/src/tests.rs +++ b/pow/src/tests.rs @@ -1,10 +1,9 @@ use crate::pow_message; use ckb_hash::blake2b_256; -use ckb_types::prelude::*; #[test] fn test_pow_message() { - let zero_hash = blake2b_256([]).pack(); + let zero_hash = blake2b_256([]).into(); let nonce = u128::max_value(); let message = pow_message(&zero_hash, nonce); assert_eq!( diff --git a/rpc/src/module/alert.rs b/rpc/src/module/alert.rs index 959ea2e3ee..fe6a243a03 100644 --- a/rpc/src/module/alert.rs +++ b/rpc/src/module/alert.rs @@ -99,7 +99,7 @@ impl AlertRpc for AlertRpcImpl { fn send_alert(&self, alert: Alert) -> Result<()> { let alert: packed::Alert = alert.into(); let now_ms = ckb_systemtime::unix_time_as_millis(); - let notice_until: u64 = alert.raw().notice_until().unpack(); + let notice_until: u64 = alert.raw().notice_until().into(); if notice_until < now_ms { return Err(RPCError::invalid_params(format!( "Expected `params[0].notice_until` in the future (> {now_ms}), got {notice_until}", diff --git a/rpc/src/module/chain.rs b/rpc/src/module/chain.rs index a7d2c861fb..94bdd20ad6 100644 --- a/rpc/src/module/chain.rs +++ b/rpc/src/module/chain.rs @@ -1634,7 +1634,7 @@ impl ChainRpc for ChainRpcImpl { with_cycles: Option, ) -> Result> { let snapshot = self.shared.snapshot(); - let block_hash = block_hash.pack(); + let block_hash = block_hash.into(); self.get_block_by_hash(&snapshot, &block_hash, verbosity, with_cycles) } @@ -1671,7 +1671,7 @@ impl ChainRpc for ChainRpcImpl { verbosity: Option, ) -> Result>> { let snapshot = self.shared.snapshot(); - let block_hash = block_hash.pack(); + let block_hash = block_hash.into(); if !snapshot.is_main_chain(&block_hash) { return Ok(None); } @@ -1729,7 +1729,7 @@ impl ChainRpc for ChainRpcImpl { fn get_block_filter(&self, block_hash: H256) -> Result> { let store = self.shared.store(); - let block_hash = block_hash.pack(); + let block_hash = block_hash.into(); if !store.is_main_chain(&block_hash) { return Ok(None); } @@ -1750,7 +1750,7 @@ impl ChainRpc for ChainRpcImpl { verbosity: Option, only_committed: Option, ) -> Result { - let tx_hash = tx_hash.pack(); + let tx_hash = tx_hash.into(); let verbosity = verbosity .map(|v| v.value()) .unwrap_or(DEFAULT_GET_TRANSACTION_VERBOSITY_LEVEL); @@ -1782,7 +1782,7 @@ impl ChainRpc for ChainRpcImpl { .shared .snapshot() .get_block_hash(block_number.into()) - .map(|h| h.unpack())) + .map(|h| h.into())) } fn get_tip_header(&self, verbosity: Option) -> Result> { @@ -1804,7 +1804,7 @@ impl ChainRpc for ChainRpcImpl { fn get_current_epoch(&self) -> Result { Ok(EpochView::from_ext( - self.shared.snapshot().epoch_ext().pack(), + self.shared.snapshot().epoch_ext().into(), )) } @@ -1815,7 +1815,7 @@ impl ChainRpc for ChainRpcImpl { .and_then(|hash| { snapshot .get_epoch_ext(&hash) - .map(|ext| EpochView::from_ext(ext.pack())) + .map(|ext| EpochView::from_ext(ext.into())) })) } @@ -1846,12 +1846,12 @@ impl ChainRpc for ChainRpcImpl { fn get_block_economic_state(&self, block_hash: H256) -> Result> { let snapshot = self.shared.snapshot(); - let block_number = if let Some(block_number) = snapshot.get_block_number(&block_hash.pack()) - { - block_number - } else { - return Ok(None); - }; + let block_number = + if let Some(block_number) = snapshot.get_block_number(&(&block_hash).into()) { + block_number + } else { + return Ok(None); + }; let delay_length = snapshot.consensus().finalization_delay_length(); let finalized_at_number = block_number + delay_length; @@ -1859,7 +1859,7 @@ impl ChainRpc for ChainRpcImpl { return Ok(None); } - let block_hash = block_hash.pack(); + let block_hash = (&block_hash).into(); let finalized_at = if let Some(block_hash) = snapshot.get_block_hash(finalized_at_number) { block_hash } else { @@ -1918,8 +1918,8 @@ impl ChainRpc for ChainRpcImpl { ) -> Result { let (block, leaf_indices) = self.get_tx_indices(tx_hashes, block_hash)?; Ok(TransactionProof { - block_hash: block.hash().unpack(), - witnesses_root: block.calc_witnesses_root().unpack(), + block_hash: block.hash().into(), + witnesses_root: block.calc_witnesses_root().into(), proof: CBMT::build_merkle_proof( &block .transactions() @@ -1937,12 +1937,12 @@ impl ChainRpc for ChainRpcImpl { let snapshot = self.shared.snapshot(); snapshot - .get_block(&tx_proof.block_hash.pack()) + .get_block(&(&tx_proof.block_hash).into()) .ok_or_else(|| { RPCError::invalid_params(format!("Cannot find block {:#x}", tx_proof.block_hash)) }) .and_then(|block| { - let witnesses_root = tx_proof.witnesses_root.pack(); + let witnesses_root = tx_proof.witnesses_root.into(); let merkle_proof = MerkleProof::new( tx_proof .proof @@ -1954,7 +1954,7 @@ impl ChainRpc for ChainRpcImpl { .proof .lemmas .into_iter() - .map(|lemma| lemma.pack()) + .map(|lemma| lemma.into()) .collect(), ); @@ -1966,7 +1966,7 @@ impl ChainRpc for ChainRpcImpl { if block.transactions_root() == merkle_root(&[raw_transactions_root, witnesses_root]) { - Some(tx_hashes.iter().map(|hash| hash.unpack()).collect()) + Some(tx_hashes.iter().map(|hash| hash.into()).collect()) } else { None } @@ -1983,7 +1983,7 @@ impl ChainRpc for ChainRpcImpl { ) -> Result { let (block, leaf_indices) = self.get_tx_indices(tx_hashes, block_hash)?; Ok(TransactionAndWitnessProof { - block_hash: block.hash().unpack(), + block_hash: block.hash().into(), transactions_proof: CBMT::build_merkle_proof( &block .transactions() @@ -2006,7 +2006,7 @@ impl ChainRpc for ChainRpcImpl { ) -> Result> { let snapshot = self.shared.snapshot(); snapshot - .get_block(&tx_proof.block_hash.pack()) + .get_block(&(&tx_proof.block_hash).into()) .ok_or_else(|| { RPCError::invalid_params(format!("Cannot find block {:#x}", tx_proof.block_hash)) }) @@ -2022,7 +2022,7 @@ impl ChainRpc for ChainRpcImpl { .transactions_proof .lemmas .into_iter() - .map(|lemma| lemma.pack()) + .map(|lemma| lemma.into()) .collect(), ); let witnesses_merkle_proof = MerkleProof::new( @@ -2036,7 +2036,7 @@ impl ChainRpc for ChainRpcImpl { .witnesses_proof .lemmas .into_iter() - .map(|lemma| lemma.pack()) + .map(|lemma| lemma.into()) .collect(), ); @@ -2053,12 +2053,7 @@ impl ChainRpc for ChainRpcImpl { witnesses_proof_root, ]) { - Some( - tx_hashes - .iter() - .map(|hash| hash.unpack()) - .collect(), - ) + Some(tx_hashes.iter().map(|hash| hash.into()).collect()) } else { None } @@ -2078,7 +2073,7 @@ impl ChainRpc for ChainRpcImpl { verbosity: Option, ) -> Result>> { let snapshot = self.shared.snapshot(); - let block_hash = block_hash.pack(); + let block_hash = block_hash.into(); if snapshot.is_main_chain(&block_hash) { return Ok(None); } @@ -2106,7 +2101,7 @@ impl ChainRpc for ChainRpcImpl { } fn get_block_median_time(&self, block_hash: H256) -> Result> { - let block_hash = block_hash.pack(); + let block_hash = block_hash.into(); let snapshot = self.shared.snapshot(); if !snapshot.is_main_chain(&block_hash) { return Ok(None); @@ -2158,7 +2153,7 @@ impl ChainRpcImpl { return Ok(TransactionWithStatus::with_committed( None, tx_info.block_number, - tx_info.block_hash.unpack(), + tx_info.block_hash.into(), cycles, None, )); @@ -2206,7 +2201,7 @@ impl ChainRpcImpl { return Ok(TransactionWithStatus::with_committed( Some(tx), tx_info.block_number, - tx_info.block_hash.unpack(), + tx_info.block_hash.into(), cycles, None, )); @@ -2292,7 +2287,7 @@ impl ChainRpcImpl { let mut retrieved_block_hash = None; let mut tx_indices = HashSet::new(); for tx_hash in tx_hashes { - match snapshot.get_transaction_info(&tx_hash.pack()) { + match snapshot.get_transaction_info(&(&tx_hash).into()) { Some(tx_info) => { if retrieved_block_hash.is_none() { retrieved_block_hash = Some(tx_info.block_hash); @@ -2318,7 +2313,7 @@ impl ChainRpcImpl { let retrieved_block_hash = retrieved_block_hash.expect("checked len"); if let Some(specified_block_hash) = block_hash { - if !retrieved_block_hash.eq(&specified_block_hash.pack()) { + if !retrieved_block_hash.eq(&specified_block_hash.into()) { return Err(RPCError::invalid_params( "Not all transactions found in specified block", )); diff --git a/rpc/src/module/experiment.rs b/rpc/src/module/experiment.rs index 90e910dc1a..fe768c3719 100644 --- a/rpc/src/module/experiment.rs +++ b/rpc/src/module/experiment.rs @@ -7,7 +7,7 @@ use ckb_jsonrpc_types::{ }; use ckb_shared::{shared::Shared, Snapshot}; use ckb_store::ChainStore; -use ckb_types::{core, packed, prelude::*}; +use ckb_types::{core, packed}; use jsonrpc_core::Result; use jsonrpc_utils::rpc; @@ -193,18 +193,18 @@ impl ExperimentRpc for ExperimentRpcImpl { .ok_or_else(|| RPCError::invalid_params("invalid out_point"))?; let output = tx .outputs() - .get(out_point.index().unpack()) + .get(out_point.index().into()) .ok_or_else(|| RPCError::invalid_params("invalid out_point"))?; let output_data = tx .outputs_data() - .get(out_point.index().unpack()) + .get(out_point.index().into()) .ok_or_else(|| RPCError::invalid_params("invalid out_point"))?; match calculator.calculate_maximum_withdraw( &output, core::Capacity::bytes(output_data.len()).expect("should not overflow"), &deposit_header_hash, - &withdrawing_header_hash.pack(), + &withdrawing_header_hash.into(), ) { Ok(capacity) => Ok(capacity.into()), Err(err) => Err(RPCError::custom_with_error(RPCError::DaoError, err)), @@ -222,11 +222,11 @@ impl ExperimentRpc for ExperimentRpcImpl { let output = withdrawing_tx .outputs() - .get(withdrawing_out_point.index().unpack()) + .get(withdrawing_out_point.index().into()) .ok_or_else(|| RPCError::invalid_params("invalid withdrawing_out_point"))?; let output_data = withdrawing_tx .outputs_data() - .get(withdrawing_out_point.index().unpack()) + .get(withdrawing_out_point.index().into()) .ok_or_else(|| RPCError::invalid_params("invalid withdrawing_out_point"))?; match calculator.calculate_maximum_withdraw( diff --git a/rpc/src/module/miner.rs b/rpc/src/module/miner.rs index 814f12f91d..262555df9c 100644 --- a/rpc/src/module/miner.rs +++ b/rpc/src/module/miner.rs @@ -316,7 +316,7 @@ impl MinerRpc for MinerRpcImpl { Ok(root) => root, Err(err) => { error!("Generate last state to light client failed: {:?}", err); - return Ok(header.hash().unpack()); + return Ok(header.hash().into()); } } }; @@ -324,7 +324,7 @@ impl MinerRpc for MinerRpcImpl { let tip_header = packed::VerifiableHeader::new_builder() .header(header.data()) .uncles_hash(block.calc_uncles_hash()) - .extension(Pack::pack(&block.extension())) + .extension(block.extension().into()) .parent_chain_root(parent_chain_root) .build(); let light_client_message = { @@ -351,7 +351,7 @@ impl MinerRpc for MinerRpcImpl { } } - Ok(header.hash().unpack()) + Ok(header.hash().into()) } } diff --git a/rpc/src/module/net.rs b/rpc/src/module/net.rs index 0513b126ab..1c049c8803 100644 --- a/rpc/src/module/net.rs +++ b/rpc/src/module/net.rs @@ -7,7 +7,7 @@ use ckb_jsonrpc_types::{ use ckb_network::{extract_peer_id, multiaddr::Multiaddr, NetworkController}; use ckb_sync::SyncShared; use ckb_systemtime::unix_time_as_millis; -use ckb_types::prelude::Pack; +use ckb_types::packed; use jsonrpc_core::Result; use jsonrpc_utils::rpc; use std::sync::Arc; @@ -733,11 +733,10 @@ impl NetRpc for NetRpcImpl { let sync_state = SyncState { ibd: chain.is_initial_block_download(), assume_valid_target_reached: state.assume_valid_target().is_none(), - assume_valid_target: state - .assume_valid_target_specified() - .unwrap_or_default() - .pack() - .into(), + assume_valid_target: Into::::into( + state.assume_valid_target_specified().unwrap_or_default(), + ) + .into(), min_chain_work: min_chain_work.into(), min_chain_work_reached: state.min_chain_work_ready(), best_known_block_number: best_known.number().into(), diff --git a/rpc/src/module/pool.rs b/rpc/src/module/pool.rs index aab1071e0d..96d1033447 100644 --- a/rpc/src/module/pool.rs +++ b/rpc/src/module/pool.rs @@ -599,7 +599,7 @@ impl PoolRpc for PoolRpcImpl { let tx_hash = tx.hash(); match submit_tx.unwrap() { - Ok(_) => Ok(tx_hash.unpack()), + Ok(_) => Ok(tx_hash.into()), Err(reject) => Err(RPCError::from_submit_transaction_reject(&reject)), } } @@ -632,7 +632,7 @@ impl PoolRpc for PoolRpcImpl { fn remove_transaction(&self, tx_hash: H256) -> Result { let tx_pool = self.shared.tx_pool_controller(); - tx_pool.remove_local_tx(tx_hash.pack()).map_err(|e| { + tx_pool.remove_local_tx(tx_hash.into()).map_err(|e| { error!("Send remove_tx request error {}", e); RPCError::ckb_internal_error(e) }) @@ -681,7 +681,7 @@ impl PoolRpc for PoolRpcImpl { fn get_pool_tx_detail_info(&self, tx_hash: H256) -> Result { let tx_pool = self.shared.tx_pool_controller(); let tx_detail = tx_pool - .get_tx_detail(tx_hash.pack()) + .get_tx_detail(tx_hash.into()) .map_err(|err| RPCError::custom(RPCError::CKBInternalError, err.to_string()))?; Ok(tx_detail.into()) } diff --git a/rpc/src/module/stats.rs b/rpc/src/module/stats.rs index 0dececa47f..8df7056955 100644 --- a/rpc/src/module/stats.rs +++ b/rpc/src/module/stats.rs @@ -3,7 +3,6 @@ use ckb_jsonrpc_types::{AlertMessage, ChainInfo, DeploymentInfo, DeploymentPos, use ckb_network_alert::notifier::Notifier as AlertNotifier; use ckb_shared::shared::Shared; use ckb_traits::HeaderFieldsProvider; -use ckb_types::prelude::Unpack; use ckb_util::Mutex; use jsonrpc_core::Result; use jsonrpc_utils::rpc; @@ -179,7 +178,7 @@ impl StatsRpc for StatsRpcImpl { .collect(); Ok(DeploymentsInfo { - hash: snapshot.tip_hash().unpack(), + hash: snapshot.tip_hash().into(), epoch: snapshot.tip_header().epoch().number().into(), deployments, }) diff --git a/rpc/src/module/test.rs b/rpc/src/module/test.rs index b5db29e0d7..0b3198647a 100644 --- a/rpc/src/module/test.rs +++ b/rpc/src/module/test.rs @@ -527,7 +527,7 @@ impl IntegrationTestRpc for IntegrationTestRpcImpl { } } if ret.is_ok() { - Ok(Some(block.hash().unpack())) + Ok(Some(block.hash().into())) } else { error!("process_block_without_verify error: {:?}", ret); Ok(None) @@ -538,7 +538,7 @@ impl IntegrationTestRpc for IntegrationTestRpcImpl { let header = { let snapshot = self.shared.snapshot(); let header = snapshot - .get_block_header(&target_tip_hash.pack()) + .get_block_header(&target_tip_hash.into()) .ok_or_else(|| { RPCError::custom(RPCError::Invalid, "block not found".to_string()) })?; @@ -612,7 +612,7 @@ impl IntegrationTestRpc for IntegrationTestRpcImpl { error!("Send notify_txs request error {}", e); return Err(RPCError::ckb_internal_error(e)); } - Ok(tx_hash.unpack()) + Ok(tx_hash.into()) } fn generate_block_with_template(&self, block_template: BlockTemplate) -> Result { @@ -628,7 +628,7 @@ impl IntegrationTestRpc for IntegrationTestRpcImpl { let snapshot: &Snapshot = &self.shared.snapshot(); let consensus = snapshot.consensus(); let parent_header = snapshot - .get_block_header(&block_template.parent_hash.pack()) + .get_block_header(&(&block_template.parent_hash).into()) .expect("parent header should be stored"); let mut seen_inputs = HashSet::new(); @@ -688,6 +688,6 @@ impl IntegrationTestRpcImpl { error!("Broadcast new block failed: {:?}", err); } - Ok(block_view.header().hash().unpack()) + Ok(block_view.header().hash().into()) } } diff --git a/rpc/src/tests/examples.rs b/rpc/src/tests/examples.rs index 03afbb9d3c..0e33e0ac9e 100644 --- a/rpc/src/tests/examples.rs +++ b/rpc/src/tests/examples.rs @@ -102,10 +102,10 @@ fn collect_code_block( } fn construct_example_transaction() -> TransactionView { - let previous_output = OutPoint::new(EXAMPLE_TX_PARENT.clone().pack(), 0); + let previous_output = OutPoint::new(EXAMPLE_TX_PARENT.clone().into(), 0); let input = CellInput::new(previous_output, 0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_cell().2.clone()) .build(); let cell_dep = CellDep::new_builder() @@ -278,7 +278,7 @@ impl RpcTestSuite { let example_tx = construct_example_transaction(); assert_eq!( EXAMPLE_TX_HASH, - example_tx.hash().unpack(), + example_tx.hash().into(), "Expect the example tx hash match the constant" ); let example_tx: ckb_jsonrpc_types::Transaction = example_tx.data().into(); diff --git a/rpc/src/tests/mod.rs b/rpc/src/tests/mod.rs index b59897bd22..992c91b6a9 100644 --- a/rpc/src/tests/mod.rs +++ b/rpc/src/tests/mod.rs @@ -11,7 +11,6 @@ use ckb_types::{ TransactionView, }, packed::{CellInput, OutPoint}, - prelude::*, }; use reqwest::blocking::Client; use serde::{Deserialize, Serialize}; @@ -195,10 +194,10 @@ fn next_block(shared: &Shared, parent: &HeaderView) -> BlockView { BlockBuilder::default() .transaction(cellbase) .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .timestamp((parent.timestamp() + 1).pack()) - .compact_target(epoch.compact_target().pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .timestamp((parent.timestamp() + 1).into()) + .compact_target(epoch.compact_target().into()) .dao(dao) .build() } @@ -212,7 +211,7 @@ fn always_success_transaction() -> TransactionView { TransactionBuilder::default() .input(CellInput::new(OutPoint::null(), 0)) .output(always_success_cell.clone()) - .output_data(always_success_cell_data.to_owned().pack()) + .output_data(always_success_cell_data.to_owned().into()) .witness(always_success_script.clone().into_witness()) .build() } diff --git a/rpc/src/tests/module/miner.rs b/rpc/src/tests/module/miner.rs index 14d1513be0..ce5f7294f0 100644 --- a/rpc/src/tests/module/miner.rs +++ b/rpc/src/tests/module/miner.rs @@ -31,7 +31,7 @@ fn test_get_block_template_cache() { parent .header() .as_advanced_builder() - .timestamp((parent.header().timestamp() + 1).pack()) + .timestamp((parent.header().timestamp() + 1).into()) .build(), ) .build(); @@ -67,7 +67,7 @@ fn test_get_block_template_cache() { let input = CellInput::new(previous_output, 0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_cell().2.clone()) .build(); let cell_dep = CellDep::new_builder() diff --git a/rpc/src/tests/module/pool.rs b/rpc/src/tests/module/pool.rs index f96bb1f24b..808ea89486 100644 --- a/rpc/src/tests/module/pool.rs +++ b/rpc/src/tests/module/pool.rs @@ -152,7 +152,7 @@ fn test_send_transaction_exceeded_maximum_ancestors_count() { .unwrap() .safe_sub(Capacity::shannons(i * 41 * 1000)) .unwrap() - .pack(), + .into(), ) .lock(always_success_cell().2.clone()) .build(); @@ -192,7 +192,7 @@ fn build_tx( let lock = packed::ScriptBuilder::default() .code_hash(code_hash.clone()) .hash_type(hash_type.into()) - .args(args.pack()) + .args(args.as_slice().into()) .build(); core::TransactionBuilder::default() .output(packed::CellOutput::new_builder().lock(lock).build()) @@ -219,7 +219,7 @@ fn build_tx_with_type( .output( packed::CellOutput::new_builder() .lock(lock) - .type_(Some(type_).pack()) + .type_(Some(type_).into()) .build(), ) .build() diff --git a/rpc/src/tests/setup.rs b/rpc/src/tests/setup.rs index 5dc0dab2b5..8f5bcc0eed 100644 --- a/rpc/src/tests/setup.rs +++ b/rpc/src/tests/setup.rs @@ -23,7 +23,7 @@ use std::{thread::sleep, time::Duration}; use ckb_types::{ core::{BlockBuilder, Capacity, EpochNumberWithFraction, Ratio}, h256, - packed::{AlertBuilder, RawAlertBuilder}, + packed::{self, AlertBuilder, RawAlertBuilder}, prelude::*, }; @@ -40,9 +40,9 @@ pub(crate) fn always_success_consensus() -> Consensus { let always_success_tx = always_success_transaction(); let dao = genesis_dao_data(vec![&always_success_tx]).unwrap(); let genesis = BlockBuilder::default() - .timestamp(GENESIS_TIMESTAMP.pack()) - .compact_target(GENESIS_TARGET.pack()) - .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).pack()) + .timestamp(GENESIS_TIMESTAMP.into()) + .compact_target(GENESIS_TARGET.into()) + .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).into()) .dao(dao) .transaction(always_success_tx) .build(); @@ -78,7 +78,7 @@ pub(crate) fn setup_rpc_test_suite(height: u64, consensus: Option) -> code_hash: h256!("0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2"), hash_type: ckb_jsonrpc_types::ScriptHashType::Type, args: json_bytes("0xb2e61ff569acf041b3c2c17724e2379c581eeac3"), - message: "message".pack().into(), + message: Into::::into("message").into(), use_binary_version_as_message_prefix: true, binary_version: "TEST".to_string(), update_interval_millis: 800, @@ -155,12 +155,12 @@ pub(crate) fn setup_rpc_test_suite(height: u64, consensus: Option) -> let alert = AlertBuilder::default() .raw( RawAlertBuilder::default() - .id(42u32.pack()) - .min_version(Some("0.0.1".to_string()).pack()) - .max_version(Some("1.0.0".to_string()).pack()) - .priority(1u32.pack()) - .notice_until((ALERT_UNTIL_TIMESTAMP * 1000).pack()) - .message("An example alert message!".pack()) + .id(42u32.into()) + .min_version(Some("0.0.1".to_string()).into()) + .max_version(Some("1.0.0".to_string()).into()) + .priority(1u32.into()) + .notice_until((ALERT_UNTIL_TIMESTAMP * 1000).into()) + .message("An example alert message!".into()) .build(), ) .build(); @@ -252,7 +252,7 @@ pub(crate) fn setup_rpc_test_suite(height: u64, consensus: Option) -> parent .header() .as_advanced_builder() - .timestamp((parent.header().timestamp() + 1).pack()) + .timestamp((parent.header().timestamp() + 1).into()) .build(), ) .build(); diff --git a/script/fuzz/fuzz_targets/syscall_exec.rs b/script/fuzz/fuzz_targets/syscall_exec.rs index 7e03cabcb5..63e6d69ccd 100644 --- a/script/fuzz/fuzz_targets/syscall_exec.rs +++ b/script/fuzz/fuzz_targets/syscall_exec.rs @@ -45,16 +45,16 @@ impl ExtensionProvider for MockDataLoader { fn mock_transaction_info() -> TransactionInfo { TransactionInfoBuilder::default() - .block_number(1u64.pack()) - .block_epoch(0u64.pack()) + .block_number(1u64.into()) + .block_epoch(0u64.into()) .key( TransactionKeyBuilder::default() .block_hash(Byte32::zero()) - .index(1u32.pack()) + .index(1u32.into()) .build(), ) .build() - .unpack() + .into() } static CALLER: &[u8] = include_bytes!("../programs/exec_caller"); @@ -103,13 +103,13 @@ fn run(data: FuzzData) { }; let exec_caller_cell = CellOutput::new_builder() - .capacity(Capacity::bytes(exec_caller_cell_data.len()).unwrap().pack()) + .capacity(Capacity::bytes(exec_caller_cell_data.len()).unwrap().into()) .build(); let exec_callee_cell = CellOutput::new_builder() - .capacity(Capacity::bytes(exec_callee_cell_data.len()).unwrap().pack()) + .capacity(Capacity::bytes(exec_callee_cell_data.len()).unwrap().into()) .build(); let exec_caller_data_cell = CellOutput::new_builder() - .capacity(Capacity::bytes(exec_caller_data_data.len()).unwrap().pack()) + .capacity(Capacity::bytes(exec_caller_data_data.len()).unwrap().into()) .build(); let exec_caller_script = Script::new_builder() @@ -117,14 +117,14 @@ fn run(data: FuzzData) { .code_hash(CellOutput::calc_data_hash(&exec_caller_cell_data)) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); let transaction = TransactionBuilder::default() .input(input) - .set_witnesses(vec![exec_callee_cell_data.pack()]) + .set_witnesses(vec![exec_callee_cell_data.into()]) .build(); let dummy_cell = CellMetaBuilder::from_cell_output(output, Bytes::new()) @@ -154,7 +154,7 @@ fn run(data: FuzzData) { let provider = MockDataLoader {}; let consensus = ConsensusBuilder::default().build(); let tx_verify_env = - TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.pack()).build()); + TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.into()).build()); let verifier = TransactionScriptsVerifier::new( rtx.into(), provider, diff --git a/script/fuzz/fuzz_targets/transaction_scripts_verifier_data0.rs b/script/fuzz/fuzz_targets/transaction_scripts_verifier_data0.rs index ccb922337e..3c2591d51c 100644 --- a/script/fuzz/fuzz_targets/transaction_scripts_verifier_data0.rs +++ b/script/fuzz/fuzz_targets/transaction_scripts_verifier_data0.rs @@ -47,16 +47,16 @@ impl ExtensionProvider for MockDataLoader { fn mock_transaction_info() -> TransactionInfo { TransactionInfoBuilder::default() - .block_number(1u64.pack()) - .block_epoch(0u64.pack()) + .block_number(1u64.into()) + .block_epoch(0u64.into()) .key( TransactionKeyBuilder::default() .block_hash(Byte32::zero()) - .index(1u32.pack()) + .index(1u32.into()) .build(), ) .build() - .unpack() + .into() } fn run(data: &[u8]) { @@ -71,17 +71,17 @@ fn run(data: &[u8]) { .build(); let dep_cell = CellMetaBuilder::from_cell_output( CellOutput::new_builder() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .build(), data, ) .transaction_info(mock_transaction_info()) - .out_point(OutPoint::new(h256!("0x0").pack(), 0)) + .out_point(OutPoint::new(h256!("0x0").into(), 0)) .build(); let input_cell = CellMetaBuilder::from_cell_output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script) .build(), Bytes::new(), @@ -105,7 +105,7 @@ fn run(data: &[u8]) { .hardfork_switch(hardfork_switch) .build(); let tx_verify_env = - TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.pack()).build()); + TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.into()).build()); let verifier = TransactionScriptsVerifier::new( rtx.into(), provider, diff --git a/script/fuzz/fuzz_targets/transaction_scripts_verifier_data1.rs b/script/fuzz/fuzz_targets/transaction_scripts_verifier_data1.rs index f9be40d6be..b005620b01 100644 --- a/script/fuzz/fuzz_targets/transaction_scripts_verifier_data1.rs +++ b/script/fuzz/fuzz_targets/transaction_scripts_verifier_data1.rs @@ -47,16 +47,16 @@ impl ExtensionProvider for MockDataLoader { fn mock_transaction_info() -> TransactionInfo { TransactionInfoBuilder::default() - .block_number(1u64.pack()) - .block_epoch(0u64.pack()) + .block_number(1u64.into()) + .block_epoch(0u64.into()) .key( TransactionKeyBuilder::default() .block_hash(Byte32::zero()) - .index(1u32.pack()) + .index(1u32.into()) .build(), ) .build() - .unpack() + .into() } fn run(data: &[u8]) { @@ -71,17 +71,17 @@ fn run(data: &[u8]) { .build(); let dep_cell = CellMetaBuilder::from_cell_output( CellOutput::new_builder() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .build(), data, ) .transaction_info(mock_transaction_info()) - .out_point(OutPoint::new(h256!("0x0").pack(), 0)) + .out_point(OutPoint::new(h256!("0x0").into(), 0)) .build(); let input_cell = CellMetaBuilder::from_cell_output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script) .build(), Bytes::new(), @@ -105,7 +105,7 @@ fn run(data: &[u8]) { .hardfork_switch(hardfork_switch) .build(); let tx_verify_env = - TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.pack()).build()); + TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.into()).build()); let verifier = TransactionScriptsVerifier::new( rtx.into(), provider, diff --git a/script/fuzz/fuzz_targets/transaction_scripts_verifier_data2.rs b/script/fuzz/fuzz_targets/transaction_scripts_verifier_data2.rs index 8c05a5baab..c14fb5d109 100644 --- a/script/fuzz/fuzz_targets/transaction_scripts_verifier_data2.rs +++ b/script/fuzz/fuzz_targets/transaction_scripts_verifier_data2.rs @@ -47,16 +47,16 @@ impl ExtensionProvider for MockDataLoader { fn mock_transaction_info() -> TransactionInfo { TransactionInfoBuilder::default() - .block_number(1u64.pack()) - .block_epoch(0u64.pack()) + .block_number(1u64.into()) + .block_epoch(0u64.into()) .key( TransactionKeyBuilder::default() .block_hash(Byte32::zero()) - .index(1u32.pack()) + .index(1u32.into()) .build(), ) .build() - .unpack() + .into() } fn run(data: &[u8]) { @@ -71,17 +71,17 @@ fn run(data: &[u8]) { .build(); let dep_cell = CellMetaBuilder::from_cell_output( CellOutput::new_builder() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .build(), data, ) .transaction_info(mock_transaction_info()) - .out_point(OutPoint::new(h256!("0x0").pack(), 0)) + .out_point(OutPoint::new(h256!("0x0").into(), 0)) .build(); let input_cell = CellMetaBuilder::from_cell_output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script) .build(), Bytes::new(), @@ -105,7 +105,7 @@ fn run(data: &[u8]) { .hardfork_switch(hardfork_switch) .build(); let tx_verify_env = - TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.pack()).build()); + TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.into()).build()); let verifier = TransactionScriptsVerifier::new( rtx.into(), provider, diff --git a/script/src/syscalls/load_cell.rs b/script/src/syscalls/load_cell.rs index 0dee77937f..e7f4253e1e 100644 --- a/script/src/syscalls/load_cell.rs +++ b/script/src/syscalls/load_cell.rs @@ -109,7 +109,7 @@ impl LoadCell
{ let result = match field { CellField::Capacity => { - let capacity: Capacity = output.capacity().unpack(); + let capacity: Capacity = output.capacity().into(); let mut buffer = vec![]; buffer.write_u64::(capacity.as_u64())?; (SUCCESS, store_data(machine, &buffer)?) diff --git a/script/src/syscalls/load_input.rs b/script/src/syscalls/load_input.rs index 8f19c0d6c9..33f427e822 100644 --- a/script/src/syscalls/load_input.rs +++ b/script/src/syscalls/load_input.rs @@ -80,7 +80,7 @@ impl LoadInput { } InputField::Since => { let mut buffer = vec![]; - buffer.write_u64::(input.since().unpack())?; + buffer.write_u64::(input.since().into())?; store_data(machine, &buffer) } } diff --git a/script/src/syscalls/tests/utils.rs b/script/src/syscalls/tests/utils.rs index de9ca6f542..b8e43abf03 100644 --- a/script/src/syscalls/tests/utils.rs +++ b/script/src/syscalls/tests/utils.rs @@ -41,7 +41,7 @@ pub(crate) fn new_mock_data_loader() -> MockDataLoader { pub(crate) fn build_cell_meta(capacity_bytes: usize, data: Bytes) -> CellMeta { let capacity = Capacity::bytes(capacity_bytes).expect("capacity bytes overflow"); - let builder = CellOutput::new_builder().capacity(capacity.pack()); + let builder = CellOutput::new_builder().capacity(capacity.into()); let data_hash = CellOutput::calc_data_hash(&data); CellMeta { out_point: OutPoint::default(), diff --git a/script/src/syscalls/tests/vm_latest/syscalls_1.rs b/script/src/syscalls/tests/vm_latest/syscalls_1.rs index 391320a556..32fad3f94c 100644 --- a/script/src/syscalls/tests/vm_latest/syscalls_1.rs +++ b/script/src/syscalls/tests/vm_latest/syscalls_1.rs @@ -7,7 +7,7 @@ use ckb_types::{ Capacity, EpochNumberWithFraction, HeaderBuilder, ScriptHashType, TransactionBuilder, TransactionInfo, }, - packed::{CellInput, CellOutput, OutPoint, Script, ScriptBuilder}, + packed::{self, CellInput, CellOutput, OutPoint, Script, ScriptBuilder}, prelude::*, H256, }; @@ -435,7 +435,7 @@ fn _test_load_cell_capacity(capacity: Capacity) -> Result<(), TestCaseError> { let input_cell = CellMeta { out_point: OutPoint::default(), transaction_info: None, - cell_output: CellOutput::new_builder().capacity(capacity.pack()).build(), + cell_output: CellOutput::new_builder().capacity(capacity.into()).build(), data_bytes: 0, mem_cell_data: Some(data), mem_cell_data_hash: Some(data_hash), @@ -496,7 +496,7 @@ fn _test_load_cell_occupied_capacity(data: &[u8]) -> Result<(), TestCaseError> { let input_cell = CellMeta { out_point: OutPoint::default(), transaction_info: None, - cell_output: CellOutput::new_builder().capacity(100.pack()).build(), + cell_output: CellOutput::new_builder().capacity(100.into()).build(), data_bytes: 0, mem_cell_data: Some(data), mem_cell_data_hash: Some(data_hash), @@ -558,7 +558,7 @@ fn test_load_missing_data_hash() { let input_cell = CellMeta { out_point: OutPoint::default(), transaction_info: None, - cell_output: CellOutput::new_builder().capacity(100.pack()).build(), + cell_output: CellOutput::new_builder().capacity(100.into()).build(), data_bytes: 0, mem_cell_data: None, mem_cell_data_hash: None, @@ -652,7 +652,7 @@ fn _test_load_header( machine.set_register(A4, source); //source: 4 header machine.set_register(A7, LOAD_HEADER_SYSCALL_NUMBER); // syscall number - let data_hash = blake2b_256(data).pack(); + let data_hash = blake2b_256(data).into(); let header = HeaderBuilder::default() .transactions_root(data_hash) .build(); @@ -668,7 +668,7 @@ fn _test_load_header( block_epoch: header.epoch(), index: 1, }), - cell_output: CellOutput::new_builder().capacity(100.pack()).build(), + cell_output: CellOutput::new_builder().capacity(100.into()).build(), data_bytes: 0, mem_cell_data: None, mem_cell_data_hash: None, @@ -772,9 +772,9 @@ fn _test_load_header_by_field(data: &[u8], field: HeaderField) -> Result<(), Tes let data_hash: H256 = blake2b_256(data).into(); let epoch = EpochNumberWithFraction::new(1, 40, 1000); let header = HeaderBuilder::default() - .transactions_root(data_hash.pack()) - .number(2000.pack()) - .epoch(epoch.pack()) + .transactions_root(data_hash.into()) + .number(2000.into()) + .epoch(epoch.into()) .build(); let mut correct_data = [0u8; 8]; @@ -845,7 +845,7 @@ fn _test_load_tx_hash(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_TX_HASH_SYSCALL_NUMBER); // syscall number let transaction_view = TransactionBuilder::default() - .output_data(data.pack()) + .output_data(data.into()) .build(); let hash = transaction_view.hash(); @@ -896,7 +896,7 @@ fn _test_load_tx(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_TRANSACTION_SYSCALL_NUMBER); // syscall number let transaction_view = TransactionBuilder::default() - .output_data(data.pack()) + .output_data(data.into()) .build(); let tx = transaction_view.data(); @@ -947,7 +947,7 @@ fn _test_load_current_script_hash(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_SCRIPT_HASH_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).pack()) + .args(Bytes::from(data.to_owned()).into()) .hash_type(ScriptHashType::Data.into()) .build(); let hash = script.calc_script_hash(); @@ -1002,7 +1002,7 @@ fn _test_load_input_lock_script_hash(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).pack()) + .args(Bytes::from(data.to_owned()).into()) .hash_type(ScriptHashType::Data.into()) .build(); let h = script.calc_script_hash(); @@ -1068,7 +1068,7 @@ fn _test_load_input_lock_script(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).pack()) + .args(Bytes::from(data.to_owned()).into()) .hash_type(ScriptHashType::Data.into()) .build(); let lock = script.as_slice(); @@ -1136,7 +1136,7 @@ fn _test_load_input_type_script(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).pack()) + .args(Bytes::from(data.to_owned()).into()) .hash_type(ScriptHashType::Data.into()) .build(); let type_ = script.as_slice(); @@ -1146,7 +1146,7 @@ fn _test_load_input_type_script(data: &[u8]) -> Result<(), TestCaseError> { .cell_output .clone() .as_builder() - .type_(Some(script.to_owned()).pack()) + .type_(Some(script.to_owned()).into()) .build(); input_cell.cell_output = output_with_type; @@ -1204,7 +1204,7 @@ fn _test_load_input_type_script_hash(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_CELL_BY_FIELD_SYSCALL_NUMBER); // syscall number let script = Script::new_builder() - .args(Bytes::from(data.to_owned()).pack()) + .args(Bytes::from(data.to_owned()).into()) .hash_type(ScriptHashType::Data.into()) .build(); @@ -1216,7 +1216,7 @@ fn _test_load_input_type_script_hash(data: &[u8]) -> Result<(), TestCaseError> { .cell_output .clone() .as_builder() - .type_(Some(script).pack()) + .type_(Some(script).into()) .build(); input_cell.cell_output = output_with_type; let outputs = Arc::new(vec![]); @@ -1271,7 +1271,7 @@ fn _test_load_witness(data: &[u8], source: SourceEntry) -> Result<(), TestCaseEr machine.set_register(A4, u64::from(Source::Transaction(source))); //source machine.set_register(A7, LOAD_WITNESS_SYSCALL_NUMBER); // syscall number - let witness = Bytes::from(data.to_owned()).pack(); + let witness: packed::Bytes = Bytes::from(data.to_owned()).into(); let witness_correct_data = witness.raw_data(); @@ -1280,7 +1280,7 @@ fn _test_load_witness(data: &[u8], source: SourceEntry) -> Result<(), TestCaseEr let group_outputs = Arc::new(vec![]); let rtx = Arc::new(ResolvedTransaction { transaction: TransactionBuilder::default() - .witnesses(witnesses.pack()) + .witnesses(Into::::into(witnesses)) .build(), resolved_cell_deps: vec![], resolved_inputs: vec![], @@ -1335,17 +1335,17 @@ fn _test_load_group_witness(data: &[u8], source: SourceEntry) -> Result<(), Test machine.set_register(A4, u64::from(Source::Group(source))); //source machine.set_register(A7, LOAD_WITNESS_SYSCALL_NUMBER); // syscall number - let witness = Bytes::from(data.to_owned()).pack(); + let witness: packed::Bytes = Bytes::from(data.to_owned()).into(); let witness_correct_data = witness.raw_data(); - let dummy_witness = Bytes::default().pack(); + let dummy_witness = Bytes::default().into(); let witnesses = vec![dummy_witness, witness]; let group_inputs = Arc::new(vec![1]); let group_outputs = Arc::new(vec![1]); let rtx = Arc::new(ResolvedTransaction { transaction: TransactionBuilder::default() - .witnesses(witnesses.pack()) + .witnesses(Into::::into(witnesses)) .build(), resolved_cell_deps: vec![], resolved_inputs: vec![], @@ -1394,7 +1394,7 @@ fn _test_load_script(data: &[u8]) -> Result<(), TestCaseError> { machine.set_register(A7, LOAD_SCRIPT_SYSCALL_NUMBER); // syscall number let script = ScriptBuilder::default() - .args(Bytes::from(data.to_owned()).pack()) + .args(Bytes::from(data.to_owned()).into()) .build(); let script_correct_data = script.as_slice(); @@ -1857,15 +1857,15 @@ fn _test_load_input( prop_assert!(machine.memory_mut().store64(&size_addr, &addr_size).is_ok()); let data = Bytes::from(data.to_owned()); - let hash = blake2b_256(&data).pack(); + let hash = blake2b_256(&data).into(); let input = CellInput::new_builder() .previous_output( OutPoint::new_builder() .tx_hash(hash) - .index(0u32.pack()) + .index(0u32.into()) .build(), ) - .since(10u64.pack()) + .since(10u64.into()) .build(); let previous_output = input.previous_output(); @@ -1883,7 +1883,7 @@ fn _test_load_input( match field { InputField::OutPoint => previous_output.as_slice(), InputField::Since => { - buffer.write_u64::(input.since().unpack())?; + buffer.write_u64::(input.since().into())?; buffer.as_slice() } } diff --git a/script/src/syscalls/tests/vm_latest/syscalls_2.rs b/script/src/syscalls/tests/vm_latest/syscalls_2.rs index 372b0377d3..3197011aab 100644 --- a/script/src/syscalls/tests/vm_latest/syscalls_2.rs +++ b/script/src/syscalls/tests/vm_latest/syscalls_2.rs @@ -129,14 +129,14 @@ fn _test_load_extension( block_epoch: header.epoch(), index: 1, }), - cell_output: CellOutput::new_builder().capacity(100.pack()).build(), + cell_output: CellOutput::new_builder().capacity(100.into()).build(), data_bytes: 0, mem_cell_data: None, mem_cell_data_hash: None, }; let mut extensions = HashMap::default(); - extensions.insert(header.hash(), data.pack()); + extensions.insert(header.hash(), (&data).into()); let data_loader = MockDataLoader { extensions, ..Default::default() diff --git a/script/src/verify.rs b/script/src/verify.rs index 207161e436..e5d1064002 100644 --- a/script/src/verify.rs +++ b/script/src/verify.rs @@ -394,7 +394,7 @@ impl Result { - if group.script.code_hash() == TYPE_ID_CODE_HASH.pack() + if group.script.code_hash() == TYPE_ID_CODE_HASH.into() && Into::::into(group.script.hash_type()) == Into::::into(ScriptHashType::Type) { let verifier = TypeIdSystemScript { @@ -952,7 +952,7 @@ impl Result { - if group.script.code_hash() == TYPE_ID_CODE_HASH.pack() + if group.script.code_hash() == TYPE_ID_CODE_HASH.into() && Into::::into(group.script.hash_type()) == Into::::into(ScriptHashType::Type) { let verifier = TypeIdSystemScript { diff --git a/script/src/verify/tests/ckb_latest/features_since_v2019.rs b/script/src/verify/tests/ckb_latest/features_since_v2019.rs index 4a25ef1602..f82a1217ce 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2019.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2019.rs @@ -25,7 +25,7 @@ fn check_always_success_hash() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_script.clone()) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -68,13 +68,13 @@ fn check_signature() { args.extend(&to_hex_signature(&signature)); let code_hash = blake2b_256(&buffer); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder() .out_point(dep_out_point.clone()) .build(); let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .build(); let dep_cell = CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) @@ -82,8 +82,8 @@ fn check_signature() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).pack()) - .code_hash(code_hash.pack()) + .args(Bytes::from(args).into()) + .code_hash(code_hash.into()) .hash_type(ScriptHashType::Data.into()) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -94,7 +94,7 @@ fn check_signature() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script) .build(); let dummy_cell = create_dummy_cell(output); @@ -137,21 +137,21 @@ fn check_signature_referenced_via_type_hash() { args.extend(&to_hex_pubkey(&pubkey)); args.extend(&to_hex_signature(&signature)); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder() .out_point(dep_out_point.clone()) .build(); let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .type_( Some( Script::new_builder() - .code_hash(h256!("0x123456abcd90").pack()) + .code_hash(h256!("0x123456abcd90").into()) .hash_type(ScriptHashType::Data.into()) .build(), ) - .pack(), + .into(), ) .build(); let type_hash = output.type_().to_opt().as_ref().unwrap().calc_script_hash(); @@ -161,7 +161,7 @@ fn check_signature_referenced_via_type_hash() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).pack()) + .args(Bytes::from(args).into()) .code_hash(type_hash) .hash_type(ScriptHashType::Type.into()) .build(); @@ -173,7 +173,7 @@ fn check_signature_referenced_via_type_hash() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script) .build(); let dummy_cell = create_dummy_cell(output); @@ -209,19 +209,19 @@ fn check_invalid_signature() { args.extend(&to_hex_signature(&signature)); let code_hash = blake2b_256(&buffer); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder().out_point(dep_out_point).build(); let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .build(); let dep_cell = CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) .build(); let script = Script::new_builder() - .args(Bytes::from(args).pack()) - .code_hash(code_hash.pack()) + .args(Bytes::from(args).into()) + .code_hash(code_hash.into()) .hash_type(ScriptHashType::Data.into()) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -232,7 +232,7 @@ fn check_invalid_signature() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script.clone()) .build(); let dummy_cell = create_dummy_cell(output); @@ -266,12 +266,12 @@ fn check_invalid_dep_reference() { args.extend(&to_hex_pubkey(&pubkey)); args.extend(&to_hex_signature(&signature)); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder().out_point(dep_out_point).build(); - let script_code_hash = blake2b_256(&buffer).pack(); + let script_code_hash: Byte32 = blake2b_256(&buffer).into(); let script = Script::new_builder() - .args(Bytes::from(args).pack()) + .args(Bytes::from(args).into()) .code_hash(script_code_hash.clone()) .hash_type(ScriptHashType::Data.into()) .build(); @@ -283,7 +283,7 @@ fn check_invalid_dep_reference() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script) .build(); let dummy_cell = create_dummy_cell(output); @@ -321,7 +321,7 @@ fn check_output_contract() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_script.clone()) .build(); let dummy_cell = create_dummy_cell(output); @@ -333,8 +333,8 @@ fn check_output_contract() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).pack()) - .code_hash(blake2b_256(&buffer).pack()) + .args(Bytes::from(args).into()) + .code_hash(blake2b_256(&buffer).into()) .hash_type(ScriptHashType::Data.into()) .build(); let output_data = Bytes::default(); @@ -344,17 +344,17 @@ fn check_output_contract() { .hash_type(ScriptHashType::Data.into()) .build(), ) - .type_(Some(script).pack()) + .type_(Some(script).into()) .build(); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder() .out_point(dep_out_point.clone()) .build(); let dep_cell = { let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .build(); CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) @@ -365,7 +365,7 @@ fn check_output_contract() { let transaction = TransactionBuilder::default() .input(input) .output(output) - .output_data(output_data.pack()) + .output_data(output_data.into()) .cell_dep(cell_dep) .build(); @@ -402,7 +402,7 @@ fn check_invalid_output_contract() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_script.clone()) .build(); let dummy_cell = create_dummy_cell(output); @@ -414,20 +414,20 @@ fn check_invalid_output_contract() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).pack()) - .code_hash(blake2b_256(&buffer).pack()) + .args(Bytes::from(args).into()) + .code_hash(blake2b_256(&buffer).into()) .hash_type(ScriptHashType::Data.into()) .build(); let output = CellOutputBuilder::default() - .type_(Some(script.clone()).pack()) + .type_(Some(script.clone()).into()) .build(); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder().out_point(dep_out_point).build(); let dep_cell = { let dep_cell_data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(dep_cell_data.len()).unwrap().pack()) + .capacity(Capacity::bytes(dep_cell_data.len()).unwrap().into()) .build(); CellMetaBuilder::from_cell_output(output, dep_cell_data) .transaction_info(default_transaction_info()) @@ -437,7 +437,7 @@ fn check_invalid_output_contract() { let transaction = TransactionBuilder::default() .input(input) .output(output) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .cell_dep(cell_dep) .build(); @@ -473,18 +473,18 @@ fn check_same_lock_and_type_script_are_executed_twice() { args.extend(&to_hex_signature(&signature)); let script = Script::new_builder() - .args(Bytes::from(args).pack()) - .code_hash(blake2b_256(&buffer).pack()) + .args(Bytes::from(args).into()) + .code_hash(blake2b_256(&buffer).into()) .hash_type(ScriptHashType::Data.into()) .build(); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder() .out_point(dep_out_point.clone()) .build(); let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .build(); let dep_cell = CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) @@ -498,9 +498,9 @@ fn check_same_lock_and_type_script_are_executed_twice() { // The lock and type scripts here are both executed. let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script.clone()) - .type_(Some(script).pack()) + .type_(Some(script).into()) .build(); let dummy_cell = create_dummy_cell(output); @@ -523,25 +523,25 @@ fn check_type_id_one_in_one_out() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(Bytes::from(h256!("0x1111").as_ref()).into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script).pack()) + .type_(Some(type_id_script).into()) .build(); let transaction = TransactionBuilder::default() @@ -587,25 +587,25 @@ fn check_type_id_one_in_one_out_not_enough_cycles() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(Bytes::from(h256!("0x1111").as_ref()).into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script).pack()) + .type_(Some(type_id_script).into()) .build(); let transaction = TransactionBuilder::default() @@ -652,11 +652,11 @@ fn check_type_id_creation() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) .build(); @@ -670,15 +670,15 @@ fn check_type_id_creation() { }; let type_id_script = Script::new_builder() - .args(input_hash.pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(input_hash.into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script).pack()) + .type_(Some(type_id_script).into()) .build(); let transaction = TransactionBuilder::default() @@ -719,23 +719,23 @@ fn check_type_id_termination() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(Bytes::from(h256!("0x1111").as_ref()).into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script).pack()) + .type_(Some(type_id_script).into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) .build(); @@ -777,11 +777,11 @@ fn check_type_id_invalid_creation() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) .build(); @@ -789,7 +789,7 @@ fn check_type_id_invalid_creation() { let mut blake2b = new_blake2b(); blake2b.update(&input.previous_output().tx_hash().as_bytes()); let mut buf = [0; 4]; - LittleEndian::write_u32(&mut buf, input.previous_output().index().unpack()); + LittleEndian::write_u32(&mut buf, input.previous_output().index().into()); blake2b.update(&buf[..]); let mut buf = [0; 8]; LittleEndian::write_u64(&mut buf, 0); @@ -801,15 +801,15 @@ fn check_type_id_invalid_creation() { }; let type_id_script = Script::new_builder() - .args(input_hash.pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(input_hash.into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let transaction = TransactionBuilder::default() @@ -853,11 +853,11 @@ fn check_type_id_invalid_creation_length() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) .build(); @@ -865,7 +865,7 @@ fn check_type_id_invalid_creation_length() { let mut blake2b = new_blake2b(); blake2b.update(&input.previous_output().tx_hash().as_bytes()); let mut buf = [0; 4]; - LittleEndian::write_u32(&mut buf, input.previous_output().index().unpack()); + LittleEndian::write_u32(&mut buf, input.previous_output().index().into()); blake2b.update(&buf[..]); let mut buf = [0; 8]; LittleEndian::write_u64(&mut buf, 0); @@ -880,15 +880,15 @@ fn check_type_id_invalid_creation_length() { }; let type_id_script = Script::new_builder() - .args(input_hash.pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(input_hash.into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let transaction = TransactionBuilder::default() @@ -932,30 +932,30 @@ fn check_type_id_one_in_two_out() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(Bytes::from(h256!("0x1111").as_ref()).into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let output_cell2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let transaction = TransactionBuilder::default() @@ -1027,7 +1027,7 @@ fn create_rtx_to_load_code_to_stack_then_reuse( vec.extend_from_slice(&flag.to_le_bytes()); vec.extend_from_slice(&size.to_le_bytes()); vec.extend_from_slice(&data_hash); - vec.pack() + vec.into() }; let (dyn_lock_cell, dyn_lock_data_hash) = @@ -1039,7 +1039,7 @@ fn create_rtx_to_load_code_to_stack_then_reuse( .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(dyn_lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1106,7 +1106,7 @@ fn check_debugger() { let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_script.clone()) .build(); let dummy_cell = create_dummy_cell(output); @@ -1118,7 +1118,7 @@ fn check_debugger() { .build(); let script = Script::new_builder() - .code_hash(blake2b_256(&buffer).pack()) + .code_hash(blake2b_256(&buffer).into()) .hash_type(ScriptHashType::Data.into()) .build(); let output_data = Bytes::default(); @@ -1128,17 +1128,17 @@ fn check_debugger() { .hash_type(ScriptHashType::Data.into()) .build(), ) - .type_(Some(script).pack()) + .type_(Some(script).into()) .build(); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder() .out_point(dep_out_point.clone()) .build(); let dep_cell = { let data = Bytes::from(buffer); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .build(); CellMetaBuilder::from_cell_output(output, data) .transaction_info(default_transaction_info()) @@ -1149,7 +1149,7 @@ fn check_debugger() { let transaction = TransactionBuilder::default() .input(input) .output(output) - .output_data(output_data.pack()) + .output_data(output_data.into()) .cell_dep(cell_dep) .build(); diff --git a/script/src/verify/tests/ckb_latest/features_since_v2021.rs b/script/src/verify/tests/ckb_latest/features_since_v2021.rs index 819d247443..2bec10bd72 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2021.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2021.rs @@ -32,7 +32,7 @@ fn test_hint_instructions() { .code_hash(always_success_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -71,7 +71,7 @@ fn test_b_extension() { let mut vec = Vec::with_capacity(8 * 2); vec.extend_from_slice(&num0.to_le_bytes()); vec.extend_from_slice(&num1.to_le_bytes()); - vec.pack() + vec.into() }; let (cpop_lock_cell, cpop_lock_data_hash) = load_cell_from_path("testdata/cpop_lock"); @@ -82,7 +82,7 @@ fn test_b_extension() { .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(cpop_lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -122,7 +122,7 @@ fn test_cycles_difference() { .code_hash(always_success_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -161,7 +161,7 @@ fn check_current_cycles() { .code_hash(current_cycles_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(current_cycles_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -193,7 +193,7 @@ fn check_current_cycles_with_snapshot() { .code_hash(current_cycles_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(current_cycles_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -238,7 +238,7 @@ fn check_vm_version() { .code_hash(vm_version_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(vm_version_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -270,7 +270,7 @@ fn check_vm_version_with_snapshot() { .code_hash(vm_version_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(vm_version_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -317,7 +317,7 @@ fn check_exec_from_cell_data() { .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -350,7 +350,7 @@ fn check_exec_from_witness() { .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -358,7 +358,7 @@ fn check_exec_from_witness() { let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let transaction = TransactionBuilder::default() .input(input) - .set_witnesses(vec![exec_callee_cell_data.pack()]) + .set_witnesses(vec![exec_callee_cell_data.into()]) .build(); let dummy_cell = create_dummy_cell(output); @@ -388,7 +388,7 @@ fn check_exec_wrong_callee_format() { .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -422,7 +422,7 @@ fn check_exec_big_offset_length() { .code_hash(exec_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(exec_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -449,25 +449,25 @@ fn _check_type_id_one_in_one_out_resume(step_cycles: Cycle) -> Result<(), TestCa let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(Bytes::from(h256!("0x1111").as_ref()).into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script).pack()) + .type_(Some(type_id_script).into()) .build(); let transaction = TransactionBuilder::default() @@ -595,25 +595,25 @@ fn _check_type_id_one_in_one_out_resume_with_state( let (always_success_cell, always_success_cell_data, always_success_script) = always_success_cell(); - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let type_id_script = Script::new_builder() - .args(Bytes::from(h256!("0x1111").as_ref()).pack()) - .code_hash(TYPE_ID_CODE_HASH.pack()) + .args(Bytes::from(h256!("0x1111").as_ref()).into()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) .build(); - let input = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 8), 0); + let input = CellInput::new(OutPoint::new(h256!("0x1234").into(), 8), 0); let input_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script.clone()).pack()) + .type_(Some(type_id_script.clone()).into()) .build(); let output_cell = CellOutputBuilder::default() - .capacity(capacity_bytes!(990).pack()) + .capacity(capacity_bytes!(990).into()) .lock(always_success_script.clone()) - .type_(Some(type_id_script).pack()) + .type_(Some(type_id_script).into()) .build(); let transaction = TransactionBuilder::default() @@ -985,7 +985,7 @@ fn load_code_into_global() { let mut vec = Vec::with_capacity(8 + data_hash.len()); vec.extend_from_slice(&number.to_le_bytes()); vec.extend_from_slice(&data_hash); - vec.pack() + vec.into() }; let (dyn_lock_cell, dyn_lock_data_hash) = @@ -997,7 +997,7 @@ fn load_code_into_global() { .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(dyn_lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1037,7 +1037,7 @@ fn load_code_with_snapshot() { let mut vec = Vec::with_capacity(8 + data_hash.len()); vec.extend_from_slice(&number.to_le_bytes()); vec.extend_from_slice(&data_hash); - vec.pack() + vec.into() }; let (dyn_lock_cell, dyn_lock_data_hash) = @@ -1049,7 +1049,7 @@ fn load_code_with_snapshot() { .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(dyn_lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1131,7 +1131,7 @@ fn load_code_with_snapshot_more_times() { vec.extend_from_slice(&div2); // num0 = 3 vec.extend_from_slice(&sub1); // num0 = 2 vec.extend_from_slice(&div2); // num0 = 1 - vec.pack() + vec.into() }; let lock_script = Script::new_builder() @@ -1140,7 +1140,7 @@ fn load_code_with_snapshot_more_times() { .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(lock_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1252,7 +1252,7 @@ fn test_exec( vec.extend_from_slice(&place.to_le_bytes()); vec.extend_from_slice(&bounds.to_le_bytes()); vec.extend_from_slice(&data_hash); - vec.pack() + vec.into() }; let rtx = { @@ -1270,7 +1270,7 @@ fn test_exec( .args(args) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(exec_caller_script.clone()) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -1282,7 +1282,7 @@ fn test_exec( let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let tx = TransactionBuilder::default() .input(input) - .set_witnesses(vec![exec_callee_cell_data.pack()]) + .set_witnesses(vec![exec_callee_cell_data.into()]) .build(); (tx, vec![create_dummy_cell(output)]) } @@ -1294,7 +1294,7 @@ fn test_exec( let tx = TransactionBuilder::default() .input(input) - .set_witnesses(vec![data.pack()]) + .set_witnesses(vec![data.into()]) .build(); (tx, vec![create_dummy_cell(output)]) } @@ -1305,18 +1305,18 @@ fn test_exec( ExecFrom::GroupOutputWitness => { let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) - .type_(Some(exec_caller_script).pack()) + .capacity(capacity_bytes!(100).into()) + .type_(Some(exec_caller_script).into()) .build(); let tx = TransactionBuilder::default() .output(output) - .set_witnesses(vec![exec_callee_cell_data.pack()]) + .set_witnesses(vec![exec_callee_cell_data.into()]) .build(); (tx, vec![]) } ExecFrom::TxInputCell => { let callee_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(always_success_script.clone()) .build(); let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); @@ -1329,9 +1329,9 @@ fn test_exec( } ExecFrom::GroupInputCell => { let caller_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(exec_caller_script) - .type_(Some(always_success_script.clone()).pack()) + .type_(Some(always_success_script.clone()).into()) .build(); let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let caller_cell = @@ -1344,38 +1344,38 @@ fn test_exec( ExecFrom::TxOutputCell => { let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let callee_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_success_script.clone()) .build(); let tx = TransactionBuilder::default() .input(input) .output(callee_output) - .output_data(exec_callee_cell_data.pack()) + .output_data(exec_callee_cell_data.into()) .build(); (tx, vec![create_dummy_cell(output)]) } ExecFrom::GroupOutputCell => { let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let callee_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) - .type_(Some(exec_caller_script).pack()) + .capacity(capacity_bytes!(100).into()) + .type_(Some(exec_caller_script).into()) .build(); let tx = TransactionBuilder::default() .output(callee_output) - .output_data(exec_callee_cell_data.pack()) + .output_data(exec_callee_cell_data.into()) .build(); (tx, vec![]) } ExecFrom::OutOfBound(..) => { let exec_callee_cell_data = exec_callee_cell.mem_cell_data.as_ref().unwrap(); let tx = TransactionBuilder::default() - .set_witnesses(vec![exec_callee_cell_data.pack()]) + .set_witnesses(vec![exec_callee_cell_data.into()]) .build(); (tx, vec![create_dummy_cell(output)]) } }; - let always_success_out_point = OutPoint::new(h256!("0x11").pack(), 0); + let always_success_out_point = OutPoint::new(h256!("0x11").into(), 0); let resolved_always_success_cell = CellMetaBuilder::from_cell_output( always_success_cell.clone(), always_success_cell_data.to_owned(), @@ -1715,20 +1715,20 @@ fn check_signature_referenced_via_type_hash_ok_with_multiple_matches() { args.extend(&to_hex_pubkey(&pubkey)); args.extend(&to_hex_signature(&signature)); - let dep_out_point = OutPoint::new(h256!("0x123").pack(), 8); + let dep_out_point = OutPoint::new(h256!("0x123").into(), 8); let cell_dep = CellDep::new_builder() .out_point(dep_out_point.clone()) .build(); let output = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .type_( Some( Script::new_builder() - .code_hash(h256!("0x123456abcd90").pack()) + .code_hash(h256!("0x123456abcd90").into()) .hash_type(ScriptHashType::Data.into()) .build(), ) - .pack(), + .into(), ) .build(); let type_hash = output.type_().to_opt().as_ref().unwrap().calc_script_hash(); @@ -1737,20 +1737,20 @@ fn check_signature_referenced_via_type_hash_ok_with_multiple_matches() { .out_point(dep_out_point) .build(); - let dep_out_point2 = OutPoint::new(h256!("0x1234").pack(), 8); + let dep_out_point2 = OutPoint::new(h256!("0x1234").into(), 8); let cell_dep2 = CellDep::new_builder() .out_point(dep_out_point2.clone()) .build(); let output2 = CellOutputBuilder::default() - .capacity(Capacity::bytes(data.len()).unwrap().pack()) + .capacity(Capacity::bytes(data.len()).unwrap().into()) .type_( Some( Script::new_builder() - .code_hash(h256!("0x123456abcd90").pack()) + .code_hash(h256!("0x123456abcd90").into()) .hash_type(ScriptHashType::Data.into()) .build(), ) - .pack(), + .into(), ) .build(); let dep_cell2 = CellMetaBuilder::from_cell_output(output2, data) @@ -1759,7 +1759,7 @@ fn check_signature_referenced_via_type_hash_ok_with_multiple_matches() { .build(); let script = Script::new_builder() - .args(Bytes::from(args).pack()) + .args(Bytes::from(args).into()) .code_hash(type_hash) .hash_type(ScriptHashType::Type.into()) .build(); @@ -1772,7 +1772,7 @@ fn check_signature_referenced_via_type_hash_ok_with_multiple_matches() { .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(script) .build(); let dummy_cell = create_dummy_cell(output); diff --git a/script/src/verify/tests/ckb_latest/features_since_v2023.rs b/script/src/verify/tests/ckb_latest/features_since_v2023.rs index aafed8439d..a613e2a240 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2023.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2023.rs @@ -41,7 +41,7 @@ fn check_vm_version() { .code_hash(vm_version_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(vm_version_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -73,7 +73,7 @@ fn check_get_memory_limit() { .code_hash(memory_limit_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(memory_limit_script) .build(); @@ -105,7 +105,7 @@ fn check_set_content() { .code_hash(set_content_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(memory_limit_script) .build(); @@ -140,7 +140,7 @@ fn check_spawn_strcat() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -173,7 +173,7 @@ fn check_spawn_strcat_data_hash() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -206,7 +206,7 @@ fn check_spawn_get_memory_limit() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -239,7 +239,7 @@ fn check_spawn_set_content() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -272,7 +272,7 @@ fn check_spawn_out_of_cycles() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -312,7 +312,7 @@ fn check_spawn_exec() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -349,7 +349,7 @@ fn check_spawn_strcat_wrap() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -386,7 +386,7 @@ fn check_spawn_out_of_cycles_wrap() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -428,7 +428,7 @@ fn check_spawn_recursive() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -463,7 +463,7 @@ fn check_spawn_big_memory_size() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -494,7 +494,7 @@ fn check_spawn_big_content_length() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -525,7 +525,7 @@ fn check_peak_memory_4m_to_32m() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -556,7 +556,7 @@ fn check_peak_memory_2m_to_32m() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -587,7 +587,7 @@ fn check_peak_memory_512k_to_32m() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -622,7 +622,7 @@ fn check_spawn_snapshot() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -663,7 +663,7 @@ fn check_spawn_state() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -728,7 +728,7 @@ fn check_spawn_current_memory() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -761,7 +761,7 @@ fn check_spawn_current_cycles() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -791,7 +791,7 @@ fn check_spawn_times_bug_1() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); @@ -823,7 +823,7 @@ fn check_spawn_times_bug_2() { .code_hash(spawn_caller_data_hash) .build(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(spawn_caller_script) .build(); let input = CellInput::new(OutPoint::null(), 0); diff --git a/script/src/verify/tests/utils.rs b/script/src/verify/tests/utils.rs index 8eaffcd64d..472a3ae739 100644 --- a/script/src/verify/tests/utils.rs +++ b/script/src/verify/tests/utils.rs @@ -67,7 +67,7 @@ pub(crate) fn load_cell_from_path(path_str: &str) -> (CellMeta, Byte32) { pub(crate) fn load_cell_from_slice(slice: &[u8]) -> (CellMeta, Byte32) { let cell_data = Bytes::copy_from_slice(slice); let cell_output = CellOutput::new_builder() - .capacity(Capacity::bytes(cell_data.len()).unwrap().pack()) + .capacity(Capacity::bytes(cell_data.len()).unwrap().into()) .build(); let cell_meta = CellMetaBuilder::from_cell_output(cell_output, cell_data) .transaction_info(default_transaction_info()) @@ -107,16 +107,16 @@ pub(crate) fn sign_args(args: &[u8], privkey: &Privkey) -> Signature { pub(crate) fn default_transaction_info() -> TransactionInfo { TransactionInfoBuilder::default() - .block_number(1u64.pack()) - .block_epoch(0u64.pack()) + .block_number(1u64.into()) + .block_epoch(0u64.into()) .key( TransactionKeyBuilder::default() .block_hash(Byte32::zero()) - .index(1u32.pack()) + .index(1u32.into()) .build(), ) .build() - .unpack() + .into() } pub(crate) struct TransactionScriptsVerifierWithEnv { @@ -248,7 +248,7 @@ impl TransactionScriptsVerifierWithEnv { ScriptVersion::V2 => EpochNumberWithFraction::new(self.version_2_enabled_at, 0, 1), }; let header = HeaderView::new_advanced_builder() - .epoch(epoch.pack()) + .epoch(epoch.into()) .build(); let tx_env = Arc::new(TxVerifyEnv::new_commit(&header)); let verifier = TransactionScriptsVerifier::new( @@ -271,8 +271,8 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { .dep_type(DepType::DepGroup.into()) .build(); - let input1 = CellInput::new(OutPoint::new(h256!("0x1234").pack(), 0), 0); - let input2 = CellInput::new(OutPoint::new(h256!("0x1111").pack(), 0), 0); + let input1 = CellInput::new(OutPoint::new(h256!("0x1234").into(), 0), 0); + let input2 = CellInput::new(OutPoint::new(h256!("0x1111").into(), 0), 0); let mut generator = Generator::non_crypto_safe_prng(42); let privkey = generator.gen_privkey(); @@ -283,23 +283,23 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { let lock_arg2 = Bytes::from((blake2b_256(pubkey_data2)[0..20]).to_owned()); let lock = Script::new_builder() - .args(lock_arg.pack()) - .code_hash(type_lock_script_code_hash().pack()) + .args(lock_arg.into()) + .code_hash(type_lock_script_code_hash().into()) .hash_type(ScriptHashType::Type.into()) .build(); let lock2 = Script::new_builder() - .args(lock_arg2.pack()) - .code_hash(type_lock_script_code_hash().pack()) + .args(lock_arg2.into()) + .code_hash(type_lock_script_code_hash().into()) .hash_type(ScriptHashType::Type.into()) .build(); let output1 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(lock.clone()) .build(); let output2 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(lock2.clone()) .build(); let tx = TransactionBuilder::default() @@ -312,11 +312,11 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { .output_data(Default::default()) .build(); - let tx_hash: H256 = tx.hash().unpack(); + let tx_hash: H256 = tx.hash().into(); // sign input1 let witness = { 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; @@ -331,11 +331,11 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { }; let sig = privkey.sign_recoverable(&message).expect("sign"); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(sig.serialize())).pack()) + .lock(Some(Bytes::from(sig.serialize())).into()) .build(); // sign input2 let witness2 = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).pack()) + .lock(Some(Bytes::from(vec![0u8; 65])).into()) .build(); let witness2_len: u64 = witness2.as_bytes().len() as u64; let mut hasher = new_blake2b(); @@ -349,12 +349,12 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { }; let sig2 = privkey2.sign_recoverable(&message2).expect("sign"); let witness2 = WitnessArgs::new_builder() - .lock(Some(Bytes::from(sig2.serialize())).pack()) + .lock(Some(Bytes::from(sig2.serialize())).into()) .build(); let tx = tx .as_advanced_builder() - .witness(witness.as_bytes().pack()) - .witness(witness2.as_bytes().pack()) + .witness(witness.as_bytes().into()) + .witness(witness2.as_bytes().into()) .build(); let serialized_size = tx.data().as_slice().len() as u64; @@ -370,7 +370,7 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { let (secp256k1_data_cell, secp256k1_data_cell_data) = secp256k1_data_cell(consensus); let input_cell1 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(lock) .build(); @@ -379,7 +379,7 @@ pub(super) fn random_2_in_2_out_rtx() -> ResolvedTransaction { .build(); let input_cell2 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(lock2) .build(); diff --git a/shared/src/shared.rs b/shared/src/shared.rs index fc3e9fea04..4bb04d4107 100644 --- a/shared/src/shared.rs +++ b/shared/src/shared.rs @@ -187,7 +187,7 @@ impl Shared { e })?; - let pack_number: packed::Uint64 = number.pack(); + let pack_number: packed::Uint64 = number.into(); let prefix = pack_number.as_slice(); for (key, value) in snapshot .get_iter( @@ -200,7 +200,7 @@ impl Shared { let block_hash = reader.block_hash().to_entity(); if &block_hash != hash { let txs = - packed::Uint32Reader::from_slice_should_be_ok(value.as_ref()).unpack(); + packed::Uint32Reader::from_slice_should_be_ok(value.as_ref()).into(); side.insert(block_hash, (reader.number().to_entity(), txs)); } } @@ -221,12 +221,10 @@ impl Shared { if !side.is_empty() { // Wipe out side chain for (hash, (number, txs)) in &side { - batch - .delete_block(number.unpack(), hash, *txs) - .map_err(|e| { - ckb_logger::error!("Freezer delete_block_body failed {}", e); - e - })?; + batch.delete_block(number.into(), hash, *txs).map_err(|e| { + ckb_logger::error!("Freezer delete_block_body failed {}", e); + e + })?; } self.store.write(&batch).map_err(|e| { @@ -246,12 +244,12 @@ impl Shared { fn compact_block_body(&self, start: &packed::Byte32, end: &packed::Byte32) { let start_t = packed::TransactionKey::new_builder() .block_hash(start.clone()) - .index(0u32.pack()) + .index(0u32.into()) .build(); let end_t = packed::TransactionKey::new_builder() .block_hash(end.clone()) - .index(TX_INDEX_UPPER_BOUND.pack()) + .index(TX_INDEX_UPPER_BOUND.into()) .build(); if let Err(e) = self.store.compact_range( diff --git a/spec/src/consensus.rs b/spec/src/consensus.rs index 2d8a16c481..1c5463b480 100644 --- a/spec/src/consensus.rs +++ b/spec/src/consensus.rs @@ -168,13 +168,13 @@ impl Default for ConsensusBuilder { let occupied = empty_output .occupied_capacity(Capacity::zero()) .expect("default occupied"); - empty_output.as_builder().capacity(occupied.pack()).build() + empty_output.as_builder().capacity(occupied.into()).build() }; let witness = Script::default().into_witness(); let cellbase = TransactionBuilder::default() .input(input) .output(output) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .witness(witness) .build(); @@ -200,8 +200,8 @@ impl Default for ConsensusBuilder { .expect("genesis dao data calculation error!"); let genesis_block = BlockBuilder::default() - .compact_target(DIFF_TWO.pack()) - .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).pack()) + .compact_target(DIFF_TWO.into()) + .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).into()) .dao(dao) .transaction(cellbase) .build(); @@ -964,7 +964,7 @@ impl Consensus { /// The network identify name, used for network identify protocol pub fn identify_name(&self) -> String { - let genesis_hash = format!("{:x}", Unpack::::unpack(&self.genesis_hash)); + let genesis_hash = format!("{:x}", Into::::into(&self.genesis_hash)); format!("/{}/{}", self.id, &genesis_hash[..8]) } @@ -1145,14 +1145,14 @@ impl From for ckb_jsonrpc_types::Consensus { }; Self { id: consensus.id, - genesis_hash: consensus.genesis_hash.unpack(), - dao_type_hash: consensus.dao_type_hash.unpack(), + genesis_hash: consensus.genesis_hash.into(), + dao_type_hash: consensus.dao_type_hash.into(), secp256k1_blake160_sighash_all_type_hash: consensus .secp256k1_blake160_sighash_all_type_hash - .map(|h| h.unpack()), + .map(|h| h.into()), secp256k1_blake160_multisig_all_type_hash: consensus .secp256k1_blake160_multisig_all_type_hash - .map(|h| h.unpack()), + .map(|h| h.into()), initial_primary_epoch_reward: consensus.initial_primary_epoch_reward.into(), secondary_epoch_reward: consensus.secondary_epoch_reward.into(), max_uncles_num: (consensus.max_uncles_num as u64).into(), diff --git a/spec/src/lib.rs b/spec/src/lib.rs index 4e029bc6cb..2d54b047c3 100644 --- a/spec/src/lib.rs +++ b/spec/src/lib.rs @@ -500,7 +500,7 @@ impl ChainSpec { fn verify_genesis_hash(&self, genesis: &BlockView) -> Result<(), Box> { if let Some(ref expect) = self.genesis.hash { - let actual: H256 = genesis.hash().unpack(); + let actual: H256 = genesis.hash().into(); if &actual != expect { return Err(SpecLoadError::genesis_mismatch(expect.clone(), actual)); } @@ -609,7 +609,7 @@ impl ChainSpec { .raw() .outputs() .iter() - .map(|output| Unpack::::unpack(&output.capacity())) + .map(|output| Into::::into(output.capacity())) .try_fold(Capacity::zero(), Capacity::safe_add) }?; @@ -633,14 +633,14 @@ impl ChainSpec { ); let block = BlockBuilder::default() - .version(self.genesis.version.pack()) - .parent_hash(self.genesis.parent_hash.pack()) - .timestamp(self.genesis.timestamp.pack()) - .compact_target(self.genesis.compact_target.pack()) - .extra_hash(self.genesis.uncles_hash.pack()) - .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).pack()) + .version(self.genesis.version.into()) + .parent_hash((&self.genesis.parent_hash).into()) + .timestamp(self.genesis.timestamp.into()) + .compact_target(self.genesis.compact_target.into()) + .extra_hash((&self.genesis.uncles_hash).into()) + .epoch(EpochNumberWithFraction::new_unchecked(0, 0, 0).into()) .dao(dao) - .nonce(u128::from_le_bytes(self.genesis.nonce.to_le_bytes()).pack()) + .nonce(u128::from_le_bytes(self.genesis.nonce.to_le_bytes()).into()) .transaction(cellbase_transaction) .transaction(dep_group_transaction) .build(); @@ -734,7 +734,7 @@ impl ChainSpec { // Check system cells data hash let check_cells_data_hash = |tx_index, output_index, hash: &H256| { - if data_hashes.get(&hash.pack()) != Some(&(tx_index, output_index)) { + if data_hashes.get(&hash.into()) != Some(&(tx_index, output_index)) { return Err(format!( "Invalid output data for tx-index: {tx_index}, output-index: {output_index}, expected data hash: {hash:x}", )); @@ -801,12 +801,12 @@ impl ChainSpec { outputs_data.extend(system_cells_data); let special_issued_lock = packed::Script::new_builder() - .args(secp_lock_arg(&Privkey::from(SPECIAL_CELL_PRIVKEY.clone())).pack()) - .code_hash(CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL.clone().pack()) + .args(secp_lock_arg(&Privkey::from(SPECIAL_CELL_PRIVKEY.clone())).into()) + .code_hash(CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL.clone().into()) .hash_type(ScriptHashType::Data.into()) .build(); let special_issued_cell = packed::CellOutput::new_builder() - .capacity(special_cell_capacity.pack()) + .capacity(special_cell_capacity.into()) .lock(special_issued_lock) .build(); outputs.push(special_issued_cell); @@ -829,7 +829,7 @@ impl ChainSpec { .outputs_data( outputs_data .iter() - .map(|d| d.pack()) + .map(|d| d.into()) .collect::>(), ) .build(); @@ -872,11 +872,11 @@ impl ChainSpec { }) .collect::>>()?; - let data = out_points.pack().as_bytes(); + let data = Into::::into(out_points).as_bytes(); let cell = packed::CellOutput::new_builder() .lock(self.genesis.system_cells_lock.clone().into()) .build_exact_capacity(Capacity::bytes(data.len())?)?; - Ok((cell, data.pack())) + Ok((cell, data.into())) }) .collect::, Box>>()? .into_iter() @@ -887,17 +887,17 @@ impl ChainSpec { let input_out_point = cellbase_tx .outputs() .into_iter() - .position(|output| Unpack::::unpack(&output.lock().args()) == lock_arg) + .position(|output| Into::::into(output.lock().args()) == lock_arg) .map(|index| packed::OutPoint::new(cellbase_tx.hash(), index as u32)) .expect("Get special issued input failed"); let input = packed::CellInput::new(input_out_point, 0); let secp_data_out_point = - find_out_point_by_data_hash(cellbase_tx, &CODE_HASH_SECP256K1_DATA.pack()) + find_out_point_by_data_hash(cellbase_tx, &CODE_HASH_SECP256K1_DATA.into()) .ok_or_else(|| String::from("Get secp data out point failed"))?; let secp_blake160_out_point = find_out_point_by_data_hash( cellbase_tx, - &CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL.pack(), + &CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL.into(), ) .ok_or_else(|| String::from("Get secp blake160 out point failed"))?; let cell_deps = vec![ @@ -915,10 +915,10 @@ impl ChainSpec { .outputs_data(outputs_data.clone()) .build(); - let tx_hash: H256 = tx.hash().unpack(); + let tx_hash: H256 = tx.hash().into(); let message = H256::from(blake2b_256(tx_hash)); let sig = privkey.sign_recoverable(&message).expect("sign"); - let witness = Bytes::from(sig.serialize()).pack(); + let witness = Bytes::from(sig.serialize()).into(); Ok(TransactionBuilder::default() .cell_deps(cell_deps) @@ -944,7 +944,7 @@ impl IssuedCell { fn build_output(&self) -> packed::CellOutput { packed::CellOutput::new_builder() .lock(self.lock.clone().into()) - .capacity(self.capacity.pack()) + .capacity(self.capacity.into()) .build() } } @@ -963,12 +963,12 @@ impl SystemCell { None }; let builder = packed::CellOutput::new_builder() - .type_(type_script.pack()) + .type_(type_script.into()) .lock(lock.clone().into()); let data_len = Capacity::bytes(data.len())?; let cell = if let Some(capacity) = self.capacity { - let cell = builder.capacity(capacity.pack()).build(); + let cell = builder.capacity(capacity.into()).build(); let occupied_capacity = cell.occupied_capacity(data_len)?.as_u64(); if occupied_capacity > capacity { return Err(format!( @@ -1004,9 +1004,9 @@ pub(crate) fn build_type_id_script(input: &packed::CellInput, output_index: u64) blake2b.finalize(&mut ret); let script_arg = Bytes::from(ret.to_vec()); packed::Script::new_builder() - .code_hash(TYPE_ID_CODE_HASH.pack()) + .code_hash(TYPE_ID_CODE_HASH.into()) .hash_type(ScriptHashType::Type.into()) - .args(script_arg.pack()) + .args(script_arg.into()) .build() } diff --git a/spec/src/tests/consensus.rs b/spec/src/tests/consensus.rs index eaa250ad76..d2fe44fe8e 100644 --- a/spec/src/tests/consensus.rs +++ b/spec/src/tests/consensus.rs @@ -5,7 +5,6 @@ use ckb_types::{ HeaderView, TransactionBuilder, }, packed::{Byte32, Bytes}, - prelude::*, utilities::DIFF_TWO, }; @@ -53,8 +52,8 @@ fn test_halving_epoch_reward() { let header = |epoch: &EpochExt, number: u64| { HeaderBuilder::default() - .number(number.pack()) - .epoch(epoch.number_with_fraction(number).pack()) + .number(number.into()) + .epoch(epoch.number_with_fraction(number).into()) .build() }; diff --git a/spec/src/tests/mod.rs b/spec/src/tests/mod.rs index ad621c1597..e5f23bb5b7 100644 --- a/spec/src/tests/mod.rs +++ b/spec/src/tests/mod.rs @@ -69,7 +69,7 @@ fn test_bundled_specs() { let consensus = consensus.unwrap(); let block = consensus.genesis_block(); let cellbase = block.transaction(0).unwrap(); - let cellbase_hash: H256 = cellbase.hash().unpack(); + let cellbase_hash: H256 = cellbase.hash().into(); assert_eq!(spec_hashes.cellbase, cellbase_hash); @@ -86,11 +86,11 @@ fn test_bundled_specs() { ) .enumerate() { - let data_hash: H256 = packed::CellOutput::calc_data_hash(&data.raw_data()).unpack(); + let data_hash: H256 = packed::CellOutput::calc_data_hash(&data.raw_data()).into(); let type_hash: Option = output .type_() .to_opt() - .map(|script| script.calc_script_hash().unpack()); + .map(|script| script.calc_script_hash().into()); assert_eq!(index_minus_one + 1, cell.index, "{bundled_spec_err}"); assert_eq!(cell.data_hash, data_hash, "{bundled_spec_err}"); assert_eq!(cell.type_hash, type_hash, "{bundled_spec_err}"); @@ -106,11 +106,11 @@ fn test_bundled_specs() { .output(dep_group_tx_input_index) .unwrap() .capacity() - .unpack(); + .into(); let outputs_capacity = dep_group_tx .outputs() .into_iter() - .map(|output| Unpack::::unpack(&output.capacity())) + .map(|output| Into::::into(&output.capacity())) .try_fold(Capacity::zero(), Capacity::safe_add) .unwrap(); // capacity for input and outputs should be same @@ -130,7 +130,7 @@ fn test_bundled_specs() { let dep_group = &spec_hashes.dep_groups[i]; // check the tx hashes of dep groups in spec file - let tx_hash = dep_group.tx_hash.pack(); + let tx_hash = Into::::into(&dep_group.tx_hash); assert_eq!(tx_hash, dep_group_tx.hash(), "{bundled_spec_err}"); let out_point_vec = packed::OutPointVec::from_slice(&output_data.raw_data()).unwrap(); @@ -148,7 +148,7 @@ fn test_bundled_specs() { // dep groups out_point should point to cellbase assert_eq!(cellbase.hash(), out_point.tx_hash(), "{bundled_spec_err}"); - let index_in_cellbase: usize = out_point.index().unpack(); + let index_in_cellbase: usize = out_point.index().into(); // check index for included cells in dep groups assert_eq!( diff --git a/spec/src/tests/versionbits.rs b/spec/src/tests/versionbits.rs index bcbb3aea57..e4aa549b4d 100644 --- a/spec/src/tests/versionbits.rs +++ b/spec/src/tests/versionbits.rs @@ -162,8 +162,8 @@ impl MockChain { let cellbase = TransactionBuilder::default().build(); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) .transaction(cellbase) .build() } @@ -175,16 +175,16 @@ impl MockChain { let version = self.compute_versionbits(parent).unwrap(); let cellbase_witness = CellbaseWitness::new_builder() - .message(version.to_le_bytes().as_slice().pack()) + .message(version.to_le_bytes().as_slice().into()) .build(); - let witness = cellbase_witness.as_bytes().pack(); + let witness = cellbase_witness.as_bytes().into(); let cellbase = TransactionBuilder::default().witness(witness).build(); BlockBuilder::default() .parent_hash(parent.hash()) - .number((parent.number() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) + .number((parent.number() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) .transaction(cellbase) .build() } @@ -208,7 +208,7 @@ fn test_versionbits_active() { DEFAULT_ORPHAN_RATE_TARGET, ); let genesis = BlockBuilder::default() - .epoch(epoch_ext.number_with_fraction(0).pack()) + .epoch(epoch_ext.number_with_fraction(0).into()) .transaction(cellbase) .build(); @@ -316,7 +316,7 @@ fn test_versionbits_failed() { DEFAULT_ORPHAN_RATE_TARGET, ); let genesis = BlockBuilder::default() - .epoch(epoch_ext.number_with_fraction(0).pack()) + .epoch(epoch_ext.number_with_fraction(0).into()) .transaction(cellbase) .build(); diff --git a/store/src/cell.rs b/store/src/cell.rs index 88c6e49e17..d840668230 100644 --- a/store/src/cell.rs +++ b/store/src/cell.rs @@ -41,23 +41,23 @@ pub fn attach_block_cell(txn: &StoreTransaction, block: &BlockView) -> Result<() .map(move |(index, (cell_output, data))| { let out_point = packed::OutPoint::new_builder() .tx_hash(tx_hash.clone()) - .index(index.pack()) + .index(index.into()) .build(); let entry = packed::CellEntryBuilder::default() .output(cell_output) .block_hash(block_hash.clone()) - .block_number(block_number.pack()) - .block_epoch(block_epoch.pack()) - .index(tx_index.pack()) - .data_size((data.len() as u64).pack()) + .block_number(block_number.into()) + .block_epoch(block_epoch.into()) + .index(tx_index.into()) + .data_size((data.len() as u64).into()) .build(); let data_entry = if !data.is_empty() { let data_hash = packed::CellOutput::calc_data_hash(&data); Some( packed::CellDataEntryBuilder::default() - .output_data(data.pack()) + .output_data(data.into()) .output_data_hash(data_hash) .build(), ) @@ -89,7 +89,7 @@ pub fn detach_block_cell(txn: &StoreTransaction, block: &BlockView) -> Result<() for tx in transactions.iter().skip(1) { for pts in tx.input_pts_iter() { let tx_hash = pts.tx_hash(); - let index: usize = pts.index().unpack(); + let index: usize = pts.index().into(); let indexes = input_pts.entry(tx_hash).or_insert_with(Vec::new); indexes.push(index); } @@ -111,23 +111,23 @@ pub fn detach_block_cell(txn: &StoreTransaction, block: &BlockView) -> Result<() tx.output_with_data(*index).map(|(cell_output, data)| { let out_point = packed::OutPoint::new_builder() .tx_hash(tx_hash.clone()) - .index(index.pack()) + .index(index.into()) .build(); let entry = packed::CellEntryBuilder::default() .output(cell_output) .block_hash(block_hash.clone()) - .block_number(block_number.pack()) - .block_epoch(block_epoch.pack()) - .index(tx_index.pack()) - .data_size((data.len() as u64).pack()) + .block_number(block_number.into()) + .block_epoch(block_epoch.into()) + .index(tx_index.into()) + .data_size((data.len() as u64).into()) .build(); let data_entry = if !data.is_empty() { let data_hash = packed::CellOutput::calc_data_hash(&data); Some( packed::CellDataEntryBuilder::default() - .output_data(data.pack()) + .output_data(data.into()) .output_data_hash(data_hash) .build(), ) diff --git a/store/src/store.rs b/store/src/store.rs index f686620701..b7c5265702 100644 --- a/store/src/store.rs +++ b/store/src/store.rs @@ -75,7 +75,7 @@ pub trait ChainStore: Send + Sync + Sized { }; let ret = self.get(COLUMN_BLOCK_HEADER, hash.as_slice()).map(|slice| { let reader = packed::HeaderViewReader::from_slice_should_be_ok(slice.as_ref()); - Unpack::::unpack(&reader) + Into::::into(reader) }); if let Some(cache) = self.cache() { @@ -98,7 +98,7 @@ pub trait ChainStore: Send + Sync + Sized { .take_while(|(key, _)| key.starts_with(prefix)) .map(|(_key, value)| { let reader = packed::TransactionViewReader::from_slice_should_be_ok(value.as_ref()); - Unpack::::unpack(&reader) + Into::::into(reader) }) .collect() } @@ -109,7 +109,7 @@ pub trait ChainStore: Send + Sync + Sized { .get(COLUMN_BLOCK_HEADER, hash.as_slice()) .map(|slice| { let reader = packed::HeaderViewReader::from_slice_should_be_ok(slice.as_ref()); - Unpack::::unpack(&reader) + Into::::into(reader) })?; let body = self.get_block_body(hash); @@ -119,7 +119,7 @@ pub trait ChainStore: Send + Sync + Sized { .map(|slice| { let reader = packed::UncleBlockVecViewReader::from_slice_should_be_ok(slice.as_ref()); - Unpack::::unpack(&reader) + Into::::into(reader) }) .expect("block uncles must be stored"); @@ -210,7 +210,7 @@ pub trait ChainStore: Send + Sync + Sized { let ret = self.get(COLUMN_BLOCK_UNCLE, hash.as_slice()).map(|slice| { let reader = packed::UncleBlockVecViewReader::from_slice_should_be_ok(slice.as_ref()); - Unpack::::unpack(&reader) + Into::::into(reader) }); if let Some(cache) = self.cache() { @@ -250,8 +250,8 @@ pub trait ChainStore: Send + Sync + Sized { let reader = packed::BlockExtReader::from_compatible_slice_should_be_ok(slice.as_ref()); match reader.count_extra_fields() { - 0 => reader.unpack(), - 2 => packed::BlockExtV1Reader::from_slice_should_be_ok(slice.as_ref()).unpack(), + 0 => reader.into(), + 2 => packed::BlockExtV1Reader::from_slice_should_be_ok(slice.as_ref()).into(), _ => { panic!( "BlockExt storage field count doesn't match, expect 7 or 5, actual {}", @@ -264,7 +264,7 @@ pub trait ChainStore: Send + Sync + Sized { /// Get block header hash by block number fn get_block_hash(&self, number: BlockNumber) -> Option { - let block_number: packed::Uint64 = number.pack(); + let block_number: packed::Uint64 = number.into(); self.get(COLUMN_INDEX, block_number.as_slice()) .map(|raw| packed::Byte32Reader::from_slice_should_be_ok(raw.as_ref()).to_entity()) } @@ -272,7 +272,7 @@ pub trait ChainStore: Send + Sync + Sized { /// Get block number by block header hash fn get_block_number(&self, hash: &packed::Byte32) -> Option { self.get(COLUMN_INDEX, hash.as_slice()) - .map(|raw| packed::Uint64Reader::from_slice_should_be_ok(raw.as_ref()).unpack()) + .map(|raw| packed::Uint64Reader::from_slice_should_be_ok(raw.as_ref()).into()) } /// TODO(doc): @quake @@ -310,7 +310,7 @@ pub trait ChainStore: Send + Sync + Sized { self.get(COLUMN_TRANSACTION_INFO, hash.as_slice()) .map(|slice| { let reader = packed::TransactionInfoReader::from_slice_should_be_ok(slice.as_ref()); - Unpack::::unpack(&reader) + Into::::into(reader) }) } @@ -334,7 +334,7 @@ pub trait ChainStore: Send + Sync + Sized { self.get(COLUMN_BLOCK_BODY, tx_info.key().as_slice()) .map(|slice| { let reader = packed::TransactionViewReader::from_slice_should_be_ok(slice.as_ref()); - (reader.unpack(), tx_info) + (reader.into(), tx_info) }) } @@ -365,7 +365,7 @@ pub trait ChainStore: Send + Sync + Sized { let ret = self.get(COLUMN_CELL_DATA, &key).map(|slice| { if !slice.as_ref().is_empty() { let reader = packed::CellDataEntryReader::from_slice_should_be_ok(slice.as_ref()); - let data = reader.output_data().unpack(); + let data = reader.output_data().into(); let data_hash = reader.output_data_hash().to_entity(); (data, data_hash) } else { @@ -374,7 +374,7 @@ pub trait ChainStore: Send + Sync + Sized { // if data.is_empty() { // packed::Byte32::zero() // } else { - // blake2b_256(data).pack() + // blake2b_256(data).into() // } // } // } @@ -410,7 +410,7 @@ pub trait ChainStore: Send + Sync + Sized { // if data.is_empty() { // packed::Byte32::zero() // } else { - // blake2b_256(data).pack() + // blake2b_256(data).into() // } // } // } @@ -431,18 +431,18 @@ pub trait ChainStore: Send + Sync + Sized { /// Gets current epoch ext fn get_current_epoch_ext(&self) -> Option { self.get(COLUMN_META, META_CURRENT_EPOCH_KEY) - .map(|slice| packed::EpochExtReader::from_slice_should_be_ok(slice.as_ref()).unpack()) + .map(|slice| packed::EpochExtReader::from_slice_should_be_ok(slice.as_ref()).into()) } /// Gets epoch ext by epoch index fn get_epoch_ext(&self, hash: &packed::Byte32) -> Option { self.get(COLUMN_EPOCH, hash.as_slice()) - .map(|slice| packed::EpochExtReader::from_slice_should_be_ok(slice.as_ref()).unpack()) + .map(|slice| packed::EpochExtReader::from_slice_should_be_ok(slice.as_ref()).into()) } /// Gets epoch index by epoch number fn get_epoch_index(&self, number: EpochNumber) -> Option { - let epoch_number: packed::Uint64 = number.pack(); + let epoch_number: packed::Uint64 = number.into(); self.get(COLUMN_EPOCH, epoch_number.as_slice()) .map(|raw| packed::Byte32Reader::from_slice_should_be_ok(raw.as_ref()).to_entity()) } @@ -468,7 +468,7 @@ pub trait ChainStore: Send + Sync + Sized { fn get_uncle_header(&self, hash: &packed::Byte32) -> Option { self.get(COLUMN_UNCLES, hash.as_slice()).map(|slice| { let reader = packed::HeaderViewReader::from_slice_should_be_ok(slice.as_ref()); - Unpack::::unpack(&reader) + Into::::into(reader) }) } @@ -489,7 +489,7 @@ pub trait ChainStore: Send + Sync + Sized { .build(); self.get(COLUMN_BLOCK_BODY, key.as_slice()).map(|slice| { let reader = packed::TransactionViewReader::from_slice_should_be_ok(slice.as_ref()); - Unpack::::unpack(&reader) + Into::::into(reader) }) } @@ -531,7 +531,8 @@ pub trait ChainStore: Send + Sync + Sized { let reader = packed::TransactionViewReader::from_slice_should_be_ok(value.as_ref()); reader.data().to_entity() }) - .pack(); + .collect::>() + .into(); let uncles = self.get_block_uncles(hash)?; let proposals = self.get_block_proposal_txs_ids(hash)?; @@ -568,7 +569,7 @@ pub trait ChainStore: Send + Sync + Sized { /// Gets a header digest. fn get_header_digest(&self, position_u64: u64) -> Option { - let position: packed::Uint64 = position_u64.pack(); + let position: packed::Uint64 = position_u64.into(); self.get(COLUMN_CHAIN_ROOT_MMR, position.as_slice()) .map(|slice| { let reader = packed::HeaderDigestReader::from_slice_should_be_ok(slice.as_ref()); @@ -597,12 +598,12 @@ fn build_cell_meta_from_reader(out_point: OutPoint, reader: packed::CellEntryRea out_point, cell_output: reader.output().to_entity(), transaction_info: Some(TransactionInfo { - block_number: reader.block_number().unpack(), + block_number: reader.block_number().into(), block_hash: reader.block_hash().to_entity(), - block_epoch: reader.block_epoch().unpack(), - index: reader.index().unpack(), + block_epoch: reader.block_epoch().into(), + index: reader.index().into(), }), - data_bytes: reader.data_size().unpack(), + data_bytes: reader.data_size().into(), mem_cell_data: None, mem_cell_data_hash: None, } diff --git a/store/src/tests/db.rs b/store/src/tests/db.rs index 39e1d24d61..39aff4e9a7 100644 --- a/store/src/tests/db.rs +++ b/store/src/tests/db.rs @@ -32,7 +32,7 @@ fn save_and_get_block_with_transactions() { (0..3) .map(|_| packed::Transaction::new_builder().build()) .collect::>() - .pack(), + .into(), ) .build() .into_view(); @@ -98,7 +98,7 @@ fn freeze_blockv0() { let freezer = Freezer::open_in(&tmp_dir2).expect("tmp freezer"); let store = ChainDB::new_with_freezer(db, freezer.clone(), Default::default()); - let raw = packed::RawHeader::new_builder().number(1u64.pack()).build(); + let raw = packed::RawHeader::new_builder().number(1u64.into()).build(); let block = packed::Block::new_builder() .header(packed::Header::new_builder().raw(raw).build()) .build() @@ -111,7 +111,7 @@ fn freeze_blockv0() { txn.insert_raw( COLUMN_BLOCK_HEADER, block_hash.as_slice(), - header.pack().as_slice(), + Into::::into(header).as_slice(), ) .expect("insert header"); txn.commit().expect("commit"); @@ -131,8 +131,8 @@ fn freeze_blockv1_with_extension() { let freezer = Freezer::open_in(&tmp_dir2).expect("tmp freezer"); let store = ChainDB::new_with_freezer(db, freezer.clone(), Default::default()); - let extension: packed::Bytes = [1u8; 96].pack(); - let raw = packed::RawHeader::new_builder().number(1u64.pack()).build(); + let extension: packed::Bytes = [1u8; 96].as_slice().into(); + let raw = packed::RawHeader::new_builder().number(1u64.into()).build(); let block = packed::BlockV1::new_builder() .header(packed::Header::new_builder().raw(raw).build()) .extension(extension) @@ -147,7 +147,7 @@ fn freeze_blockv1_with_extension() { txn.insert_raw( COLUMN_BLOCK_HEADER, block_hash.as_slice(), - header.pack().as_slice(), + Into::::into(header).as_slice(), ) .expect("insert header"); txn.commit().expect("commit"); diff --git a/store/src/transaction.rs b/store/src/transaction.rs index 62ba110b0f..ea7506728e 100644 --- a/store/src/transaction.rs +++ b/store/src/transaction.rs @@ -173,10 +173,10 @@ impl StoreTransaction { /// TODO(doc): @quake pub fn insert_block(&self, block: &BlockView) -> Result<(), Error> { let hash = block.hash(); - let header = block.header().pack(); - let uncles = block.uncles().pack(); + let header = Into::::into(block.header()); + let uncles = Into::::into(block.uncles()); let proposals = block.data().proposals(); - let txs_len: packed::Uint32 = (block.transactions().len() as u32).pack(); + let txs_len: packed::Uint32 = (block.transactions().len() as u32).into(); self.insert_raw(COLUMN_BLOCK_HEADER, hash.as_slice(), header.as_slice())?; self.insert_raw(COLUMN_BLOCK_UNCLE, hash.as_slice(), uncles.as_slice())?; if let Some(extension) = block.extension() { @@ -189,7 +189,7 @@ impl StoreTransaction { self.insert_raw( COLUMN_NUMBER_HASH, packed::NumberHash::new_builder() - .number(block.number().pack()) + .number(block.number().into()) .block_hash(hash.clone()) .build() .as_slice(), @@ -203,9 +203,9 @@ impl StoreTransaction { for (index, tx) in block.transactions().into_iter().enumerate() { let key = packed::TransactionKey::new_builder() .block_hash(hash.clone()) - .index(index.pack()) + .index(index.into()) .build(); - let tx_data = tx.pack(); + let tx_data = Into::::into(tx); self.insert_raw(COLUMN_BLOCK_BODY, key.as_slice(), tx_data.as_slice())?; } Ok(()) @@ -222,7 +222,7 @@ impl StoreTransaction { self.delete( COLUMN_NUMBER_HASH, packed::NumberHash::new_builder() - .number(block.number().pack()) + .number(block.number().into()) .block_hash(hash.clone()) .build() .as_slice(), @@ -232,7 +232,7 @@ impl StoreTransaction { for index in 0..txs_len { let key = packed::TransactionKey::new_builder() .block_hash(hash.clone()) - .index(index.pack()) + .index(index.into()) .build(); self.delete(COLUMN_BLOCK_BODY, key.as_slice())?; } @@ -245,7 +245,7 @@ impl StoreTransaction { block_hash: &packed::Byte32, ext: &BlockExt, ) -> Result<(), Error> { - let packed_ext: packed::BlockExtV1 = ext.pack(); + let packed_ext: packed::BlockExtV1 = ext.into(); self.insert_raw( COLUMN_BLOCK_EXT, block_hash.as_slice(), @@ -260,7 +260,7 @@ impl StoreTransaction { for (index, tx_hash) in block.tx_hashes().iter().enumerate() { let key = packed::TransactionKey::new_builder() .block_hash(block_hash.clone()) - .index(index.pack()) + .index(index.into()) .build(); let info = packed::TransactionInfo::new_builder() .key(key) @@ -269,13 +269,13 @@ impl StoreTransaction { .build(); self.insert_raw(COLUMN_TRANSACTION_INFO, tx_hash.as_slice(), info.as_slice())?; } - let block_number: packed::Uint64 = block.number().pack(); + let block_number: packed::Uint64 = block.number().into(); self.insert_raw(COLUMN_INDEX, block_number.as_slice(), block_hash.as_slice())?; for uncle in block.uncles().into_iter() { self.insert_raw( COLUMN_UNCLES, uncle.hash().as_slice(), - uncle.header().pack().as_slice(), + Into::::into(uncle.header()).as_slice(), )?; } self.insert_raw(COLUMN_INDEX, block_hash.as_slice(), block_number.as_slice()) @@ -309,14 +309,22 @@ impl StoreTransaction { /// TODO(doc): @quake pub fn insert_epoch_ext(&self, hash: &packed::Byte32, epoch: &EpochExt) -> Result<(), Error> { - self.insert_raw(COLUMN_EPOCH, hash.as_slice(), epoch.pack().as_slice())?; - let epoch_number: packed::Uint64 = epoch.number().pack(); + self.insert_raw( + COLUMN_EPOCH, + hash.as_slice(), + Into::::into(epoch).as_slice(), + )?; + let epoch_number: packed::Uint64 = epoch.number().into(); self.insert_raw(COLUMN_EPOCH, epoch_number.as_slice(), hash.as_slice()) } /// TODO(doc): @quake pub fn insert_current_epoch_ext(&self, epoch: &EpochExt) -> Result<(), Error> { - self.insert_raw(COLUMN_META, META_CURRENT_EPOCH_KEY, epoch.pack().as_slice()) + self.insert_raw( + COLUMN_META, + META_CURRENT_EPOCH_KEY, + Into::::into(epoch).as_slice(), + ) } /// TODO(doc): @quake @@ -368,7 +376,7 @@ impl StoreTransaction { position_u64: u64, header_digest: &packed::HeaderDigest, ) -> Result<(), Error> { - let position: packed::Uint64 = position_u64.pack(); + let position: packed::Uint64 = position_u64.into(); self.insert_raw( COLUMN_CHAIN_ROOT_MMR, position.as_slice(), @@ -378,7 +386,7 @@ impl StoreTransaction { /// Deletes a header digest. pub fn delete_header_digest(&self, position_u64: u64) -> Result<(), Error> { - let position: packed::Uint64 = position_u64.pack(); + let position: packed::Uint64 = position_u64.into(); self.delete(COLUMN_CHAIN_ROOT_MMR, position.as_slice()) } diff --git a/store/src/write_batch.rs b/store/src/write_batch.rs index 65d74e2dc1..367b9bb165 100644 --- a/store/src/write_batch.rs +++ b/store/src/write_batch.rs @@ -100,7 +100,7 @@ impl StoreWriteBatch { self.inner.delete( COLUMN_NUMBER_HASH, packed::NumberHash::new_builder() - .number(number.pack()) + .number(number.into()) .block_hash(hash.clone()) .build() .as_slice(), @@ -109,7 +109,7 @@ impl StoreWriteBatch { let key_range = (0u32..txs_len).map(|i| { packed::TransactionKey::new_builder() .block_hash(hash.clone()) - .index(i.pack()) + .index(i.into()) .build() }); diff --git a/sync/src/filter/get_block_filter_check_points_process.rs b/sync/src/filter/get_block_filter_check_points_process.rs index a194525052..56ef4e08db 100644 --- a/sync/src/filter/get_block_filter_check_points_process.rs +++ b/sync/src/filter/get_block_filter_check_points_process.rs @@ -33,7 +33,7 @@ impl<'a> GetBlockFilterCheckPointsProcess<'a> { pub fn execute(self) -> Status { let active_chain = self.filter.shared.active_chain(); - let start_number: BlockNumber = self.message.to_entity().start_number().unpack(); + let start_number: BlockNumber = self.message.to_entity().start_number().into(); let latest: BlockNumber = active_chain.get_latest_built_filter_block_number(); let mut block_filter_hashes = Vec::new(); @@ -52,8 +52,8 @@ impl<'a> GetBlockFilterCheckPointsProcess<'a> { } } let content = packed::BlockFilterCheckPoints::new_builder() - .start_number(start_number.pack()) - .block_filter_hashes(block_filter_hashes.pack()) + .start_number(start_number.into()) + .block_filter_hashes(block_filter_hashes.into()) .build(); let message = packed::BlockFilterMessage::new_builder() diff --git a/sync/src/filter/get_block_filter_hashes_process.rs b/sync/src/filter/get_block_filter_hashes_process.rs index c1a3f5a6e0..25142bc2d6 100644 --- a/sync/src/filter/get_block_filter_hashes_process.rs +++ b/sync/src/filter/get_block_filter_hashes_process.rs @@ -31,7 +31,7 @@ impl<'a> GetBlockFilterHashesProcess<'a> { pub fn execute(self) -> Status { let active_chain = self.filter.shared.active_chain(); - let start_number: BlockNumber = self.message.to_entity().start_number().unpack(); + let start_number: BlockNumber = self.message.to_entity().start_number().into(); let latest: BlockNumber = active_chain.get_latest_built_filter_block_number(); let mut block_filter_hashes = Vec::new(); @@ -60,9 +60,9 @@ impl<'a> GetBlockFilterHashesProcess<'a> { } } let content = packed::BlockFilterHashes::new_builder() - .start_number(start_number.pack()) + .start_number(start_number.into()) .parent_block_filter_hash(parent_block_filter_hash) - .block_filter_hashes(block_filter_hashes.pack()) + .block_filter_hashes(block_filter_hashes.into()) .build(); let message = packed::BlockFilterMessage::new_builder() diff --git a/sync/src/filter/get_block_filters_process.rs b/sync/src/filter/get_block_filters_process.rs index 22e527f0e5..8d8257a04b 100644 --- a/sync/src/filter/get_block_filters_process.rs +++ b/sync/src/filter/get_block_filters_process.rs @@ -32,7 +32,7 @@ impl<'a> GetBlockFiltersProcess<'a> { pub fn execute(self) -> Status { let active_chain = self.filter.shared.active_chain(); - let start_number: BlockNumber = self.message.to_entity().start_number().unpack(); + let start_number: BlockNumber = self.message.to_entity().start_number().into(); let latest: BlockNumber = active_chain.get_latest_built_filter_block_number(); if latest >= start_number { @@ -51,9 +51,9 @@ impl<'a> GetBlockFiltersProcess<'a> { } } let content = packed::BlockFilters::new_builder() - .start_number(start_number.pack()) - .block_hashes(block_hashes.pack()) - .filters(filters.pack()) + .start_number(start_number.into()) + .block_hashes(block_hashes.into()) + .filters(filters.into()) .build(); let message = packed::BlockFilterMessage::new_builder() diff --git a/sync/src/net_time_checker.rs b/sync/src/net_time_checker.rs index 259a2eae57..3b7c2acc79 100644 --- a/sync/src/net_time_checker.rs +++ b/sync/src/net_time_checker.rs @@ -118,7 +118,7 @@ impl CKBProtocolHandler for NetTimeProtocol { // send local time to inbound peers if let Some(true) = nc.get_peer(peer_index).map(|peer| peer.is_inbound()) { let now = ckb_systemtime::unix_time_as_millis(); - let time = packed::Time::new_builder().timestamp(now.pack()).build(); + let time = packed::Time::new_builder().timestamp(now.into()).build(); let _status = send_message_to(nc.as_ref(), peer_index, &time); } } @@ -137,7 +137,7 @@ impl CKBProtocolHandler for NetTimeProtocol { } let timestamp: u64 = match packed::TimeReader::from_slice(&data) - .map(|time| time.timestamp().unpack()) + .map(|time| time.timestamp().into()) .ok() { Some(timestamp) => timestamp, diff --git a/sync/src/relayer/block_transactions_process.rs b/sync/src/relayer/block_transactions_process.rs index 6b1161b36e..da236e034e 100644 --- a/sync/src/relayer/block_transactions_process.rs +++ b/sync/src/relayer/block_transactions_process.rs @@ -163,8 +163,8 @@ impl<'a> BlockTransactionsProcess<'a> { let content = packed::GetBlockTransactions::new_builder() .block_hash(block_hash.clone()) - .indexes(missing_transactions.pack()) - .uncle_indexes(missing_uncles.pack()) + .indexes(missing_transactions.as_slice().into()) + .uncle_indexes(missing_uncles.as_slice().into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/sync/src/relayer/compact_block_process.rs b/sync/src/relayer/compact_block_process.rs index 3bd1d5043c..cb92337ce0 100644 --- a/sync/src/relayer/compact_block_process.rs +++ b/sync/src/relayer/compact_block_process.rs @@ -111,7 +111,7 @@ impl<'a> CompactBlockProcess<'a> { // use epoch as the judgment condition because we accept // all block in current epoch as uncle block pending_compact_blocks.retain(|_, (v, _, _)| { - Unpack::::unpack(&v.header().as_reader().raw().epoch()) + Into::::into(v.header().as_reader().raw().epoch()) .number() >= block.epoch().number() }); @@ -359,8 +359,8 @@ fn missing_or_collided_post_process( let content = packed::GetBlockTransactions::new_builder() .block_hash(block_hash) - .indexes(missing_transactions.pack()) - .uncle_indexes(missing_uncles.pack()) + .indexes(missing_transactions.as_slice().into()) + .uncle_indexes(missing_uncles.as_slice().into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let sending = send_message_to(nc.as_ref(), peer, &message); diff --git a/sync/src/relayer/compact_block_verifier.rs b/sync/src/relayer/compact_block_verifier.rs index 549735c1cb..61ce34772e 100644 --- a/sync/src/relayer/compact_block_verifier.rs +++ b/sync/src/relayer/compact_block_verifier.rs @@ -1,5 +1,5 @@ use crate::{attempt, Status, StatusCode}; -use ckb_types::{packed, prelude::*}; +use ckb_types::packed; use std::collections::HashSet; // we assume that all the short_ids and prefilled transactions @@ -28,7 +28,7 @@ impl PrefilledVerifier { return StatusCode::CompactBlockHasNotPrefilledCellbase.into(); } else { // Check first prefilled index is zero - let index: usize = prefilled_transactions.get(0).unwrap().index().unpack(); + let index: usize = prefilled_transactions.get(0).unwrap().index().into(); if index != 0 { return StatusCode::CompactBlockHasNotPrefilledCellbase.into(); } @@ -38,7 +38,7 @@ impl PrefilledVerifier { .get(prefilled_transactions.len() - 1) .unwrap() .index() - .unpack(); + .into(); if index >= txs_len { return StatusCode::CompactBlockHasOutOfIndexPrefilledTransactions.into(); } @@ -46,8 +46,8 @@ impl PrefilledVerifier { // Check indices order of prefilled transactions for i in 0..(prefilled_transactions.len() - 1) { - let idx0: usize = prefilled_transactions.get(i).unwrap().index().unpack(); - let idx1: usize = prefilled_transactions.get(i + 1).unwrap().index().unpack(); + let idx0: usize = prefilled_transactions.get(i).unwrap().index().into(); + let idx1: usize = prefilled_transactions.get(i + 1).unwrap().index().into(); if idx0 >= idx1 { return StatusCode::CompactBlockHasOutOfOrderPrefilledTransactions.into(); } diff --git a/sync/src/relayer/get_block_proposal_process.rs b/sync/src/relayer/get_block_proposal_process.rs index b7321ba1c3..052c684c37 100644 --- a/sync/src/relayer/get_block_proposal_process.rs +++ b/sync/src/relayer/get_block_proposal_process.rs @@ -97,7 +97,7 @@ impl<'a> GetBlockProposalProcess<'a> { fn send_block_proposals(&self, txs: Vec) -> Status { let content = packed::BlockProposal::new_builder() - .transactions(txs.into_iter().pack()) + .transactions(txs.into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); send_message_to(self.nc.as_ref(), self.peer, &message) diff --git a/sync/src/relayer/get_block_transactions_process.rs b/sync/src/relayer/get_block_transactions_process.rs index bfff3ebc11..acb332993f 100644 --- a/sync/src/relayer/get_block_transactions_process.rs +++ b/sync/src/relayer/get_block_transactions_process.rs @@ -4,6 +4,7 @@ use crate::{attempt, Status, StatusCode}; use ckb_logger::debug_target; use ckb_network::{CKBProtocolContext, PeerIndex}; use ckb_store::ChainStore; +use ckb_types::packed::{Transaction, UncleBlock}; use ckb_types::{packed, prelude::*}; use std::sync::Arc; @@ -65,7 +66,7 @@ impl<'a> GetBlockTransactionsProcess<'a> { .filter_map(|i| { block .transactions() - .get(Unpack::::unpack(&i) as usize) + .get(Into::::into(i) as usize) .cloned() }) .collect::>(); @@ -74,13 +75,25 @@ impl<'a> GetBlockTransactionsProcess<'a> { .message .uncle_indexes() .iter() - .filter_map(|i| block.uncles().get(Unpack::::unpack(&i) as usize)) + .filter_map(|i| block.uncles().get(Into::::into(i) as usize)) .collect::>(); let content = packed::BlockTransactions::new_builder() .block_hash(block_hash) - .transactions(transactions.into_iter().map(|tx| tx.data()).pack()) - .uncles(uncles.into_iter().map(|uncle| uncle.data()).pack()) + .transactions( + transactions + .into_iter() + .map(|tx| tx.data()) + .collect::>() + .into(), + ) + .uncles( + uncles + .into_iter() + .map(|uncle| uncle.data()) + .collect::>() + .into(), + ) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/sync/src/relayer/get_transactions_process.rs b/sync/src/relayer/get_transactions_process.rs index 60e8067455..36370f22ae 100644 --- a/sync/src/relayer/get_transactions_process.rs +++ b/sync/src/relayer/get_transactions_process.rs @@ -76,7 +76,7 @@ impl<'a> GetTransactionsProcess<'a> { .into_iter() .map(|(_, (tx, cycles))| { packed::RelayTransaction::new_builder() - .cycles(cycles.pack()) + .cycles(cycles.into()) .transaction(tx.data()) .build() }) diff --git a/sync/src/relayer/mod.rs b/sync/src/relayer/mod.rs index bfcdc28dfa..dd2620412b 100644 --- a/sync/src/relayer/mod.rs +++ b/sync/src/relayer/mod.rs @@ -35,6 +35,7 @@ use ckb_network::{ }; use ckb_systemtime::unix_time_as_millis; use ckb_tx_pool::service::TxVerificationResult; +use ckb_types::packed::Transaction; use ckb_types::BlockNumberAndHash; use ckb_types::{ core::{self, BlockView}, @@ -269,7 +270,7 @@ impl Relayer { if !to_ask_proposals.is_empty() { let content = packed::GetBlockProposal::new_builder() .block_hash(block_hash_and_number.hash) - .proposals(to_ask_proposals.clone().pack()) + .proposals(to_ask_proposals.clone().into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); if !send_message_to(nc, peer, &message).is_ok() { @@ -373,7 +374,7 @@ impl Relayer { let tip_header = packed::VerifiableHeader::new_builder() .header(boxed.header().data()) .uncles_hash(boxed.calc_uncles_hash()) - .extension(Pack::pack(&boxed.extension())) + .extension(boxed.extension().into()) .parent_chain_root(parent_chain_root) .build(); let light_client_message = { @@ -465,7 +466,7 @@ impl Relayer { .prefilled_transactions() .into_iter() .for_each(|pt| { - let index: usize = pt.index().unpack(); + let index: usize = pt.index().into(); let gap = index - block_transactions.len(); if gap > 0 { short_ids_iter @@ -542,8 +543,13 @@ impl Relayer { let block = if let Some(extension) = compact_block.extension() { packed::BlockV1::new_builder() .header(compact_block.header()) - .uncles(uncles.pack()) - .transactions(txs.into_iter().map(|tx| tx.data()).pack()) + .uncles(uncles.into()) + .transactions( + txs.into_iter() + .map(|tx| tx.data()) + .collect::>() + .into(), + ) .proposals(compact_block.proposals()) .extension(extension) .build() @@ -551,8 +557,13 @@ impl Relayer { } else { packed::Block::new_builder() .header(compact_block.header()) - .uncles(uncles.pack()) - .transactions(txs.into_iter().map(|tx| tx.data()).pack()) + .uncles(uncles.into()) + .transactions( + txs.into_iter() + .map(|tx| tx.data()) + .collect::>() + .into(), + ) .proposals(compact_block.proposals()) .build() } @@ -640,7 +651,7 @@ impl Relayer { let send_block_proposals = |nc: &dyn CKBProtocolContext, peer_index: PeerIndex, txs: Vec| { let content = packed::BlockProposal::new_builder() - .transactions(txs.into_iter().pack()) + .transactions(txs.into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let status = send_message_to(nc, peer_index, &message); @@ -686,7 +697,7 @@ impl Relayer { ); tx_hashes.truncate(MAX_RELAY_TXS_NUM_PER_BATCH); let content = packed::GetRelayTransactions::new_builder() - .tx_hashes(tx_hashes.pack()) + .tx_hashes(tx_hashes.into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let status = send_message_to(nc, peer, &message); @@ -757,7 +768,7 @@ impl Relayer { } for (peer, hashes) in selected { let content = packed::RelayTransactionHashes::new_builder() - .tx_hashes(hashes.pack()) + .tx_hashes(hashes.into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/sync/src/relayer/tests/block_proposal_process.rs b/sync/src/relayer/tests/block_proposal_process.rs index e88ec876ad..bca97bcb0a 100644 --- a/sync/src/relayer/tests/block_proposal_process.rs +++ b/sync/src/relayer/tests/block_proposal_process.rs @@ -1,7 +1,7 @@ use crate::relayer::block_proposal_process::BlockProposalProcess; use crate::relayer::tests::helper::{build_chain, new_transaction}; use crate::Status; -use ckb_types::packed::{self, ProposalShortId}; +use ckb_types::packed::{self, ProposalShortId, Transaction}; use ckb_types::prelude::*; #[test] @@ -16,7 +16,13 @@ fn test_no_unknown() { relayer.shared.state().mark_as_known_tx(transaction.hash()); } let content = packed::BlockProposal::new_builder() - .transactions(transactions.into_iter().map(|tx| tx.data()).pack()) + .transactions( + transactions + .into_iter() + .map(|tx| tx.data()) + .collect::>() + .into(), + ) .build(); let process = BlockProposalProcess::new(content.as_reader(), &relayer); @@ -31,7 +37,13 @@ fn test_no_asked() { let transactions = vec![transaction.clone()]; let content = packed::BlockProposal::new_builder() - .transactions(transactions.into_iter().map(|tx| tx.data()).pack()) + .transactions( + transactions + .into_iter() + .map(|tx| tx.data()) + .collect::>() + .into(), + ) .build(); let process = BlockProposalProcess::new(content.as_reader(), &relayer); @@ -60,7 +72,13 @@ fn test_ok() { } let content = packed::BlockProposal::new_builder() - .transactions(transactions.into_iter().map(|tx| tx.data()).pack()) + .transactions( + transactions + .into_iter() + .map(|tx| tx.data()) + .collect::>() + .into(), + ) .build(); let process = BlockProposalProcess::new(content.as_reader(), &relayer); @@ -89,7 +107,13 @@ fn test_clear_expired_inflight_proposals() { } let content = packed::BlockProposal::new_builder() - .transactions(transactions.into_iter().map(|tx| tx.data()).pack()) + .transactions( + transactions + .into_iter() + .map(|tx| tx.data()) + .collect::>() + .into(), + ) .build(); let process = BlockProposalProcess::new(content.as_reader(), &relayer); diff --git a/sync/src/relayer/tests/block_transactions_process.rs b/sync/src/relayer/tests/block_transactions_process.rs index 8b106b7d3f..ad32e0c018 100644 --- a/sync/src/relayer/tests/block_transactions_process.rs +++ b/sync/src/relayer/tests/block_transactions_process.rs @@ -26,22 +26,24 @@ fn test_accept_block() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().pack()) + .capacity(Capacity::bytes(1).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let tx3 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(2).unwrap().pack()) + .capacity(Capacity::bytes(2).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let uncle = BlockBuilder::default() - .proposals(vec![tx3.proposal_short_id()].pack()) + .proposals(Into::::into(vec![ + tx3.proposal_short_id() + ])) .build(); let block = BlockBuilder::default() @@ -70,8 +72,8 @@ fn test_accept_block() { let block_transactions: BlockTransactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data()].pack()) - .uncles(vec![uncle.as_uncle().data()].pack()) + .transactions(vec![tx2.data()].into()) + .uncles(vec![uncle.as_uncle().data()].into()) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -104,10 +106,10 @@ fn test_unknown_request() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().pack()) + .capacity(Capacity::bytes(1).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let block = BlockBuilder::default() @@ -133,7 +135,7 @@ fn test_unknown_request() { let block_transactions: BlockTransactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data()].pack()) + .transactions(vec![tx2.data()].into()) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -157,14 +159,14 @@ fn test_invalid_transaction_root() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().pack()) + .capacity(Capacity::bytes(1).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let prefilled = IndexTransaction::new_builder() - .index(0u32.pack()) + .index(0u32.into()) .transaction(tx1.data()) .build(); @@ -178,8 +180,8 @@ fn test_invalid_transaction_root() { let compact_block = packed::CompactBlock::new_builder() .header(header_with_invalid_tx_root) - .short_ids(vec![tx2.proposal_short_id()].pack()) - .prefilled_transactions(vec![prefilled].pack()) + .short_ids(vec![tx2.proposal_short_id()].into()) + .prefilled_transactions(vec![prefilled].into()) .build(); let block_hash = compact_block.header().calc_header_hash(); @@ -198,7 +200,7 @@ fn test_invalid_transaction_root() { let block_transactions: BlockTransactions = packed::BlockTransactions::new_builder() .block_hash(block_hash) - .transactions(vec![tx2.data()].pack()) + .transactions(vec![tx2.data()].into()) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -234,19 +236,19 @@ fn test_collision_and_send_missing_indexes() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1000).unwrap().pack()) + .capacity(Capacity::bytes(1000).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let tx3 = TransactionBuilder::default() .input(CellInput::new(OutPoint::new(last_cellbase.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(2).unwrap().pack()) + .capacity(Capacity::bytes(2).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let fake_hash = tx3 @@ -294,7 +296,7 @@ fn test_collision_and_send_missing_indexes() { let block_transactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data()].pack()) + .transactions(vec![tx2.data()].into()) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -313,7 +315,7 @@ fn test_collision_and_send_missing_indexes() { let content = packed::GetBlockTransactions::new_builder() .block_hash(block.header().hash()) - .indexes([1u32, 2u32].pack()) + .indexes([1u32, 2u32].into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let data = message.as_bytes(); @@ -337,7 +339,7 @@ fn test_collision_and_send_missing_indexes() { // resend BlockTransactions with all the transactions without prefilled let new_block_transactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data(), tx3.data()].pack()) + .transactions(vec![tx2.data(), tx3.data()].into()) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -370,18 +372,18 @@ fn test_missing() { let tx2 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().pack()) + .capacity(Capacity::bytes(1).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let tx3 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(2).unwrap().pack()) + .capacity(Capacity::bytes(2).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let block = BlockBuilder::default() @@ -408,7 +410,7 @@ fn test_missing() { let block_transactions = packed::BlockTransactions::new_builder() .block_hash(block.header().hash()) - .transactions(vec![tx2.data()].pack()) + .transactions(vec![tx2.data()].into()) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); @@ -427,7 +429,7 @@ fn test_missing() { let content = packed::GetBlockTransactions::new_builder() .block_hash(block.header().hash()) - .indexes([1, 2u32].pack()) + .indexes([1, 2u32].into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/sync/src/relayer/tests/block_transactions_verifier.rs b/sync/src/relayer/tests/block_transactions_verifier.rs index 16d49ac962..485fe1573a 100644 --- a/sync/src/relayer/tests/block_transactions_verifier.rs +++ b/sync/src/relayer/tests/block_transactions_verifier.rs @@ -1,21 +1,25 @@ use super::helper::new_index_transaction; use crate::relayer::block_transactions_verifier::BlockTransactionsVerifier; use crate::{Status, StatusCode}; -use ckb_types::packed::{CompactBlock, CompactBlockBuilder}; +use ckb_types::packed::{self, CompactBlock, CompactBlockBuilder}; use ckb_types::prelude::*; // block_short_ids: vec![None, Some(1), None, Some(3), Some(4), None] fn build_compact_block() -> CompactBlock { - let prefilled_iter = vec![0, 2, 5].into_iter().map(new_index_transaction); + let prefilled_iter = vec![0, 2, 5] + .into_iter() + .map(new_index_transaction) + .collect::>(); let short_ids = vec![1, 3, 4] .into_iter() .map(new_index_transaction) - .map(|tx| tx.transaction().proposal_short_id()); + .map(|tx| tx.transaction().proposal_short_id()) + .collect::>(); CompactBlockBuilder::default() - .short_ids(short_ids.pack()) - .prefilled_transactions(prefilled_iter.pack()) + .short_ids(short_ids.into()) + .prefilled_transactions(prefilled_iter.into()) .build() } diff --git a/sync/src/relayer/tests/compact_block.rs b/sync/src/relayer/tests/compact_block.rs index 12845293f8..92ecaadb50 100644 --- a/sync/src/relayer/tests/compact_block.rs +++ b/sync/src/relayer/tests/compact_block.rs @@ -13,18 +13,18 @@ fn test_block_short_ids() { ]; let prefilled_transactions = vec![ IndexTransactionBuilder::default() - .index(0u32.pack()) + .index(0u32.into()) .transaction(TransactionBuilder::default().build().data()) .build(), IndexTransactionBuilder::default() - .index(2u32.pack()) + .index(2u32.into()) .transaction(TransactionBuilder::default().build().data()) .build(), ]; let compact_block = compact_block_builder - .short_ids(short_ids.into_iter().pack()) - .prefilled_transactions(prefilled_transactions.into_iter().pack()) + .short_ids(short_ids.into()) + .prefilled_transactions(prefilled_transactions.into()) .build(); assert_eq!( diff --git a/sync/src/relayer/tests/compact_block_process.rs b/sync/src/relayer/tests/compact_block_process.rs index 3088aae90c..ee9a6a4d2b 100644 --- a/sync/src/relayer/tests/compact_block_process.rs +++ b/sync/src/relayer/tests/compact_block_process.rs @@ -112,9 +112,9 @@ fn test_unknow_parent() { let block = BlockBuilder::default() .header( HeaderBuilder::default() - .number(5.pack()) - .epoch(EpochNumberWithFraction::new(1, 5, 1000).pack()) - .timestamp(unix_time_as_millis().pack()) + .number(5.into()) + .epoch(EpochNumberWithFraction::new(1, 5, 1000).into()) + .timestamp(unix_time_as_millis().into()) .build(), ) .transaction(TransactionBuilder::default().build()) @@ -144,7 +144,7 @@ fn test_unknow_parent() { let locator_hash = active_chain.get_locator((&header).into()); let content = packed::GetHeaders::new_builder() - .block_locator_hashes(locator_hash.pack()) + .block_locator_hashes(locator_hash.into()) .hash_stop(packed::Byte32::zero()) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); @@ -211,7 +211,7 @@ fn test_header_invalid() { // Better block but block number is invalid let header = new_header_builder(relayer.shared.shared(), &parent) - .number(4.pack()) + .number(4.into()) .build(); let block = BlockBuilder::default() @@ -269,10 +269,10 @@ fn test_send_missing_indexes() { TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1).unwrap().pack()) + .capacity(Capacity::bytes(1).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(), ) .uncle(uncle.as_uncle()) @@ -305,8 +305,8 @@ fn test_send_missing_indexes() { let content = packed::GetBlockTransactions::new_builder() .block_hash(block.header().hash()) - .indexes([1u32].pack()) - .uncle_indexes([0u32].pack()) + .indexes([1u32].into()) + .uncle_indexes([0u32].into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let data = message.as_bytes(); @@ -322,7 +322,7 @@ fn test_send_missing_indexes() { let content = packed::GetBlockProposal::new_builder() .block_hash(block.header().hash()) - .proposals(vec![proposal_id].into_iter().pack()) + .proposals(vec![proposal_id].into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let data = message.as_bytes(); @@ -350,12 +350,12 @@ fn test_accept_block() { ); let mock_block_1 = BlockBuilder::default() - .number(4.pack()) - .epoch(EpochNumberWithFraction::new(1, 4, 1000).pack()) + .number(4.into()) + .epoch(EpochNumberWithFraction::new(1, 4, 1000).into()) .build(); let mock_compact_block_1 = CompactBlock::build_from_block(&mock_block_1, &Default::default()); - let mock_block_2 = block.as_advanced_builder().number(7.pack()).build(); + let mock_block_2 = block.as_advanced_builder().number(7.into()).build(); let mock_compact_block_2 = CompactBlock::build_from_block(&mock_block_2, &Default::default()); { let mut pending_compact_blocks = relayer.shared.state().pending_compact_blocks(); @@ -502,11 +502,11 @@ fn test_collision() { let missing_tx = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(1000).unwrap().pack()) + .capacity(Capacity::bytes(1000).unwrap().into()) .build(), ) .input(CellInput::new(OutPoint::new(last_cellbase.hash(), 0), 0)) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let fake_hash = missing_tx @@ -569,7 +569,7 @@ fn test_collision() { let content = packed::GetBlockTransactions::new_builder() .block_hash(block.header().hash()) - .indexes([1u32].pack()) + .indexes([1u32].into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); let data = message.as_bytes(); diff --git a/sync/src/relayer/tests/compact_block_verifier.rs b/sync/src/relayer/tests/compact_block_verifier.rs index e0d7f3125d..4c0b9e686d 100644 --- a/sync/src/relayer/tests/compact_block_verifier.rs +++ b/sync/src/relayer/tests/compact_block_verifier.rs @@ -1,14 +1,17 @@ use super::helper::new_index_transaction; use crate::relayer::compact_block_verifier::{PrefilledVerifier, ShortIdsVerifier}; use crate::{Status, StatusCode}; -use ckb_types::packed::{CompactBlockBuilder, ProposalShortId}; +use ckb_types::packed::{self, CompactBlockBuilder, ProposalShortId}; use ckb_types::prelude::*; #[test] fn test_unordered_prefilled() { - let prefilled = vec![0, 1, 2, 4, 3].into_iter().map(new_index_transaction); + let prefilled = vec![0, 1, 2, 4, 3] + .into_iter() + .map(new_index_transaction) + .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.pack()) + .prefilled_transactions(prefilled.into()) .build(); assert_eq!( PrefilledVerifier::verify(&block), @@ -18,18 +21,23 @@ fn test_unordered_prefilled() { #[test] fn test_ordered_prefilled() { - let prefilled = (0..5).map(new_index_transaction); + let prefilled = (0..5) + .map(new_index_transaction) + .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.pack()) + .prefilled_transactions(prefilled.into()) .build(); assert_eq!(PrefilledVerifier::verify(&block), Status::ok()); } #[test] fn test_overflow_prefilled() { - let prefilled = vec![0, 1, 2, 5].into_iter().map(new_index_transaction); + let prefilled = vec![0, 1, 2, 5] + .into_iter() + .map(new_index_transaction) + .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.pack()) + .prefilled_transactions(prefilled.into()) .build(); assert_eq!( PrefilledVerifier::verify(&block), @@ -45,9 +53,11 @@ fn test_cellbase_not_prefilled() { StatusCode::CompactBlockHasNotPrefilledCellbase.into(), ); - let prefilled = (1..5).map(new_index_transaction); + let prefilled = (1..5) + .map(new_index_transaction) + .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.pack()) + .prefilled_transactions(prefilled.into()) .build(); assert_eq!( PrefilledVerifier::verify(&block), @@ -63,7 +73,7 @@ fn test_duplicated_short_ids() { short_ids.push(short_ids[0].clone()); let block = CompactBlockBuilder::default() - .short_ids(short_ids.into_iter().pack()) + .short_ids(short_ids.into()) .build(); assert_eq!( ShortIdsVerifier::verify(&block), @@ -73,12 +83,16 @@ fn test_duplicated_short_ids() { #[test] fn test_intersected_short_ids() { - let prefilled = (0..=5).map(new_index_transaction); - let short_ids = (5..9).map(|i| new_index_transaction(i).transaction().proposal_short_id()); + let prefilled = (0..=5) + .map(new_index_transaction) + .collect::>(); + let short_ids = (5..9) + .map(|i| new_index_transaction(i).transaction().proposal_short_id()) + .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.pack()) - .short_ids(short_ids.pack()) + .prefilled_transactions(prefilled.into()) + .short_ids(short_ids.into()) .build(); assert_eq!( ShortIdsVerifier::verify(&block), @@ -88,13 +102,17 @@ fn test_intersected_short_ids() { #[test] fn test_normal() { - let prefilled = vec![1, 2, 5].into_iter().map(new_index_transaction); + let prefilled = vec![1, 2, 5] + .into_iter() + .map(new_index_transaction) + .collect::>(); let short_ids = vec![0, 3, 4] .into_iter() - .map(|i| new_index_transaction(i).transaction().proposal_short_id()); + .map(|i| new_index_transaction(i).transaction().proposal_short_id()) + .collect::>(); let block = CompactBlockBuilder::default() - .prefilled_transactions(prefilled.pack()) - .short_ids(short_ids.pack()) + .prefilled_transactions(prefilled.into()) + .short_ids(short_ids.into()) .build(); assert_eq!(ShortIdsVerifier::verify(&block), Status::ok()); } diff --git a/sync/src/relayer/tests/get_block_proposal_process.rs b/sync/src/relayer/tests/get_block_proposal_process.rs index 568ba83dc7..55a9adda42 100644 --- a/sync/src/relayer/tests/get_block_proposal_process.rs +++ b/sync/src/relayer/tests/get_block_proposal_process.rs @@ -17,7 +17,7 @@ fn test_duplicate() { let content = packed::GetBlockProposal::new_builder() .block_hash(hash) - .proposals(vec![id.clone(), id].into_iter().pack()) + .proposals(vec![id.clone(), id].into()) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); let nc = Arc::new(mock_protocol_context); diff --git a/sync/src/relayer/tests/get_transactions_process.rs b/sync/src/relayer/tests/get_transactions_process.rs index 7f38edf5ad..9b206cdd50 100644 --- a/sync/src/relayer/tests/get_transactions_process.rs +++ b/sync/src/relayer/tests/get_transactions_process.rs @@ -13,7 +13,7 @@ fn test_duplicate() { let tx = new_transaction(&relayer, 1, &always_success_out_point); let tx_hash = tx.hash(); let content = packed::GetRelayTransactions::new_builder() - .tx_hashes(vec![tx_hash.clone(), tx_hash].pack()) + .tx_hashes(vec![tx_hash.clone(), tx_hash].into()) .build(); let mock_protocol_context = MockProtocolContext::new(SupportProtocols::RelayV2); let nc = Arc::new(mock_protocol_context); diff --git a/sync/src/relayer/tests/helper.rs b/sync/src/relayer/tests/helper.rs index d81da762a4..564a47f1f8 100644 --- a/sync/src/relayer/tests/helper.rs +++ b/sync/src/relayer/tests/helper.rs @@ -38,14 +38,14 @@ pub(crate) fn new_index_transaction(index: usize) -> IndexTransaction { let transaction = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(index).unwrap().pack()) + .capacity(Capacity::bytes(index).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); IndexTransactionBuilder::default() - .index(index.pack()) + .index(index.into()) .transaction(transaction.data()) .build() } @@ -60,10 +60,10 @@ pub(crate) fn new_header_builder(shared: &Shared, parent: &HeaderView) -> Header .epoch(); HeaderBuilder::default() .parent_hash(parent_hash) - .number((parent.number() + 1).pack()) - .timestamp((parent.timestamp() + 1).pack()) - .epoch(epoch.number_with_fraction(parent.number() + 1).pack()) - .compact_target(epoch.compact_target().pack()) + .number((parent.number() + 1).into()) + .timestamp((parent.timestamp() + 1).into()) + .epoch(epoch.number_with_fraction(parent.number() + 1).into()) + .compact_target(epoch.compact_target().into()) } pub(crate) fn new_transaction( @@ -89,10 +89,10 @@ pub(crate) fn new_transaction( .input(CellInput::new(previous_output, 0)) .output( CellOutputBuilder::default() - .capacity(Capacity::bytes(500 + index).unwrap().pack()) // use capacity to identify transactions + .capacity(Capacity::bytes(500 + index).unwrap().into()) // use capacity to identify transactions .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .cell_dep( CellDep::new_builder() .out_point(always_success_out_point.to_owned()) @@ -138,7 +138,7 @@ pub(crate) fn build_chain(tip: BlockNumber) -> (Relayer, OutPoint) { let always_success_tx = TransactionBuilder::default() .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()) .witness(always_success_script.clone().into_witness()) .build(); let always_success_out_point = OutPoint::new(always_success_tx.hash(), 0); @@ -146,9 +146,9 @@ pub(crate) fn build_chain(tip: BlockNumber) -> (Relayer, OutPoint) { let (shared, mut pack) = { let dao = genesis_dao_data(vec![&always_success_tx]).unwrap(); let genesis = BlockBuilder::default() - .timestamp(unix_time_as_millis().pack()) + .timestamp(unix_time_as_millis().into()) .dao(dao) - .compact_target(difficulty_to_compact(U256::from(1000u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) .transaction(always_success_tx) .build(); let epoch_ext = build_genesis_epoch_ext( @@ -187,11 +187,11 @@ pub(crate) fn build_chain(tip: BlockNumber) -> (Relayer, OutPoint) { .input(CellInput::new_cellbase_input(parent.header().number() + 1)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(50000).pack()) + .capacity(capacity_bytes!(50000).into()) .lock(always_success_script.to_owned()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .witness(Script::default().into_witness()) .build(); let header = new_header_builder(&shared, &parent.header()).build(); @@ -276,18 +276,18 @@ pub(crate) fn gen_block( .timestamp() .checked_add_signed(timestamp_delta) .unwrap()) - .pack(), + .into(), ) - .number(number.pack()) + .number(number.into()) .compact_target( (epoch .compact_target() .checked_add_signed(target_delta) .unwrap()) - .pack(), + .into(), ) .dao(dao) - .epoch(epoch.number_with_fraction(number).pack()) + .epoch(epoch.number_with_fraction(number).into()) .transactions(txs); if let Some(uncle) = uncle_opt { block_builder = block_builder.uncle(uncle) diff --git a/sync/src/relayer/tests/reconstruct_block.rs b/sync/src/relayer/tests/reconstruct_block.rs index a7e55ec1a7..303e48db32 100644 --- a/sync/src/relayer/tests/reconstruct_block.rs +++ b/sync/src/relayer/tests/reconstruct_block.rs @@ -20,9 +20,12 @@ fn test_missing_txs() { // Case: miss tx.0 { let compact_block_builder = CompactBlockBuilder::default(); - let short_ids = prepare.iter().map(|tx| tx.proposal_short_id()); + let short_ids = prepare + .iter() + .map(|tx| tx.proposal_short_id()) + .collect::>(); let transactions: Vec = prepare.iter().skip(1).cloned().collect(); - let compact = compact_block_builder.short_ids(short_ids.pack()).build(); + let compact = compact_block_builder.short_ids(short_ids.into()).build(); assert_eq!( relayer.reconstruct_block( &relayer.shared().active_chain(), @@ -38,7 +41,10 @@ fn test_missing_txs() { // Case: miss multiple txs { let compact_block_builder = CompactBlockBuilder::default(); - let short_ids = prepare.iter().map(|tx| tx.proposal_short_id()); + let short_ids = prepare + .iter() + .map(|tx| tx.proposal_short_id()) + .collect::>(); let transactions: Vec = prepare.iter().skip(1).step_by(2).cloned().collect(); let missing = prepare @@ -47,7 +53,7 @@ fn test_missing_txs() { .step_by(2) .map(|(i, _)| i) .collect(); - let compact = compact_block_builder.short_ids(short_ids.pack()).build(); + let compact = compact_block_builder.short_ids(short_ids.into()).build(); assert_eq!( relayer.reconstruct_block( &relayer.shared().active_chain(), @@ -104,7 +110,7 @@ fn test_reconstruct_transactions_and_uncles() { // BLOCK_VALID let ext = packed::BlockExtBuilder::default() - .verified(Some(true).pack()) + .verified(Some(true).into()) .build(); let compact = packed::CompactBlock::build_from_block(&block, &prefilled); @@ -127,7 +133,7 @@ fn test_reconstruct_transactions_and_uncles() { { let db_txn = relayer.shared().shared().store().begin_transaction(); db_txn.insert_block(&uncle).unwrap(); - db_txn.insert_block_ext(&uncle_hash, &ext.unpack()).unwrap(); + db_txn.insert_block_ext(&uncle_hash, &ext.into()).unwrap(); db_txn.commit().unwrap(); } relayer.shared().shared().refresh_snapshot(); @@ -149,7 +155,7 @@ fn test_reconstruct_invalid_uncles() { let uncle = BlockBuilder::default().build(); // BLOCK_VALID let ext = packed::BlockExtBuilder::default() - .verified(Some(false).pack()) + .verified(Some(false).into()) .build(); let block = BlockBuilder::default() @@ -163,7 +169,7 @@ fn test_reconstruct_invalid_uncles() { let db_txn = relayer.shared().shared().store().begin_transaction(); db_txn.insert_block(&uncle).unwrap(); db_txn.attach_block(&uncle).unwrap(); - db_txn.insert_block_ext(&uncle_hash, &ext.unpack()).unwrap(); + db_txn.insert_block_ext(&uncle_hash, &ext.into()).unwrap(); db_txn.commit().unwrap(); } relayer.shared().shared().refresh_snapshot(); diff --git a/sync/src/relayer/transactions_process.rs b/sync/src/relayer/transactions_process.rs index 11ad489500..146cb41be0 100644 --- a/sync/src/relayer/transactions_process.rs +++ b/sync/src/relayer/transactions_process.rs @@ -45,12 +45,7 @@ impl<'a> TransactionsProcess<'a> { self.message .transactions() .iter() - .map(|tx| { - ( - tx.transaction().to_entity().into_view(), - tx.cycles().unpack(), - ) - }) + .map(|tx| (tx.transaction().to_entity().into_view(), tx.cycles().into())) .filter(|(tx, _)| { !tx_filter.contains(&tx.hash()) && unknown_tx_hashes diff --git a/sync/src/synchronizer/get_headers_process.rs b/sync/src/synchronizer/get_headers_process.rs index 3b4b44cf12..491f8582f0 100644 --- a/sync/src/synchronizer/get_headers_process.rs +++ b/sync/src/synchronizer/get_headers_process.rs @@ -81,7 +81,13 @@ impl<'a> GetHeadersProcess<'a> { debug!("headers len={}", headers.len()); let content = packed::SendHeaders::new_builder() - .headers(headers.into_iter().map(|x| x.data()).pack()) + .headers( + headers + .into_iter() + .map(|x| x.data()) + .collect::>() + .into(), + ) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 18c34204be..cbb40bc0fe 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -223,7 +223,7 @@ impl BlockFetchCMD { let assume_valid_target_find = |flag: &mut CanStart| { let mut assume_valid_target = state.assume_valid_target(); if let Some(ref target) = *assume_valid_target { - match state.header_map().get(&target.pack()) { + match state.header_map().get(&target.into()) { Some(header) => { *flag = CanStart::Ready; info!("assume valid target found in header_map; CKB will start fetch blocks now"); @@ -268,7 +268,7 @@ impl BlockFetchCMD { fn send_getblocks(v_fetch: Vec, nc: &ServiceControl, peer: PeerIndex) { let content = packed::GetBlocks::new_builder() - .block_hashes(v_fetch.clone().pack()) + .block_hashes(v_fetch.clone().into()) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); @@ -737,7 +737,7 @@ impl Synchronizer { peer: PeerIndex, ) { let content = packed::GetBlocks::new_builder() - .block_hashes(v_fetch.clone().pack()) + .block_hashes(v_fetch.clone().into()) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); diff --git a/sync/src/tests/inflight_blocks.rs b/sync/src/tests/inflight_blocks.rs index 4511a85821..6f793bfaa7 100644 --- a/sync/src/tests/inflight_blocks.rs +++ b/sync/src/tests/inflight_blocks.rs @@ -1,7 +1,6 @@ use crate::types::InflightBlocks; use ckb_constant::sync::BLOCK_DOWNLOAD_TIMEOUT; use ckb_types::h256; -use ckb_types::prelude::*; use ckb_types::BlockNumberAndHash; use std::collections::HashSet; @@ -10,24 +9,24 @@ fn inflight_blocks_count() { let mut inflight_blocks = InflightBlocks::default(); // don't allow 2 peer for one block - assert!(inflight_blocks.insert(2.into(), (1, h256!("0x1").pack()).into())); - assert!(!inflight_blocks.insert(1.into(), (1, h256!("0x1").pack()).into())); + assert!(inflight_blocks.insert(2.into(), (1, h256!("0x1").into()).into())); + assert!(!inflight_blocks.insert(1.into(), (1, h256!("0x1").into()).into())); // peer 1 inflight - assert!(!inflight_blocks.insert(1.into(), (1, h256!("0x1").pack()).into())); + assert!(!inflight_blocks.insert(1.into(), (1, h256!("0x1").into()).into())); - assert!(inflight_blocks.insert(1.into(), (2, h256!("0x2").pack()).into())); + assert!(inflight_blocks.insert(1.into(), (2, h256!("0x2").into()).into())); assert_eq!(inflight_blocks.total_inflight_count(), 2); // 0x1 0x2 assert_eq!(inflight_blocks.peer_inflight_count(1.into()), 1); assert_eq!(inflight_blocks.peer_inflight_count(2.into()), 1); // one block inflight assert_eq!( inflight_blocks.inflight_block_by_peer(1.into()).cloned(), - Some(HashSet::from_iter(vec![(2, h256!("0x2").pack()).into()])) + Some(HashSet::from_iter(vec![(2, h256!("0x2").into()).into()])) ); // receive block 0x1 - inflight_blocks.remove_by_block((1, h256!("0x1").pack()).into()); + inflight_blocks.remove_by_block((1, h256!("0x1").into()).into()); assert_eq!(inflight_blocks.total_inflight_count(), 1); // 0x2 assert_eq!(inflight_blocks.peer_inflight_count(1.into()), 1); @@ -36,7 +35,7 @@ fn inflight_blocks_count() { inflight_blocks .inflight_block_by_peer(1.into()) .map(|set| set.iter().collect()), - Some(vec![&(2, h256!("0x2").pack()).into()]) + Some(vec![&(2, h256!("0x2").into()).into()]) ); } @@ -44,19 +43,19 @@ fn inflight_blocks_count() { fn inflight_blocks_state() { let mut inflight_blocks = InflightBlocks::default(); - assert!(inflight_blocks.insert(1.into(), (1, h256!("0x1").pack()).into())); - assert!(!inflight_blocks.insert(2.into(), (1, h256!("0x1").pack()).into())); - assert!(!inflight_blocks.insert(3.into(), (1, h256!("0x1").pack()).into())); + assert!(inflight_blocks.insert(1.into(), (1, h256!("0x1").into()).into())); + assert!(!inflight_blocks.insert(2.into(), (1, h256!("0x1").into()).into())); + assert!(!inflight_blocks.insert(3.into(), (1, h256!("0x1").into()).into())); // peer 1 inflight - assert!(!inflight_blocks.insert(1.into(), (1, h256!("0x1").pack()).into())); - assert!(inflight_blocks.insert(1.into(), (2, h256!("0x2").pack()).into())); + assert!(!inflight_blocks.insert(1.into(), (1, h256!("0x1").into()).into())); + assert!(inflight_blocks.insert(1.into(), (2, h256!("0x2").into()).into())); - assert!(inflight_blocks.insert(3.into(), (3, h256!("0x3").pack()).into())); + assert!(inflight_blocks.insert(3.into(), (3, h256!("0x3").into()).into())); assert_eq!( inflight_blocks - .inflight_state_by_block(&(1, h256!("0x1").pack()).into()) + .inflight_state_by_block(&(1, h256!("0x1").into()).into()) .cloned() .map(|state| { state.peer }), Some(1.into()) @@ -64,7 +63,7 @@ fn inflight_blocks_state() { assert_eq!( inflight_blocks - .inflight_state_by_block(&(3, h256!("0x3").pack()).into()) + .inflight_state_by_block(&(3, h256!("0x3").into()).into()) .map(|state| state.peer), Some(3.into()) ); @@ -75,14 +74,14 @@ fn inflight_blocks_state() { assert_eq!( inflight_blocks - .inflight_state_by_block(&(1, h256!("0x1").pack()).into()) + .inflight_state_by_block(&(1, h256!("0x1").into()).into()) .map(|state| state.peer), None ); assert_eq!( inflight_blocks - .inflight_state_by_block(&(3, h256!("0x3").pack()).into()) + .inflight_state_by_block(&(3, h256!("0x3").into()).into()) .map(|state| state.peer), Some(3.into()) ); @@ -95,45 +94,45 @@ fn inflight_blocks_timeout() { let mut inflight_blocks = InflightBlocks::default(); inflight_blocks.protect_num = 0; - assert!(inflight_blocks.insert(1.into(), (1, h256!("0x1").pack()).into())); - assert!(inflight_blocks.insert(1.into(), (2, h256!("0x2").pack()).into())); - assert!(inflight_blocks.insert(2.into(), (3, h256!("0x3").pack()).into())); - assert!(!inflight_blocks.insert(1.into(), (3, h256!("0x3").pack()).into())); - assert!(inflight_blocks.insert(1.into(), (4, h256!("0x4").pack()).into())); - assert!(inflight_blocks.insert(2.into(), (5, h256!("0x5").pack()).into())); - assert!(!inflight_blocks.insert(2.into(), (5, h256!("0x5").pack()).into())); + assert!(inflight_blocks.insert(1.into(), (1, h256!("0x1").into()).into())); + assert!(inflight_blocks.insert(1.into(), (2, h256!("0x2").into()).into())); + assert!(inflight_blocks.insert(2.into(), (3, h256!("0x3").into()).into())); + assert!(!inflight_blocks.insert(1.into(), (3, h256!("0x3").into()).into())); + assert!(inflight_blocks.insert(1.into(), (4, h256!("0x4").into()).into())); + assert!(inflight_blocks.insert(2.into(), (5, h256!("0x5").into()).into())); + assert!(!inflight_blocks.insert(2.into(), (5, h256!("0x5").into()).into())); _faketime_guard.set_faketime(BLOCK_DOWNLOAD_TIMEOUT + 1); - assert!(!inflight_blocks.insert(3.into(), (3, h256!("0x3").pack()).into())); - assert!(!inflight_blocks.insert(3.into(), (2, h256!("0x2").pack()).into())); - assert!(inflight_blocks.insert(4.into(), (6, h256!("0x6").pack()).into())); - assert!(inflight_blocks.insert(1.into(), (7, h256!("0x7").pack()).into())); + assert!(!inflight_blocks.insert(3.into(), (3, h256!("0x3").into()).into())); + assert!(!inflight_blocks.insert(3.into(), (2, h256!("0x2").into()).into())); + assert!(inflight_blocks.insert(4.into(), (6, h256!("0x6").into()).into())); + assert!(inflight_blocks.insert(1.into(), (7, h256!("0x7").into()).into())); let peers = inflight_blocks.prune(0); assert_eq!(peers, HashSet::from_iter(vec![1.into()])); - assert!(inflight_blocks.insert(3.into(), (2, h256!("0x2").pack()).into())); - assert!(inflight_blocks.insert(3.into(), (3, h256!("0x3").pack()).into())); + assert!(inflight_blocks.insert(3.into(), (2, h256!("0x2").into()).into())); + assert!(inflight_blocks.insert(3.into(), (3, h256!("0x3").into()).into())); assert_eq!(inflight_blocks.peer_can_fetch_count(2.into()), 32 >> 4); assert_eq!( inflight_blocks - .inflight_state_by_block(&(3, h256!("0x3").pack()).into()) + .inflight_state_by_block(&(3, h256!("0x3").into()).into()) .map(|state| state.peer), Some(3.into()) ); assert_eq!( inflight_blocks - .inflight_state_by_block(&(2, h256!("0x2").pack()).into()) + .inflight_state_by_block(&(2, h256!("0x2").into()).into()) .map(|state| state.peer), Some(3.into()) ); assert_eq!( inflight_blocks - .inflight_state_by_block(&(6, h256!("0x6").pack()).into()) + .inflight_state_by_block(&(6, h256!("0x6").into()).into()) .cloned() .map(|state| state.peer), Some(4.into()) @@ -148,13 +147,13 @@ fn inflight_trace_number_state() { let mut inflight_blocks = InflightBlocks::default(); inflight_blocks.protect_num = 0; - assert!(inflight_blocks.insert(1.into(), (1, h256!("0x1").pack()).into())); - assert!(inflight_blocks.insert(2.into(), (2, h256!("0x2").pack()).into())); - assert!(inflight_blocks.insert(3.into(), (3, h256!("0x3").pack()).into())); - assert!(inflight_blocks.insert(4.into(), (3, h256!("0x33").pack()).into())); - assert!(inflight_blocks.insert(5.into(), (4, h256!("0x4").pack()).into())); - assert!(inflight_blocks.insert(6.into(), (5, h256!("0x5").pack()).into())); - assert!(inflight_blocks.insert(7.into(), (5, h256!("0x55").pack()).into())); + assert!(inflight_blocks.insert(1.into(), (1, h256!("0x1").into()).into())); + assert!(inflight_blocks.insert(2.into(), (2, h256!("0x2").into()).into())); + assert!(inflight_blocks.insert(3.into(), (3, h256!("0x3").into()).into())); + assert!(inflight_blocks.insert(4.into(), (3, h256!("0x33").into()).into())); + assert!(inflight_blocks.insert(5.into(), (4, h256!("0x4").into()).into())); + assert!(inflight_blocks.insert(6.into(), (5, h256!("0x5").into()).into())); + assert!(inflight_blocks.insert(7.into(), (5, h256!("0x55").into()).into())); let list = inflight_blocks.prune(2); assert!(list.is_empty()); @@ -172,10 +171,10 @@ fn inflight_trace_number_state() { .cloned() .collect::>(), HashSet::from_iter(vec![ - (1, h256!("0x1").pack()).into(), - (2, h256!("0x2").pack()).into(), - (3, h256!("0x3").pack()).into(), - (3, h256!("0x33").pack()).into() + (1, h256!("0x1").into()).into(), + (2, h256!("0x2").into()).into(), + (3, h256!("0x3").into()).into(), + (3, h256!("0x33").into()).into() ]) ); @@ -187,10 +186,10 @@ fn inflight_trace_number_state() { assert!(inflight_blocks.restart_number == 3); assert!(inflight_blocks - .inflight_state_by_block(&(3, h256!("0x3").pack()).into()) + .inflight_state_by_block(&(3, h256!("0x3").into()).into()) .is_none()); assert!(inflight_blocks - .inflight_state_by_block(&(3, h256!("0x33").pack()).into()) + .inflight_state_by_block(&(3, h256!("0x33").into()).into()) .is_none()); assert_eq!(inflight_blocks.peer_can_fetch_count(3.into()), 32 >> 1); diff --git a/sync/src/tests/orphan_block_pool.rs b/sync/src/tests/orphan_block_pool.rs index f535871b03..c761ce89b1 100644 --- a/sync/src/tests/orphan_block_pool.rs +++ b/sync/src/tests/orphan_block_pool.rs @@ -1,7 +1,6 @@ use ckb_chain_spec::consensus::ConsensusBuilder; use ckb_systemtime::unix_time_as_millis; use ckb_types::core::{BlockBuilder, BlockView, EpochNumberWithFraction, HeaderView}; -use ckb_types::prelude::*; use std::collections::HashSet; use std::sync::Arc; use std::thread; @@ -12,10 +11,10 @@ fn gen_block(parent_header: &HeaderView) -> BlockView { let number = parent_header.number() + 1; BlockBuilder::default() .parent_hash(parent_header.hash()) - .timestamp(unix_time_as_millis().pack()) - .number(number.pack()) - .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 1000).pack()) - .nonce((parent_header.nonce() + 1).pack()) + .timestamp(unix_time_as_millis().into()) + .number(number.into()) + .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 1000).into()) + .nonce((parent_header.nonce() + 1).into()) .build() } @@ -136,10 +135,10 @@ fn test_remove_expired_blocks() { for _ in 1..block_number { let new_block = BlockBuilder::default() .parent_hash(parent.hash()) - .timestamp(unix_time_as_millis().pack()) - .number((parent.number() + 1).pack()) - .epoch(deprecated.clone().pack()) - .nonce((parent.nonce() + 1).pack()) + .timestamp(unix_time_as_millis().into()) + .number((parent.number() + 1).into()) + .epoch(deprecated.into()) + .nonce((parent.nonce() + 1).into()) .build(); pool.insert(new_block.clone()); parent = new_block.header(); diff --git a/sync/src/tests/sync_shared.rs b/sync/src/tests/sync_shared.rs index b743a6d59c..34446bade5 100644 --- a/sync/src/tests/sync_shared.rs +++ b/sync/src/tests/sync_shared.rs @@ -6,7 +6,6 @@ use ckb_shared::SharedBuilder; use ckb_store::{self, ChainStore}; use ckb_test_chain_utils::always_success_cellbase; use ckb_types::core::Capacity; -use ckb_types::prelude::*; use std::sync::Arc; #[test] @@ -79,7 +78,7 @@ fn test_insert_parent_unknown_block() { let invalid_orphan = block .as_advanced_builder() .header(block.header()) - .number(1000.pack()) + .number(1000.into()) .build(); Arc::new(invalid_orphan) @@ -137,7 +136,7 @@ fn test_switch_valid_fork() { .unwrap(); for _ in 3..shared.active_chain().tip_number() { let block = inherit_block(fork_shared.shared(), &parent_header.hash()) - .timestamp((parent_header.timestamp() + 3).pack()) + .timestamp((parent_header.timestamp() + 3).into()) .build(); let arc_block = Arc::new(block.clone()); assert!(fork_shared @@ -162,7 +161,7 @@ fn test_switch_valid_fork() { // Make the fork switch as the main chain. for _ in tip_number..tip_number + 2 { let block = inherit_block(fork_shared.shared(), &parent_header.hash()) - .timestamp((parent_header.timestamp() + 3).pack()) + .timestamp((parent_header.timestamp() + 3).into()) .build(); let arc_block = Arc::new(block.clone()); assert!(fork_shared diff --git a/sync/src/tests/synchronizer/basic_sync.rs b/sync/src/tests/synchronizer/basic_sync.rs index 0d1af241b6..12373c10be 100644 --- a/sync/src/tests/synchronizer/basic_sync.rs +++ b/sync/src/tests/synchronizer/basic_sync.rs @@ -78,14 +78,14 @@ fn setup_node(height: u64) -> (TestNode, Shared) { .witness(always_success_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(); let dao = genesis_dao_data(vec![&always_success_tx]).unwrap(); let mut block = BlockBuilder::default() - .timestamp(unix_time_as_millis().pack()) - .compact_target(difficulty_to_compact(U256::from(1000u64)).pack()) + .timestamp(unix_time_as_millis().into()) + .compact_target(difficulty_to_compact(U256::from(1000u64)).into()) .dao(dao) .transaction(always_success_tx) .build(); @@ -127,11 +127,11 @@ fn setup_node(height: u64) -> (TestNode, Shared) { builder .output( CellOutputBuilder::default() - .capacity(reward.total.pack()) + .capacity(reward.total.into()) .lock(always_success_script.to_owned()) .build(), ) - .output_data(Bytes::default().pack()) + .output_data(Bytes::default().into()) .build() }; @@ -153,15 +153,15 @@ fn setup_node(height: u64) -> (TestNode, Shared) { .chain_root_mmr(block.header().number()) .get_root() .expect("chain root_mmr"); - let bytes = chain_root.calc_mmr_hash().as_bytes().pack(); + let bytes = chain_root.calc_mmr_hash().as_bytes().into(); block = BlockBuilder::default() .transaction(cellbase) .parent_hash(block.header().hash()) - .number(number.pack()) - .epoch(epoch.number_with_fraction(number).pack()) - .timestamp(timestamp.pack()) - .compact_target(epoch.compact_target().pack()) + .number(number.into()) + .epoch(epoch.number_with_fraction(number).into()) + .timestamp(timestamp.into()) + .compact_target(epoch.compact_target().into()) .dao(dao) .extension(Some(bytes)) .build(); diff --git a/sync/src/tests/synchronizer/functions.rs b/sync/src/tests/synchronizer/functions.rs index 4f181ba59b..42cb58869d 100644 --- a/sync/src/tests/synchronizer/functions.rs +++ b/sync/src/tests/synchronizer/functions.rs @@ -79,10 +79,10 @@ fn create_cellbase( builder .output( CellOutputBuilder::default() - .capacity(reward.total.pack()) + .capacity(reward.total.into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build() } } @@ -110,16 +110,16 @@ fn gen_block( .chain_root_mmr(parent_header.number()) .get_root() .expect("chain root_mmr"); - let bytes = chain_root.calc_mmr_hash().as_bytes().pack(); + let bytes = chain_root.calc_mmr_hash().as_bytes().into(); BlockBuilder::default() .transaction(cellbase) .parent_hash(parent_header.hash()) - .timestamp(now.pack()) - .epoch(epoch.number_with_fraction(number).pack()) - .number(number.pack()) - .compact_target(epoch.compact_target().pack()) - .nonce(nonce.pack()) + .timestamp(now.into()) + .epoch(epoch.number_with_fraction(number).into()) + .number(number.into()) + .compact_target(epoch.compact_target().into()) + .nonce(nonce.into()) .dao(dao) .extension(Some(bytes)) .build() @@ -625,7 +625,13 @@ fn test_sync_process() { ); let sendheaders = SendHeadersBuilder::default() - .headers(headers.iter().map(|h| h.data()).pack()) + .headers( + headers + .iter() + .map(|h| h.data()) + .collect::>() + .into(), + ) .build(); let mock_nc = mock_network_context(4); @@ -682,7 +688,13 @@ fn test_sync_process() { insert_block(&synchronizer2.chain, &shared2, 201u128, 201); let headers = vec![synchronizer2.shared.active_chain().tip_header()]; let sendheaders = SendHeadersBuilder::default() - .headers(headers.iter().map(|h| h.data()).pack()) + .headers( + headers + .iter() + .map(|h| h.data()) + .collect::>() + .into(), + ) .build(); assert_eq!( HeadersProcess::new(sendheaders.as_reader(), &synchronizer1, peer1, &mock_nc).execute(), @@ -759,7 +771,7 @@ fn test_chain_sync_timeout() { let consensus = Consensus::default(); let block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(3u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(3u64)).into()) .transaction(consensus.genesis_block().transactions()[0].clone()) .build(); let consensus = ConsensusBuilder::default().genesis_block(block).build(); @@ -956,7 +968,7 @@ fn test_n_sync_started() { let consensus = Consensus::default(); let block = BlockBuilder::default() - .compact_target(difficulty_to_compact(U256::from(3u64)).pack()) + .compact_target(difficulty_to_compact(U256::from(3u64)).into()) .transaction(consensus.genesis_block().transactions()[0].clone()) .build(); let consensus = ConsensusBuilder::default().genesis_block(block).build(); @@ -1101,7 +1113,7 @@ fn test_fix_last_common_header() { .map(|block| block.header().data()) .collect::>(); let sendheaders = SendHeadersBuilder::default() - .headers(fork_headers.pack()) + .headers(fork_headers.into()) .build(); synchronizer.on_connected(&nc, peer); assert!( @@ -1177,7 +1189,7 @@ fn get_blocks_process() { let genesis_hash = shared.consensus().genesis_hash(); let message_with_genesis = packed::GetBlocks::new_builder() - .block_hashes(vec![genesis_hash].pack()) + .block_hashes(vec![genesis_hash].into()) .build(); let nc = mock_network_context(1); @@ -1190,7 +1202,7 @@ fn get_blocks_process() { let hash = shared.snapshot().get_block_hash(1).unwrap(); let message_with_dup = packed::GetBlocks::new_builder() - .block_hashes(vec![hash.clone(), hash].pack()) + .block_hashes(vec![hash.clone(), hash].into()) .build(); let nc = mock_network_context(1); diff --git a/sync/src/tests/types.rs b/sync/src/tests/types.rs index 148e6b2308..6891aacf11 100644 --- a/sync/src/tests/types.rs +++ b/sync/src/tests/types.rs @@ -1,7 +1,6 @@ use ckb_types::{ core::{BlockNumber, EpochNumberWithFraction, HeaderBuilder}, packed::Byte32, - prelude::*, U256, }; use rand::{thread_rng, Rng}; @@ -22,8 +21,8 @@ fn test_get_ancestor_use_skip_list() { let mut parent_hash = None; for number in 0..SKIPLIST_LENGTH { let mut header_builder = HeaderBuilder::default() - .number(number.pack()) - .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 1000).pack()); + .number(number.into()) + .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 1000).into()); if let Some(parent_hash) = parent_hash.take() { header_builder = header_builder.parent_hash(parent_hash); } diff --git a/sync/src/tests/util.rs b/sync/src/tests/util.rs index 3149b80ba5..2a64fac4c8 100644 --- a/sync/src/tests/util.rs +++ b/sync/src/tests/util.rs @@ -74,14 +74,14 @@ pub fn inherit_block(shared: &Shared, parent_hash: &Byte32) -> BlockBuilder { .chain_root_mmr(parent_number) .get_root() .expect("chain root_mmr"); - let bytes = chain_root.calc_mmr_hash().as_bytes().pack(); + let bytes = chain_root.calc_mmr_hash().as_bytes().into(); BlockBuilder::default() .parent_hash(parent_hash.to_owned()) - .number((parent.header().number() + 1).pack()) - .timestamp((parent.header().timestamp() + 1).pack()) - .epoch(epoch.number_with_fraction(parent_number + 1).pack()) - .compact_target(epoch.compact_target().pack()) + .number((parent.header().number() + 1).into()) + .timestamp((parent.header().timestamp() + 1).into()) + .epoch(epoch.number_with_fraction(parent_number + 1).into()) + .compact_target(epoch.compact_target().into()) .dao(dao) .transaction(cellbase) .extension(Some(bytes)) diff --git a/sync/src/types/mod.rs b/sync/src/types/mod.rs index a98431de21..5928adb1a2 100644 --- a/sync/src/types/mod.rs +++ b/sync/src/types/mod.rs @@ -1247,7 +1247,7 @@ impl SyncShared { /// Check whether the data already exists in the database before starting fn check_assume_valid_target_already_exists(sync_config: &SyncConfig, shared: &Shared) -> bool { if let Some(ref target) = sync_config.assume_valid_target { - if shared.snapshot().block_exists(&target.pack()) { + if shared.snapshot().block_exists(&target.into()) { info!("assume valid target is already in db, CKB will do full verification from now on"); return true; } @@ -1433,7 +1433,7 @@ impl SyncShared { let mut assume_valid_target = self.state.assume_valid_target(); if let Some(ref target) = *assume_valid_target { // if the target has been reached, delete it - let switch = if target == &Unpack::::unpack(&core::BlockView::hash(&block)) { + let switch = if target == &Into::::into(&core::BlockView::hash(&block)) { assume_valid_target.take(); info!("assume valid target reached; CKB will do full verification from now on"); Switch::NONE @@ -2305,7 +2305,7 @@ impl ActiveChain { ); let locator_hash = self.get_locator(block_number_and_hash); let content = packed::GetHeaders::new_builder() - .block_locator_hashes(locator_hash.pack()) + .block_locator_hashes(locator_hash.into()) .hash_stop(packed::Byte32::zero()) .build(); let message = packed::SyncMessage::new_builder().set(content).build(); diff --git a/test/src/assertion/reward_assertion.rs b/test/src/assertion/reward_assertion.rs index 229bf9bd3f..6825700c5a 100644 --- a/test/src/assertion/reward_assertion.rs +++ b/test/src/assertion/reward_assertion.rs @@ -1,7 +1,6 @@ use crate::Node; use ckb_types::core::{BlockEconomicState, BlockView, Capacity, Ratio, TransactionView}; use ckb_types::packed::{Byte32, OutPoint, ProposalShortId}; -use ckb_types::prelude::*; use std::collections::HashMap; pub fn check_fee(node: &Node) { @@ -113,7 +112,7 @@ impl RewardChecker { fn apply_new_transaction(&mut self, tx: &TransactionView) { for (index, output) in tx.outputs().into_iter().enumerate() { let out_point = OutPoint::new(tx.hash(), index as u32); - let capacity: u64 = output.capacity().unpack(); + let capacity: u64 = output.capacity().into(); self.cells_capacity.insert(out_point, capacity); } diff --git a/test/src/node.rs b/test/src/node.rs index 650c43533d..a2aacc65ec 100644 --- a/test/src/node.rs +++ b/test/src/node.rs @@ -345,7 +345,7 @@ impl Node { let timestamp = block.timestamp(); let uncle = block .as_advanced_builder() - .timestamp((timestamp + 1).pack()) + .timestamp((timestamp + 1).into()) .build(); (block, uncle) } @@ -381,7 +381,7 @@ impl Node { let res = self .rpc_client() .send_transaction_result(transaction.data().into())? - .pack(); + .into(); Ok(res) } @@ -573,7 +573,7 @@ impl Node { .cell_dep(always_success_cell_dep) .output( CellOutputBuilder::default() - .capacity(capacity.pack()) + .capacity(capacity.into()) .lock(always_success_script) .build(), ) @@ -599,7 +599,7 @@ impl Node { .cell_dep(always_failure_cell_dep) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(always_failure_script) .build(), ) diff --git a/test/src/rpc.rs b/test/src/rpc.rs index 2502f8ad76..b1d1507729 100644 --- a/test/src/rpc.rs +++ b/test/src/rpc.rs @@ -15,7 +15,7 @@ use ckb_types::core::{ BlockNumber as CoreBlockNumber, Capacity as CoreCapacity, EpochNumber as CoreEpochNumber, Version as CoreVersion, }; -use ckb_types::{packed::Byte32, prelude::*, H256}; +use ckb_types::{packed::Byte32, H256}; use lazy_static::lazy_static; lazy_static! { @@ -42,13 +42,13 @@ impl RpcClient { pub fn get_block(&self, hash: Byte32) -> Option { self.inner - .get_block(hash.unpack()) + .get_block(hash.into()) .expect("rpc call get_block") } pub fn get_fork_block(&self, hash: Byte32) -> Option { self.inner - .get_fork_block(hash.unpack()) + .get_fork_block(hash.into()) .expect("rpc call get_fork_block") } @@ -60,7 +60,7 @@ impl RpcClient { pub fn get_header(&self, hash: Byte32) -> Option { self.inner - .get_header(hash.unpack()) + .get_header(hash.into()) .expect("rpc call get_header") } @@ -72,7 +72,7 @@ impl RpcClient { pub fn get_block_filter(&self, hash: Byte32) -> Option { self.inner - .get_block_filter(hash.unpack()) + .get_block_filter(hash.into()) .expect("rpc call get_block_filter") } @@ -86,13 +86,13 @@ impl RpcClient { verbosity: u32, ) -> TransactionWithStatusResponse { self.inner - .get_transaction(hash.unpack(), Some(verbosity.into()), None) + .get_transaction(hash.into(), Some(verbosity.into()), None) .expect("rpc call get_transaction") } pub fn get_pool_tx_detail_info(&self, hash: Byte32) -> PoolTxDetailInfo { self.inner - .get_pool_tx_detail_info(hash.unpack()) + .get_pool_tx_detail_info(hash.into()) .expect("rpc call get_transaction_tx_pool_details") } @@ -100,7 +100,7 @@ impl RpcClient { self.inner .get_block_hash(number.into()) .expect("rpc call get_block_hash") - .map(|x| x.pack()) + .map(|x| x.into()) } pub fn get_tip_header(&self) -> HeaderView { @@ -184,7 +184,7 @@ impl RpcClient { } pub fn submit_block(&self, work_id: String, block: Block) -> Result { - self.inner.submit_block(work_id, block).map(|x| x.pack()) + self.inner.submit_block(work_id, block).map(|x| x.into()) } pub fn get_blockchain_info(&self) -> ChainInfo { @@ -195,14 +195,14 @@ impl RpcClient { pub fn get_block_median_time(&self, block_hash: Byte32) -> Option { self.inner - .get_block_median_time(block_hash.unpack()) + .get_block_median_time(block_hash.into()) .expect("rpc call get_block_median_time") } pub fn send_transaction(&self, tx: Transaction) -> Byte32 { self.send_transaction_result(tx) .expect("rpc call send_transaction") - .pack() + .into() } pub fn send_transaction_result(&self, tx: Transaction) -> Result { @@ -212,7 +212,7 @@ impl RpcClient { pub fn remove_transaction(&self, tx_hash: Byte32) -> bool { self.inner - .remove_transaction(tx_hash.unpack()) + .remove_transaction(tx_hash.into()) .expect("rpc call remove_transaction") } @@ -252,12 +252,12 @@ impl RpcClient { self.inner .process_block_without_verify(block, broadcast) .expect("rpc call process_block_without verify") - .map(|x| x.pack()) + .map(|x| x.into()) } pub fn truncate(&self, target_tip_hash: Byte32) { self.inner() - .truncate(target_tip_hash.unpack()) + .truncate(target_tip_hash.into()) .expect("rpc call truncate") } @@ -265,14 +265,14 @@ impl RpcClient { self.inner() .generate_block() .expect("rpc call generate_block") - .pack() + .into() } pub fn generate_block_with_template(&self, block_template: BlockTemplate) -> Byte32 { self.inner() .generate_block_with_template(block_template) .expect("rpc call generate_block_with_template") - .pack() + .into() } pub fn calculate_dao_maximum_withdraw( @@ -281,14 +281,14 @@ impl RpcClient { hash: Byte32, ) -> CoreCapacity { self.inner() - .calculate_dao_maximum_withdraw(out_point, hash.unpack()) + .calculate_dao_maximum_withdraw(out_point, hash.into()) .expect("rpc call calculate_dao_maximum_withdraw") .into() } pub fn get_block_economic_state(&self, hash: Byte32) -> Option { self.inner() - .get_block_economic_state(hash.unpack()) + .get_block_economic_state(hash.into()) .expect("rpc call get_block_economic_state") } @@ -296,7 +296,7 @@ impl RpcClient { self.inner() .notify_transaction(tx) .expect("rpc call send_transaction") - .pack() + .into() } pub fn tx_pool_ready(&self) -> bool { diff --git a/test/src/specs/alert/alert_propagation.rs b/test/src/specs/alert/alert_propagation.rs index d5e8164753..027cfd9574 100644 --- a/test/src/specs/alert/alert_propagation.rs +++ b/test/src/specs/alert/alert_propagation.rs @@ -44,9 +44,9 @@ impl Spec for AlertPropagation { let id1: u32 = 42; let warning1: Bytes = b"pretend we are in dangerous status".to_vec().into(); let raw_alert = RawAlert::new_builder() - .id(id1.pack()) - .message(warning1.pack()) - .notice_until(notice_until.pack()) + .id(id1.into()) + .message((&warning1).into()) + .notice_until(notice_until.into()) .build(); let alert = create_alert(raw_alert, &self.privkeys); node0.rpc_client().send_alert(alert.clone().into()); @@ -74,10 +74,10 @@ impl Spec for AlertPropagation { let id2: u32 = 43; let warning2: Bytes = b"alert is canceled".to_vec().into(); let raw_alert2 = RawAlert::new_builder() - .id(id2.pack()) - .cancel(id1.pack()) - .message(warning2.pack()) - .notice_until(notice_until.pack()) + .id(id2.into()) + .cancel(id1.into()) + .message((&warning2).into()) + .notice_until(notice_until.into()) .build(); let alert2 = create_alert(raw_alert2, &self.privkeys); node0.rpc_client().send_alert(alert2.into()); @@ -141,7 +141,7 @@ impl Spec for AlertPropagation { } fn create_alert(raw_alert: RawAlert, privkeys: &[Privkey]) -> Alert { - let msg: Message = raw_alert.calc_alert_hash().unpack(); + let msg: Message = raw_alert.calc_alert_hash().into(); let signatures = privkeys .iter() .take(2) @@ -151,11 +151,11 @@ fn create_alert(raw_alert: RawAlert, privkeys: &[Privkey]) -> Alert { .expect("Sign failed") .serialize() .into(); - data.pack() + data.into() }) .collect::>(); Alert::new_builder() .raw(raw_alert) - .signatures(signatures.pack()) + .signatures(signatures.into()) .build() } diff --git a/test/src/specs/consensus/insufficient_reward.rs b/test/src/specs/consensus/insufficient_reward.rs index 45d1e6bf3d..0c0c9042b5 100644 --- a/test/src/specs/consensus/insufficient_reward.rs +++ b/test/src/specs/consensus/insufficient_reward.rs @@ -46,7 +46,7 @@ impl Spec for InsufficientReward { // build a block with insufficient reward let output = CellOutput::new_builder() - .capacity(capacity_bytes!(1).pack()) + .capacity(capacity_bytes!(1).into()) .lock(Default::default()) .build(); let cellbase = new_block_builder.clone().build().transactions()[0] diff --git a/test/src/specs/dao/dao_tx.rs b/test/src/specs/dao/dao_tx.rs index 64eec88332..9bed9be765 100644 --- a/test/src/specs/dao/dao_tx.rs +++ b/test/src/specs/dao/dao_tx.rs @@ -27,7 +27,7 @@ impl Spec for WithdrawDAO { let withdrawal = user.withdraw(); let since = EpochNumberWithFraction::from_full_value( - withdrawal.inputs().get(0).unwrap().since().unpack(), + withdrawal.inputs().get(0).unwrap().since().into(), ); goto_target_point(node, since); ensure_committed(node, &withdrawal); @@ -59,11 +59,11 @@ impl Spec for WithdrawDAOWithOverflowCapacity { .outputs() .into_iter() .map(|cell_output| { - let old_capacity: Capacity = cell_output.capacity().unpack(); + let old_capacity: Capacity = cell_output.capacity().into(); let new_capacity = old_capacity.safe_add(Capacity::one()).unwrap(); cell_output .as_builder() - .capacity(new_capacity.pack()) + .capacity(new_capacity.into()) .build() }) .collect(); @@ -73,7 +73,7 @@ impl Spec for WithdrawDAOWithOverflowCapacity { .build() }; let since = EpochNumberWithFraction::from_full_value( - withdrawal.inputs().get(0).unwrap().since().unpack(), + withdrawal.inputs().get(0).unwrap().since().into(), ); goto_target_point(node, since); assert_send_transaction_fail(node, &invalid_withdrawal, "Overflow"); diff --git a/test/src/specs/dao/dao_user.rs b/test/src/specs/dao/dao_user.rs index aa729e8476..4f9587c16a 100644 --- a/test/src/specs/dao/dao_user.rs +++ b/test/src/specs/dao/dao_user.rs @@ -2,7 +2,7 @@ use crate::utils::since_from_absolute_epoch_number; use crate::{Node, TXOSet, TXO}; use ckb_chain_spec::OUTPUT_INDEX_DAO; use ckb_types::core::{EpochNumberWithFraction, HeaderView}; -use ckb_types::packed::WitnessArgs; +use ckb_types::packed::{self, WitnessArgs}; use ckb_types::{ bytes::Bytes, core::{ScriptHashType, TransactionBuilder, TransactionView}, @@ -41,7 +41,7 @@ impl<'a> DAOUser<'a> { .iter() .map(|txo| CellInput::new(txo.out_point(), 0)) .collect::>(); - let output_data = Bytes::from(&[0u8; 8][..]).pack(); + let output_data: packed::Bytes = Bytes::from(&[0u8; 8][..]).into(); let outputs = { // TRICK: When we change the always_outputs to deposit_outputs, the always_output's // capacity will be insufficient. So here uses part of always_outputs' capacity @@ -51,9 +51,9 @@ impl<'a> DAOUser<'a> { (0..outputs_len) .map(|_| { CellOutput::new_builder() - .capacity(capacity.pack()) + .capacity(capacity.into()) .lock(node.always_success_script()) - .type_(Some(self.dao_type_script()).pack()) + .type_(Some(self.dao_type_script()).into()) .build() }) .collect::>() @@ -83,14 +83,14 @@ impl<'a> DAOUser<'a> { .map(|(txo, _)| CellInput::new(txo.out_point(), 0)); let outputs = deposit_utxo_headers.iter().map(|(txo, _)| { CellOutput::new_builder() - .capacity(txo.capacity().pack()) + .capacity(txo.capacity().into()) .lock(txo.lock()) .type_(txo.type_()) .build() }); let outputs_data = deposit_utxo_headers.iter().map(|(_, header)| { let deposit_number = header.number(); - Bytes::from(deposit_number.to_le_bytes().to_vec()).pack() + Bytes::from(deposit_number.to_le_bytes().to_vec()).into() }); let cell_deps = vec![node.always_success_cell_dep(), self.dao_cell_dep()]; // NOTE: dao.c uses `deposit_header` to ensure the prepare_output.capacity == deposit_output.capacity @@ -108,10 +108,10 @@ impl<'a> DAOUser<'a> { .position(|hash| hash == &header.hash()) .unwrap() as u64; WitnessArgs::new_builder() - .input_type(Some(Bytes::from(index.to_le_bytes().to_vec())).pack()) + .input_type(Some(Bytes::from(index.to_le_bytes().to_vec())).into()) .build() .as_bytes() - .pack() + .into() }) .collect::>(); let tx = TransactionBuilder::default() @@ -148,7 +148,7 @@ impl<'a> DAOUser<'a> { }) .sum::(); let output = CellOutput::new_builder() - .capacity(output_capacity.pack()) + .capacity(output_capacity.into()) .lock(node.always_success_script()) .build(); let cell_deps = vec![node.always_success_cell_dep(), self.dao_cell_dep()]; @@ -167,10 +167,10 @@ impl<'a> DAOUser<'a> { .position(|hash| hash == &header.hash()) .unwrap() as u64; WitnessArgs::new_builder() - .input_type(Some(Bytes::from(index.to_le_bytes().to_vec())).pack()) + .input_type(Some(Bytes::from(index.to_le_bytes().to_vec())).into()) .build() .as_bytes() - .pack() + .into() }) .collect::>(); let tx = TransactionBuilder::default() @@ -220,7 +220,7 @@ impl<'a> DAOUser<'a> { let header = self .node .rpc_client() - .get_header(block_hash.pack()) + .get_header(block_hash.into()) .expect("get utxo transaction block header") .into(); (txo, header) @@ -240,7 +240,7 @@ impl<'a> DAOUser<'a> { .expect("get deposit transaction block hash"); let deposit_header = node .rpc_client() - .get_header(deposit_hash.pack()) + .get_header(deposit_hash.into()) .expect("get deposit transaction block header"); EpochNumberWithFraction::from_full_value(deposit_header.inner.epoch.value()) }; diff --git a/test/src/specs/dao/dao_verifier.rs b/test/src/specs/dao/dao_verifier.rs index b2b1fab86a..989a321180 100644 --- a/test/src/specs/dao/dao_verifier.rs +++ b/test/src/specs/dao/dao_verifier.rs @@ -5,7 +5,6 @@ use ckb_dao_utils::extract_dao_data; use ckb_jsonrpc_types::EpochView; use ckb_types::core::{BlockEconomicState, BlockNumber, BlockView, Capacity, TransactionView}; use ckb_types::packed::{Byte32, CellOutput, OutPoint}; -use ckb_types::prelude::Unpack; use ckb_util::Mutex; use std::collections::HashMap; @@ -148,7 +147,7 @@ impl DAOVerifier { && tx_index == 0 && output.lock().args().raw_data() == satoshi_pubkey_hash.0[..] { - sum += Unpack::::unpack(&output.capacity()) + sum += Into::::into(&output.capacity()) .safe_mul_ratio(satoshi_cell_occupied_ratio) .unwrap() .as_u64(); @@ -219,7 +218,7 @@ impl DAOVerifier { let prepare_tx = self.get_transaction(&o.tx_hash()); let deposit_out_point = prepare_tx .inputs() - .get(o.index().unpack()) + .get(o.index().into()) .unwrap() .previous_output(); let deposit_header_number = @@ -246,7 +245,7 @@ impl DAOVerifier { let input_tx = self.get_transaction(&out_point.tx_hash()); let input_data = input_tx .outputs_data() - .get(out_point.index().unpack()) + .get(out_point.index().into()) .unwrap(); if input_data.len() != 8 { return false; @@ -333,12 +332,12 @@ impl DAOVerifier { fn get_output(&self, out_point: &OutPoint) -> CellOutput { self.get_transaction(&out_point.tx_hash()) - .output(out_point.index().unpack()) + .output(out_point.index().into()) .expect("exist") } fn get_output_capacity(&self, out_point: &OutPoint) -> u64 { - self.get_output(out_point).capacity().unpack() + self.get_output(out_point).capacity().into() } fn get_output_occupied_capacity(&self, out_point: &OutPoint) -> u64 { @@ -346,12 +345,12 @@ impl DAOVerifier { let satoshi_cell_occupied_ratio = self.consensus.satoshi_cell_occupied_ratio; let (output, data) = self .get_transaction(&out_point.tx_hash()) - .output_with_data(out_point.index().unpack()) + .output_with_data(out_point.index().into()) .expect("exist"); - if Unpack::::unpack(&out_point.index()) == 0 + if Into::::into(&out_point.index()) == 0 && output.lock().args().raw_data() == satoshi_pubkey_hash.0[..] { - Unpack::::unpack(&output.capacity()) + Into::::into(&output.capacity()) .safe_mul_ratio(satoshi_cell_occupied_ratio) .unwrap() .as_u64() diff --git a/test/src/specs/dao/satoshi_dao_occupied.rs b/test/src/specs/dao/satoshi_dao_occupied.rs index 5756d25ceb..6fb8965cea 100644 --- a/test/src/specs/dao/satoshi_dao_occupied.rs +++ b/test/src/specs/dao/satoshi_dao_occupied.rs @@ -35,7 +35,7 @@ impl Spec for DAOWithSatoshiCellOccupied { let withdrawal = user.withdraw(); let since = EpochNumberWithFraction::from_full_value( - withdrawal.inputs().get(0).unwrap().since().unpack(), + withdrawal.inputs().get(0).unwrap().since().into(), ); goto_target_point(node, since); ensure_committed(node, &withdrawal); @@ -95,7 +95,7 @@ impl Spec for SpendSatoshiCell { 0, ); let output = CellOutput::new_builder() - .capacity(satoshi_cell_occupied.pack()) + .capacity(satoshi_cell_occupied.into()) .lock(always_success_cell().2.clone()) .build(); @@ -103,19 +103,19 @@ impl Spec for SpendSatoshiCell { .cell_deps(vec![node0.always_success_cell_dep()]) .input(satoshi_input) .output(output) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let tx_hash = transaction.hash(); let sig = self .privkey - .sign_recoverable(&tx_hash.unpack()) + .sign_recoverable(&(&tx_hash).into()) .expect("sign"); let mut witness_vec = sig.serialize(); witness_vec.extend_from_slice(&self.pubkey.serialize()); let witness = Bytes::from(witness_vec); let transaction = transaction .as_advanced_builder() - .witness(witness.pack()) + .witness(witness.into()) .build(); node0.mine(1); @@ -152,7 +152,7 @@ fn issue_satoshi_cell() -> IssuedCell { .2 .clone() .as_builder() - .args(Bytes::from(&SATOSHI_PUBKEY_HASH.0[..]).pack()) + .args(Bytes::from(&SATOSHI_PUBKEY_HASH.0[..]).into()) .build(); IssuedCell { capacity: SATOSHI_CELL_CAPACITY, diff --git a/test/src/specs/hardfork/v2021/cell_deps.rs b/test/src/specs/hardfork/v2021/cell_deps.rs index 929a2e2f54..801c12650c 100644 --- a/test/src/specs/hardfork/v2021/cell_deps.rs +++ b/test/src/specs/hardfork/v2021/cell_deps.rs @@ -219,7 +219,7 @@ impl NewScript { }; let cell_input = inputs.next().unwrap(); let cell_output = packed::CellOutput::new_builder() - .type_(Some(type_script).pack()) + .type_(Some(type_script).into()) .build_exact_capacity(core::Capacity::bytes(data.len()).unwrap()) .unwrap(); let tx = tx_template @@ -375,7 +375,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { fn wait_block_assembler_reset(&self, block_hash: Byte32) { self.node - .new_block_with_blocking(|template| template.parent_hash != block_hash.unpack()); + .new_block_with_blocking(|template| template.parent_hash != (&block_hash).into()); } } @@ -443,7 +443,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { type_script: &NewScript, ) -> TransactionView { let output = packed::CellOutput::new_builder() - .type_(Some(type_script.as_data_script(0)).pack()) + .type_(Some(type_script.as_data_script(0)).into()) .build_exact_capacity(core::Capacity::bytes(data_script.data().len()).unwrap()) .unwrap(); let tx = TransactionView::new_advanced_builder() @@ -469,13 +469,14 @@ impl<'a> CheckCellDepsTestRunner<'a> { inputs: &mut impl Iterator, dep_txs: &[&TransactionView], ) -> packed::CellDep { - let dep_data = dep_txs - .iter() - .map(|tx| packed::OutPoint::new(tx.hash(), 0)) - .collect::>() - .pack() - .as_bytes() - .pack(); + let dep_data: packed::Bytes = Into::::into( + dep_txs + .iter() + .map(|tx| packed::OutPoint::new(tx.hash(), 0)) + .collect::>(), + ) + .as_bytes() + .into(); let dep_output = packed::CellOutput::new_builder() .build_exact_capacity(core::Capacity::bytes(dep_data.len()).unwrap()) .unwrap(); @@ -503,7 +504,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { fn get_previous_output(&self, cell_input: &packed::CellInput) -> rpc::CellOutput { let previous_output = cell_input.previous_output(); - let previous_output_index: usize = previous_output.index().unpack(); + let previous_output_index: usize = previous_output.index().into(); if let Either::Left(tx) = self .node .rpc_client() @@ -525,7 +526,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { let new_script = &self.deps.default_script; let input_cell = self.get_previous_output(&cell_input); let cell_output = packed::CellOutput::new_builder() - .capacity(input_cell.capacity.value().pack()) + .capacity(input_cell.capacity.value().into()) .lock(new_script.as_data_script(0)) .build(); let tx = TransactionView::new_advanced_builder() @@ -545,9 +546,9 @@ impl<'a> CheckCellDepsTestRunner<'a> { let new_script = &self.deps.default_script; let input_cell = self.get_previous_output(&cell_input); let cell_output = packed::CellOutput::new_builder() - .capacity(input_cell.capacity.value().pack()) + .capacity(input_cell.capacity.value().into()) .lock(self.node.always_success_script()) - .type_(Some(new_script.as_data_script(0)).pack()) + .type_(Some(new_script.as_data_script(0)).into()) .build(); let tx = TransactionView::new_advanced_builder() .cell_dep(self.node.always_success_cell_dep()) @@ -566,7 +567,7 @@ impl<'a> CheckCellDepsTestRunner<'a> { let new_script = &self.deps.default_script; let input_cell = self.get_previous_output(&cell_input); let cell_output = packed::CellOutput::new_builder() - .capacity(input_cell.capacity.value().pack()) + .capacity(input_cell.capacity.value().into()) .lock(new_script.as_type_script()) .build(); let tx = TransactionView::new_advanced_builder() @@ -586,9 +587,9 @@ impl<'a> CheckCellDepsTestRunner<'a> { let new_script = &self.deps.default_script; let input_cell = self.get_previous_output(&cell_input); let cell_output = packed::CellOutput::new_builder() - .capacity(input_cell.capacity.value().pack()) + .capacity(input_cell.capacity.value().into()) .lock(self.node.always_success_script()) - .type_(Some(new_script.as_type_script()).pack()) + .type_(Some(new_script.as_type_script()).into()) .build(); let tx = TransactionView::new_advanced_builder() .cell_dep(self.node.always_success_cell_dep()) @@ -626,11 +627,11 @@ impl<'a> CheckCellDepsTestRunner<'a> { (HT::Data, ST::Lock) => cob.lock(new_script.as_data_script(0)), (HT::Data, ST::Type) => cob .lock(self.node.always_success_script()) - .type_(Some(new_script.as_data_script(0)).pack()), + .type_(Some(new_script.as_data_script(0)).into()), (HT::Type, ST::Lock) => cob.lock(new_script.as_type_script()), (HT::Type, ST::Type) => cob .lock(self.node.always_success_script()) - .type_(Some(new_script.as_type_script()).pack()), + .type_(Some(new_script.as_type_script()).into()), } } } diff --git a/test/src/specs/hardfork/v2021/vm_b_extension.rs b/test/src/specs/hardfork/v2021/vm_b_extension.rs index 22882c4140..d03ac41f50 100644 --- a/test/src/specs/hardfork/v2021/vm_b_extension.rs +++ b/test/src/specs/hardfork/v2021/vm_b_extension.rs @@ -80,7 +80,7 @@ impl Spec for CheckVmBExtension { impl BExtScript { fn new(node: &Node, cell_input: packed::CellInput) -> Self { - let data: packed::Bytes = include_bytes!("../../../../../script/testdata/cpop_lock").pack(); + let data: packed::Bytes = include_bytes!("../../../../../script/testdata/cpop_lock").into(); let tx = Self::deploy(node, &data, cell_input); let cell_dep = packed::CellDep::new_builder() .out_point(packed::OutPoint::new(tx.hash(), 0)) @@ -105,7 +105,7 @@ impl BExtScript { let type_script = node.always_success_script(); let tx_template = TransactionView::new_advanced_builder(); let cell_output = packed::CellOutput::new_builder() - .type_(Some(type_script).pack()) + .type_(Some(type_script).into()) .build_exact_capacity(Capacity::bytes(data.len()).unwrap()) .unwrap(); let tx = tx_template @@ -220,12 +220,12 @@ impl<'a> CheckVmBExtensionTestRunner<'a> { let mut vec = Vec::with_capacity(8 * 2); vec.extend_from_slice(&num0.to_le_bytes()); vec.extend_from_slice(&num1.to_le_bytes()); - vec.pack() + vec.into() }; let script = self.script.as_script(vm_opt, args); packed::CellOutput::new_builder() .lock(self.node.always_success_script()) - .type_(Some(script).pack()) + .type_(Some(script).into()) .build_exact_capacity(Capacity::shannons(0)) .unwrap() }; diff --git a/test/src/specs/hardfork/v2021/vm_version1.rs b/test/src/specs/hardfork/v2021/vm_version1.rs index f49d955275..53911c67a6 100644 --- a/test/src/specs/hardfork/v2021/vm_version1.rs +++ b/test/src/specs/hardfork/v2021/vm_version1.rs @@ -127,7 +127,7 @@ impl NewScript { let tx_template = TransactionView::new_advanced_builder(); let cell_input = inputs.next().unwrap(); let cell_output = packed::CellOutput::new_builder() - .type_(Some(type_script).pack()) + .type_(Some(type_script).into()) .build_exact_capacity(Capacity::bytes(data.len()).unwrap()) .unwrap(); let tx = tx_template @@ -218,7 +218,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { TransactionView::new_advanced_builder().cell_dep(cell_dep), packed::CellOutput::new_builder() .lock(self.node.always_success_script()) - .type_(Some(script).pack()), + .type_(Some(script).into()), ) } else { ( @@ -229,7 +229,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { let cell_input = inputs.next().unwrap(); let input_cell = self.get_previous_output(&cell_input); let cell_output = co_builder - .capacity((input_cell.capacity.value() - 1).pack()) + .capacity((input_cell.capacity.value() - 1).into()) .build(); let tx = tx_builder .cell_dep(self.node.always_success_cell_dep()) @@ -277,7 +277,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { fn get_previous_output(&self, cell_input: &packed::CellInput) -> rpc::CellOutput { let previous_output = cell_input.previous_output(); - let previous_output_index: usize = previous_output.index().unpack(); + let previous_output_index: usize = previous_output.index().into(); if let Either::Left(tx) = self .node .rpc_client() diff --git a/test/src/specs/hardfork/v2023/vm_version2.rs b/test/src/specs/hardfork/v2023/vm_version2.rs index 972fb74f9e..f28e4dd4c4 100644 --- a/test/src/specs/hardfork/v2023/vm_version2.rs +++ b/test/src/specs/hardfork/v2023/vm_version2.rs @@ -147,7 +147,7 @@ impl NewScript { let tx_template = TransactionView::new_advanced_builder(); let cell_input = inputs.next().unwrap(); let cell_output = packed::CellOutput::new_builder() - .type_(Some(type_script).pack()) + .type_(Some(type_script).into()) .build_exact_capacity(Capacity::bytes(data.len()).unwrap()) .unwrap(); let tx = tx_template @@ -239,7 +239,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { TransactionView::new_advanced_builder().cell_dep(cell_dep), packed::CellOutput::new_builder() .lock(self.node.always_success_script()) - .type_(Some(script).pack()), + .type_(Some(script).into()), ) } else { ( @@ -250,7 +250,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { let cell_input = inputs.next().unwrap(); let input_cell = self.get_previous_output(&cell_input); let cell_output = co_builder - .capacity((input_cell.capacity.value() - 1).pack()) + .capacity((input_cell.capacity.value() - 1).into()) .build(); let tx = tx_builder .cell_dep(self.node.always_success_cell_dep()) @@ -298,7 +298,7 @@ impl<'a> CheckVmVersionTestRunner<'a> { fn get_previous_output(&self, cell_input: &packed::CellInput) -> rpc::CellOutput { let previous_output = cell_input.previous_output(); - let previous_output_index: usize = previous_output.index().unpack(); + let previous_output_index: usize = previous_output.index().into(); if let Either::Left(tx) = self .node diff --git a/test/src/specs/mining/basic.rs b/test/src/specs/mining/basic.rs index c08357e5b5..f78ec326c6 100644 --- a/test/src/specs/mining/basic.rs +++ b/test/src/specs/mining/basic.rs @@ -3,7 +3,6 @@ use crate::util::cell::gen_spendable; use crate::util::transaction::always_success_transaction; use crate::{Node, Spec}; use ckb_jsonrpc_types::BlockTemplate; -use ckb_types::prelude::*; pub struct MiningBasic; @@ -50,7 +49,7 @@ impl Spec for BlockTemplates { block1 .header() .as_advanced_builder() - .timestamp((block1.header().timestamp() + 1).pack()) + .timestamp((block1.header().timestamp() + 1).into()) .build(), ) .build(); @@ -61,13 +60,13 @@ impl Spec for BlockTemplates { node.submit_block(&block2); assert_eq!( block1.hash(), - rpc_client.get_tip_header().hash.pack(), + rpc_client.get_tip_header().hash.into(), "Block1 should be the tip block according first-received policy" ); let template1 = rpc_client.get_block_template(None, None, None); assert_eq!( block1.hash(), - template1.parent_hash.pack(), + (&template1.parent_hash).into(), "Block1 should be block template's parent block since it's tip block" ); diff --git a/test/src/specs/mining/bootstrap.rs b/test/src/specs/mining/bootstrap.rs index 0bf13bbfcd..861f718abd 100644 --- a/test/src/specs/mining/bootstrap.rs +++ b/test/src/specs/mining/bootstrap.rs @@ -20,8 +20,8 @@ impl Spec for BootstrapCellbase { node.mine(DEFAULT_TX_PROPOSAL_WINDOW.1 + 1); let miner = packed::Script::new_builder() - .args(Bytes::from(vec![2, 1]).pack()) - .code_hash(h256!("0xa2").pack()) + .args(Bytes::from(vec![2, 1]).into()) + .code_hash(h256!("0xa2").into()) .hash_type(ScriptHashType::Data.into()) .build(); diff --git a/test/src/specs/mining/fee.rs b/test/src/specs/mining/fee.rs index abadc4daf8..c9cb84afb4 100644 --- a/test/src/specs/mining/fee.rs +++ b/test/src/specs/mining/fee.rs @@ -79,7 +79,7 @@ impl Spec for FeeOfMaxBlockProposalsLimit { let maximal_capacity = cell.capacity().as_u64(); let random_capacity = rng.gen_range(minimal_capacity..=maximal_capacity); let output = CellOutput::new_builder() - .capacity(random_capacity.pack()) + .capacity(random_capacity.into()) .lock(cell.cell_output.lock()) .type_(cell.cell_output.type_()) .build(); @@ -135,7 +135,7 @@ impl Spec for FeeOfMultipleMaxBlockProposalsLimit { let maximal_capacity = cell.capacity().as_u64(); let random_capacity = rng.gen_range(minimal_capacity..=maximal_capacity); let output = CellOutput::new_builder() - .capacity(random_capacity.pack()) + .capacity(random_capacity.into()) .lock(cell.cell_output.lock()) .type_(cell.cell_output.type_()) .build(); @@ -225,7 +225,7 @@ impl Spec for ProposeDuplicated { let uncle = node .new_block_builder(None, None, None) .proposal(tx.proposal_short_id()) - .nonce(99999.pack()) + .nonce(99999.into()) .build() .as_uncle(); node.mine(1); @@ -256,7 +256,7 @@ impl Spec for MalformedTx { let tx0 = node0.new_transaction_spend_tip_cellbase(); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .build(); let child = tx0 diff --git a/test/src/specs/mining/proposal.rs b/test/src/specs/mining/proposal.rs index 272252671c..5a29009c77 100644 --- a/test/src/specs/mining/proposal.rs +++ b/test/src/specs/mining/proposal.rs @@ -2,7 +2,6 @@ use crate::generic::GetProposalTxIds; use crate::util::cell::gen_spendable; use crate::util::transaction::always_success_transaction; use crate::{Node, Spec}; -use ckb_types::prelude::*; pub struct AvoidDuplicatedProposalsWithUncles; @@ -21,7 +20,7 @@ impl Spec for AvoidDuplicatedProposalsWithUncles { let block = node.new_block(None, None, None); let uncle = block .as_advanced_builder() - .timestamp((block.timestamp() + 1).pack()) + .timestamp((block.timestamp() + 1).into()) .set_proposals(vec![tx.proposal_short_id()]) .build(); node.submit_block(&block); diff --git a/test/src/specs/mining/uncle.rs b/test/src/specs/mining/uncle.rs index 04d044421f..9ef25609bc 100644 --- a/test/src/specs/mining/uncle.rs +++ b/test/src/specs/mining/uncle.rs @@ -1,6 +1,5 @@ use crate::{Node, Spec}; use ckb_types::core::{BlockView, EpochNumberWithFraction}; -use ckb_types::prelude::*; // Convention: // main-block: a block on the main fork @@ -86,9 +85,9 @@ impl Spec for UncleInheritFromForkUncle { let uncle_child = uncle_parent .as_advanced_builder() - .number((uncle_parent.number() + 1).pack()) + .number((uncle_parent.number() + 1).into()) .parent_hash(uncle_parent.hash()) - .timestamp((uncle_parent.timestamp() + 1).pack()) + .timestamp((uncle_parent.timestamp() + 1).into()) .epoch( { let parent_epoch = uncle_parent.epoch(); @@ -97,7 +96,7 @@ impl Spec for UncleInheritFromForkUncle { let epoch_length = parent_epoch.length(); EpochNumberWithFraction::new(epoch_number, epoch_index + 1, epoch_length) } - .pack(), + .into(), ) .build(); diff --git a/test/src/specs/relay/block_relay.rs b/test/src/specs/relay/block_relay.rs index 22569ce61e..1f5b5a2efb 100644 --- a/test/src/specs/relay/block_relay.rs +++ b/test/src/specs/relay/block_relay.rs @@ -3,7 +3,6 @@ use crate::util::mining::out_ibd_mode; use crate::utils::{now_ms, sleep, wait_until}; use crate::{Node, Spec}; use ckb_logger::info; -use ckb_types::prelude::*; use std::time::Duration; pub struct RelayTooNewBlock; @@ -22,7 +21,7 @@ impl Spec for RelayTooNewBlock { let future = Duration::from_secs(6_000).as_millis() as u64; let too_new_block = node0 .new_block_builder(None, None, None) - .timestamp((now_ms() + future).pack()) + .timestamp((now_ms() + future).into()) .build(); let _too_new_hash = node0.process_block_without_verify(&too_new_block, true); diff --git a/test/src/specs/relay/compact_block.rs b/test/src/specs/relay/compact_block.rs index 9b8c078b7f..ab2b70a2c7 100644 --- a/test/src/specs/relay/compact_block.rs +++ b/test/src/specs/relay/compact_block.rs @@ -40,7 +40,7 @@ impl Spec for CompactBlockEmptyParentUnknown { .new_block_builder(None, None, None) .header( HeaderBuilder::default() - .parent_hash(h256!("0x123456").pack()) + .parent_hash(h256!("0x123456").into()) .build(), ) .build(); @@ -297,7 +297,7 @@ impl Spec for CompactBlockMissingWithDropTx { .as_reader() .indexes() .iter() - .map(|i| Unpack::::unpack(&i)) + .map(Into::::into) .collect::>(); vec![2] == msg } else { @@ -316,7 +316,7 @@ impl Spec for CompactBlockMissingWithDropTx { let content = packed::BlockTransactions::new_builder() .block_hash(new_block.hash()) - .transactions(vec![new_tx_2.data()].pack()) + .transactions(vec![new_tx_2.data()].into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); @@ -331,7 +331,7 @@ impl Spec for CompactBlockMissingWithDropTx { .as_reader() .indexes() .iter() - .map(|i| Unpack::::unpack(&i)) + .map(Into::::into) .collect::>(); vec![1, 2] == msg } else { @@ -348,7 +348,7 @@ impl Spec for CompactBlockMissingWithDropTx { let content = packed::BlockTransactions::new_builder() .block_hash(new_block.hash()) - .transactions(vec![new_tx_1.data(), new_tx_2.data()].pack()) + .transactions(vec![new_tx_1.data(), new_tx_2.data()].into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/test/src/specs/relay/get_block_proposal_process.rs b/test/src/specs/relay/get_block_proposal_process.rs index f3e59b45e1..b076b37666 100644 --- a/test/src/specs/relay/get_block_proposal_process.rs +++ b/test/src/specs/relay/get_block_proposal_process.rs @@ -46,7 +46,7 @@ impl Spec for ProposalRespondSizelimit { let content = packed::GetBlockProposal::new_builder() .block_hash(tip_hash) - .proposals(proposal_ids.pack()) + .proposals(proposal_ids.into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/test/src/specs/relay/get_block_transactions_process.rs b/test/src/specs/relay/get_block_transactions_process.rs index e621ad336d..d36fd6b579 100644 --- a/test/src/specs/relay/get_block_transactions_process.rs +++ b/test/src/specs/relay/get_block_transactions_process.rs @@ -24,21 +24,21 @@ impl Spec for MissingUncleRequest { node.mine(1); let builder = node.new_block_builder(None, None, None); - let block1 = builder.clone().nonce(0.pack()).build(); - let block2 = builder.nonce(1.pack()).build(); + let block1 = builder.clone().nonce(0.into()).build(); + let block2 = builder.nonce(1.into()).build(); node.submit_block(&block1); node.submit_block(&block2); let builder = node.new_block_builder(None, None, None); let block = builder .set_uncles(vec![block2.as_uncle()]) - .nonce(0.pack()) + .nonce(0.into()) .build(); node.submit_block(&block); let content = packed::GetBlockTransactions::new_builder() .block_hash(block.hash()) - .uncle_indexes([0u32].pack()) + .uncle_indexes([0u32].into()) .build(); let message = packed::RelayMessage::new_builder().set(content).build(); diff --git a/test/src/specs/relay/transaction_relay.rs b/test/src/specs/relay/transaction_relay.rs index 1a9512314c..46c7597216 100644 --- a/test/src/specs/relay/transaction_relay.rs +++ b/test/src/specs/relay/transaction_relay.rs @@ -241,7 +241,7 @@ impl Spec for TransactionRelayConflict { let tx1 = node0.new_transaction(tx_hash_0.clone()); let tx2_temp = node0.new_transaction(tx_hash_0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).pack()) + .capacity(capacity_bytes!(80).into()) .build(); let tx2 = tx2_temp diff --git a/test/src/specs/rpc/get_block_template.rs b/test/src/specs/rpc/get_block_template.rs index 58a076e117..46c509b44d 100644 --- a/test/src/specs/rpc/get_block_template.rs +++ b/test/src/specs/rpc/get_block_template.rs @@ -1,6 +1,6 @@ use crate::{Node, Spec}; use ckb_jsonrpc_types::AsEpochNumberWithFraction; -use ckb_types::prelude::*; +use ckb_types::packed; pub struct RpcGetBlockTemplate; @@ -48,10 +48,10 @@ impl Spec for RpcGetBlockTemplate { let parent_block_hash = node0.get_tip_block().hash(); assert_eq!( parent_block_hash, - genesis_block_template.parent_hash.pack(), + (&genesis_block_template.parent_hash).into(), "Parent block hash should be {}, but got {}", parent_block_hash, - genesis_block_template.parent_hash.pack() + Into::::into(&genesis_block_template.parent_hash) ); assert_eq!( 0, diff --git a/test/src/specs/rpc/submit_block.rs b/test/src/specs/rpc/submit_block.rs index 6a06fa8025..adfa9ae399 100644 --- a/test/src/specs/rpc/submit_block.rs +++ b/test/src/specs/rpc/submit_block.rs @@ -1,9 +1,6 @@ use crate::utils::now_ms; use crate::{Node, Spec}; -use ckb_types::{ - core::{EpochNumberWithFraction, HeaderView}, - prelude::*, -}; +use ckb_types::core::{EpochNumberWithFraction, HeaderView}; pub struct RpcSubmitBlock; @@ -19,7 +16,7 @@ impl Spec for RpcSubmitBlock { // build block with wrong block number let block = node0 .new_block_builder(None, None, None) - .number(2.pack()) + .number(2.into()) .build(); let block_err = node0 .rpc_client() @@ -41,7 +38,7 @@ impl Spec for RpcSubmitBlock { let epoch = EpochNumberWithFraction::new(tip_epoch.number() + 1, 0, 100); let block = node0 .new_block_builder(None, None, None) - .epoch(epoch.pack()) + .epoch(epoch.into()) .build(); let block_err = node0 .rpc_client() @@ -87,7 +84,7 @@ impl Spec for RpcSubmitBlock { // so here plus another 15s to make sure when submit the block it still out of the limit let block = node0 .new_block_builder(None, None, None) - .timestamp((now_ms() + 30_000).pack()) + .timestamp((now_ms() + 30_000).into()) .build(); let block_err = node0 .rpc_client() @@ -102,7 +99,7 @@ impl Spec for RpcSubmitBlock { let median_time = node0.rpc_client().get_blockchain_info().median_time.value(); let block = node0 .new_block_builder(None, None, None) - .timestamp((median_time - 1).pack()) + .timestamp((median_time - 1).into()) .build(); let block_err = node0 .rpc_client() diff --git a/test/src/specs/rpc/transaction_proof.rs b/test/src/specs/rpc/transaction_proof.rs index 0b5d83384e..d4eefcb4c4 100644 --- a/test/src/specs/rpc/transaction_proof.rs +++ b/test/src/specs/rpc/transaction_proof.rs @@ -1,5 +1,4 @@ use crate::{Node, Spec, DEFAULT_TX_PROPOSAL_WINDOW}; -use ckb_types::prelude::*; pub struct RpcTransactionProof; @@ -10,7 +9,7 @@ impl Spec for RpcTransactionProof { let tx_hash = node0.generate_transaction(); node0.mine_until_transaction_confirm(&tx_hash); - let tx_hashes = vec![tx_hash.unpack()]; + let tx_hashes = vec![tx_hash.into()]; let proof = node0 .rpc_client() .inner() diff --git a/test/src/specs/sync/block_filter.rs b/test/src/specs/sync/block_filter.rs index 0996da7935..cc4f85d83b 100644 --- a/test/src/specs/sync/block_filter.rs +++ b/test/src/specs/sync/block_filter.rs @@ -31,7 +31,7 @@ impl Spec for GetBlockFilterCheckPoints { let start_number: u64 = 0; let request = { let content = packed::GetBlockFilterCheckPoints::new_builder() - .start_number(start_number.pack()) + .start_number(start_number.into()) .build(); packed::BlockFilterMessage::new_builder() .set(content) @@ -45,7 +45,7 @@ impl Spec for GetBlockFilterCheckPoints { match packed::BlockFilterMessageReader::from_slice(&data) { Ok(msg) => match msg.to_enum() { packed::BlockFilterMessageUnionReader::BlockFilterCheckPoints(reader) => { - let resp_start_number: u64 = reader.start_number().unpack(); + let resp_start_number: u64 = reader.start_number().into(); assert_eq!(start_number, resp_start_number); info!("start_number matched"); @@ -113,7 +113,7 @@ impl Spec for GetBlockFilterHashes { let start_number: u64 = 2; let request = { let content = packed::GetBlockFilterHashes::new_builder() - .start_number(start_number.pack()) + .start_number(start_number.into()) .build(); packed::BlockFilterMessage::new_builder() .set(content) @@ -127,7 +127,7 @@ impl Spec for GetBlockFilterHashes { match packed::BlockFilterMessageReader::from_slice(&data) { Ok(msg) => match msg.to_enum() { packed::BlockFilterMessageUnionReader::BlockFilterHashes(reader) => { - let resp_start_number: u64 = reader.start_number().unpack(); + let resp_start_number: u64 = reader.start_number().into(); assert_eq!(start_number, resp_start_number); info!("start_number matched"); @@ -205,7 +205,7 @@ impl Spec for GetBlockFilters { let start_number: u64 = 42; let request = { let content = packed::GetBlockFilters::new_builder() - .start_number(start_number.pack()) + .start_number(start_number.into()) .build(); packed::BlockFilterMessage::new_builder() .set(content) @@ -219,7 +219,7 @@ impl Spec for GetBlockFilters { match packed::BlockFilterMessageReader::from_slice(&data) { Ok(msg) => match msg.to_enum() { packed::BlockFilterMessageUnionReader::BlockFilters(reader) => { - let resp_start_number: u64 = reader.start_number().unpack(); + let resp_start_number: u64 = reader.start_number().into(); assert_eq!(start_number, resp_start_number); info!("start_number matched"); @@ -231,7 +231,7 @@ impl Spec for GetBlockFilters { let filters: Vec = reader .filters() .iter() - .map(|item| item.to_entity().unpack()) + .map(|item| item.to_entity().into()) .collect(); assert_eq!( @@ -289,7 +289,7 @@ impl Spec for GetBlockFiltersNotReachBatch { info!("start_number: {start_number}"); let request = { let content = packed::GetBlockFilters::new_builder() - .start_number(start_number.pack()) + .start_number(start_number.into()) .build(); packed::BlockFilterMessage::new_builder() .set(content) @@ -303,7 +303,7 @@ impl Spec for GetBlockFiltersNotReachBatch { match packed::BlockFilterMessageReader::from_slice(&data) { Ok(msg) => match msg.to_enum() { packed::BlockFilterMessageUnionReader::BlockFilters(reader) => { - let resp_start_number: u64 = reader.start_number().unpack(); + let resp_start_number: u64 = reader.start_number().into(); assert_eq!(start_number, resp_start_number); info!("start_number matched"); @@ -315,7 +315,7 @@ impl Spec for GetBlockFiltersNotReachBatch { let filters: Vec = reader .filters() .iter() - .map(|item| item.to_entity().unpack()) + .map(|item| item.to_entity().into()) .collect(); assert_eq!( diff --git a/test/src/specs/sync/block_sync.rs b/test/src/specs/sync/block_sync.rs index 900ca0f4bc..669e96c589 100644 --- a/test/src/specs/sync/block_sync.rs +++ b/test/src/specs/sync/block_sync.rs @@ -54,8 +54,8 @@ impl Spec for BlockSyncWithUncle { let node1 = &nodes[1]; let new_builder = node1.new_block_builder(None, None, None); - let new_block1 = new_builder.clone().nonce(0.pack()).build(); - let new_block2 = new_builder.nonce(1.pack()).build(); + let new_block1 = new_builder.clone().nonce(0.into()).build(); + let new_block2 = new_builder.nonce(1.into()).build(); node1.submit_block(&new_block1); node1.submit_block(&new_block2); @@ -322,7 +322,7 @@ impl Spec for BlockSyncNonAncestorBestBlocks { let b = a .data() .as_advanced_builder() - .timestamp((a.timestamp() + 1).pack()) + .timestamp((a.timestamp() + 1).into()) .build(); assert_ne!(a.hash(), b.hash()); node1.submit_block(&b); @@ -425,7 +425,7 @@ impl Spec for SyncTooNewBlock { for _ in 0..3 { let too_new_block = node0 .new_block_builder(None, None, None) - .timestamp((now_ms() + future).pack()) + .timestamp((now_ms() + future).into()) .build(); // node1 sync node1 with too new block @@ -465,7 +465,7 @@ impl Spec for HeaderSyncCycle { net.connect(node0); let send_headers = SendHeaders::new_builder() - .headers(Vec::new().pack()) + .headers(Vec::new().into()) .build(); let msg = SyncMessage::new_builder() diff --git a/test/src/specs/sync/chain_forks.rs b/test/src/specs/sync/chain_forks.rs index b1d9132f6c..d7c777b904 100644 --- a/test/src/specs/sync/chain_forks.rs +++ b/test/src/specs/sync/chain_forks.rs @@ -144,10 +144,10 @@ impl Spec for ChainFork3 { .get(0) .unwrap() .to_entity(); - let old_capacity: Capacity = old_output.capacity().unpack(); + let old_capacity: Capacity = old_output.capacity().into(); let new_output = old_output .as_builder() - .capacity(old_capacity.safe_add(capacity_bytes!(1)).unwrap().pack()) + .capacity(old_capacity.safe_add(capacity_bytes!(1)).unwrap().into()) .build(); transaction .as_advanced_builder() @@ -214,7 +214,7 @@ impl Spec for ChainFork4 { .unwrap() .to_entity() .as_builder() - .capacity(capacity_bytes!(1).pack()) + .capacity(capacity_bytes!(1).into()) .build(); transaction .as_advanced_builder() @@ -344,7 +344,7 @@ impl Spec for ChainFork6 { node1.mine(2); info!("Generate 1 block (F) with spending non-existent transaction on node1"); let block = node1.new_block(None, None, None); - let invalid_transaction = node1.new_transaction(h256!("0x1").pack()); + let invalid_transaction = node1.new_transaction(h256!("0x1").into()); let invalid_block = block .as_advanced_builder() .transaction(invalid_transaction) @@ -405,7 +405,7 @@ impl Spec for ChainFork7 { let previous_output = input .previous_output() .as_builder() - .index(999u32.pack()) + .index(999u32.into()) .build(); let input = input.as_builder().previous_output(previous_output).build(); let invalid_transaction = transaction @@ -576,7 +576,7 @@ impl Spec for ForksContainSameUncle { let block_b = node_b .new_block_builder(None, None, None) .set_uncles(vec![uncle.as_uncle()]) - .timestamp((block_a.timestamp() + 2).pack()) + .timestamp((block_a.timestamp() + 2).into()) .build(); node_a.submit_block(&block_a); node_b.submit_block(&block_b); diff --git a/test/src/specs/sync/invalid_locator_size.rs b/test/src/specs/sync/invalid_locator_size.rs index e11262ca30..44af4a7143 100644 --- a/test/src/specs/sync/invalid_locator_size.rs +++ b/test/src/specs/sync/invalid_locator_size.rs @@ -21,13 +21,13 @@ impl Spec for InvalidLocatorSize { net.connect(node0); let hashes: Vec = (0..=MAX_LOCATOR_SIZE) - .map(|_| h256!("0x1").pack()) + .map(|_| h256!("0x1").into()) .collect(); let message = SyncMessage::new_builder() .set( GetHeaders::new_builder() - .block_locator_hashes(hashes.pack()) + .block_locator_hashes(hashes.into()) .build(), ) .build() diff --git a/test/src/specs/tx_pool/collision.rs b/test/src/specs/tx_pool/collision.rs index 0d93697c03..3a870e7328 100644 --- a/test/src/specs/tx_pool/collision.rs +++ b/test/src/specs/tx_pool/collision.rs @@ -194,7 +194,7 @@ fn conflict_transactions_with_capacity( .unwrap(); let txb = txa .as_advanced_builder() - .set_outputs_data(vec![output_data.pack()]) + .set_outputs_data(vec![output_data.into()]) .set_outputs(vec![output]) .build(); assert_ne!(txa.hash(), txb.hash()); diff --git a/test/src/specs/tx_pool/different_txs_with_same_input.rs b/test/src/specs/tx_pool/different_txs_with_same_input.rs index f590f7ae81..52ce496367 100644 --- a/test/src/specs/tx_pool/different_txs_with_same_input.rs +++ b/test/src/specs/tx_pool/different_txs_with_same_input.rs @@ -22,7 +22,7 @@ impl Spec for DifferentTxsWithSameInputWithOutRBF { // Set tx2 fee to a higher value, tx1 capacity is 100, set tx2 capacity to 80 for +20 fee. let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).pack()) + .capacity(capacity_bytes!(80).into()) .build(); let tx2 = tx2_temp diff --git a/test/src/specs/tx_pool/mod.rs b/test/src/specs/tx_pool/mod.rs index 436fc44b93..b8e1abc45c 100644 --- a/test/src/specs/tx_pool/mod.rs +++ b/test/src/specs/tx_pool/mod.rs @@ -55,12 +55,12 @@ use ckb_app_config::BlockAssemblerConfig; use ckb_chain_spec::{build_genesis_type_id_script, OUTPUT_INDEX_SECP256K1_BLAKE160_SIGHASH_ALL}; use ckb_jsonrpc_types::JsonBytes; use ckb_resource::CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL; -use ckb_types::{bytes::Bytes, core::ScriptHashType, prelude::*, H256}; +use ckb_types::{bytes::Bytes, core::ScriptHashType, H256}; fn type_lock_script_code_hash() -> H256 { build_genesis_type_id_script(OUTPUT_INDEX_SECP256K1_BLAKE160_SIGHASH_ALL) .calc_script_hash() - .unpack() + .into() } fn new_block_assembler_config(lock_arg: Bytes, hash_type: ScriptHashType) -> BlockAssemblerConfig { diff --git a/test/src/specs/tx_pool/orphan_tx.rs b/test/src/specs/tx_pool/orphan_tx.rs index 0d94ea4609..9762ed1459 100644 --- a/test/src/specs/tx_pool/orphan_tx.rs +++ b/test/src/specs/tx_pool/orphan_tx.rs @@ -132,7 +132,7 @@ fn build_tx_chain( let script = node0.always_success_script(); let new_output1 = CellOutputBuilder::default() - .capacity(capacity_bytes!(200).pack()) + .capacity(capacity_bytes!(200).into()) .lock(script.clone()) .build(); let new_output2 = new_output1.clone(); @@ -154,7 +154,7 @@ fn build_tx_chain( let cell_dep = node0.always_success_cell_dep(); let final_output = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).pack()) + .capacity(capacity_bytes!(80).into()) .lock(script) .build(); let final_tx = TransactionBuilder::default() @@ -312,7 +312,7 @@ impl Spec for TxPoolOrphanDoubleSpend { let script = node0.always_success_script(); let new_output1 = CellOutputBuilder::default() - .capacity(capacity_bytes!(200).pack()) + .capacity(capacity_bytes!(200).into()) .lock(script) .build(); let new_output2 = new_output1.clone(); diff --git a/test/src/specs/tx_pool/pool_reconcile.rs b/test/src/specs/tx_pool/pool_reconcile.rs index 280c506cc8..277e433f8e 100644 --- a/test/src/specs/tx_pool/pool_reconcile.rs +++ b/test/src/specs/tx_pool/pool_reconcile.rs @@ -112,7 +112,7 @@ impl Spec for PoolResolveConflictAfterReorg { !(template .transactions .iter() - .any(|tx| tx.hash == tx1.hash().unpack())) + .any(|tx| tx.hash == tx1.hash().into())) }) .set_proposals(txs.iter().map(|tx| tx.proposal_short_id()).collect()) .build(); @@ -161,7 +161,7 @@ impl Spec for PoolResolveConflictAfterReorg { .build() }]) .set_outputs(vec![CellOutputBuilder::default() - .capacity(capacity_bytes!(99).pack()) + .capacity(capacity_bytes!(99).into()) .build()]) .build(); diff --git a/test/src/specs/tx_pool/replace.rs b/test/src/specs/tx_pool/replace.rs index 3d5a61c6bc..2b64548f69 100644 --- a/test/src/specs/tx_pool/replace.rs +++ b/test/src/specs/tx_pool/replace.rs @@ -28,7 +28,7 @@ impl Spec for RbfEnable { let tx1 = node0.new_transaction(tx_hash_0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).pack()) + .capacity(capacity_bytes!(70).into()) .build(); let tx1 = tx1.as_advanced_builder().set_outputs(vec![output]).build(); @@ -59,7 +59,7 @@ impl Spec for RbfBasic { let tx1 = node0.new_transaction(tx_hash_0.clone()); let tx2_temp = node0.new_transaction(tx_hash_0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(99).pack()) + .capacity(capacity_bytes!(99).into()) .build(); let tx1 = tx1.as_advanced_builder().set_outputs(vec![output]).build(); @@ -76,7 +76,7 @@ impl Spec for RbfBasic { // Set tx2 fee to a higher value, tx1 capacity is 99, set tx2 capacity to 95 for +4 fee. let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(95).pack()) + .capacity(capacity_bytes!(95).into()) .build(); let tx2 = tx2_temp @@ -88,7 +88,7 @@ impl Spec for RbfBasic { .rpc_client() .send_transaction_result(tx2.data().into()); assert!(res.is_ok(), "tx2 should replace with old tx"); - assert_eq!(get_tx_pool_conflicts(node0), vec![tx1.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node0), vec![tx1.hash().into()]); let ret = node0 .rpc_client() @@ -141,7 +141,7 @@ impl Spec for RbfBasic { assert!(ret.transaction.is_none()); assert!(matches!(ret.tx_status.status, Status::Rejected)); assert!(ret.tx_status.reason.unwrap().contains("RBFRejected")); - assert_eq!(get_tx_pool_conflicts(node0), vec![tx1.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node0), vec![tx1.hash().into()]); } fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) { @@ -230,14 +230,14 @@ impl Spec for RbfSameInputwithLessFee { let tx2_temp = node0.new_transaction(tx_hash_0); let output1 = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).pack()) + .capacity(capacity_bytes!(80).into()) .build(); let tx1 = tx1.as_advanced_builder().set_outputs(vec![output1]).build(); // Set tx2 fee to a lower value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(90).pack()) + .capacity(capacity_bytes!(90).into()) .build(); let tx2 = tx2_temp @@ -256,7 +256,7 @@ impl Spec for RbfSameInputwithLessFee { )); // local submit tx RBF check failed, will be added into conflicts pool - assert_eq!(get_tx_pool_conflicts(node0), vec![tx2.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node0), vec![tx2.hash().into()]); } fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) { @@ -300,7 +300,7 @@ impl Spec for RbfTooManyDescendants { // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).pack()) + .capacity(capacity_bytes!(70).into()) .build(); let tx2 = tx0_temp @@ -319,7 +319,7 @@ impl Spec for RbfTooManyDescendants { .contains("Tx conflict with too many txs")); // local submit tx RBF check failed, will not in conflicts pool - assert_eq!(get_tx_pool_conflicts(node0), vec![tx2.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node0), vec![tx2.hash().into()]); } fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) { @@ -363,7 +363,7 @@ impl Spec for RbfContainNewTx { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).pack()) + .capacity(capacity_bytes!(70).into()) .build(); let tx2 = clone_tx @@ -394,7 +394,7 @@ impl Spec for RbfContainNewTx { .contains("new Tx contains unconfirmed inputs")); // local submit tx RBF check failed, will be in conflicts pool - assert_eq!(get_tx_pool_conflicts(node0), vec![tx2.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node0), vec![tx2.hash().into()]); } fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) { @@ -438,7 +438,7 @@ impl Spec for RbfContainInvalidInput { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).pack()) + .capacity(capacity_bytes!(70).into()) .build(); let tx2 = clone_tx @@ -469,7 +469,7 @@ impl Spec for RbfContainInvalidInput { .contains("new Tx contains inputs in descendants of to be replaced Tx")); // local submit tx RBF check failed, will not in conflicts pool - assert_eq!(get_tx_pool_conflicts(node0), vec![tx2.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node0), vec![tx2.hash().into()]); } fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) { @@ -492,7 +492,7 @@ impl Spec for RbfChildPayForParent { let max_count = 5; let output5 = CellOutputBuilder::default() - .capacity(capacity_bytes!(50).pack()) + .capacity(capacity_bytes!(50).into()) .build(); while txs.len() <= max_count { @@ -524,7 +524,7 @@ impl Spec for RbfChildPayForParent { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value, but not enough to pay for tx4 let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).pack()) + .capacity(capacity_bytes!(70).into()) .build(); let new_tx = clone_tx @@ -548,11 +548,11 @@ impl Spec for RbfChildPayForParent { .contains("RBF rejected: Tx's current fee is 3000000000, expect it to >= 5000000363 to replace old txs")); // local submit tx RBF check failed, will be in conflicts pool - assert_eq!(get_tx_pool_conflicts(node0), vec![new_tx.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node0), vec![new_tx.hash().into()]); // let's try a new transaction with new higher fee let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(45).pack()) + .capacity(capacity_bytes!(45).into()) .build(); let new_tx_ok = clone_tx .as_advanced_builder() @@ -572,9 +572,9 @@ impl Spec for RbfChildPayForParent { // tx2 tx3 tx4 is replaced let mut expected: Vec = txs[2..=max_count - 1] .iter() - .map(|tx| tx.hash().unpack()) + .map(|tx| tx.hash().into()) .collect::>(); - expected.push(new_tx.hash().unpack()); + expected.push(new_tx.hash().into()); expected.sort_unstable(); let conflicts = get_tx_pool_conflicts(node0); assert_eq!(conflicts, expected); @@ -609,7 +609,7 @@ impl Spec for RbfContainInvalidCells { // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).pack()) + .capacity(capacity_bytes!(70).into()) .build(); let tx2 = clone_tx .as_advanced_builder() @@ -688,7 +688,7 @@ impl Spec for RbfRejectReplaceProposed { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).pack()) + .capacity(capacity_bytes!(70).into()) .build(); let tx1_hash = txs[2].hash(); @@ -798,7 +798,7 @@ impl Spec for RbfReplaceProposedSuccess { let clone_tx = txs[2].clone(); // Set tx2 fee to a higher value let output2 = CellOutputBuilder::default() - .capacity(capacity_bytes!(70).pack()) + .capacity(capacity_bytes!(70).into()) .build(); let tx1_hash = txs[2].hash(); @@ -843,9 +843,9 @@ impl Spec for RbfReplaceProposedSuccess { assert_eq!(tx1_status.status, Status::Rejected); let mut expected = [ - txs[2].hash().unpack(), - txs[3].hash().unpack(), - txs[4].hash().unpack(), + txs[2].hash().into(), + txs[3].hash().into(), + txs[4].hash().into(), ]; expected.sort_unstable(); assert_eq!(get_tx_pool_conflicts(node0), expected); @@ -893,7 +893,7 @@ impl Spec for RbfConcurrency { ]; for fee in fees.iter() { let tx2_temp = node0.new_transaction(tx_hash_0.clone()); - let output = CellOutputBuilder::default().capacity(fee.pack()).build(); + let output = CellOutputBuilder::default().capacity(fee.into()).build(); let tx2 = tx2_temp .as_advanced_builder() @@ -931,11 +931,8 @@ impl Spec for RbfConcurrency { assert_eq!(*s, Status::Rejected); } - let mut expected: Vec = conflicts - .iter() - .take(4) - .map(|x| x.hash().unpack()) - .collect(); + let mut expected: Vec = + conflicts.iter().take(4).map(|x| x.hash().into()).collect(); expected.sort_unstable(); assert_eq!(get_tx_pool_conflicts(node0), expected); } @@ -991,7 +988,7 @@ impl Spec for RbfCellDepsCheck { // Create a new transaction for cell dep with high fee let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(80).pack()) + .capacity(capacity_bytes!(80).into()) .build(); let new_tx = tx_a .as_advanced_builder() @@ -1005,7 +1002,7 @@ impl Spec for RbfCellDepsCheck { .unwrap() .to_string() .contains("new Tx contains cell deps from conflicts")); - assert_eq!(get_tx_pool_conflicts(node0), vec![new_tx.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node0), vec![new_tx.hash().into()]); } fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) { @@ -1027,7 +1024,7 @@ fn run_spec_send_conflict_relay(nodes: &mut [Node]) { let tx1 = node0.new_transaction(tx_hash_0.clone()); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(90).pack()) + .capacity(capacity_bytes!(90).into()) .build(); let tx1 = tx1.as_advanced_builder().set_outputs(vec![output]).build(); @@ -1053,7 +1050,7 @@ fn run_spec_send_conflict_relay(nodes: &mut [Node]) { // node0 will accept it and node1 will reject it and put it in conflicts pool let tx2_temp = node0.new_transaction(tx_hash_0); let output = CellOutputBuilder::default() - .capacity(capacity_bytes!(95).pack()) + .capacity(capacity_bytes!(95).into()) .build(); let tx2 = tx2_temp @@ -1075,7 +1072,7 @@ fn run_spec_send_conflict_relay(nodes: &mut [Node]) { assert_eq!(res.status, Status::Rejected); let res = node1.get_transaction(tx1.hash()); assert_eq!(res.status, Status::Pending); - assert_eq!(get_tx_pool_conflicts(node1), vec![tx2.hash().unpack()]); + assert_eq!(get_tx_pool_conflicts(node1), vec![tx2.hash().into()]); } pub struct SendConflictTxToRelay; diff --git a/test/src/specs/tx_pool/send_defected_binary.rs b/test/src/specs/tx_pool/send_defected_binary.rs index 76dab8dbe3..a28b8d8f26 100644 --- a/test/src/specs/tx_pool/send_defected_binary.rs +++ b/test/src/specs/tx_pool/send_defected_binary.rs @@ -58,7 +58,7 @@ impl Spec for SendDefectedBinary { .dep_type(DepType::DepGroup.into()) .build(); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(5000).pack()) + .capacity(capacity_bytes!(5000).into()) .lock(node.always_success_script()) .build(); let data = include_bytes!("../../../../script/testdata/defected_binary"); @@ -66,12 +66,12 @@ impl Spec for SendDefectedBinary { .cell_dep(cell_dep.clone()) .inputs(inputs.clone()) .output(output.clone()) - .output_data(data[..].pack()) + .output_data(data[..].into()) .build(); let tx_hash = tx.hash(); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).pack()) + .lock(Some(Bytes::from(vec![0u8; 65])).into()) .build(); let witness_len = witness.as_slice().len() as u64; let message = { @@ -86,14 +86,14 @@ impl Spec for SendDefectedBinary { let sig = self.privkey.sign_recoverable(&message).expect("sign"); let witness = witness .as_builder() - .lock(Some(Bytes::from(sig.serialize())).pack()) + .lock(Some(Bytes::from(sig.serialize())).into()) .build(); let tx = TransactionBuilder::default() .cell_dep(cell_dep) .inputs(inputs) .output(output) - .output_data(data[..].pack()) - .witness(witness.as_bytes().pack()) + .output_data(data[..].into()) + .witness(witness.as_bytes().into()) .build(); info!("Send 1 secp tx with defected binary"); diff --git a/test/src/specs/tx_pool/send_large_cycles_tx.rs b/test/src/specs/tx_pool/send_large_cycles_tx.rs index c8701fc99d..6df6a24c96 100644 --- a/test/src/specs/tx_pool/send_large_cycles_tx.rs +++ b/test/src/specs/tx_pool/send_large_cycles_tx.rs @@ -319,8 +319,8 @@ impl RandomKey { fn build_tx(node: &Node, privkey: &Privkey, lock_arg: Bytes) -> TransactionView { let secp_out_point = OutPoint::new(node.dep_group_tx_hash(), 0); let lock = Script::new_builder() - .args(lock_arg.pack()) - .code_hash(type_lock_script_code_hash().pack()) + .args(lock_arg.into()) + .code_hash(type_lock_script_code_hash().into()) .hash_type(ScriptHashType::Type.into()) .build(); let cell_dep = CellDep::new_builder() @@ -333,7 +333,7 @@ fn build_tx(node: &Node, privkey: &Privkey, lock_arg: Bytes) -> TransactionView CellInput::new(OutPoint::new(cellbase_hash, 0), 0) }; let output1 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(lock) .build(); let tx = TransactionBuilder::default() @@ -342,9 +342,9 @@ fn build_tx(node: &Node, privkey: &Privkey, lock_arg: Bytes) -> TransactionView .output(output1) .output_data(Default::default()) .build(); - let tx_hash: H256 = tx.hash().unpack(); + let tx_hash: H256 = tx.hash().into(); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).pack()) + .lock(Some(Bytes::from(vec![0u8; 65])).into()) .build(); let witness_len = witness.as_slice().len() as u64; let message = { @@ -359,9 +359,9 @@ fn build_tx(node: &Node, privkey: &Privkey, lock_arg: Bytes) -> TransactionView let sig = privkey.sign_recoverable(&message).expect("sign"); let witness = witness .as_builder() - .lock(Some(Bytes::from(sig.serialize())).pack()) + .lock(Some(Bytes::from(sig.serialize())).into()) .build(); tx.as_advanced_builder() - .witness(witness.as_bytes().pack()) + .witness(witness.as_bytes().into()) .build() } diff --git a/test/src/specs/tx_pool/send_low_fee_rate_tx.rs b/test/src/specs/tx_pool/send_low_fee_rate_tx.rs index befbf60722..03341cade9 100644 --- a/test/src/specs/tx_pool/send_low_fee_rate_tx.rs +++ b/test/src/specs/tx_pool/send_low_fee_rate_tx.rs @@ -44,7 +44,7 @@ impl Spec for SendLowFeeRateTx { .get(0) .unwrap() .as_builder() - .capacity(capacity.pack()) + .capacity(capacity.into()) .build(); let tx_low_fee = tx_low_fee .data() @@ -64,7 +64,7 @@ impl Spec for SendLowFeeRateTx { .get(0) .unwrap() .as_builder() - .capacity(capacity.safe_sub(1000u32).unwrap().pack()) + .capacity(capacity.safe_sub(1000u32).unwrap().into()) .build(); let tx_high_fee = tx_high_fee .data() diff --git a/test/src/specs/tx_pool/send_multisig_secp_tx.rs b/test/src/specs/tx_pool/send_multisig_secp_tx.rs index f0de38db6f..31c10a2e9f 100644 --- a/test/src/specs/tx_pool/send_multisig_secp_tx.rs +++ b/test/src/specs/tx_pool/send_multisig_secp_tx.rs @@ -53,7 +53,7 @@ impl Spec for SendMultiSigSecpTxUseDepGroup { .dep_type(DepType::DepGroup.into()) .build(); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(node.always_success_script()) .build(); let input = CellInput::new(OutPoint::new(cellbase_hash, 0), 0); @@ -69,7 +69,7 @@ impl Spec for SendMultiSigSecpTxUseDepGroup { let mut lock = multi_sign_script.to_vec(); lock.extend(vec![0u8; 65 * self.keys.len()]); WitnessArgs::new_builder() - .lock(Some(Bytes::from(lock)).pack()) + .lock(Some(Bytes::from(lock)).into()) .build() }; let witness_len = witness.as_slice().len() as u64; @@ -90,14 +90,14 @@ impl Spec for SendMultiSigSecpTxUseDepGroup { }); let witness = witness .as_builder() - .lock(Some(Bytes::from(lock)).pack()) + .lock(Some(Bytes::from(lock)).into()) .build(); let tx = TransactionBuilder::default() .cell_dep(cell_dep) .input(input) .output(output) .output_data(Default::default()) - .witness(witness.as_bytes().pack()) + .witness(witness.as_bytes().into()) .build(); info!("Send 1 multisig tx use dep group"); @@ -136,7 +136,7 @@ fn gen_multi_sign_script(keys: &[Privkey], threshold: u8, require_first_n: u8) - fn type_lock_script_code_hash() -> H256 { build_genesis_type_id_script(OUTPUT_INDEX_SECP256K1_BLAKE160_MULTISIG_ALL) .calc_script_hash() - .unpack() + .into() } fn new_block_assembler_config(lock_arg: Bytes, hash_type: ScriptHashType) -> BlockAssemblerConfig { diff --git a/test/src/specs/tx_pool/send_secp_tx.rs b/test/src/specs/tx_pool/send_secp_tx.rs index 7449c7454c..4e7c9b0c9e 100644 --- a/test/src/specs/tx_pool/send_secp_tx.rs +++ b/test/src/specs/tx_pool/send_secp_tx.rs @@ -50,7 +50,7 @@ impl Spec for SendSecpTxUseDepGroup { .dep_type(DepType::DepGroup.into()) .build(); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(node.always_success_script()) .build(); let input = CellInput::new(OutPoint::new(cellbase_hash, 0), 0); @@ -63,7 +63,7 @@ impl Spec for SendSecpTxUseDepGroup { let tx_hash = tx.hash(); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).pack()) + .lock(Some(Bytes::from(vec![0u8; 65])).into()) .build(); let witness_len = witness.as_slice().len() as u64; let message = { @@ -78,14 +78,14 @@ impl Spec for SendSecpTxUseDepGroup { let sig = self.privkey.sign_recoverable(&message).expect("sign"); let witness = witness .as_builder() - .lock(Some(Bytes::from(sig.serialize())).pack()) + .lock(Some(Bytes::from(sig.serialize())).into()) .build(); let tx = TransactionBuilder::default() .cell_dep(cell_dep) .input(input) .output(output) .output_data(Default::default()) - .witness(witness.as_bytes().pack()) + .witness(witness.as_bytes().into()) .build(); info!("Send 1 secp tx use dep group"); @@ -154,16 +154,16 @@ impl Spec for CheckTypical2In2OutTx { CellInput::new(OutPoint::new(cellbase_hash, 0), 0) }; let lock = Script::new_builder() - .args(self.lock_arg.pack()) - .code_hash(type_lock_script_code_hash().pack()) + .args((&self.lock_arg).into()) + .code_hash(type_lock_script_code_hash().into()) .hash_type(ScriptHashType::Type.into()) .build(); let output1 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(lock.clone()) .build(); let output2 = CellOutput::new_builder() - .capacity(capacity_bytes!(100).pack()) + .capacity(capacity_bytes!(100).into()) .lock(lock) .build(); let tx = TransactionBuilder::default() @@ -176,9 +176,9 @@ impl Spec for CheckTypical2In2OutTx { .output_data(Default::default()) .build(); - let tx_hash: H256 = tx.hash().unpack(); + let tx_hash: H256 = tx.hash().into(); let witness = WitnessArgs::new_builder() - .lock(Some(Bytes::from(vec![0u8; 65])).pack()) + .lock(Some(Bytes::from(vec![0u8; 65])).into()) .build(); let witness_len = witness.as_slice().len() as u64; let witness2 = Bytes::new(); @@ -197,20 +197,19 @@ impl Spec for CheckTypical2In2OutTx { let sig = self.privkey.sign_recoverable(&message).expect("sign"); let witness = witness .as_builder() - .lock(Some(Bytes::from(sig.serialize())).pack()) + .lock(Some(Bytes::from(sig.serialize())).into()) .build(); let tx = tx .as_advanced_builder() - .witness(witness.as_bytes().pack()) - .witness(witness2.pack()) + .witness(witness.as_bytes().into()) + .witness(witness2.into()) .build(); info!("Send 1 secp tx use dep group"); node.rpc_client() .inner() .send_transaction(tx.data().into(), None) - .expect("should pass default outputs validator") - .pack(); + .expect("should pass default outputs validator"); node.mine(20); assert!(is_transaction_committed(node, &tx)); diff --git a/test/src/txo.rs b/test/src/txo.rs index 7d9868b6f4..9d3697d98c 100644 --- a/test/src/txo.rs +++ b/test/src/txo.rs @@ -31,7 +31,7 @@ impl TXO { } pub fn capacity(&self) -> u64 { - self.output.capacity().unpack() + self.output.capacity().into() } pub fn lock(&self) -> Script { @@ -52,7 +52,7 @@ impl TXO { pub fn to_equivalent_output(&self) -> CellOutput { CellOutput::new_builder() .lock(self.lock()) - .capacity(self.capacity().pack()) + .capacity(self.capacity().into()) .build() } @@ -161,12 +161,12 @@ impl TXOSet { self.iter() .map(|txo| { let maximal_capacity = txo.capacity(); - let minimal_capacity: u64 = txo.to_minimal_output().capacity().unpack(); + let minimal_capacity: u64 = txo.to_minimal_output().capacity().into(); let actual_capacity = rng.gen_range(minimal_capacity..=maximal_capacity); let output = txo .to_equivalent_output() .as_builder() - .capacity(actual_capacity.pack()) + .capacity(actual_capacity.into()) .build(); TransactionBuilder::default() .cell_deps(cell_deps.clone()) @@ -181,11 +181,11 @@ impl TXOSet { fn boom_to_minimals(&self) -> Vec { let mut input_capacity = self.total_capacity(); let minimal = self.iter().next().unwrap().to_minimal_output(); - let minimal_capacity: u64 = minimal.capacity().unpack(); + let minimal_capacity: u64 = minimal.capacity().into(); let mut outputs = Vec::new(); while outputs.len() < EXPLODE_LIMIT { if input_capacity < 2 * minimal_capacity || outputs.len() == EXPLODE_LIMIT { - outputs.push(minimal.as_builder().capacity(input_capacity.pack()).build()); + outputs.push(minimal.as_builder().capacity(input_capacity.into()).build()); break; } else { input_capacity -= minimal_capacity; @@ -214,7 +214,7 @@ impl From<&TransactionView> for TXOSet { .map(move |(i, output)| { let out_point = OutPoint::new_builder() .tx_hash(tx_hash.clone()) - .index(i.pack()) + .index(i.into()) .build(); TXO::new(out_point, output) }); diff --git a/test/src/util/cell.rs b/test/src/util/cell.rs index 78a2303235..70608c1123 100644 --- a/test/src/util/cell.rs +++ b/test/src/util/cell.rs @@ -102,6 +102,6 @@ pub fn as_output(cell: &CellMeta) -> CellOutput { CellOutput::new_builder() .lock(cell.cell_output.lock()) .type_(cell.cell_output.type_()) - .capacity(cell.capacity().pack()) + .capacity(cell.capacity().into()) .build() } diff --git a/test/src/util/mining.rs b/test/src/util/mining.rs index ebbf686522..17bd1ff87c 100644 --- a/test/src/util/mining.rs +++ b/test/src/util/mining.rs @@ -147,7 +147,7 @@ impl Node { !template .transactions .iter() - .any(|tx| tx.hash == tx_hash.unpack()) + .any(|tx| tx.hash == tx_hash.into()) }); } diff --git a/test/src/util/transaction.rs b/test/src/util/transaction.rs index d699e61da0..568692f8b3 100644 --- a/test/src/util/transaction.rs +++ b/test/src/util/transaction.rs @@ -39,7 +39,7 @@ pub fn always_success_transactions_with_rand_data( (0..1600) .map(|_| rand::random::()) .collect::>() - .pack() + .into() }) .collect::>(), ) @@ -51,7 +51,7 @@ pub fn relay_tx(net: &Net, node: &Node, tx: TransactionView, cycles: u64) { let tx_hashes_msg = packed::RelayMessage::new_builder() .set( packed::RelayTransactionHashes::new_builder() - .tx_hashes(vec![tx.hash()].pack()) + .tx_hashes(vec![tx.hash()].into()) .build(), ) .build(); @@ -65,7 +65,7 @@ pub fn relay_tx(net: &Net, node: &Node, tx: TransactionView, cycles: u64) { assert!(ret, "node should ask for tx"); let relay_tx = packed::RelayTransaction::new_builder() - .cycles(cycles.pack()) + .cycles(cycles.into()) .transaction(tx.data()) .build(); diff --git a/test/src/utils.rs b/test/src/utils.rs index 57d9227ac9..263ca9291e 100644 --- a/test/src/utils.rs +++ b/test/src/utils.rs @@ -5,7 +5,7 @@ use ckb_network::bytes::Bytes; use ckb_types::{ core::{BlockNumber, BlockView, EpochNumberWithFraction, HeaderView, TransactionView}, packed::{ - BlockFilterMessage, BlockTransactions, Byte32, CompactBlock, GetBlocks, RelayMessage, + self, BlockFilterMessage, BlockTransactions, Byte32, CompactBlock, GetBlocks, RelayMessage, RelayTransaction, RelayTransactionHashes, RelayTransactions, SendBlock, SendHeaders, SyncMessage, }, @@ -55,7 +55,8 @@ pub fn build_block_transactions(block: &BlockView) -> Bytes { .into_iter() .map(|view| view.data()) .skip(1) - .pack(), + .collect::>() + .into(), ) .build(); @@ -76,7 +77,7 @@ pub fn build_headers(headers: &[HeaderView]) -> Bytes { .iter() .map(|view| view.data()) .collect::>() - .pack(), + .into(), ) .build(); @@ -95,7 +96,13 @@ pub fn build_block(block: &BlockView) -> Bytes { pub fn build_get_blocks(hashes: &[Byte32]) -> Bytes { let get_blocks = GetBlocks::new_builder() - .block_hashes(hashes.iter().map(ToOwned::to_owned).pack()) + .block_hashes( + hashes + .iter() + .map(ToOwned::to_owned) + .collect::>() + .into(), + ) .build(); SyncMessage::new_builder() @@ -105,14 +112,17 @@ pub fn build_get_blocks(hashes: &[Byte32]) -> Bytes { } pub fn build_relay_txs(transactions: &[(TransactionView, u64)]) -> Bytes { - let transactions = transactions.iter().map(|(tx, cycles)| { - RelayTransaction::new_builder() - .cycles(cycles.pack()) - .transaction(tx.data()) - .build() - }); + let transactions = transactions + .iter() + .map(|(tx, cycles)| { + RelayTransaction::new_builder() + .cycles(cycles.into()) + .transaction(tx.data()) + .build() + }) + .collect::>(); let txs = RelayTransactions::new_builder() - .transactions(transactions.pack()) + .transactions(transactions.into()) .build(); RelayMessage::new_builder().set(txs).build().as_bytes() @@ -120,7 +130,13 @@ pub fn build_relay_txs(transactions: &[(TransactionView, u64)]) -> Bytes { pub fn build_relay_tx_hashes(hashes: &[Byte32]) -> Bytes { let content = RelayTransactionHashes::new_builder() - .tx_hashes(hashes.iter().map(ToOwned::to_owned).pack()) + .tx_hashes( + hashes + .iter() + .map(ToOwned::to_owned) + .collect::>() + .into(), + ) .build(); RelayMessage::new_builder().set(content).build().as_bytes() diff --git a/tx-pool/src/block_assembler/mod.rs b/tx-pool/src/block_assembler/mod.rs index 81acca0951..661f084b75 100644 --- a/tx-pool/src/block_assembler/mod.rs +++ b/tx-pool/src/block_assembler/mod.rs @@ -459,8 +459,8 @@ impl BlockAssembler { ) -> CellbaseWitness { let hash_type: ScriptHashType = config.hash_type.clone().into(); let cellbase_lock = Script::new_builder() - .args(config.args.as_bytes().pack()) - .code_hash(config.code_hash.pack()) + .args(config.args.as_bytes().into()) + .code_hash((&config.code_hash).into()) .hash_type(hash_type.into()) .build(); let tip = snapshot.tip_header(); @@ -480,7 +480,7 @@ impl BlockAssembler { CellbaseWitness::new_builder() .lock(cellbase_lock) - .message(message.pack()) + .message(message.into()) .build() } @@ -502,11 +502,11 @@ impl BlockAssembler { })?; let input = CellInput::new_cellbase_input(candidate_number); let output = CellOutput::new_builder() - .capacity(block_reward.total.pack()) + .capacity(block_reward.total.into()) .lock(target_lock) .build(); - let witness = cellbase_witness.as_bytes().pack(); + let witness = cellbase_witness.as_bytes().into(); let no_finalization_target = candidate_number <= snapshot.consensus().finalization_delay_length(); let tx_builder = TransactionBuilder::default().input(input).witness(witness); @@ -536,7 +536,7 @@ impl BlockAssembler { .chain_root_mmr(tip_header.number()) .get_root() .map_err(|e| InternalErrorKind::MMR.other(e))?; - let bytes = chain_root.calc_mmr_hash().as_bytes().pack(); + let bytes = chain_root.calc_mmr_hash().as_bytes().into(); Ok(Some(bytes)) } else { Ok(None) @@ -564,18 +564,30 @@ impl BlockAssembler { let block = if let Some(extension) = extension_opt { packed::BlockV1::new_builder() .header(header) - .transactions(vec![cellbase].pack()) - .uncles(uncles.iter().map(|u| u.data()).pack()) - .proposals(proposals.cloned().collect::>().pack()) + .transactions(vec![cellbase].into()) + .uncles( + uncles + .iter() + .map(|u| u.data()) + .collect::>() + .into(), + ) + .proposals(proposals.cloned().collect::>().into()) .extension(extension) .build() .as_v0() } else { packed::Block::new_builder() .header(header) - .transactions(vec![cellbase].pack()) - .uncles(uncles.iter().map(|u| u.data()).pack()) - .proposals(proposals.cloned().collect::>().pack()) + .transactions(vec![cellbase].into()) + .uncles( + uncles + .iter() + .map(|u| u.data()) + .collect::>() + .into(), + ) + .proposals(proposals.cloned().collect::>().into()) .build() }; block.serialized_size_without_uncle_proposals() @@ -728,7 +740,7 @@ impl<'a> From<&'a BlockTemplate> for JsonBlockTemplate { compact_target: template.compact_target.into(), number: template.number.into(), epoch: template.epoch.into(), - parent_hash: template.parent_hash.unpack(), + parent_hash: (&template.parent_hash).into(), cycles_limit: template.cycles_limit.into(), bytes_limit: template.bytes_limit.into(), uncles_count_limit: u64::from(template.uncles_count_limit).into(), @@ -918,7 +930,7 @@ impl BlockTemplateBuilder { pub(crate) fn uncle_to_template(uncle: &UncleBlockView) -> UncleTemplate { UncleTemplate { - hash: uncle.hash().unpack(), + hash: uncle.hash().into(), required: false, proposals: uncle .data() @@ -932,7 +944,7 @@ pub(crate) fn uncle_to_template(uncle: &UncleBlockView) -> UncleTemplate { pub(crate) fn tx_entry_to_template(entry: &TxEntry) -> TransactionTemplate { TransactionTemplate { - hash: entry.transaction().hash().unpack(), + hash: entry.transaction().hash().into(), required: false, // unimplemented cycles: Some(entry.cycles.into()), depends: None, // unimplemented @@ -942,7 +954,7 @@ pub(crate) fn tx_entry_to_template(entry: &TxEntry) -> TransactionTemplate { pub(crate) fn cellbase_to_template(tx: &TransactionView) -> CellbaseTemplate { CellbaseTemplate { - hash: tx.hash().unpack(), + hash: tx.hash().into(), cycles: None, data: tx.data().into(), } diff --git a/tx-pool/src/block_assembler/tests.rs b/tx-pool/src/block_assembler/tests.rs index 6d39933ecb..8c66d154ca 100644 --- a/tx-pool/src/block_assembler/tests.rs +++ b/tx-pool/src/block_assembler/tests.rs @@ -1,7 +1,4 @@ -use ckb_types::{ - core::{BlockBuilder, BlockNumber, EpochNumberWithFraction}, - prelude::*, -}; +use ckb_types::core::{BlockBuilder, BlockNumber, EpochNumberWithFraction}; use crate::block_assembler::candidate_uncles::{ CandidateUncles, MAX_CANDIDATE_UNCLES, MAX_PER_HEIGHT, @@ -30,8 +27,8 @@ fn test_candidate_uncles_max_size() { for i in 0..(MAX_CANDIDATE_UNCLES + 3) { let number = i as BlockNumber; let block = BlockBuilder::default() - .number(number.pack()) - .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 10000).pack()) + .number(number.into()) + .epoch(EpochNumberWithFraction::new(number / 1000, number % 1000, 10000).into()) .build() .as_uncle(); blocks.push(block); @@ -60,7 +57,7 @@ fn test_candidate_uncles_max_per_height() { let mut blocks = Vec::new(); for i in 0..(MAX_PER_HEIGHT + 3) { let block = BlockBuilder::default() - .timestamp((i as u64).pack()) + .timestamp((i as u64).into()) .build() .as_uncle(); blocks.push(block); diff --git a/tx-pool/src/component/pool_map.rs b/tx-pool/src/component/pool_map.rs index 575452785c..b62f55d4c6 100644 --- a/tx-pool/src/component/pool_map.rs +++ b/tx-pool/src/component/pool_map.rs @@ -11,7 +11,6 @@ use ckb_logger::{debug, error, trace}; use ckb_types::core::error::OutPointError; use ckb_types::core::Cycle; use ckb_types::packed::OutPoint; -use ckb_types::prelude::*; use ckb_types::{ bytes::Bytes, core::TransactionView, @@ -186,7 +185,7 @@ impl PoolMap { .and_then(|entry| { entry .transaction() - .output_with_data(out_point.index().unpack()) + .output_with_data(out_point.index().into()) }) } diff --git a/tx-pool/src/component/tests/pending.rs b/tx-pool/src/component/tests/pending.rs index e262248354..bcef42ef01 100644 --- a/tx-pool/src/component/tests/pending.rs +++ b/tx-pool/src/component/tests/pending.rs @@ -8,7 +8,7 @@ use crate::component::{ }; use ckb_types::core::Capacity; use ckb_types::packed::OutPoint; -use ckb_types::{h256, packed::Byte32, prelude::*}; +use ckb_types::{h256, packed::Byte32}; use std::collections::HashSet; use std::time::Duration; @@ -18,7 +18,7 @@ fn test_basic() { assert_eq!(pool.size(), 0); let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&Byte32::zero(), 2)], 1); let tx2 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x3").pack(), 2)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x3").into(), 2)], 3, ); let entry1 = TxEntry::dummy_resolve(tx1.clone(), MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); @@ -51,21 +51,21 @@ fn test_basic() { #[test] fn test_resolve_conflict() { let mut pool = PoolMap::new(100); - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); let tx2 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x3").pack(), 1)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x3").into(), 1)], 3, ); let tx3 = build_tx_with_dep( - vec![(&h256!("0x4").pack(), 1)], - vec![(&h256!("0x5").pack(), 1)], + vec![(&h256!("0x4").into(), 1)], + vec![(&h256!("0x5").into(), 1)], 3, ); let tx4 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x1").pack(), 1)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x1").into(), 1)], 3, ); - let tx5 = build_tx(vec![(&h256!("0x5").pack(), 1)], 3); + let tx5 = build_tx(vec![(&h256!("0x5").into(), 1)], 3); let entry1 = TxEntry::dummy_resolve(tx1, MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); let entry2 = TxEntry::dummy_resolve(tx2, MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); @@ -114,9 +114,9 @@ fn test_resolve_conflict_descendants() { fn test_resolve_conflict_header_dep() { let mut pool = PoolMap::new(1000); - let header: Byte32 = h256!("0x1").pack(); + let header: Byte32 = h256!("0x1").into(); let tx = build_tx_with_header_dep( - vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], + vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], vec![header.clone()], 1, ); @@ -143,9 +143,9 @@ fn test_resolve_conflict_header_dep() { #[test] fn test_remove_entry() { let mut pool = PoolMap::new(1000); - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); - let header: Byte32 = h256!("0x1").pack(); - let tx2 = build_tx_with_header_dep(vec![(&h256!("0x2").pack(), 1)], vec![header], 1); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); + let header: Byte32 = h256!("0x1").into(); + let tx2 = build_tx_with_header_dep(vec![(&h256!("0x2").into(), 1)], vec![header], 1); let entry1 = TxEntry::dummy_resolve(tx1.clone(), MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); let entry2 = TxEntry::dummy_resolve(tx2.clone(), MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); @@ -165,14 +165,14 @@ fn test_remove_entry() { #[test] fn test_get_proposals() { let mut pool = PoolMap::new(1000); - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); let tx2 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x3").pack(), 1)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x3").into(), 1)], 3, ); let tx3 = build_tx_with_dep( - vec![(&h256!("0x4").pack(), 1)], - vec![(&h256!("0x5").pack(), 1)], + vec![(&h256!("0x4").into(), 1)], + vec![(&h256!("0x5").into(), 1)], 3, ); let entry1 = TxEntry::dummy_resolve(tx1.clone(), MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); @@ -214,14 +214,14 @@ fn test_get_proposals() { #[test] fn test_get_proposals_with_high_score() { let mut pool = PoolMap::new(1000); - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); let tx2 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x3").pack(), 1)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x3").into(), 1)], 3, ); let tx3 = build_tx_with_dep( - vec![(&h256!("0x4").pack(), 1)], - vec![(&h256!("0x5").pack(), 1)], + vec![(&h256!("0x4").into(), 1)], + vec![(&h256!("0x5").into(), 1)], 3, ); let entry1 = TxEntry::dummy_resolve(tx1.clone(), MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); @@ -258,8 +258,8 @@ fn test_get_proposals_with_high_score() { #[test] fn test_edges() { - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); - let tx2 = build_tx(vec![(&h256!("0x1").pack(), 1)], 1); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); + let tx2 = build_tx(vec![(&h256!("0x1").into(), 1)], 1); let short_id1 = tx1.proposal_short_id(); let short_id2 = tx2.proposal_short_id(); @@ -277,14 +277,14 @@ fn test_edges() { #[test] fn test_pool_evict() { let mut pool = PoolMap::new(1000); - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); let tx2 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x3").pack(), 1)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x3").into(), 1)], 3, ); let tx3 = build_tx_with_dep( - vec![(&h256!("0x4").pack(), 1)], - vec![(&h256!("0x5").pack(), 1)], + vec![(&h256!("0x4").into(), 1)], + vec![(&h256!("0x5").into(), 1)], 3, ); let entry1 = TxEntry::dummy_resolve(tx1.clone(), MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); @@ -315,14 +315,14 @@ fn test_pool_evict() { #[test] fn test_pool_min_weight_evict() { let mut pool = PoolMap::new(1000); - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); let tx2 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x3").pack(), 1)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x3").into(), 1)], 3, ); let tx3 = build_tx_with_dep( - vec![(&h256!("0x4").pack(), 1)], - vec![(&h256!("0x5").pack(), 1)], + vec![(&h256!("0x4").into(), 1)], + vec![(&h256!("0x5").into(), 1)], 3, ); let entry1 = TxEntry::dummy_resolve(tx1.clone(), 2, Capacity::shannons(100), 2); @@ -353,14 +353,14 @@ fn test_pool_min_weight_evict() { #[test] fn test_pool_max_size_evict() { let mut pool = PoolMap::new(1000); - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); let tx2 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x3").pack(), 1)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x3").into(), 1)], 3, ); let tx3 = build_tx_with_dep( - vec![(&h256!("0x4").pack(), 1)], - vec![(&h256!("0x5").pack(), 1)], + vec![(&h256!("0x4").into(), 1)], + vec![(&h256!("0x5").into(), 1)], 3, ); let entry1 = TxEntry::dummy_resolve(tx1.clone(), 2, Capacity::shannons(100), 3); @@ -391,9 +391,9 @@ fn test_pool_max_size_evict() { #[test] fn test_pool_min_descendants_evict() { let mut pool = PoolMap::new(1000); - let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], 1); - let tx2 = build_tx(vec![(&tx1.hash(), 1), (&h256!("0x3").pack(), 1)], 3); - let tx3 = build_tx_with_dep(vec![(&tx2.hash(), 1)], vec![(&h256!("0x5").pack(), 1)], 3); + let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], 1); + let tx2 = build_tx(vec![(&tx1.hash(), 1), (&h256!("0x3").into(), 1)], 3); + let tx3 = build_tx_with_dep(vec![(&tx2.hash(), 1)], vec![(&h256!("0x5").into(), 1)], 3); let entry1 = TxEntry::dummy_resolve(tx1.clone(), 2, Capacity::shannons(100), 1); std::thread::sleep(Duration::from_millis(1)); let entry2 = TxEntry::dummy_resolve(tx2.clone(), 2, Capacity::shannons(100), 1); diff --git a/tx-pool/src/component/tests/proposed.rs b/tx-pool/src/component/tests/proposed.rs index 236d4b10a9..86f24b9704 100644 --- a/tx-pool/src/component/tests/proposed.rs +++ b/tx-pool/src/component/tests/proposed.rs @@ -4,7 +4,7 @@ use crate::component::tests::util::{ MOCK_CYCLES, MOCK_FEE, MOCK_SIZE, }; use ckb_types::core::{capacity_bytes, ScriptHashType}; -use ckb_types::packed::{CellOutputBuilder, ScriptBuilder}; +use ckb_types::packed::{self, CellOutputBuilder, ScriptBuilder}; use ckb_types::H256; use std::time::Instant; @@ -197,7 +197,7 @@ fn test_add_entry_from_detached() { fn test_add_roots() { let tx1 = build_tx(vec![(&Byte32::zero(), 1), (&Byte32::zero(), 2)], 1); let tx2 = build_tx( - vec![(&h256!("0x2").pack(), 1), (&h256!("0x3").pack(), 2)], + vec![(&h256!("0x2").into(), 1), (&h256!("0x3").into(), 2)], 3, ); @@ -517,19 +517,19 @@ fn test_get_ancestors() { #[test] fn test_dep_group() { - let tx1 = build_tx(vec![(&h256!("0x1").pack(), 0)], 1); + let tx1 = build_tx(vec![(&h256!("0x1").into(), 0)], 1); let tx1_out_point = OutPoint::new(tx1.hash(), 0); // Dep group cell - let tx2_data = vec![tx1_out_point.clone()].pack().as_bytes(); + let tx2_data = Into::::into(vec![tx1_out_point.clone()]).as_bytes(); let tx2 = TransactionBuilder::default() - .input(CellInput::new(OutPoint::new(h256!("0x2").pack(), 0), 0)) + .input(CellInput::new(OutPoint::new(h256!("0x2").into(), 0), 0)) .output( CellOutput::new_builder() - .capacity(Capacity::bytes(1000).unwrap().pack()) + .capacity(Capacity::bytes(1000).unwrap().into()) .build(), ) - .output_data(tx2_data.pack()) + .output_data((&tx2_data).into()) .build(); let tx2_out_point = OutPoint::new(tx2.hash(), 0); @@ -540,13 +540,13 @@ fn test_dep_group() { .build(); let tx3 = TransactionBuilder::default() .cell_dep(dep) - .input(CellInput::new(OutPoint::new(h256!("0x3").pack(), 0), 0)) + .input(CellInput::new(OutPoint::new(h256!("0x3").into(), 0), 0)) .output( CellOutput::new_builder() - .capacity(Capacity::bytes(3).unwrap().pack()) + .capacity(Capacity::bytes(3).unwrap().into()) .build(), ) - .output_data(Bytes::new().pack()) + .output_data(Bytes::new().into()) .build(); let tx3_out_point = OutPoint::new(tx3.hash(), 0); @@ -590,9 +590,9 @@ fn test_dep_group() { fn test_resolve_conflict_header_dep() { let mut pool = PoolMap::new(DEFAULT_MAX_ANCESTORS_COUNT); - let header: Byte32 = h256!("0x1").pack(); + let header: Byte32 = h256!("0x1").into(); let tx = build_tx_with_header_dep( - vec![(&Byte32::zero(), 1), (&h256!("0x1").pack(), 1)], + vec![(&Byte32::zero(), 1), (&h256!("0x1").into(), 1)], vec![header.clone()], 1, ); @@ -672,12 +672,12 @@ fn test_max_ancestors_with_dep() { let mut pool = PoolMap::new(1); let tx1 = build_tx_with_dep( vec![(&Byte32::zero(), 0)], - vec![(&h256!("0x1").pack(), 0)], + vec![(&h256!("0x1").into(), 0)], 1, ); let tx1_id = tx1.proposal_short_id(); let tx1_hash = tx1.hash(); - let tx2 = build_tx_with_dep(vec![(&tx1_hash, 0)], vec![(&h256!("0x2").pack(), 0)], 1); + let tx2 = build_tx_with_dep(vec![(&tx1_hash, 0)], vec![(&h256!("0x2").into(), 0)], 1); let entry1 = TxEntry::dummy_resolve(tx1, MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); let entry2 = TxEntry::dummy_resolve(tx2, MOCK_CYCLES, MOCK_FEE, MOCK_SIZE); @@ -687,7 +687,7 @@ fn test_max_ancestors_with_dep() { assert!(pool .edges .deps - .contains_key(&OutPoint::new(h256!("0x1").pack(), 0))); + .contains_key(&OutPoint::new(h256!("0x1").into(), 0))); assert!(pool.calc_descendants(&tx1_id).is_empty()); assert_eq!(pool.edges.inputs_len(), 1); @@ -716,12 +716,12 @@ fn test_container_bench_add_limits() { .previous_output( OutPoint::new_builder() .tx_hash(prev_tx.transaction().hash()) - .index(0u32.pack()) + .index(0u32.into()) .build(), ) .build(), ) - .witness(Bytes::new().pack()) + .witness(Bytes::new().into()) .build(), rng.gen_range(0..1000), Capacity::shannons(200), @@ -748,23 +748,23 @@ fn test_pool_map_bench() { let mut time_spend = vec![]; for i in 0..20000 { let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let tx = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) diff --git a/tx-pool/src/component/tests/score_key.rs b/tx-pool/src/component/tests/score_key.rs index c12cc7426c..2a3660be7b 100644 --- a/tx-pool/src/component/tests/score_key.rs +++ b/tx-pool/src/component/tests/score_key.rs @@ -111,12 +111,12 @@ fn test_remove_entry() { .previous_output( OutPoint::new_builder() .tx_hash(tx1.transaction().hash()) - .index(0u32.pack()) + .index(0u32.into()) .build(), ) .build(), ) - .witness(Bytes::new().pack()) + .witness(Bytes::new().into()) .build(), 200, Capacity::shannons(200), @@ -129,12 +129,12 @@ fn test_remove_entry() { .previous_output( OutPoint::new_builder() .tx_hash(tx2.transaction().hash()) - .index(0u32.pack()) + .index(0u32.into()) .build(), ) .build(), ) - .witness(Bytes::new().pack()) + .witness(Bytes::new().into()) .build(), 200, Capacity::shannons(200), @@ -184,12 +184,12 @@ fn test_remove_entry_and_descendants() { .previous_output( OutPoint::new_builder() .tx_hash(tx1.transaction().hash()) - .index(0u32.pack()) + .index(0u32.into()) .build(), ) .build(), ) - .witness(Bytes::new().pack()) + .witness(Bytes::new().into()) .build(), 200, Capacity::shannons(200), @@ -202,12 +202,12 @@ fn test_remove_entry_and_descendants() { .previous_output( OutPoint::new_builder() .tx_hash(tx2.transaction().hash()) - .index(0u32.pack()) + .index(0u32.into()) .build(), ) .build(), ) - .witness(Bytes::new().pack()) + .witness(Bytes::new().into()) .build(), 200, Capacity::shannons(200), diff --git a/tx-pool/src/component/tests/util.rs b/tx-pool/src/component/tests/util.rs index 32d4563d61..aa04530696 100644 --- a/tx-pool/src/component/tests/util.rs +++ b/tx-pool/src/component/tests/util.rs @@ -19,10 +19,10 @@ pub(crate) fn build_tx(inputs: Vec<(&Byte32, u32)>, outputs_len: usize) -> Trans ) .outputs((0..outputs_len).map(|i| { CellOutput::new_builder() - .capacity(Capacity::bytes(i + 1).unwrap().pack()) + .capacity(Capacity::bytes(i + 1).unwrap().into()) .build() })) - .outputs_data((0..outputs_len).map(|_| Bytes::new().pack())) + .outputs_data((0..outputs_len).map(|_| Bytes::new().into())) .build() } @@ -44,10 +44,10 @@ pub(crate) fn build_tx_with_dep( })) .outputs((0..outputs_len).map(|i| { CellOutput::new_builder() - .capacity(Capacity::bytes(i + 1).unwrap().pack()) + .capacity(Capacity::bytes(i + 1).unwrap().into()) .build() })) - .outputs_data((0..outputs_len).map(|_| Bytes::new().pack())) + .outputs_data((0..outputs_len).map(|_| Bytes::new().into())) .build() } @@ -65,9 +65,9 @@ pub(crate) fn build_tx_with_header_dep( .set_header_deps(header_deps) .outputs((0..outputs_len).map(|i| { CellOutput::new_builder() - .capacity(Capacity::bytes(i + 1).unwrap().pack()) + .capacity(Capacity::bytes(i + 1).unwrap().into()) .build() })) - .outputs_data((0..outputs_len).map(|_| Bytes::new().pack())) + .outputs_data((0..outputs_len).map(|_| Bytes::new().into())) .build() } diff --git a/util/dao/src/lib.rs b/util/dao/src/lib.rs index ebb550871c..eb56e7df3e 100644 --- a/util/dao/src/lib.rs +++ b/util/dao/src/lib.rs @@ -197,7 +197,7 @@ impl<'a, DL: CellDataProvider + EpochProvider + HeaderProvider> DaoCalculator<'a let tx_input_capacities = rtx.resolved_inputs.iter().try_fold( Capacity::zero(), |tx_capacities, cell_meta| { - let output_capacity: Capacity = cell_meta.cell_output.capacity().unpack(); + let output_capacity: Capacity = cell_meta.cell_output.capacity().into(); tx_capacities.safe_add(output_capacity) }, )?; @@ -248,14 +248,11 @@ impl<'a, DL: CellDataProvider + EpochProvider + HeaderProvider> DaoCalculator<'a .ok_or(DaoError::InvalidOutPoint) .and_then(|witness_data| { // dao contract stores header deps index as u64 in the input_type field of WitnessArgs - let witness = WitnessArgs::from_slice(&Unpack::::unpack( - &witness_data, - )) - .map_err(|_| DaoError::InvalidDaoFormat)?; - let header_deps_index_data: Option = witness - .input_type() - .to_opt() - .map(|witness| witness.unpack()); + let witness = + WitnessArgs::from_slice(&Into::::into(witness_data)) + .map_err(|_| DaoError::InvalidDaoFormat)?; + let header_deps_index_data: Option = + witness.input_type().to_opt().map(|witness| witness.into()); if header_deps_index_data.is_none() || header_deps_index_data.clone().map(|data| data.len()) != Some(8) @@ -278,7 +275,7 @@ impl<'a, DL: CellDataProvider + EpochProvider + HeaderProvider> DaoCalculator<'a withdrawing_header_hash, ) } else { - Ok(output.capacity().unpack()) + Ok(output.capacity().into()) } }; capacity.and_then(|c| c.safe_add(capacities).map_err(Into::into)) @@ -310,7 +307,7 @@ impl<'a, DL: CellDataProvider + EpochProvider + HeaderProvider> DaoCalculator<'a let (withdrawing_ar, _, _, _) = extract_dao_data(withdrawing_header.dao()); let occupied_capacity = output.occupied_capacity(output_data_capacity)?; - let output_capacity: Capacity = output.capacity().unpack(); + let output_capacity: Capacity = output.capacity().into(); let counted_capacity = output_capacity.safe_sub(occupied_capacity)?; let withdraw_counted_capacity = u128::from(counted_capacity.as_u64()) * u128::from(withdrawing_ar) @@ -333,7 +330,7 @@ pub fn modified_occupied_capacity( && tx_info.is_cellbase() && cell_meta.cell_output.lock().args().raw_data() == consensus.satoshi_pubkey_hash.0[..] { - return Unpack::::unpack(&cell_meta.cell_output.capacity()) + return Into::::into(&cell_meta.cell_output.capacity()) .safe_mul_ratio(consensus.satoshi_cell_occupied_ratio); } } diff --git a/util/dao/src/tests.rs b/util/dao/src/tests.rs index bbb4c2cf36..586d8b50ba 100644 --- a/util/dao/src/tests.rs +++ b/util/dao/src/tests.rs @@ -40,12 +40,12 @@ fn prepare_store( .base_block_reward(Capacity::shannons(50_000_000_000)) .remainder_reward(Capacity::shannons(1_000_128)) .previous_epoch_hash_rate(U256::one()) - .last_block_hash_in_previous_epoch(h256!("0x1").pack()) + .last_block_hash_in_previous_epoch(h256!("0x1").into()) .start_number(epoch_start.unwrap_or_else(|| parent.number() - 1000)) .length(2091) .compact_target(DIFF_TWO) .build(); - let epoch_hash = h256!("0x123455").pack(); + let epoch_hash = h256!("0x123455").into(); txn.insert_block_epoch_index(&parent.hash(), &epoch_hash) .unwrap(); @@ -63,8 +63,8 @@ fn check_dao_data_calculation() { let parent_number = 12345; let epoch = EpochNumberWithFraction::new(12, 345, 1000); let parent_header = HeaderBuilder::default() - .number(parent_number.pack()) - .epoch(epoch.pack()) + .number(parent_number.into()) + .epoch(epoch.into()) .dao(pack_dao_data( 10_000_000_000_123_456, Capacity::shannons(500_000_000_123_000), @@ -95,7 +95,7 @@ fn check_initial_dao_data_calculation() { let parent_number = 0; let parent_header = HeaderBuilder::default() - .number(parent_number.pack()) + .number(parent_number.into()) .dao(pack_dao_data( 10_000_000_000_000_000, Capacity::shannons(500_000_000_000_000), @@ -127,8 +127,8 @@ fn check_first_epoch_block_dao_data_calculation() { let parent_number = 12340; let epoch = EpochNumberWithFraction::new(12, 340, 1000); let parent_header = HeaderBuilder::default() - .number(parent_number.pack()) - .epoch(epoch.pack()) + .number(parent_number.into()) + .epoch(epoch.into()) .dao(pack_dao_data( 10_000_000_000_123_456, Capacity::shannons(500_000_000_123_000), @@ -160,8 +160,8 @@ fn check_dao_data_calculation_overflows() { let parent_number = 12345; let epoch = EpochNumberWithFraction::new(12, 345, 1000); let parent_header = HeaderBuilder::default() - .number(parent_number.pack()) - .epoch(epoch.pack()) + .number(parent_number.into()) + .epoch(epoch.into()) .dao(pack_dao_data( 10_000_000_000_123_456, Capacity::shannons(18_446_744_073_709_000_000), @@ -183,8 +183,8 @@ fn check_dao_data_calculation_with_transactions() { let parent_number = 12345; let epoch = EpochNumberWithFraction::new(12, 345, 1000); let parent_header = HeaderBuilder::default() - .number(parent_number.pack()) - .epoch(epoch.pack()) + .number(parent_number.into()) + .epoch(epoch.into()) .dao(pack_dao_data( 10_000_000_000_123_456, Capacity::shannons(500_000_000_123_000), @@ -196,16 +196,16 @@ fn check_dao_data_calculation_with_transactions() { let (_tmp_dir, store, parent_header) = prepare_store(&parent_header, None); let input_cell_data = Bytes::from("abcde"); let input_cell = CellOutput::new_builder() - .capacity(capacity_bytes!(10000).pack()) + .capacity(capacity_bytes!(10000).into()) .build(); let output_cell_data = Bytes::from("abcde12345"); let output_cell = CellOutput::new_builder() - .capacity(capacity_bytes!(20000).pack()) + .capacity(capacity_bytes!(20000).into()) .build(); let tx = TransactionBuilder::default() .output(output_cell) - .output_data(output_cell_data.pack()) + .output_data(output_cell_data.into()) .build(); let rtx = ResolvedTransaction { transaction: tx, @@ -235,16 +235,16 @@ fn check_dao_data_calculation_with_transactions() { fn check_withdraw_calculation() { let data = Bytes::from(vec![1; 10]); let output = CellOutput::new_builder() - .capacity(capacity_bytes!(1000000).pack()) + .capacity(capacity_bytes!(1000000).into()) .build(); let tx = TransactionBuilder::default() .output(output.clone()) - .output_data(data.pack()) + .output_data((&data).into()) .build(); let epoch = EpochNumberWithFraction::new(1, 100, 1000); let deposit_header = HeaderBuilder::default() - .number(100.pack()) - .epoch(epoch.pack()) + .number(100.into()) + .epoch(epoch.into()) .dao(pack_dao_data( 10_000_000_000_123_456, Default::default(), @@ -259,8 +259,8 @@ fn check_withdraw_calculation() { let epoch = EpochNumberWithFraction::new(1, 200, 1000); let withdrawing_header = HeaderBuilder::default() - .number(200.pack()) - .epoch(epoch.pack()) + .number(200.into()) + .epoch(epoch.into()) .dao(pack_dao_data( 10_000_000_001_123_456, Default::default(), @@ -295,13 +295,13 @@ fn check_withdraw_calculation() { #[test] fn check_withdraw_calculation_overflows() { let output = CellOutput::new_builder() - .capacity(Capacity::shannons(18_446_744_073_709_550_000).pack()) + .capacity(Capacity::shannons(18_446_744_073_709_550_000).into()) .build(); let tx = TransactionBuilder::default().output(output.clone()).build(); let epoch = EpochNumberWithFraction::new(1, 100, 1000); let deposit_header = HeaderBuilder::default() - .number(100.pack()) - .epoch(epoch.pack()) + .number(100.into()) + .epoch(epoch.into()) .dao(pack_dao_data( 10_000_000_000_123_456, Default::default(), @@ -316,8 +316,8 @@ fn check_withdraw_calculation_overflows() { let epoch = EpochNumberWithFraction::new(1, 200, 1000); let withdrawing_header = HeaderBuilder::default() - .number(200.pack()) - .epoch(epoch.pack()) + .number(200.into()) + .epoch(epoch.into()) .dao(pack_dao_data( 10_000_000_001_123_456, Default::default(), diff --git a/util/dao/utils/src/lib.rs b/util/dao/utils/src/lib.rs index 3e67098a43..ef2da02c14 100644 --- a/util/dao/utils/src/lib.rs +++ b/util/dao/utils/src/lib.rs @@ -52,7 +52,7 @@ pub fn genesis_dao_data_with_satoshi_gift( .enumerate() .filter(|(index, _)| !dead_cells.contains(&OutPoint::new(tx.hash(), *index as u32))) .try_fold(Capacity::zero(), |capacity, (_, output)| { - let cap: Capacity = output.capacity().unpack(); + let cap: Capacity = output.capacity().into(); capacity.safe_add(cap) })?; let u = tx @@ -64,7 +64,7 @@ pub fn genesis_dao_data_with_satoshi_gift( let occupied_capacity = if tx_index == 0 && output.lock().args().raw_data() == satoshi_pubkey_hash.0[..] { - Unpack::::unpack(&output.capacity()) + Into::::into(&output.capacity()) .safe_mul_ratio(satoshi_cell_occupied_ratio) } else { Capacity::bytes(data.len()).and_then(|c| output.occupied_capacity(c)) @@ -128,7 +128,6 @@ mod tests { pub use ckb_types::core::Capacity; pub use ckb_types::h256; pub use ckb_types::packed::Byte32; - pub use ckb_types::prelude::Pack; #[test] #[allow(clippy::unreadable_literal)] @@ -160,7 +159,7 @@ mod tests { ), ]; for (dao_h256, ar, c, s, u) in cases { - let dao_byte32: Byte32 = dao_h256.pack(); + let dao_byte32: Byte32 = dao_h256.into(); assert_eq!((ar, c, s, u), extract_dao_data(dao_byte32.clone())); assert_eq!(dao_byte32, pack_dao_data(ar, c, s, u,)); } diff --git a/util/fixed-hash/core/src/std_str.rs b/util/fixed-hash/core/src/std_str.rs index 01ee940cc5..664298d50c 100644 --- a/util/fixed-hash/core/src/std_str.rs +++ b/util/fixed-hash/core/src/std_str.rs @@ -1,6 +1,6 @@ use crate::{error::FromStrError, H160, H256, H512, H520}; -pub(crate) const DICT_HEX_ERROR: u8 = u8::max_value(); +pub(crate) const DICT_HEX_ERROR: u8 = u8::MAX; pub(crate) static DICT_HEX_LO: [u8; 256] = { const ____: u8 = DICT_HEX_ERROR; [ diff --git a/util/gen-types/src/conversion/blockchain/mod.rs b/util/gen-types/src/conversion/blockchain/mod.rs index 3a73bd2084..e400ed16d7 100644 --- a/util/gen-types/src/conversion/blockchain/mod.rs +++ b/util/gen-types/src/conversion/blockchain/mod.rs @@ -24,10 +24,10 @@ impl<'r> Unpack<[u8; 32]> for packed::Byte32Reader<'r> { } impl_conversion_for_entity_unpack!([u8; 32], Byte32); -impl<'r> Into<[u8; 32]> for packed::Byte32Reader<'r> { - fn into(self) -> [u8; 32] { +impl<'r> From> for [u8; 32] { + fn from(value: packed::Byte32Reader<'r>) -> [u8; 32] { let mut b = [0u8; 32]; - b.copy_from_slice(self.raw_data()); + b.copy_from_slice(value.raw_data()); b } } @@ -48,10 +48,10 @@ impl<'r> Unpack<[u8; 10]> for packed::ProposalShortIdReader<'r> { } impl_conversion_for_entity_unpack!([u8; 10], ProposalShortId); -impl<'r> Into<[u8; 10]> for packed::ProposalShortIdReader<'r> { - fn into(self) -> [u8; 10] { +impl<'r> From> for [u8; 10] { + fn from(value: packed::ProposalShortIdReader<'r>) -> [u8; 10] { let mut b = [0u8; 10]; - b.copy_from_slice(self.raw_data()); + b.copy_from_slice(value.raw_data()); b } } @@ -88,9 +88,9 @@ impl<'r> Unpack for packed::BytesReader<'r> { } } -impl<'r> Into for packed::BytesReader<'r> { - fn into(self) -> Bytes { - Bytes::from(self.raw_data().to_owned()) +impl<'r> From> for Bytes { + fn from(value: packed::BytesReader<'r>) -> Bytes { + Bytes::from(value.raw_data().to_owned()) } } @@ -100,9 +100,9 @@ impl Unpack for packed::Bytes { } } -impl Into for packed::Bytes { - fn into(self) -> Bytes { - self.raw_data() +impl From for Bytes { + fn from(value: packed::Bytes) -> Bytes { + value.raw_data() } } diff --git a/util/gen-types/src/conversion/blockchain/std_env.rs b/util/gen-types/src/conversion/blockchain/std_env.rs index 93343709b3..696fe77123 100644 --- a/util/gen-types/src/conversion/blockchain/std_env.rs +++ b/util/gen-types/src/conversion/blockchain/std_env.rs @@ -29,9 +29,9 @@ impl<'r> Unpack for packed::Uint64Reader<'r> { } impl_conversion_for_entity_unpack!(Capacity, Uint64); -impl<'r> Into for packed::Uint64Reader<'r> { - fn into(self) -> Capacity { - Capacity::shannons(self.into()) +impl<'r> From> for Capacity { + fn from(value: packed::Uint64Reader<'r>) -> Capacity { + Capacity::shannons(value.into()) } } impl_conversion_for_entity_from!(Capacity, Uint64); @@ -62,9 +62,9 @@ impl<'r> Unpack for packed::Uint256Reader<'r> { } impl_conversion_for_entity_unpack!(U256, Uint256); -impl<'r> Into for packed::Uint256Reader<'r> { - fn into(self) -> U256 { - U256::from_little_endian(self.as_slice()).expect("internal error: fail to unpack U256") +impl<'r> From> for U256 { + fn from(value: packed::Uint256Reader<'r>) -> U256 { + U256::from_little_endian(value.as_slice()).expect("internal error: fail to unpack U256") } } impl_conversion_for_entity_from!(U256, Uint256); @@ -94,9 +94,9 @@ impl<'r> Unpack for packed::Byte32Reader<'r> { } impl_conversion_for_entity_unpack!(H256, Byte32); -impl<'r> Into for packed::Byte32Reader<'r> { - fn into(self) -> H256 { - H256::from_slice(self.as_slice()).expect("internal error: fail to unpack H256") +impl<'r> From> for H256 { + fn from(value: packed::Byte32Reader<'r>) -> H256 { + H256::from_slice(value.as_slice()).expect("internal error: fail to unpack H256") } } impl_conversion_for_entity_from!(H256, Byte32); diff --git a/util/gen-types/src/conversion/primitive.rs b/util/gen-types/src/conversion/primitive.rs index 80ef6b55de..b0a326abe8 100644 --- a/util/gen-types/src/conversion/primitive.rs +++ b/util/gen-types/src/conversion/primitive.rs @@ -26,9 +26,9 @@ impl From<&bool> for packed::Bool { } } -impl<'r> Into for packed::BoolReader<'r> { - fn into(self) -> bool { - match self.as_slice()[0] { +impl<'r> From> for bool { + fn from(value: packed::BoolReader<'r>) -> bool { + match value.as_slice()[0] { 0 => false, 1 => true, _ => unreachable!(), @@ -119,10 +119,10 @@ impl From<&usize> for packed::Uint32 { } } -impl<'r> Into for packed::Uint32Reader<'r> { - fn into(self) -> u32 { +impl<'r> From> for u32 { + fn from(value: packed::Uint32Reader<'r>) -> u32 { let mut b = [0u8; 4]; - b.copy_from_slice(self.as_slice()); + b.copy_from_slice(value.as_slice()); u32::from_le_bytes(b) } } @@ -136,10 +136,10 @@ impl<'r> Unpack for packed::Uint32Reader<'r> { } impl_conversion_for_entity_unpack!(u32, Uint32); -impl<'r> Into for packed::Uint64Reader<'r> { - fn into(self) -> u64 { +impl<'r> From> for u64 { + fn from(value: packed::Uint64Reader<'r>) -> u64 { let mut b = [0u8; 8]; - b.copy_from_slice(self.as_slice()); + b.copy_from_slice(value.as_slice()); u64::from_le_bytes(b) } } @@ -153,10 +153,10 @@ impl<'r> Unpack for packed::Uint64Reader<'r> { } impl_conversion_for_entity_unpack!(u64, Uint64); -impl<'r> Into for packed::Uint128Reader<'r> { - fn into(self) -> u128 { +impl<'r> From> for u128 { + fn from(value: packed::Uint128Reader<'r>) -> u128 { let mut b = [0u8; 16]; - b.copy_from_slice(self.as_slice()); + b.copy_from_slice(value.as_slice()); u128::from_le_bytes(b) } } @@ -170,9 +170,9 @@ impl<'r> Unpack for packed::Uint128Reader<'r> { } impl_conversion_for_entity_unpack!(u128, Uint128); -impl<'r> Into for packed::Uint32Reader<'r> { - fn into(self) -> usize { - let x: u32 = self.into(); +impl<'r> From> for usize { + fn from(value: packed::Uint32Reader<'r>) -> usize { + let x: u32 = value.into(); x as usize } } @@ -239,10 +239,10 @@ impl From<&usize> for packed::BeUint32 { } } -impl<'r> Into for packed::BeUint32Reader<'r> { - fn into(self) -> u32 { +impl<'r> From> for u32 { + fn from(value: packed::BeUint32Reader<'r>) -> u32 { let mut b = [0u8; 4]; - b.copy_from_slice(self.as_slice()); + b.copy_from_slice(value.as_slice()); u32::from_be_bytes(b) } } @@ -256,10 +256,10 @@ impl<'r> Unpack for packed::BeUint32Reader<'r> { } impl_conversion_for_entity_unpack!(u32, BeUint32); -impl<'r> Into for packed::BeUint64Reader<'r> { - fn into(self) -> u64 { +impl<'r> From> for u64 { + fn from(value: packed::BeUint64Reader<'r>) -> u64 { let mut b = [0u8; 8]; - b.copy_from_slice(self.as_slice()); + b.copy_from_slice(value.as_slice()); u64::from_be_bytes(b) } } @@ -273,9 +273,9 @@ impl<'r> Unpack for packed::BeUint64Reader<'r> { } impl_conversion_for_entity_unpack!(u64, BeUint64); -impl<'r> Into for packed::BeUint32Reader<'r> { - fn into(self) -> usize { - let x: u32 = self.into(); +impl<'r> From> for usize { + fn from(value: packed::BeUint32Reader<'r>) -> usize { + let x: u32 = value.into(); x as usize } } @@ -320,9 +320,9 @@ impl From<&[u8; N]> for packed::Bytes { } } -impl<'r> Into> for packed::BytesReader<'r> { - fn into(self) -> Vec { - self.raw_data().to_owned() +impl<'r> From> for Vec { + fn from(value: packed::BytesReader<'r>) -> Vec { + value.raw_data().to_owned() } } impl_conversion_for_entity_from!(Vec, Bytes); @@ -386,9 +386,9 @@ impl<'r> Unpack>> for packed::Uint64VecOptReader<'r> { } } -impl<'r> Into>> for packed::Uint64VecOptReader<'r> { - fn into(self) -> Option> { - self.to_opt().map(|x| x.into()) +impl<'r> From> for Option> { + fn from(value: packed::Uint64VecOptReader<'r>) -> Option> { + value.to_opt().map(|x| x.into()) } } diff --git a/util/gen-types/src/conversion/utilities.rs b/util/gen-types/src/conversion/utilities.rs index 7ddb20265b..2109c79bff 100644 --- a/util/gen-types/src/conversion/utilities.rs +++ b/util/gen-types/src/conversion/utilities.rs @@ -65,11 +65,11 @@ macro_rules! impl_conversion_for_option_unpack { }; } -macro_rules! impl_conversion_for_option_into { +macro_rules! impl_conversion_for_option_reader_from { ($original:ty, $entity:ident, $reader:ident) => { - impl<'r> Into> for packed::$reader<'r> { - fn into(self) -> Option<$original> { - self.to_opt().map(|x| x.into()) + impl<'r> From> for Option<$original> { + fn from(value: packed::$reader<'r>) -> Option<$original> { + value.to_opt().map(|x| x.into()) } } impl_conversion_for_entity_from!(Option<$original>, $entity); @@ -86,7 +86,7 @@ macro_rules! impl_conversion_for_option { macro_rules! impl_conversion_for_option_from_into { ($original:ty, $entity:ident, $reader:ident, $entity_inner:ident) => { impl_conversion_for_option_from!($original, $entity, $entity_inner); - impl_conversion_for_option_into!($original, $entity, $reader); + impl_conversion_for_option_reader_from!($original, $entity, $reader); }; } @@ -137,11 +137,11 @@ macro_rules! impl_conversion_for_vector_unpack { }; } -macro_rules! impl_conversion_for_vector_into { +macro_rules! impl_conversion_for_vector_reader_from { ($original:ty, $entity:ident, $reader:ident) => { - impl<'r> Into> for packed::$reader<'r> { - fn into(self) -> Vec<$original> { - self.iter().map(|x| x.into()).collect() + impl<'r> From> for Vec<$original> { + fn from(value: packed::$reader<'r>) -> Vec<$original> { + value.iter().map(|x| x.into()).collect() } } impl_conversion_for_entity_from!(Vec<$original>, $entity); @@ -158,7 +158,7 @@ macro_rules! impl_conversion_for_vector { macro_rules! impl_conversion_for_vector_from_into { ($original:ty, $entity:ident, $reader:ident) => { impl_conversion_for_vector_from!($original, $entity); - impl_conversion_for_vector_into!($original, $entity, $reader); + impl_conversion_for_vector_reader_from!($original, $entity, $reader); }; } diff --git a/util/gen-types/src/generated/mod.rs b/util/gen-types/src/generated/mod.rs index fd81a946d0..03d3f97092 100644 --- a/util/gen-types/src/generated/mod.rs +++ b/util/gen-types/src/generated/mod.rs @@ -3,6 +3,8 @@ #![doc(hidden)] #![allow(warnings)] #![allow(missing_docs)] +#![allow(clippy::all)] +#![allow(clippy::fallible_impl_from)] #[allow(clippy::all)] mod blockchain; diff --git a/util/indexer-sync/src/lib.rs b/util/indexer-sync/src/lib.rs index 135d516e17..4c8325be7e 100644 --- a/util/indexer-sync/src/lib.rs +++ b/util/indexer-sync/src/lib.rs @@ -26,7 +26,6 @@ use ckb_store::ChainStore; use ckb_types::{ core::{self, BlockNumber, BlockView}, packed::Byte32, - prelude::*, H256, }; use rocksdb::prelude::*; @@ -112,7 +111,7 @@ impl IndexerSyncService { .tip() .expect("indexer_service tip should be OK"); if let Some((indexer_tip, _)) = indexer_tip { - if let Some(init_tip) = self.secondary_db.get_block_header(&init_tip_hash.pack()) { + if let Some(init_tip) = self.secondary_db.get_block_header(&init_tip_hash.into()) { if indexer_tip >= init_tip.number() { return; } @@ -127,7 +126,7 @@ impl IndexerSyncService { if let Err(e) = self.secondary_db.try_catch_up_with_primary() { error!("secondary_db try_catch_up_with_primary error {}", e); } - if let Some(header) = self.secondary_db.get_block_header(&init_tip_hash.pack()) { + if let Some(header) = self.secondary_db.get_block_header(&init_tip_hash.into()) { let init_tip_number = header.number(); indexer_service.set_init_tip(init_tip_number, init_tip_hash); break; diff --git a/util/indexer/src/indexer.rs b/util/indexer/src/indexer.rs index 33f0813e86..6b87fd4378 100644 --- a/util/indexer/src/indexer.rs +++ b/util/indexer/src/indexer.rs @@ -354,10 +354,10 @@ where block_number, i as u32, &tx.outputs() - .get(out_point.index().unpack()) + .get(out_point.index().into()) .expect("index should match"), &tx.outputs_data() - .get(out_point.index().unpack()) + .get(out_point.index().into()) .expect("index should match"), ) .into() @@ -380,7 +380,7 @@ where &output.lock(), generated_by_block_number, generated_by_tx_index, - out_point.index().unpack(), + out_point.index().into(), ) .into_vec(), )?; @@ -400,7 +400,7 @@ where &script, generated_by_block_number, generated_by_tx_index, - out_point.index().unpack(), + out_point.index().into(), ) .into_vec(), )?; @@ -629,7 +629,7 @@ where &output.lock(), generated_by_block_number, generated_by_tx_index, - out_point.index().unpack(), + out_point.index().into(), ), Value::TxHash(&out_point.tx_hash()), )?; @@ -649,7 +649,7 @@ where &script, generated_by_block_number, generated_by_tx_index, - out_point.index().unpack(), + out_point.index().into(), ), Value::TxHash(&out_point.tx_hash()), )?; @@ -702,7 +702,7 @@ where let mut batch = self.store.batch().expect("create batch should be OK"); batch .put_kv( - Key::Header(init_tip_number, &init_tip_hash.pack(), true), + Key::Header(init_tip_number, &init_tip_hash.into(), true), vec![], ) .expect("insert init tip header should be OK"); @@ -955,27 +955,27 @@ mod tests { let indexer = new_indexer::("append_and_rollback_to_empty"); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script2".to_vec()).pack()) + .args(Bytes::from(b"lock_script2".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"type_script2".to_vec()).pack()) + .args(Bytes::from(b"type_script2".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -983,7 +983,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -993,9 +993,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) @@ -1004,9 +1004,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2) - .type_(Some(type_script2).pack()) + .type_(Some(type_script2).into()) .build(), ) .output_data(Default::default()) @@ -1016,7 +1016,7 @@ mod tests { .transaction(cellbase0) .transaction(tx00) .transaction(tx01) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1038,27 +1038,27 @@ mod tests { let indexer = new_indexer::("append_two_blocks_and_rollback_one"); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script2".to_vec()).pack()) + .args(Bytes::from(b"lock_script2".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"type_script2".to_vec()).pack()) + .args(Bytes::from(b"type_script2".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1066,7 +1066,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1076,9 +1076,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1087,9 +1087,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1099,7 +1099,7 @@ mod tests { .transaction(cellbase0) .transaction(tx00.clone()) .transaction(tx01.clone()) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1108,7 +1108,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1119,9 +1119,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx00.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) @@ -1131,9 +1131,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx01.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2) - .type_(Some(type_script2).pack()) + .type_(Some(type_script2).into()) .build(), ) .output_data(Default::default()) @@ -1145,11 +1145,11 @@ mod tests { .transaction(tx11) .header( HeaderBuilder::default() - .number(1.pack()) + .number(1.into()) .parent_hash(block0.hash()) .epoch( EpochNumberWithFraction::new(block0.number() + 1, block0.number(), 1000) - .pack(), + .into(), ) .build(), ) @@ -1199,27 +1199,27 @@ mod tests { let indexer = new_indexer::("consume_output_in_same_block"); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script2".to_vec()).pack()) + .args(Bytes::from(b"lock_script2".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"type_script2".to_vec()).pack()) + .args(Bytes::from(b"type_script2".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1227,7 +1227,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1237,9 +1237,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1248,9 +1248,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1260,7 +1260,7 @@ mod tests { .transaction(cellbase0.clone()) .transaction(tx00.clone()) .transaction(tx01.clone()) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1269,7 +1269,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1280,9 +1280,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx00.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) @@ -1292,9 +1292,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx01.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1304,9 +1304,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx11.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2).pack()) + .type_(Some(type_script2).into()) .build(), ) .output_data(Default::default()) @@ -1319,11 +1319,11 @@ mod tests { .transaction(tx12) .header( HeaderBuilder::default() - .number(1.pack()) + .number(1.into()) .parent_hash(block0.hash()) .epoch( EpochNumberWithFraction::new(block0.number() + 1, block0.number(), 1000) - .pack(), + .into(), ) .build(), ) @@ -1371,27 +1371,27 @@ mod tests { let indexer = new_indexer::("prune"); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script2".to_vec()).pack()) + .args(Bytes::from(b"lock_script2".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"type_script2".to_vec()).pack()) + .args(Bytes::from(b"type_script2".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1399,7 +1399,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1409,9 +1409,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1420,9 +1420,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1432,7 +1432,7 @@ mod tests { .transaction(cellbase0) .transaction(tx00.clone()) .transaction(tx01.clone()) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1445,7 +1445,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1456,9 +1456,9 @@ mod tests { .input(CellInput::new(OutPoint::new(pre_tx0.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1468,9 +1468,9 @@ mod tests { .input(CellInput::new(OutPoint::new(pre_tx1.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1482,7 +1482,7 @@ mod tests { .transaction(pre_tx1.clone()) .header( HeaderBuilder::default() - .number((pre_block.number() + 1).pack()) + .number((pre_block.number() + 1).into()) .parent_hash(pre_block.hash()) .epoch( EpochNumberWithFraction::new( @@ -1490,7 +1490,7 @@ mod tests { pre_block.number(), 1000, ) - .pack(), + .into(), ) .build(), ) @@ -1526,9 +1526,9 @@ mod tests { let indexer = new_indexer::("prune"); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1536,7 +1536,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1545,7 +1545,7 @@ mod tests { let block0 = BlockBuilder::default() .transaction(cellbase0) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1558,7 +1558,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1569,7 +1569,7 @@ mod tests { .transaction(cellbase) .header( HeaderBuilder::default() - .number((pre_block.number() + 1).pack()) + .number((pre_block.number() + 1).into()) .parent_hash(pre_block.hash()) .epoch( EpochNumberWithFraction::new( @@ -1577,7 +1577,7 @@ mod tests { pre_block.number(), 1000, ) - .pack(), + .into(), ) .build(), ) @@ -1598,27 +1598,27 @@ mod tests { let indexer = new_indexer::("append_and_rollback_with_cellbase"); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script2".to_vec()).pack()) + .args(Bytes::from(b"lock_script2".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"type_script2".to_vec()).pack()) + .args(Bytes::from(b"type_script2".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1626,7 +1626,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1636,9 +1636,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) @@ -1647,9 +1647,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2) - .type_(Some(type_script2).pack()) + .type_(Some(type_script2).into()) .build(), ) .output_data(Default::default()) @@ -1659,7 +1659,7 @@ mod tests { .transaction(cellbase0) .transaction(tx00) .transaction(tx01) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1682,14 +1682,14 @@ mod tests { let indexer = new_indexer::("prune_should_not_delete_live_cells"); let all_zero_lock_script = ScriptBuilder::default() - .code_hash(H256([0; 32]).pack()) + .code_hash(H256([0; 32]).into()) .hash_type(ScriptHashType::Data.into()) .build(); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1697,7 +1697,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(all_zero_lock_script.clone()) .build(), ) @@ -1706,7 +1706,7 @@ mod tests { let block0 = BlockBuilder::default() .transaction(cellbase0) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1728,7 +1728,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1739,7 +1739,7 @@ mod tests { .transaction(cellbase) .header( HeaderBuilder::default() - .number((pre_block.number() + 1).pack()) + .number((pre_block.number() + 1).into()) .parent_hash(pre_block.hash()) .epoch( EpochNumberWithFraction::new( @@ -1747,7 +1747,7 @@ mod tests { pre_block.number(), 1000, ) - .pack(), + .into(), ) .build(), ) @@ -1778,8 +1778,8 @@ mod tests { .transaction(cellbase) .header( HeaderBuilder::default() - .number(i.pack()) - .epoch(EpochNumberWithFraction::new(i + 1, i, 1000).pack()) + .number(i.into()) + .epoch(EpochNumberWithFraction::new(i + 1, i, 1000).into()) .build(), ) .build(); @@ -1804,15 +1804,15 @@ mod tests { ); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1820,7 +1820,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1830,9 +1830,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1841,7 +1841,7 @@ mod tests { let block0 = BlockBuilder::default() .transaction(cellbase0.clone()) .transaction(tx00.clone()) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1850,7 +1850,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1861,9 +1861,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx00.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1874,11 +1874,11 @@ mod tests { .transaction(tx10) .header( HeaderBuilder::default() - .number(1.pack()) + .number(1.into()) .parent_hash(block0.hash()) .epoch( EpochNumberWithFraction::new(block0.number() + 1, block0.number(), 1000) - .pack(), + .into(), ) .build(), ) @@ -1958,27 +1958,27 @@ mod tests { ); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script2".to_vec()).pack()) + .args(Bytes::from(b"lock_script2".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"type_script2".to_vec()).pack()) + .args(Bytes::from(b"type_script2".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1986,7 +1986,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1996,9 +1996,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -2007,9 +2007,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -2019,7 +2019,7 @@ mod tests { .transaction(cellbase0) .transaction(tx00.clone()) .transaction(tx01.clone()) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); let (tip_number, tip_hash) = indexer.tip().unwrap().unwrap(); @@ -2031,7 +2031,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -2042,9 +2042,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx00.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) @@ -2054,9 +2054,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx01.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2) - .type_(Some(type_script2).pack()) + .type_(Some(type_script2).into()) .build(), ) .output_data(Default::default()) @@ -2068,11 +2068,11 @@ mod tests { .transaction(tx11) .header( HeaderBuilder::default() - .number(1.pack()) + .number(1.into()) .parent_hash(block0.hash()) .epoch( EpochNumberWithFraction::new(block0.number() + 1, block0.number(), 1000) - .pack(), + .into(), ) .build(), ) @@ -2126,27 +2126,27 @@ mod tests { ); let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script2".to_vec()).pack()) + .args(Bytes::from(b"lock_script2".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"type_script2".to_vec()).pack()) + .args(Bytes::from(b"type_script2".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -2154,7 +2154,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -2164,9 +2164,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -2175,9 +2175,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -2187,7 +2187,7 @@ mod tests { .transaction(cellbase0) .transaction(tx00.clone()) .transaction(tx01.clone()) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); let (tip_number, tip_hash) = indexer.tip().unwrap().unwrap(); @@ -2213,7 +2213,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -2224,9 +2224,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx00.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) @@ -2236,9 +2236,9 @@ mod tests { .input(CellInput::new(OutPoint::new(tx01.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2) - .type_(Some(type_script2).pack()) + .type_(Some(type_script2).into()) .build(), ) .output_data(Default::default()) @@ -2250,11 +2250,11 @@ mod tests { .transaction(tx11) .header( HeaderBuilder::default() - .number(1.pack()) + .number(1.into()) .parent_hash(block0.hash()) .epoch( EpochNumberWithFraction::new(block0.number() + 1, block0.number(), 1000) - .pack(), + .into(), ) .build(), ) diff --git a/util/indexer/src/service.rs b/util/indexer/src/service.rs index 774276e392..bf48ce7d20 100644 --- a/util/indexer/src/service.rs +++ b/util/indexer/src/service.rs @@ -136,7 +136,7 @@ impl IndexerHandle { Ok(iter.next().map(|(key, _)| IndexerTip { block_hash: packed::Byte32::from_slice(&key[9..41]) .expect("stored block key") - .unpack(), + .into(), block_number: core::BlockNumber::from_be_bytes( key[1..9].try_into().expect("stored block key"), ) @@ -290,7 +290,7 @@ impl IndexerHandle { } if let Some([r0, r1]) = filter_options.output_capacity_range { - let capacity: core::Capacity = output.capacity().unpack(); + let capacity: core::Capacity = output.capacity().into(); if capacity < r0 || capacity >= r1 { return None; } @@ -412,7 +412,7 @@ impl IndexerHandle { } let tx_hash: H256 = packed::Byte32::from_slice(&value) .expect("stored tx hash") - .unpack(); + .into(); if tx_with_cells.len() == limit && tx_with_cells.last_mut().unwrap().tx_hash != tx_hash { @@ -596,7 +596,7 @@ impl IndexerHandle { last_key = key.to_vec(); Some(IndexerTx::Ungrouped(IndexerTxWithCell { - tx_hash: tx_hash.unpack(), + tx_hash: tx_hash.into(), block_number: block_number.into(), tx_index: tx_index.into(), io_index: io_index.into(), @@ -746,7 +746,7 @@ impl IndexerHandle { } if let Some([r0, r1]) = filter_options.output_capacity_range { - let capacity: core::Capacity = output.capacity().unpack(); + let capacity: core::Capacity = output.capacity().into(); if capacity < r0 || capacity >= r1 { return None; } @@ -758,7 +758,7 @@ impl IndexerHandle { } } - Some(Unpack::::unpack(&output.capacity()).as_u64()) + Some(Into::::into(&output.capacity()).as_u64()) }) .sum(); @@ -768,7 +768,7 @@ impl IndexerHandle { capacity: capacity.into(), block_hash: packed::Byte32::from_slice(&key[9..41]) .expect("stored block key") - .unpack(), + .into(), block_number: core::BlockNumber::from_be_bytes( key[1..9].try_into().expect("stored block key"), ) @@ -936,27 +936,27 @@ mod tests { // setup test data let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script2".to_vec()).pack()) + .args(Bytes::from(b"lock_script2".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script2 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"type_script2".to_vec()).pack()) + .args(Bytes::from(b"type_script2".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -964,7 +964,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -974,9 +974,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -985,9 +985,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -997,7 +997,7 @@ mod tests { .transaction(cellbase0) .transaction(tx00.clone()) .transaction(tx01.clone()) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1010,20 +1010,20 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) - .output_data(Bytes::from(i.to_string()).pack()) + .output_data(Bytes::from(i.to_string()).into()) .build(); pre_tx0 = TransactionBuilder::default() .input(CellInput::new(OutPoint::new(pre_tx0.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1033,9 +1033,9 @@ mod tests { .input(CellInput::new(OutPoint::new(pre_tx1.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script2.clone()) - .type_(Some(type_script2.clone()).pack()) + .type_(Some(type_script2.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1047,7 +1047,7 @@ mod tests { .transaction(pre_tx1.clone()) .header( HeaderBuilder::default() - .number((pre_block.number() + 1).pack()) + .number((pre_block.number() + 1).into()) .parent_hash(pre_block.hash()) .epoch( EpochNumberWithFraction::new( @@ -1055,7 +1055,7 @@ mod tests { pre_block.number(), 1000, ) - .pack(), + .into(), ) .build(), ) @@ -1066,7 +1066,7 @@ mod tests { // test get_tip rpc let tip = rpc.get_indexer_tip().unwrap().unwrap(); - assert_eq!(Unpack::::unpack(&pre_block.hash()), tip.block_hash); + assert_eq!(Into::::into(&pre_block.hash()), tip.block_hash); assert_eq!(pre_block.number(), tip.block_number.value()); // test get_cells rpc @@ -1458,9 +1458,9 @@ mod tests { .input(CellInput::new(OutPoint::new(pre_tx0.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) @@ -1520,27 +1520,27 @@ mod tests { // setup test data let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script11 = ScriptBuilder::default() .code_hash(lock_script1.code_hash()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script11".to_vec()).pack()) + .args(Bytes::from(b"lock_script11".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script11 = ScriptBuilder::default() .code_hash(type_script1.code_hash()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script11".to_vec()).pack()) + .args(Bytes::from(b"type_script11".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1548,7 +1548,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1558,9 +1558,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1569,9 +1569,9 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script11.clone()) - .type_(Some(type_script11.clone()).pack()) + .type_(Some(type_script11.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1581,7 +1581,7 @@ mod tests { .transaction(cellbase0) .transaction(tx00.clone()) .transaction(tx01.clone()) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); @@ -1594,20 +1594,20 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) - .output_data(Bytes::from(i.to_string()).pack()) + .output_data(Bytes::from(i.to_string()).into()) .build(); pre_tx0 = TransactionBuilder::default() .input(CellInput::new(OutPoint::new(pre_tx0.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) - .type_(Some(type_script1.clone()).pack()) + .type_(Some(type_script1.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1617,9 +1617,9 @@ mod tests { .input(CellInput::new(OutPoint::new(pre_tx1.hash(), 0), 0)) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script11.clone()) - .type_(Some(type_script11.clone()).pack()) + .type_(Some(type_script11.clone()).into()) .build(), ) .output_data(Default::default()) @@ -1631,7 +1631,7 @@ mod tests { .transaction(pre_tx1.clone()) .header( HeaderBuilder::default() - .number((pre_block.number() + 1).pack()) + .number((pre_block.number() + 1).into()) .parent_hash(pre_block.hash()) .epoch( EpochNumberWithFraction::new( @@ -1639,7 +1639,7 @@ mod tests { pre_block.number(), 1000, ) - .pack(), + .into(), ) .build(), ) @@ -1763,27 +1763,27 @@ mod tests { // setup test data let lock_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script1".to_vec()).pack()) + .args(Bytes::from(b"lock_script1".to_vec()).into()) .build(); let lock_script11 = ScriptBuilder::default() .code_hash(lock_script1.code_hash()) .hash_type(ScriptHashType::Type.into()) - .args(Bytes::from(b"lock_script11".to_vec()).pack()) + .args(Bytes::from(b"lock_script11".to_vec()).into()) .build(); let type_script1 = ScriptBuilder::default() - .code_hash(H256(rand::random()).pack()) + .code_hash(H256(rand::random()).into()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script1".to_vec()).pack()) + .args(Bytes::from(b"type_script1".to_vec()).into()) .build(); let type_script11 = ScriptBuilder::default() .code_hash(type_script1.code_hash()) .hash_type(ScriptHashType::Data.into()) - .args(Bytes::from(b"type_script11".to_vec()).pack()) + .args(Bytes::from(b"type_script11".to_vec()).into()) .build(); let cellbase0 = TransactionBuilder::default() @@ -1791,7 +1791,7 @@ mod tests { .witness(Script::default().into_witness()) .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1.clone()) .build(), ) @@ -1801,9 +1801,9 @@ mod tests { let tx00 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(1000).pack()) + .capacity(capacity_bytes!(1000).into()) .lock(lock_script1) - .type_(Some(type_script1).pack()) + .type_(Some(type_script1).into()) .build(), ) .output_data(Default::default()) @@ -1814,19 +1814,19 @@ mod tests { let tx01 = TransactionBuilder::default() .output( CellOutputBuilder::default() - .capacity(capacity_bytes!(2000).pack()) + .capacity(capacity_bytes!(2000).into()) .lock(lock_script11.clone()) - .type_(Some(type_script11).pack()) + .type_(Some(type_script11).into()) .build(), ) - .output_data(data.to_vec().pack()) + .output_data(data.to_vec().into()) .build(); let block0 = BlockBuilder::default() .transaction(cellbase0) .transaction(tx00) .transaction(tx01) - .header(HeaderBuilder::default().number(0.pack()).build()) + .header(HeaderBuilder::default().number(0.into()).build()) .build(); indexer.append(&block0).unwrap(); diff --git a/util/jsonrpc-types/src/alert.rs b/util/jsonrpc-types/src/alert.rs index bbb459830c..7c10afc782 100644 --- a/util/jsonrpc-types/src/alert.rs +++ b/util/jsonrpc-types/src/alert.rs @@ -86,17 +86,23 @@ impl From for packed::Alert { signatures, } = json; let raw = packed::RawAlert::new_builder() - .id(id.pack()) - .cancel(cancel.pack()) - .min_version(min_version.pack()) - .max_version(max_version.pack()) - .priority(priority.pack()) - .notice_until(notice_until.pack()) - .message(message.pack()) + .id(id.into()) + .cancel(cancel.into()) + .min_version(min_version.into()) + .max_version(max_version.into()) + .priority(priority.into()) + .notice_until(notice_until.into()) + .message(message.into()) .build(); packed::Alert::new_builder() .raw(raw) - .signatures(signatures.into_iter().map(Into::into).pack()) + .signatures( + signatures + .into_iter() + .map(Into::into) + .collect::>() + .into(), + ) .build() } } @@ -105,8 +111,8 @@ impl From for Alert { fn from(input: packed::Alert) -> Self { let raw = input.raw(); Alert { - id: raw.id().unpack(), - cancel: raw.cancel().unpack(), + id: raw.id().into(), + cancel: raw.cancel().into(), min_version: raw .as_reader() .min_version() @@ -117,8 +123,8 @@ impl From for Alert { .max_version() .to_opt() .map(|b| unsafe { b.as_utf8_unchecked() }.to_owned()), - priority: raw.priority().unpack(), - notice_until: raw.notice_until().unpack(), + priority: raw.priority().into(), + notice_until: raw.notice_until().into(), message: unsafe { raw.as_reader().message().as_utf8_unchecked() }.to_owned(), signatures: input.signatures().into_iter().map(Into::into).collect(), } @@ -129,9 +135,9 @@ impl From for AlertMessage { fn from(input: packed::Alert) -> Self { let raw = input.raw(); AlertMessage { - id: raw.id().unpack(), - priority: raw.priority().unpack(), - notice_until: raw.notice_until().unpack(), + id: raw.id().into(), + priority: raw.priority().into(), + notice_until: raw.notice_until().into(), message: unsafe { raw.as_reader().message().as_utf8_unchecked() }.to_owned(), } } diff --git a/util/jsonrpc-types/src/block_template.rs b/util/jsonrpc-types/src/block_template.rs index 8e49f9bf72..908abc66e5 100644 --- a/util/jsonrpc-types/src/block_template.rs +++ b/util/jsonrpc-types/src/block_template.rs @@ -115,12 +115,12 @@ impl From for packed::Block { .. } = block_template; let raw = packed::RawHeader::new_builder() - .version(version.pack()) - .compact_target(compact_target.pack()) - .parent_hash(parent_hash.pack()) - .timestamp(current_time.pack()) - .number(number.pack()) - .epoch(epoch.pack()) + .version(version.into()) + .compact_target(compact_target.into()) + .parent_hash(parent_hash.into()) + .timestamp(current_time.into()) + .number(number.into()) + .epoch(epoch.into()) .dao(dao.into()) .build(); let header = packed::Header::new_builder().raw(raw).build(); @@ -137,7 +137,7 @@ impl From for packed::Block { .into_iter() .map(|u| u.into()) .collect::>() - .pack(), + .into(), ) .transactions(txs) .proposals( @@ -145,7 +145,7 @@ impl From for packed::Block { .into_iter() .map(|p| p.into()) .collect::>() - .pack(), + .into(), ) .extension(extension) .build() @@ -158,7 +158,7 @@ impl From for packed::Block { .into_iter() .map(|u| u.into()) .collect::>() - .pack(), + .into(), ) .transactions(txs) .proposals( @@ -166,7 +166,7 @@ impl From for packed::Block { .into_iter() .map(|p| p.into()) .collect::>() - .pack(), + .into(), ) .build() } @@ -198,7 +198,13 @@ impl From for packed::UncleBlock { } = template; packed::UncleBlock::new_builder() .header(header.into()) - .proposals(proposals.into_iter().map(Into::into).pack()) + .proposals( + proposals + .into_iter() + .map(Into::into) + .collect::>() + .into(), + ) .build() } } diff --git a/util/jsonrpc-types/src/blockchain.rs b/util/jsonrpc-types/src/blockchain.rs index 47fbfff606..3e5b13fb9b 100644 --- a/util/jsonrpc-types/src/blockchain.rs +++ b/util/jsonrpc-types/src/blockchain.rs @@ -105,8 +105,8 @@ impl From