Skip to content

Commit 6a6a8c2

Browse files
authored
Merge pull request #4910 from driftluo/impl-from-into-for-gen-type
feat: impl from/into for gen-type
2 parents 7fefda1 + e410c25 commit 6a6a8c2

File tree

248 files changed

+7252
-4273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+7252
-4273
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.DEFAULT_GOAL:=help
22
SHELL = /bin/sh
33
MOLC := moleculec
4-
MOLC_VERSION := 0.7.5
4+
MOLC_VERSION := 0.9.0
55
VERBOSE := $(if ${CI},--verbose,)
66
CLIPPY_OPTS := -D warnings -D clippy::clone_on_ref_ptr -D clippy::redundant_clone -D clippy::enum_glob_use -D clippy::fallible_impl_from \
77
-A clippy::mutable_key_type -A clippy::upper_case_acronyms -A clippy::needless_return -A clippy::needless_lifetimes -A clippy::extra_unused_lifetimes

benches/benches/benchmarks/overall.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ const SIZES: &[usize] = &[2usize];
3434

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

4040
BlockAssemblerConfig {
41-
code_hash: secp_script.code_hash().unpack(),
41+
code_hash: secp_script.code_hash().into(),
4242
hash_type: hash_type.into(),
4343
args,
4444
message: Default::default(),
@@ -93,21 +93,21 @@ pub fn setup_chain(txs_size: usize) -> (Shared, ChainController) {
9393
.map(|i| {
9494
let data = Bytes::from(i.to_le_bytes().to_vec());
9595
let output = CellOutput::new_builder()
96-
.capacity(capacity_bytes!(50_000).pack())
96+
.capacity(capacity_bytes!(50_000))
9797
.lock(secp_script.clone())
9898
.build();
9999
TransactionBuilder::default()
100100
.input(CellInput::new(OutPoint::null(), 0))
101101
.output(output.clone())
102102
.output(output)
103-
.output_data(data.pack())
104-
.output_data(data.pack())
103+
.output_data(&data)
104+
.output_data(data)
105105
.build()
106106
})
107107
.collect();
108108

109109
let genesis_block = BlockBuilder::default()
110-
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
110+
.compact_target(difficulty_to_compact(U256::from(1000u64)))
111111
.dao(dao)
112112
.transaction(tx)
113113
.transactions(transactions)
@@ -208,7 +208,7 @@ fn bench(c: &mut Criterion) {
208208
let raw_header = raw_block.header().raw();
209209
let header = Header::new_builder()
210210
.raw(raw_header)
211-
.nonce(random::<u128>().pack())
211+
.nonce(random::<u128>())
212212
.build();
213213
let block = raw_block.as_builder().header(header).build().into_view();
214214

benches/benches/benchmarks/resolve.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,29 @@ const DEFAULT_CODE_HASH: H256 =
3232

3333
fn script() -> Script {
3434
Script::new_builder()
35-
.code_hash(DEFAULT_CODE_HASH.pack())
36-
.args(Bytes::from(PUBKEY_HASH.as_bytes()).pack())
37-
.hash_type(ScriptHashType::Type.into())
35+
.code_hash(DEFAULT_CODE_HASH)
36+
.args(Bytes::from(PUBKEY_HASH.as_bytes()))
37+
.hash_type(ScriptHashType::Type)
3838
.build()
3939
}
4040

4141
fn cell_dep(genesis: &BlockView) -> CellDep {
4242
let tx_hash = genesis.transaction(1).unwrap().hash();
43-
let out_point = OutPoint::new_builder()
44-
.tx_hash(tx_hash)
45-
.index(0u32.pack())
46-
.build();
43+
let out_point = OutPoint::new_builder().tx_hash(tx_hash).index(0u32).build();
4744

4845
CellDep::new_builder()
4946
.out_point(out_point)
50-
.dep_type(DepType::DepGroup.into())
47+
.dep_type(DepType::DepGroup)
5148
.build()
5249
}
5350

5451
fn block_assembler_config() -> BlockAssemblerConfig {
5552
let secp_script = script();
56-
let args = JsonBytes::from_bytes(secp_script.args().unpack());
53+
let args = JsonBytes::from_bytes(secp_script.args().into());
5754
let hash_type = ScriptHashType::try_from(secp_script.hash_type()).expect("checked data");
5855

5956
BlockAssemblerConfig {
60-
code_hash: secp_script.code_hash().unpack(),
57+
code_hash: secp_script.code_hash().into(),
6158
hash_type: hash_type.into(),
6259
args,
6360
message: Default::default(),

benches/benches/benchmarks/util.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ pub fn new_always_success_chain(txs_size: usize, chains_num: usize) -> Chains {
4747
.input(CellInput::new(OutPoint::null(), 0))
4848
.output(
4949
CellOutput::new_builder()
50-
.capacity(capacity_bytes!(50_000).pack())
50+
.capacity(capacity_bytes!(50_000))
5151
.lock(always_success_script.clone())
5252
.build(),
5353
)
54-
.output_data(data.pack())
54+
.output_data(data)
5555
.build()
5656
})
5757
.collect();
5858

5959
let genesis_block = BlockBuilder::default()
6060
.dao(dao)
61-
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
61+
.compact_target(difficulty_to_compact(U256::from(1000u64)))
6262
.transaction(tx)
6363
.transactions(transactions)
6464
.build();
@@ -90,7 +90,7 @@ pub fn create_always_success_tx() -> TransactionView {
9090
.witness(script.clone().into_witness())
9191
.input(CellInput::new(OutPoint::null(), 0))
9292
.output(always_success_cell.clone())
93-
.output_data(always_success_cell_data.pack())
93+
.output_data(always_success_cell_data)
9494
.build()
9595
}
9696

@@ -108,11 +108,11 @@ pub fn create_always_success_cellbase(shared: &Shared, parent: &HeaderView) -> T
108108
builder
109109
.output(
110110
CellOutput::new_builder()
111-
.capacity(capacity.pack())
111+
.capacity(capacity)
112112
.lock(always_success_script.clone())
113113
.build(),
114114
)
115-
.output_data(Bytes::new().pack())
115+
.output_data(Bytes::new())
116116
.build()
117117
}
118118
}
@@ -183,11 +183,11 @@ pub fn gen_always_success_block(
183183
.transactions(transactions)
184184
.proposals(proposals)
185185
.parent_hash(p_block.hash())
186-
.number(number.pack())
187-
.timestamp(timestamp.pack())
188-
.compact_target(epoch.compact_target().pack())
189-
.epoch(epoch.number_with_fraction(number).pack())
190-
.nonce(random::<u128>().pack())
186+
.number(number)
187+
.timestamp(timestamp)
188+
.compact_target(epoch.compact_target())
189+
.epoch(epoch.number_with_fraction(number))
190+
.nonce(random::<u128>())
191191
.dao(dao)
192192
.build();
193193

@@ -205,7 +205,7 @@ static SECP_DATA_CELL: std::sync::LazyLock<(CellOutput, Bytes)> = std::sync::Laz
205205
let data: Bytes = raw_data.to_vec().into();
206206

207207
let cell = CellOutput::new_builder()
208-
.capacity(Capacity::bytes(data.len()).unwrap().pack())
208+
.capacity(Capacity::bytes(data.len()).unwrap())
209209
.build();
210210
(cell, data)
211211
});
@@ -217,13 +217,13 @@ static SECP_CELL: std::sync::LazyLock<(CellOutput, Bytes, Script)> =
217217
let data: Bytes = raw_data.to_vec().into();
218218

219219
let cell = CellOutput::new_builder()
220-
.capacity(Capacity::bytes(data.len()).unwrap().pack())
220+
.capacity(Capacity::bytes(data.len()).unwrap())
221221
.build();
222222

223223
let script = Script::new_builder()
224224
.code_hash(CellOutput::calc_data_hash(&data))
225-
.args(Bytes::from(PUBKEY_HASH.as_bytes()).pack())
226-
.hash_type(ScriptHashType::Data.into())
225+
.args(Bytes::from(PUBKEY_HASH.as_bytes()))
226+
.hash_type(ScriptHashType::Data)
227227
.build();
228228

229229
(cell, data, script)
@@ -241,7 +241,7 @@ pub fn create_secp_tx() -> TransactionView {
241241
let (secp_data_cell, secp_data_cell_data) = secp_data_cell();
242242
let (secp_cell, secp_cell_data, script) = secp_cell();
243243
let outputs = vec![secp_data_cell.clone(), secp_cell.clone()];
244-
let outputs_data = vec![secp_data_cell_data.pack(), secp_cell_data.pack()];
244+
let outputs_data = vec![secp_data_cell_data.into(), secp_cell_data.into()];
245245
TransactionBuilder::default()
246246
.witness(script.clone().into_witness())
247247
.input(CellInput::new(OutPoint::null(), 0))
@@ -260,21 +260,21 @@ pub fn new_secp_chain(txs_size: usize, chains_num: usize) -> Chains {
260260
.map(|i| {
261261
let data = Bytes::from(i.to_le_bytes().to_vec());
262262
let output = CellOutput::new_builder()
263-
.capacity(capacity_bytes!(50_000).pack())
263+
.capacity(capacity_bytes!(50_000))
264264
.lock(secp_script.clone())
265265
.build();
266266
TransactionBuilder::default()
267267
.input(CellInput::new(OutPoint::null(), 0))
268268
.output(output.clone())
269269
.output(output)
270-
.output_data(data.pack())
271-
.output_data(data.pack())
270+
.output_data(&data)
271+
.output_data(data)
272272
.build()
273273
})
274274
.collect();
275275

276276
let genesis_block = BlockBuilder::default()
277-
.compact_target(difficulty_to_compact(U256::from(1000u64)).pack())
277+
.compact_target(difficulty_to_compact(U256::from(1000u64)))
278278
.dao(dao)
279279
.transaction(tx)
280280
.transactions(transactions)
@@ -315,11 +315,11 @@ pub fn create_secp_cellbase(shared: &Shared, parent: &HeaderView) -> Transaction
315315
builder
316316
.output(
317317
CellOutput::new_builder()
318-
.capacity(capacity.pack())
318+
.capacity(capacity)
319319
.lock(secp_script.clone())
320320
.build(),
321321
)
322-
.output_data(Bytes::new().pack())
322+
.output_data(Bytes::new())
323323
.build()
324324
}
325325
}
@@ -392,11 +392,11 @@ pub fn gen_secp_block(
392392
.transactions(transactions)
393393
.proposals(proposals)
394394
.parent_hash(p_block.hash())
395-
.number(number.pack())
396-
.timestamp(timestamp.pack())
397-
.compact_target(epoch.compact_target().pack())
398-
.epoch(epoch.number_with_fraction(number).pack())
399-
.nonce(random::<u128>().pack())
395+
.number(number)
396+
.timestamp(timestamp)
397+
.compact_target(epoch.compact_target())
398+
.epoch(epoch.number_with_fraction(number))
399+
.nonce(random::<u128>())
400400
.dao(dao)
401401
.build();
402402

@@ -409,11 +409,11 @@ fn create_transaction(parent_hash: &Byte32, lock: Script, dep: OutPoint) -> Tran
409409
TransactionBuilder::default()
410410
.output(
411411
CellOutput::new_builder()
412-
.capacity(capacity_bytes!(50_000).pack())
412+
.capacity(capacity_bytes!(50_000))
413413
.lock(lock)
414414
.build(),
415415
)
416-
.output_data(data.pack())
416+
.output_data(data)
417417
.input(CellInput::new(OutPoint::new(parent_hash.to_owned(), 0), 0))
418418
.cell_dep(CellDep::new_builder().out_point(dep).build())
419419
.build()
@@ -428,7 +428,7 @@ pub fn create_2out_transaction(
428428

429429
let cell_inputs = inputs.into_iter().map(|pts| CellInput::new(pts, 0));
430430
let cell_output = CellOutput::new_builder()
431-
.capacity(capacity_bytes!(50_000).pack())
431+
.capacity(capacity_bytes!(50_000))
432432
.lock(lock)
433433
.build();
434434

@@ -437,15 +437,15 @@ pub fn create_2out_transaction(
437437
let raw = TransactionBuilder::default()
438438
.output(cell_output.clone())
439439
.output(cell_output)
440-
.output_data(data.pack())
441-
.output_data(data.pack())
440+
.output_data(&data)
441+
.output_data(data)
442442
.inputs(cell_inputs)
443443
.cell_deps(cell_deps)
444444
.build();
445445

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

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

475475
raw.as_advanced_builder().set_witnesses(witnesses).build()
476476
}

block-filter/src/filter.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use ckb_store::{ChainDB, ChainStore};
66
use ckb_types::{
77
core::HeaderView,
88
packed::{Byte32, CellOutput, OutPoint},
9-
prelude::*,
109
utilities::{FilterDataProvider, build_filter_data},
1110
};
1211

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

@@ -158,7 +157,7 @@ impl BlockFilter {
158157
db_transaction
159158
.insert_block_filter(
160159
&header.hash(),
161-
&filter_data.pack(),
160+
&(filter_data.clone().into()),
162161
&parent_block_filter_hash,
163162
)
164163
.expect("insert_block_filter should be ok");

chain/src/init_load_unverified.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ckb_stop_handler::has_received_stop_signal;
99
use ckb_store::ChainStore;
1010
use ckb_types::core::{BlockNumber, BlockView};
1111
use ckb_types::packed;
12-
use ckb_types::prelude::{Entity, FromSliceShouldBeOk, Pack, Reader};
12+
use ckb_types::prelude::{Entity, FromSliceShouldBeOk, Reader};
1313
use std::cmp;
1414
use std::sync::Arc;
1515
use std::sync::atomic::AtomicBool;
@@ -34,7 +34,7 @@ impl InitLoadUnverified {
3434
}
3535

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

4040
// If a block has `COLUMN_NUMBER_HASH` but not `BlockExt`,

chain/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub mod verify;
2828
pub use chain_controller::ChainController;
2929
use ckb_logger::{error, info};
3030
use ckb_store::{ChainDB, ChainStore};
31-
use ckb_types::prelude::{Pack, Unpack};
3231
use ckb_types::{BlockNumberAndHash, H256};
3332
pub use init::{ChainServiceScope, build_chain_services, start_chain_services};
3433

@@ -89,11 +88,11 @@ impl From<LonelyBlock> for LonelyBlockHash {
8988
switch,
9089
verify_callback,
9190
} = val;
92-
let block_hash_h256: H256 = block.hash().unpack();
91+
let block_hash_h256: H256 = block.hash().into();
9392
let block_number: BlockNumber = block.number();
94-
let parent_hash_h256: H256 = block.parent_hash().unpack();
95-
let block_hash = block_hash_h256.pack();
96-
let parent_hash = parent_hash_h256.pack();
93+
let parent_hash_h256: H256 = block.parent_hash().into();
94+
let block_hash = block_hash_h256.into();
95+
let parent_hash = parent_hash_h256.into();
9796

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

0 commit comments

Comments
 (0)