diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 363178a7..8acf7dab 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -71,7 +71,7 @@ jobs: - name: Security Audit & Licenses run: | rustup toolchain install stable --profile minimal - cargo deny --version || cargo install cargo-deny@0.17.0 + cargo deny --version || cargo install cargo-deny@0.17.0 --locked make security-audit make check-crates make check-licenses diff --git a/Cargo.toml b/Cargo.toml index 74e706db..76bca3c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-sdk" -version = "4.4.0" +version = "5.0.0" authors = [ "Linfeng Qian ", "Nervos Core Dev ", @@ -32,25 +32,25 @@ dashmap = "5.4" dyn-clone = "1.0" async-trait = "0.1" -ckb-types = "0.202.0" -ckb-dao-utils = "0.202.0" -ckb-traits = "0.202.0" -ckb-jsonrpc-types = "0.202.0" -ckb-hash = "0.202.0" -ckb-resource = "0.202.0" +ckb-types = "1.0.0" +ckb-dao-utils = "1.0.0" +ckb-traits = "1.0.0" +ckb-jsonrpc-types = "1.0.0" +ckb-hash = "1.0.0" +ckb-resource = "1.0.0" ckb-system-scripts-v0_5_4 = { package="ckb-system-scripts", version="=0.5.4" } ckb-system-scripts-v0_6_0 = { package="ckb-system-scripts", version="=0.6.0" } -ckb-crypto = { version = "=0.202.0", features = ["secp"] } -ckb-script = "0.202.0" +ckb-crypto = "1.0.0" +ckb-script = "1.0.0" bitflags = "1.3.2" -sha3 = "0.10.1" +sha3 = "0.10.8" enum-repr-derive = "0.2.0" hex = "0.4" # for feature test rand = { version = "0.7.3", optional = true } -ckb-mock-tx-types = { version = "0.202.0" } -ckb-chain-spec = "0.202.0" +ckb-mock-tx-types = "1.0.0" +ckb-chain-spec = "1.0.0" sparse-merkle-tree = { version = "0.6", optional = true } async-iterator = "2.3.0" diff --git a/README.md b/README.md index aa3be085..fa685fba 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ These features allow for seamless interaction with CKB and facilitate the develo ```toml # Cargo.toml [dependencies] -ckb-sdk = "4.4.0" +ckb-sdk = "5" ``` ## Build @@ -124,7 +124,7 @@ let tx_dep_provider = DefaultTransactionDependencyProvider::new(ckb_rpc, 10); // Build the transaction let output = CellOutput::new_builder() .lock(Script::from(&receiver)) - .capacity(capacity.0.pack()) + .capacity(capacity.0) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); let (_tx, _) = builder diff --git a/examples/chain_transfer_sighash.rs b/examples/chain_transfer_sighash.rs index 5b473fbc..c18f45c6 100644 --- a/examples/chain_transfer_sighash.rs +++ b/examples/chain_transfer_sighash.rs @@ -74,7 +74,7 @@ fn main() -> Result<(), Box> { let hash160 = blake2b_256(&pubkey.serialize()[..])[0..20].to_vec(); Script::new_builder() .code_hash(SIGHASH_TYPE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(Bytes::from(hash160).pack()) .build() }; @@ -84,7 +84,7 @@ fn main() -> Result<(), Box> { let hash160 = blake2b_256(&pubkey.serialize()[..])[0..20].to_vec(); Script::new_builder() .code_hash(SIGHASH_TYPE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(Bytes::from(hash160).pack()) .build() }; @@ -177,7 +177,7 @@ fn build_transfer_tx( // Build the transaction let output = CellOutput::new_builder() .lock(Script::from(receiver)) - .capacity(capacity.pack()) + .capacity(capacity) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); let (tx, still_locked_groups) = builder.build_unlocked( diff --git a/examples/deploy_script_with_type_id.rs b/examples/deploy_script_with_type_id.rs index 25b7a2f5..f51ac772 100644 --- a/examples/deploy_script_with_type_id.rs +++ b/examples/deploy_script_with_type_id.rs @@ -67,7 +67,7 @@ fn build_output_and_data(deployer: &Address) -> (CellOutput, Bytes) { let type_script = ScriptId::new_type(constants::TYPE_ID_CODE_HASH.clone()).dummy_type_id_script(); let dummy_output = CellOutput::new_builder() - .lock(deployer.into()) + .lock(deployer) .type_(Some(type_script).pack()) .build(); let required_capacity = dummy_output diff --git a/examples/transfer_from_multisig.rs b/examples/transfer_from_multisig.rs index 81c7c664..9ddd9908 100644 --- a/examples/transfer_from_multisig.rs +++ b/examples/transfer_from_multisig.rs @@ -228,7 +228,7 @@ fn build_transfer_tx( // Build CapacityBalancer let sender = Script::new_builder() .code_hash(MultisigScript::V2.script_id().code_hash.pack()) - .hash_type(MultisigScript::V2.script_id().hash_type.into()) + .hash_type(MultisigScript::V2.script_id().hash_type) .args(Bytes::from(multisig_config.hash160().as_bytes().to_vec()).pack()) .build(); let sender_addr = Address::new(args.receiver.network(), sender.clone().into(), true); @@ -254,7 +254,7 @@ fn build_transfer_tx( let unlockers = build_multisig_unlockers(Vec::new(), multisig_config.clone()); let output = CellOutput::new_builder() .lock(Script::from(&args.receiver)) - .capacity(args.capacity.0.pack()) + .capacity(args.capacity.0) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); let tx = builder.build_balanced( diff --git a/examples/transfer_from_omnilock.rs b/examples/transfer_from_omnilock.rs index b9a0b7cd..6ddcf636 100644 --- a/examples/transfer_from_omnilock.rs +++ b/examples/transfer_from_omnilock.rs @@ -266,7 +266,7 @@ fn build_transfer_tx( // Build CapacityBalancer let sender = Script::new_builder() .code_hash(cell.type_hash.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(omnilock_config.build_args().pack()) .build(); let placeholder_witness = omnilock_config.placeholder_witness(OmniUnlockMode::Normal)?; @@ -290,7 +290,7 @@ fn build_transfer_tx( let unlockers = build_omnilock_unlockers(Vec::new(), omnilock_config.clone(), cell.type_hash); let output = CellOutput::new_builder() .lock(Script::from(&args.receiver)) - .capacity(args.capacity.0.pack()) + .capacity(args.capacity.0) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); diff --git a/examples/transfer_from_omnilock_ethereum.rs b/examples/transfer_from_omnilock_ethereum.rs index 52543ac8..a29ee0f7 100644 --- a/examples/transfer_from_omnilock_ethereum.rs +++ b/examples/transfer_from_omnilock_ethereum.rs @@ -273,7 +273,7 @@ fn build_transfer_tx( // Build CapacityBalancer let sender = Script::new_builder() .code_hash(cell.type_hash.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(omnilock_config.build_args().pack()) .build(); let placeholder_witness = omnilock_config.placeholder_witness(OmniUnlockMode::Normal)?; @@ -297,7 +297,7 @@ fn build_transfer_tx( let unlockers = build_omnilock_unlockers(Vec::new(), omnilock_config.clone(), cell.type_hash); let output = CellOutput::new_builder() .lock(Script::from(&args.receiver)) - .capacity(args.capacity.0.pack()) + .capacity(args.capacity.0) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); diff --git a/examples/transfer_from_omnilock_multisig.rs b/examples/transfer_from_omnilock_multisig.rs index fb8e140e..a309f5b5 100644 --- a/examples/transfer_from_omnilock_multisig.rs +++ b/examples/transfer_from_omnilock_multisig.rs @@ -325,7 +325,7 @@ fn build_transfer_tx( // Build CapacityBalancer let sender = Script::new_builder() .code_hash(cell.type_hash.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(omnilock_config.build_args().pack()) .build(); let placeholder_witness = omnilock_config.placeholder_witness(OmniUnlockMode::Normal)?; @@ -349,7 +349,7 @@ fn build_transfer_tx( let unlockers = build_omnilock_unlockers(Vec::new(), omnilock_config.clone(), cell.type_hash); let output = CellOutput::new_builder() .lock(Script::from(&args.receiver)) - .capacity(args.capacity.0.pack()) + .capacity(args.capacity.0) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); diff --git a/examples/transfer_from_sighash.rs b/examples/transfer_from_sighash.rs index 06edc3d4..a0d3f93e 100644 --- a/examples/transfer_from_sighash.rs +++ b/examples/transfer_from_sighash.rs @@ -59,7 +59,7 @@ fn main() -> Result<(), Box> { let hash160 = blake2b_256(&pubkey.serialize()[..])[0..20].to_vec(); Script::new_builder() .code_hash(SIGHASH_TYPE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(Bytes::from(hash160).pack()) .build() }; @@ -116,7 +116,7 @@ fn build_transfer_tx( // Build the transaction let output = CellOutput::new_builder() .lock(Script::from(&args.receiver)) - .capacity(args.capacity.0.pack()) + .capacity(args.capacity.0) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); let (tx, still_locked_groups) = builder.build_unlocked( diff --git a/src/test_util.rs b/src/test_util.rs index b9dc5028..ae593948 100644 --- a/src/test_util.rs +++ b/src/test_util.rs @@ -129,7 +129,7 @@ impl Context { { let cell_dep = CellDep::new_builder() .out_point(OutPoint::new(tx.hash(), idx as u32)) - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .build(); ctx.add_cell_dep(cell_dep, output, data.raw_data(), Some(block_hash.clone())); } @@ -146,7 +146,7 @@ impl Context { let group_out_point = ctx.deploy_cell(out_points.as_bytes()); let cell_dep = CellDep::new_builder() .out_point(group_out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let script_id = ScriptId::new_data1(data_hash); ctx.add_cell_dep_map(script_id, cell_dep); @@ -204,7 +204,7 @@ impl Context { .as_u64() }); let output = CellOutput::new_builder() - .capacity(capacity.pack()) + .capacity(capacity) .lock(lock_script) .build(); self.add_live_cell(input, output, Bytes::default(), None) @@ -216,7 +216,7 @@ impl Context { let out_point = random_out_point(); let cell_dep = CellDep::new_builder() .out_point(out_point.clone()) - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .build(); let output = CellOutput::default(); self.add_cell_dep(cell_dep, output, data, None); @@ -374,7 +374,7 @@ impl Context { ckb2023: CKB2023::new_dev_default(), }) .build(); - let tip = HeaderBuilder::default().number(0.pack()).build(); + let tip = HeaderBuilder::default().number(0).build(); let tx_verify_env = TxVerifyEnv::new_submit(&tip); let verifier = TransactionScriptsVerifier::new( diff --git a/src/tests/ckb_indexer_rpc.rs b/src/tests/ckb_indexer_rpc.rs index 36873ae3..7a8771bb 100644 --- a/src/tests/ckb_indexer_rpc.rs +++ b/src/tests/ckb_indexer_rpc.rs @@ -37,7 +37,7 @@ fn test_cells_search_mode_default_partitial() { // default with partitial args let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); @@ -60,7 +60,7 @@ fn test_cells_search_mode_prefix_partitial() { // prefix with partitial args let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); @@ -82,7 +82,7 @@ fn test_cells_search_mode_exact_partitial() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); // exact with partitial args @@ -104,7 +104,7 @@ fn test_cells_search_mode_exact() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[..].pack()) .build(); @@ -127,7 +127,7 @@ fn test_get_transactions_search_mode_default() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); @@ -150,7 +150,7 @@ fn test_get_transactions_search_mode_prefix_partial() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); @@ -172,7 +172,7 @@ fn test_get_transactions_search_mode_exact_partitial() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); @@ -195,7 +195,7 @@ fn test_get_transactions_search_mode_exact_full() { // exact search let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[..].pack()) .build(); @@ -217,7 +217,7 @@ fn test_get_cells_capacity_search_mode_default() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); @@ -238,7 +238,7 @@ fn test_get_cells_capacity_search_mode_prefix_partial() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); @@ -259,7 +259,7 @@ fn test_get_cells_capacity_search_mode_exact_partital() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[0..2].pack()) .build(); // exact with partitial args @@ -280,7 +280,7 @@ fn test_get_cells_capacity_search_mode_exact() { let block_range = Some(ValueRangeOption::new(0, 1)); let script = ckb_types::packed::Script::new_builder() .code_hash(CODE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(ARGS[..].pack()) .build(); diff --git a/src/tests/cycle.rs b/src/tests/cycle.rs index 355a3e94..e9b779f8 100644 --- a/src/tests/cycle.rs +++ b/src/tests/cycle.rs @@ -71,7 +71,7 @@ fn build_script(loops: u64) -> Script { let cycle_data_hash = H256::from(blake2b_256(CYCLE_BIN)); Script::new_builder() .code_hash(cycle_data_hash.pack()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .args(build_args(loops).pack()) .build() } @@ -107,7 +107,7 @@ fn test_change_enough(loops: u64) { ))); let output = CellOutput::new_builder() - .capacity((140 * ONE_CKB).pack()) + .capacity(140 * ONE_CKB) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output.clone(), Bytes::default())]); @@ -153,7 +153,7 @@ fn vsize_big_and_fee_enough() { ))); let output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output.clone(), Bytes::default())]); @@ -199,7 +199,7 @@ fn vsize_big_and_fee_not_enough() { ))); let output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); @@ -235,7 +235,7 @@ fn vsize_big_and_can_find_more_capacity() { ))); let output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output.clone(), Bytes::default())]); @@ -325,7 +325,7 @@ fn vsize_big_and_cannot_find_more_capacity() { ))); let output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output, Bytes::default())]); diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 67e3610a..3f7b7991 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -66,7 +66,7 @@ const ALWAYS_SUCCESS_BIN: &[u8] = include_bytes!("../test-data/always_success"); fn build_sighash_script(args: H160) -> Script { Script::new_builder() .code_hash(SIGHASH_TYPE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(Bytes::from(args.0.to_vec()).pack()) .build() } @@ -83,7 +83,7 @@ fn build_multisig_script(cfg: &MultisigConfig) -> Script { .script_id(); Script::new_builder() .code_hash(multisig_script.code_hash.pack()) - .hash_type(multisig_script.hash_type.into()) + .hash_type(multisig_script.hash_type) .args(Bytes::from(cfg.hash160().0.to_vec()).pack()) .build() } @@ -91,7 +91,7 @@ fn build_multisig_script(cfg: &MultisigConfig) -> Script { fn build_dao_script() -> Script { Script::new_builder() .code_hash(DAO_TYPE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build() } @@ -103,7 +103,7 @@ fn build_cheque_script(sender: &Script, receiver: &Script, cheque_data_hash: H25 script_args[20..40].copy_from_slice(&sender_script_hash.as_slice()[0..20]); Script::new_builder() .code_hash(cheque_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(Bytes::from(script_args).pack()) .build() } @@ -157,7 +157,7 @@ fn test_transfer_from_sighash() { ); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output.clone(), Bytes::default())]); @@ -208,7 +208,7 @@ fn test_transfer_capacity_overflow() { let large_amount: u64 = u64::MAX; let output = CellOutput::new_builder() - .capacity((large_amount).pack()) + .capacity(large_amount) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output.clone(), Bytes::default())]); @@ -251,7 +251,7 @@ fn test_transfer_from_multisig() { ); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output.clone(), Bytes::default())]); @@ -301,7 +301,7 @@ fn test_transfer_from_acp() { let data_hash = H256::from(blake2b_256(ACP_BIN)); let sender = Script::new_builder() .code_hash(data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(Bytes::from(ACCOUNT1_ARG.0.to_vec()).pack()) .build(); let receiver = build_sighash_script(ACCOUNT2_ARG); @@ -315,7 +315,7 @@ fn test_transfer_from_acp() { ); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(receiver) .build(); let builder = CapacityTransferBuilder::new(vec![(output.clone(), Bytes::default())]); @@ -363,7 +363,7 @@ fn test_transfer_to_acp() { let sender = build_sighash_script(ACCOUNT1_ARG); let receiver = Script::new_builder() .code_hash(data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(Bytes::from(ACCOUNT2_ARG.0.to_vec()).pack()) .build(); let ctx = init_context( @@ -406,15 +406,15 @@ fn test_transfer_to_acp() { assert_eq!(tx.inputs().len(), 3); let input_cells = [ CellOutput::new_builder() - .capacity((99 * ONE_CKB).pack()) + .capacity(99 * ONE_CKB) .lock(receiver.clone()) .build(), CellOutput::new_builder() - .capacity((100 * ONE_CKB).pack()) + .capacity(100 * ONE_CKB) .lock(sender.clone()) .build(), CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(sender.clone()) .build(), ]; @@ -423,7 +423,7 @@ fn test_transfer_to_acp() { } assert_eq!(tx.outputs().len(), 2); let acp_output = CellOutput::new_builder() - .capacity(((99 + 150) * ONE_CKB).pack()) + .capacity((99 + 150) * ONE_CKB) .lock(receiver) .build(); assert_eq!(tx.output(0).unwrap(), acp_output); @@ -449,7 +449,7 @@ fn test_cheque_claim() { let cheque_script = build_cheque_script(&sender, &receiver, cheque_data_hash.clone()); let type_script = Script::new_builder() .code_hash(sudt_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(Bytes::from(vec![9u8; 32]).pack()) .build(); let mut ctx = init_context( @@ -462,7 +462,7 @@ fn test_cheque_claim() { let receiver_input = CellInput::new(random_out_point(), 0); let receiver_output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(receiver.clone()) .type_(Some(type_script.clone()).pack()) .build(); @@ -476,7 +476,7 @@ fn test_cheque_claim() { let cheque_input = CellInput::new(random_out_point(), 0); let cheque_output = CellOutput::new_builder() - .capacity((220 * ONE_CKB).pack()) + .capacity(220 * ONE_CKB) .lock(cheque_script) .type_(Some(type_script).pack()) .build(); @@ -522,7 +522,7 @@ fn test_cheque_claim() { cheque_output, receiver_output.clone(), CellOutput::new_builder() - .capacity((100 * ONE_CKB).pack()) + .capacity(100 * ONE_CKB) .lock(receiver.clone()) .build(), ]; @@ -532,7 +532,7 @@ fn test_cheque_claim() { assert_eq!(tx.outputs().len(), 3); assert_eq!(tx.output(0).unwrap(), receiver_output); let sender_output = CellOutput::new_builder() - .capacity((220 * ONE_CKB).pack()) + .capacity(220 * ONE_CKB) .lock(sender) .build(); assert_eq!(tx.output(1).unwrap(), sender_output); @@ -569,7 +569,7 @@ fn test_cheque_withdraw() { let cheque_script = build_cheque_script(&sender, &receiver, cheque_data_hash.clone()); let type_script = Script::new_builder() .code_hash(sudt_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(Bytes::from(vec![9u8; 32]).pack()) .build(); let mut ctx = init_context( @@ -583,7 +583,7 @@ fn test_cheque_withdraw() { let cheque_out_point = random_out_point(); let cheque_input = CellInput::new(cheque_out_point.clone(), CHEQUE_CELL_SINCE); let cheque_output = CellOutput::new_builder() - .capacity((220 * ONE_CKB).pack()) + .capacity(220 * ONE_CKB) .lock(cheque_script) .type_(Some(type_script).pack()) .build(); @@ -624,7 +624,7 @@ fn test_cheque_withdraw() { let input_cells = [ cheque_output.clone(), CellOutput::new_builder() - .capacity((100 * ONE_CKB).pack()) + .capacity(100 * ONE_CKB) .lock(sender.clone()) .build(), ]; @@ -697,7 +697,7 @@ fn test_dao_deposit() { } assert_eq!(tx.outputs().len(), 2); let deposit_output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(sender.clone()) .type_(Some(build_dao_script()).pack()) .build(); @@ -738,13 +738,13 @@ fn test_dao_prepare() { let deposit_input = CellInput::new(random_out_point(), 0); let deposit_output = CellOutput::new_builder() - .capacity((220 * ONE_CKB).pack()) + .capacity(220 * ONE_CKB) .lock(sender.clone()) .type_(Some(build_dao_script()).pack()) .build(); let deposit_header = HeaderBuilder::default() - .epoch(deposit_point.full_value().pack()) - .number(deposit_number.pack()) + .epoch(deposit_point.full_value()) + .number(deposit_number) .build(); let deposit_block_hash = deposit_header.hash(); ctx.add_live_cell( @@ -828,8 +828,8 @@ fn test_dao_withdraw() { let prepare_point = EpochNumberWithFraction::new(prepare_point.0, prepare_point.1, prepare_point.2); let deposit_header = HeaderBuilder::default() - .epoch(deposit_point.full_value().pack()) - .number(deposit_number.pack()) + .epoch(deposit_point.full_value()) + .number(deposit_number) .dao(pack_dao_data( 10_000_000_000_123_456, Default::default(), @@ -838,8 +838,8 @@ fn test_dao_withdraw() { )) .build(); let prepare_header = HeaderBuilder::default() - .epoch(prepare_point.full_value().pack()) - .number(prepare_number.pack()) + .epoch(prepare_point.full_value()) + .number(prepare_number) .dao(pack_dao_data( 10_000_000_001_123_456, Default::default(), @@ -859,7 +859,7 @@ fn test_dao_withdraw() { let prepare_out_point = random_out_point(); let prepare_input = CellInput::new(prepare_out_point.clone(), since.value()); let prepare_output = CellOutput::new_builder() - .capacity((220 * ONE_CKB).pack()) + .capacity(220 * ONE_CKB) .lock(sender.clone()) .type_(Some(build_dao_script()).pack()) .build(); @@ -921,7 +921,7 @@ fn test_dao_withdraw() { ); let expected_output = prepare_output .as_builder() - .capacity(expected_capacity.pack()) + .capacity(expected_capacity) .type_(ScriptOpt::default()) .build(); assert_eq!(tx.output(0).unwrap(), expected_output); @@ -998,7 +998,7 @@ fn test_udt_issue() { assert_eq!(tx.outputs().len(), 2); let type_script = Script::new_builder() .code_hash(sudt_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(owner.calc_script_hash().as_bytes().pack()) .build(); let output = CellOutput::new_builder() @@ -1009,10 +1009,7 @@ fn test_udt_issue() { .occupied_capacity(Capacity::bytes(16).unwrap()) .unwrap() .as_u64(); - let output = output - .as_builder() - .capacity(occupied_capacity.pack()) - .build(); + let output = output.as_builder().capacity(occupied_capacity).build(); assert_eq!(tx.output(0).unwrap(), output); assert_eq!(tx.output(1).unwrap().lock(), owner); let expected_outputs_data = vec![ @@ -1042,7 +1039,7 @@ fn test_udt_transfer() { let owner = build_sighash_script(H160::default()); let type_script = Script::new_builder() .code_hash(sudt_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(owner.calc_script_hash().as_bytes().pack()) .build(); let mut ctx = init_context( @@ -1055,7 +1052,7 @@ fn test_udt_transfer() { let sender_input = CellInput::new(random_out_point(), 0); let sender_output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(sender.clone()) .type_(Some(type_script.clone()).pack()) .build(); @@ -1064,12 +1061,12 @@ fn test_udt_transfer() { let receiver_acp_lock = Script::new_builder() .code_hash(acp_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(Bytes::from(ACCOUNT2_ARG.0.to_vec()).pack()) .build(); let receiver_input = CellInput::new(random_out_point(), 0); let receiver_output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(receiver_acp_lock.clone()) .type_(Some(type_script.clone()).pack()) .build(); diff --git a/src/tests/omni_lock.rs b/src/tests/omni_lock.rs index f5dbdd70..fc4205d5 100644 --- a/src/tests/omni_lock.rs +++ b/src/tests/omni_lock.rs @@ -45,7 +45,7 @@ fn build_omnilock_script(cfg: &OmniLockConfig) -> Script { let omnilock_data_hash = H256::from(blake2b_256(OMNILOCK_BIN)); Script::new_builder() .code_hash(omnilock_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(cfg.build_args().pack()) .build() } @@ -106,7 +106,7 @@ fn test_omnilock_simple_hash(cfg: OmniLockConfig) { ); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(receiver) .build(); let builder = @@ -220,7 +220,7 @@ fn test_omnilock_simple_hash_rc_input(mut cfg: OmniLockConfig) { } let output = CellOutput::new_builder() - .capacity((110 * ONE_CKB).pack()) + .capacity(110 * ONE_CKB) .lock(receiver) .build(); let builder = OmniLockTransferBuilder::new( @@ -412,7 +412,7 @@ fn test_omnilock_simple_hash_rc(mut cfg: OmniLockConfig, unlock_mode: OmniUnlock } let output = CellOutput::new_builder() - .capacity((110 * ONE_CKB).pack()) + .capacity(110 * ONE_CKB) .lock(receiver) .build(); let builder = OmniLockTransferBuilder::new( @@ -522,7 +522,7 @@ fn test_omnilock_simple_hash_rc2(mut cfg: OmniLockConfig) { } let output = CellOutput::new_builder() - .capacity((110 * ONE_CKB).pack()) + .capacity(110 * ONE_CKB) .lock(receiver) .build(); let builder = OmniLockTransferBuilder::new( @@ -602,7 +602,7 @@ fn test_omnilock_transfer_from_multisig() { ); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(receiver) .build(); let builder = @@ -696,7 +696,7 @@ fn test_omnilock_transfer_from_multisig_wl_commnon(unlock_mode: OmniUnlockMode) let receiver = build_sighash_script(ACCOUNT2_ARG); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(receiver) .build(); let builder = OmniLockTransferBuilder::new( @@ -782,7 +782,7 @@ fn test_omnilock_transfer_from_ownerlock() { ); let output = CellOutput::new_builder() - .capacity((110 * ONE_CKB).pack()) + .capacity(110 * ONE_CKB) .lock(receiver.clone()) .build(); let builder = @@ -879,7 +879,7 @@ fn test_omnilock_transfer_from_ownerlock_wl_admin() { } let output = CellOutput::new_builder() - .capacity((110 * ONE_CKB).pack()) + .capacity(110 * ONE_CKB) .lock(receiver.clone()) .build(); let builder = OmniLockTransferBuilder::new( @@ -988,7 +988,7 @@ fn test_omnilock_transfer_from_acp() { ], ); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(receiver) .build(); @@ -1091,7 +1091,7 @@ fn test_omnilock_transfer_to_acp() { assert_eq!(tx.cell_deps().len(), 2); assert_eq!(tx.inputs().len(), 2); let acp_output = CellOutput::new_builder() - .capacity(((61 + 10) * ONE_CKB).pack()) + .capacity((61 + 10) * ONE_CKB) .lock(receiver) .build(); assert_eq!(tx.outputs().len(), 2); @@ -1140,7 +1140,7 @@ fn test_omnilock_udt_transfer() { let owner = build_sighash_script(H160::default()); let type_script = Script::new_builder() .code_hash(sudt_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(owner.calc_script_hash().as_bytes().pack()) .build(); let mut ctx = init_context( @@ -1153,7 +1153,7 @@ fn test_omnilock_udt_transfer() { let sender_input = CellInput::new(random_out_point(), 0); let sender_output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(sender.clone()) .type_(Some(type_script.clone()).pack()) .build(); @@ -1163,7 +1163,7 @@ fn test_omnilock_udt_transfer() { let receiver_acp_lock = build_omnilock_script(&receiver_cfg); let receiver_input = CellInput::new(random_out_point(), 0); let receiver_output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(receiver_acp_lock.clone()) .type_(Some(type_script.clone()).pack()) .build(); @@ -1258,13 +1258,13 @@ fn test_omnilock_simple_hash_timelock(mut cfg: OmniLockConfig) { let prepare_out_point = random_out_point(); let prepare_input = CellInput::new(prepare_out_point, since.value()); let prepare_output = CellOutput::new_builder() - .capacity((300 * ONE_CKB + 1000).pack()) + .capacity(300 * ONE_CKB + 1000) .lock(sender.clone()) .build(); ctx.add_live_cell(prepare_input, prepare_output, Bytes::default(), None); let output = CellOutput::new_builder() - .capacity((200 * ONE_CKB).pack()) + .capacity(200 * ONE_CKB) .lock(receiver) .build(); let builder = @@ -1318,7 +1318,7 @@ fn build_sudt_script(omnilock_hash: Byte32) -> Script { let sudt_data_hash = H256::from(blake2b_256(SUDT_BIN)); Script::new_builder() .code_hash(sudt_data_hash.pack()) - .hash_type(ScriptHashType::Data1.into()) + .hash_type(ScriptHashType::Data1) .args(omnilock_hash.as_bytes().pack()) .build() } @@ -1330,7 +1330,7 @@ fn build_info_cell_type_script() -> (Script, H256) { rng.fill(&mut args[..]); let script = Script::new_builder() .code_hash(data_hash.pack()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .args(Bytes::from(args).pack()) .build(); let script_hash = script.calc_script_hash(); @@ -1371,7 +1371,7 @@ fn test_omnilock_sudt_supply() { ); let input = CellInput::new(random_out_point(), 0); let output = CellOutput::new_builder() - .capacity((1000 * ONE_CKB + 1000).pack()) + .capacity(1000 * ONE_CKB + 1000) .lock(sender.clone()) .type_(Some(info_cell_type_script.clone()).pack()) .build(); @@ -1381,14 +1381,14 @@ fn test_omnilock_sudt_supply() { info_cell.current_supply = 3000u128; let output_supply_data = info_cell.pack(); let output_supply = CellOutput::new_builder() - .capacity(((1000 - 16) * ONE_CKB).pack()) + .capacity((1000 - 16) * ONE_CKB) .lock(sender.clone()) .type_(Some(info_cell_type_script).pack()) .build(); let mint_receiver = build_sighash_script(ACCOUNT1_ARG); let mint_output = CellOutput::new_builder() - .capacity((16 * ONE_CKB).pack()) + .capacity(16 * ONE_CKB) .type_(Some(sudt_script).pack()) .lock(mint_receiver.clone()) .build(); diff --git a/src/tests/omni_lock_util.rs b/src/tests/omni_lock_util.rs index 1c2632fc..1f638055 100644 --- a/src/tests/omni_lock_util.rs +++ b/src/tests/omni_lock_util.rs @@ -38,7 +38,7 @@ pub fn build_always_success_script() -> Script { let data_hash = CellOutput::calc_data_hash(ALWAYS_SUCCESS_BIN); Script::new_builder() .code_hash(data_hash) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build() } // @@ -76,7 +76,7 @@ fn build_script( Script::new_builder() .args(args.pack()) .code_hash(hash.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build() } }; @@ -85,7 +85,7 @@ fn build_script( // it not needed to set "type script" when is_type is false let capacity = bin.len() as u64 * ONE_CKB; let output = CellOutput::new_builder() - .capacity(capacity.pack()) + .capacity(capacity) .lock(lock_script) .type_(Some(type_script_in_code.clone()).pack()) .build(); @@ -96,7 +96,7 @@ fn build_script( } else { let cell_dep = CellDep::new_builder() .out_point(out_point.clone()) - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .build(); ctx.add_cell_dep(cell_dep, output, bin.clone(), None); } @@ -117,7 +117,7 @@ fn build_script( Script::new_builder() .args(args.pack()) .code_hash(code_hash.pack()) - .hash_type(hash_type.into()) + .hash_type(hash_type) .build() } diff --git a/src/tests/transaction/sighash.rs b/src/tests/transaction/sighash.rs index a2c6ca65..be2be0bf 100644 --- a/src/tests/transaction/sighash.rs +++ b/src/tests/transaction/sighash.rs @@ -30,7 +30,7 @@ fn test_transfer_from_sighash() { let network_info = NetworkInfo::testnet(); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(receiver) .build(); let configuration = diff --git a/src/tests/transaction/typeid.rs b/src/tests/transaction/typeid.rs index d29cc9aa..1f0a2deb 100644 --- a/src/tests/transaction/typeid.rs +++ b/src/tests/transaction/typeid.rs @@ -22,7 +22,7 @@ fn test_deploy_id() { ScriptId::new_type(constants::TYPE_ID_CODE_HASH.clone()).dummy_type_id_script(); let output = CellOutput::new_builder() - .capacity((120 * ONE_CKB).pack()) + .capacity(120 * ONE_CKB) .lock(sender.clone()) .type_(Some(type_script).pack()) .build(); diff --git a/src/traits/default_impls.rs b/src/traits/default_impls.rs index 3be3a229..d22d22b6 100644 --- a/src/traits/default_impls.rs +++ b/src/traits/default_impls.rs @@ -158,7 +158,7 @@ impl DefaultCellDepResolver { let sighash_dep = CellDep::new_builder() .out_point(out_points[SIGHASH_GROUP_OUTPUT_LOC.0][SIGHASH_GROUP_OUTPUT_LOC.1].clone()) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let multisig_legacy_dep = CellDep::new_builder() @@ -166,7 +166,7 @@ impl DefaultCellDepResolver { out_points[MULTISIG_LEGACY_GROUP_OUTPUT_LOC.0][MULTISIG_LEGACY_GROUP_OUTPUT_LOC.1] .clone(), ) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); let dao_dep = CellDep::new_builder() @@ -195,7 +195,7 @@ impl DefaultCellDepResolver { { let multisig_v2_dep = CellDep::new_builder() .out_point(OutPoint::new(v2_dep_hash.pack(), v2_dep_index)) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); items.insert( diff --git a/src/transaction/builder/mod.rs b/src/transaction/builder/mod.rs index 0c9b24a2..34da3fca 100644 --- a/src/transaction/builder/mod.rs +++ b/src/transaction/builder/mod.rs @@ -11,7 +11,7 @@ use crate::{ use ckb_types::{ core::{Capacity, TransactionView}, packed::{self, Byte32, CellOutput, Script}, - prelude::{Builder, Entity, Pack, Unpack}, + prelude::{Builder, Entity, Unpack}, }; pub mod fee_calculator; pub mod simple; @@ -134,7 +134,7 @@ impl ChangeBuilder for DefaultChangeBuilder<'_> { .unwrap() .clone() .as_builder() - .capacity(change_capacity.pack()) + .capacity(change_capacity) .build(); tx.set_output(tx.outputs.len() - 1, change_output); tx.build() diff --git a/src/transaction/builder/sudt.rs b/src/transaction/builder/sudt.rs index 34251437..54208eca 100644 --- a/src/transaction/builder/sudt.rs +++ b/src/transaction/builder/sudt.rs @@ -317,7 +317,7 @@ fn build_sudt_type_script( Script::new_builder() .code_hash(code_hash.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .args(sudt_owner_lock_script.calc_script_hash().as_bytes().pack()) .build() } diff --git a/src/transaction/handler/multisig.rs b/src/transaction/handler/multisig.rs index 3c654891..0730def6 100644 --- a/src/transaction/handler/multisig.rs +++ b/src/transaction/handler/multisig.rs @@ -106,12 +106,12 @@ impl ScriptHandler for Secp256k1Blake160MultisigAllScriptHandler { )))?; let out_point = OutPoint::new_builder() .tx_hash(dep_group.0.pack()) - .index(dep_group.1.pack()) + .index(dep_group.1) .build(); let cell_dep = CellDep::new_builder() .out_point(out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); self.cell_deps.push(cell_dep); Ok(()) @@ -127,12 +127,12 @@ impl ScriptHandler for Secp256k1Blake160MultisigAllScriptHandler { )))?; let out_point = OutPoint::new_builder() .tx_hash(dep_group.0.pack()) - .index(dep_group.1.pack()) + .index(dep_group.1) .build(); let cell_dep = CellDep::new_builder() .out_point(out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); self.cell_deps.push(cell_dep); Ok(()) diff --git a/src/transaction/handler/sighash.rs b/src/transaction/handler/sighash.rs index c0a4e75a..ee69dabf 100644 --- a/src/transaction/handler/sighash.rs +++ b/src/transaction/handler/sighash.rs @@ -87,7 +87,7 @@ impl ScriptHandler for Secp256k1Blake160SighashAllScriptHandler { h256!("0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c") .pack(), ) - .index(0u32.pack()) + .index(0u32) .build() } else if network.network_type == NetworkType::Testnet { OutPoint::new_builder() @@ -95,7 +95,7 @@ impl ScriptHandler for Secp256k1Blake160SighashAllScriptHandler { h256!("0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37") .pack(), ) - .index(0u32.pack()) + .index(0u32) .build() } else if network.network_type == NetworkType::Preview { OutPoint::new_builder() @@ -103,7 +103,7 @@ impl ScriptHandler for Secp256k1Blake160SighashAllScriptHandler { h256!("0x0fab65924f2784f17ad7f86d6aef4b04ca1ca237102a68961594acebc5c77816") .pack(), ) - .index(0u32.pack()) + .index(0u32) .build() } else { return Err(TxBuilderError::UnsupportedNetworkType(network.network_type)); @@ -111,7 +111,7 @@ impl ScriptHandler for Secp256k1Blake160SighashAllScriptHandler { let cell_dep = CellDep::new_builder() .out_point(out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); self.cell_deps.push(cell_dep); Ok(()) @@ -123,7 +123,7 @@ impl ScriptHandler for Secp256k1Blake160SighashAllScriptHandler { h256!("0x71a7ba8fc96349fea0ed3a5c47992e3b4084b031a42264a018e0072e8172e46c") .pack(), ) - .index(0u32.pack()) + .index(0u32) .build() } else if network.network_type == NetworkType::Testnet { OutPoint::new_builder() @@ -131,7 +131,7 @@ impl ScriptHandler for Secp256k1Blake160SighashAllScriptHandler { h256!("0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37") .pack(), ) - .index(0u32.pack()) + .index(0u32) .build() } else if network.network_type == NetworkType::Preview { OutPoint::new_builder() @@ -139,7 +139,7 @@ impl ScriptHandler for Secp256k1Blake160SighashAllScriptHandler { h256!("0x0fab65924f2784f17ad7f86d6aef4b04ca1ca237102a68961594acebc5c77816") .pack(), ) - .index(0u32.pack()) + .index(0u32) .build() } else { return Err(TxBuilderError::UnsupportedNetworkType(network.network_type)); @@ -147,7 +147,7 @@ impl ScriptHandler for Secp256k1Blake160SighashAllScriptHandler { let cell_dep = CellDep::new_builder() .out_point(out_point) - .dep_type(DepType::DepGroup.into()) + .dep_type(DepType::DepGroup) .build(); self.cell_deps.push(cell_dep); Ok(()) diff --git a/src/transaction/handler/sudt.rs b/src/transaction/handler/sudt.rs index cdad9020..c0515752 100644 --- a/src/transaction/handler/sudt.rs +++ b/src/transaction/handler/sudt.rs @@ -31,7 +31,7 @@ impl SudtHandler { h256!("0xc7813f6a415144643970c2e88e0bb6ca6a8edc5dd7c1022746f628284a9936d5") .pack(), ) - .index(0u32.pack()) + .index(0u32) .build(), ScriptId::new_type(h256!( "0x5e7a36a77e68eecc013dfa2fe6a23f3b6c344b04005808694ae6dd45eea4cfd5" @@ -44,7 +44,7 @@ impl SudtHandler { h256!("0xe12877ebd2c3c364dc46c5c992bcfaf4fee33fa13eebdf82c591fc9825aab769") .pack(), ) - .index(0u32.pack()) + .index(0u32) .build(), ScriptId::new_type(h256!( "0xc5e5dcf215925f7ef4dfaf5f4b4f105bc321c02776d6e7d52a1db3fcd9d011a4" @@ -56,7 +56,7 @@ impl SudtHandler { let cell_dep = CellDep::new_builder() .out_point(out_point) - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .build(); Ok(Self { diff --git a/src/transaction/input/transaction_input.rs b/src/transaction/input/transaction_input.rs index 9f2bb3c1..54470c65 100644 --- a/src/transaction/input/transaction_input.rs +++ b/src/transaction/input/transaction_input.rs @@ -1,6 +1,6 @@ use ckb_types::{ packed, - prelude::{Builder, Entity, Pack}, + prelude::{Builder, Entity}, }; use crate::traits::LiveCell; @@ -23,7 +23,7 @@ impl TransactionInput { pub fn cell_input(&self) -> packed::CellInput { packed::CellInput::new_builder() - .since(self.since.pack()) + .since(self.since) .previous_output(self.live_cell.out_point.clone()) .build() } diff --git a/src/tx_builder/acp.rs b/src/tx_builder/acp.rs index 6b08c79a..8651eb0c 100644 --- a/src/tx_builder/acp.rs +++ b/src/tx_builder/acp.rs @@ -70,7 +70,7 @@ impl TxBuilder for AcpTransferBuilder { .output .clone() .as_builder() - .capacity(output_capacity.pack()) + .capacity(output_capacity) .build(); let output_data = input_cell.output_data.clone(); diff --git a/src/tx_builder/cheque.rs b/src/tx_builder/cheque.rs index 525df320..3020424e 100644 --- a/src/tx_builder/cheque.rs +++ b/src/tx_builder/cheque.rs @@ -168,7 +168,7 @@ impl TxBuilder for ChequeClaimBuilder { }; let sender_output = CellOutput::new_builder() .lock(self.sender_lock_script.clone()) - .capacity(cheque_total_capacity.pack()) + .capacity(cheque_total_capacity) .build(); let sender_output_data = Bytes::new(); @@ -309,7 +309,7 @@ impl TxBuilder for ChequeWithdrawBuilder { if let Some(script_id) = self.acp_script_id.as_ref() { let acp_lock = Script::new_builder() .code_hash(script_id.code_hash.pack()) - .hash_type(script_id.hash_type.into()) + .hash_type(script_id.hash_type) .args(self.sender_lock_script.args()) .build(); let mut query = CellQueryOptions::new_lock(acp_lock.clone()); @@ -354,7 +354,7 @@ impl TxBuilder for ChequeWithdrawBuilder { let sender_output = CellOutput::new_builder() .lock(sender_lock) .type_(Some(type_script).pack()) - .capacity(total_capacity.pack()) + .capacity(total_capacity) .build(); let sender_output_data = Bytes::from(total_amount.to_le_bytes().to_vec()); diff --git a/src/tx_builder/dao.rs b/src/tx_builder/dao.rs index bc1a8280..4886e832 100644 --- a/src/tx_builder/dao.rs +++ b/src/tx_builder/dao.rs @@ -61,7 +61,7 @@ impl TxBuilder for DaoDepositBuilder { } let dao_type_script = Script::new_builder() .code_hash(DAO_TYPE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build(); let dao_cell_dep = cell_dep_resolver .resolve(&dao_type_script) @@ -71,7 +71,7 @@ impl TxBuilder for DaoDepositBuilder { let mut outputs_data = Vec::new(); for receiver in &self.receivers { let output = CellOutput::new_builder() - .capacity(receiver.capacity.pack()) + .capacity(receiver.capacity) .lock(receiver.lock_script.clone()) .type_(Some(dao_type_script.clone()).pack()) .build(); @@ -140,7 +140,7 @@ impl TxBuilder for DaoPrepareBuilder { let dao_type_script = Script::new_builder() .code_hash(DAO_TYPE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build(); let dao_cell_dep = cell_dep_resolver .resolve(&dao_type_script) @@ -262,7 +262,7 @@ impl TxBuilder for DaoWithdrawBuilder { let dao_type_script = Script::new_builder() .code_hash(DAO_TYPE_HASH.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build(); let dao_cell_dep = cell_dep_resolver .resolve(&dao_type_script) @@ -399,10 +399,7 @@ impl TxBuilder for DaoWithdrawBuilder { input_total }; let final_capacity = std::cmp::max(occupied_capacity, capacity); - let output = tmp_output - .as_builder() - .capacity(final_capacity.pack()) - .build(); + let output = tmp_output.as_builder().capacity(final_capacity).build(); (vec![output], vec![Bytes::new().pack()]) } DaoWithdrawReceiver::Custom { diff --git a/src/tx_builder/mod.rs b/src/tx_builder/mod.rs index 87945f55..5465ae22 100644 --- a/src/tx_builder/mod.rs +++ b/src/tx_builder/mod.rs @@ -762,7 +762,7 @@ impl CapacityBalancer { if original_capacity >= base_change_occupied_capacity + extra_min_fee + extra_fee { let output = output .as_builder() - .capacity((original_capacity - extra_fee).pack()) + .capacity(original_capacity - extra_fee) .build(); let mut outputs: Vec<_> = tx.outputs().into_iter().collect(); outputs[idx] = output; @@ -823,7 +823,7 @@ impl CapacityBalancer { if original_capacity >= base_change_occupied_capacity + extra_min_fee + extra_fee { let output = output .as_builder() - .capacity((original_capacity - extra_fee).pack()) + .capacity(original_capacity - extra_fee) .build(); let mut outputs: Vec<_> = tx.outputs().into_iter().collect(); outputs[idx] = output; @@ -1126,7 +1126,9 @@ fn rebalance_tx_capacity( .set_witnesses(all_witnesses); if let Some(output) = change_output.clone() { ret_change_index = Some(output_len); - builder = builder.output(output).output_data(Default::default()); + builder = builder + .output(output) + .output_data(ckb_types::packed::Bytes::default()); } builder.build() }; @@ -1148,7 +1150,7 @@ fn rebalance_tx_capacity( .checked_add(delta) .expect("change cell capacity add overflow"); // next loop round must return new_tx; - change_output = Some(output.as_builder().capacity(new_capacity.pack()).build()); + change_output = Some(output.as_builder().capacity(new_capacity).build()); need_more_capacity = 0; } else { // If change cell not exists, add a change cell. @@ -1171,7 +1173,7 @@ fn rebalance_tx_capacity( base_change_output .clone() .as_builder() - .capacity((delta - extra_min_fee).pack()) + .capacity(delta - extra_min_fee) .build(), ); need_more_capacity = 0; @@ -1203,7 +1205,7 @@ fn rebalance_tx_capacity( base_change_output .clone() .as_builder() - .capacity(base_change_occupied_capacity.pack()) + .capacity(base_change_occupied_capacity) .build(), ); } @@ -1424,7 +1426,9 @@ async fn rebalance_tx_capacity_async( .set_witnesses(all_witnesses); if let Some(output) = change_output.clone() { ret_change_index = Some(output_len); - builder = builder.output(output).output_data(Default::default()); + builder = builder + .output(output) + .output_data(ckb_types::packed::Bytes::default()); } builder.build() }; @@ -1446,7 +1450,7 @@ async fn rebalance_tx_capacity_async( .checked_add(delta) .expect("change cell capacity add overflow"); // next loop round must return new_tx; - change_output = Some(output.as_builder().capacity(new_capacity.pack()).build()); + change_output = Some(output.as_builder().capacity(new_capacity).build()); need_more_capacity = 0; } else { // If change cell not exists, add a change cell. @@ -1469,7 +1473,7 @@ async fn rebalance_tx_capacity_async( base_change_output .clone() .as_builder() - .capacity((delta - extra_min_fee).pack()) + .capacity(delta - extra_min_fee) .build(), ); need_more_capacity = 0; @@ -1502,7 +1506,7 @@ async fn rebalance_tx_capacity_async( base_change_output .clone() .as_builder() - .capacity(base_change_occupied_capacity.pack()) + .capacity(base_change_occupied_capacity) .build(), ); } diff --git a/src/tx_builder/omni_lock.rs b/src/tx_builder/omni_lock.rs index 5d88b938..ca134ee7 100644 --- a/src/tx_builder/omni_lock.rs +++ b/src/tx_builder/omni_lock.rs @@ -89,7 +89,7 @@ impl TxBuilder for OmniLockTransferBuilder { for cell in rce_cells { let cell_dep = CellDep::new_builder() .out_point(cell.clone()) - .dep_type(DepType::Code.into()) + .dep_type(DepType::Code) .build(); cell_deps.insert(cell_dep); } diff --git a/src/tx_builder/udt/mod.rs b/src/tx_builder/udt/mod.rs index d38ce91a..32a00403 100644 --- a/src/tx_builder/udt/mod.rs +++ b/src/tx_builder/udt/mod.rs @@ -37,7 +37,7 @@ impl UdtType { }; Script::new_builder() .code_hash(script_id.code_hash.pack()) - .hash_type(script_id.hash_type.into()) + .hash_type(script_id.hash_type) .args(type_script_args.pack()) .build() } @@ -129,10 +129,7 @@ impl UdtTargetReceiver { } else { base_occupied_capacity }; - let output = base_output - .as_builder() - .capacity(final_capacity.pack()) - .build(); + let output = base_output.as_builder().capacity(final_capacity).build(); Ok(ReceiverBuildOutput { input: None, output, diff --git a/src/types/address.rs b/src/types/address.rs index 68a9a363..6e43bde0 100644 --- a/src/types/address.rs +++ b/src/types/address.rs @@ -105,12 +105,9 @@ impl AddressPayload { match self { AddressPayload::Short { .. } => AddressType::Short, AddressPayload::Full { hash_type, .. } => match (hash_type, is_new) { - (ScriptHashType::Data, true) => AddressType::Full, - (ScriptHashType::Type, true) => AddressType::Full, - (ScriptHashType::Data1, _) => AddressType::Full, - (ScriptHashType::Data2, _) => AddressType::Full, (ScriptHashType::Data, false) => AddressType::FullData, (ScriptHashType::Type, false) => AddressType::FullType, + _ => AddressType::Full, }, } } @@ -223,6 +220,7 @@ impl fmt::Debug for AddressPayload { ScriptHashType::Data => "data", ScriptHashType::Data1 => "data1", ScriptHashType::Data2 => "data2", + _ => "unsupported hash_type", }; f.debug_struct("AddressPayload") .field("hash_type", &hash_type) @@ -235,7 +233,7 @@ impl fmt::Debug for AddressPayload { impl From<&AddressPayload> for Script { fn from(payload: &AddressPayload) -> Script { Script::new_builder() - .hash_type(payload.hash_type().into()) + .hash_type(payload.hash_type()) .code_hash(payload.code_hash(None)) .args(payload.args().pack()) .build() @@ -329,6 +327,7 @@ impl fmt::Debug for Address { ScriptHashType::Data => "data", ScriptHashType::Data1 => "data1", ScriptHashType::Data2 => "data2", + _ => "unsupported hash_type", }; f.debug_struct("Address") .field("network", &self.network) @@ -343,7 +342,7 @@ impl fmt::Debug for Address { impl From<&Address> for Script { fn from(addr: &Address) -> Script { Script::new_builder() - .hash_type(addr.payload.hash_type().into()) + .hash_type(addr.payload.hash_type()) .code_hash(addr.payload.code_hash(Some(addr.network))) .args(addr.payload.args().pack()) .build() @@ -505,7 +504,7 @@ mod old_addr { Script::new_builder() .args(self.hash.as_bytes().pack()) .code_hash(code_hash.pack()) - .hash_type(ScriptHashType::Data.into()) + .hash_type(ScriptHashType::Data) .build() } diff --git a/src/types/script_id.rs b/src/types/script_id.rs index f11f7da1..037b2d9e 100644 --- a/src/types/script_id.rs +++ b/src/types/script_id.rs @@ -39,7 +39,7 @@ impl ScriptId { pub fn dummy_type_id_script(&self) -> Script { Script::new_builder() .code_hash(self.code_hash.pack()) - .hash_type(self.hash_type.into()) + .hash_type(self.hash_type) .args(<[u8]>::pack(&[0u8; 32])) .build() } diff --git a/src/types/transaction_with_groups.rs b/src/types/transaction_with_groups.rs index 4c30661f..db8d5772 100644 --- a/src/types/transaction_with_groups.rs +++ b/src/types/transaction_with_groups.rs @@ -74,7 +74,7 @@ impl TransactionWithScriptGroupsBuilder { let script = Script::new_builder() .code_hash(code_hash.pack()) .args(args.pack()) - .hash_type(ScriptHashType::Type.into()) + .hash_type(ScriptHashType::Type) .build(); self.add_lock_script_group(&script, input_indices) } diff --git a/src/unlock/signer.rs b/src/unlock/signer.rs index aa61be3f..b1ec6ae4 100644 --- a/src/unlock/signer.rs +++ b/src/unlock/signer.rs @@ -197,7 +197,7 @@ impl MultisigConfig { self.lock_code_hash.clone() } pub fn lock_hash_type(&self) -> ScriptHashType { - self.lock_hash_type.clone() + self.lock_hash_type } pub fn require_first_n(&self) -> u8 { self.require_first_n @@ -277,7 +277,7 @@ impl From<&MultisigConfig> for Script { .script_id(); Script::new_builder() .code_hash(multisig_script.code_hash.pack()) - .hash_type(multisig_script.hash_type.into()) + .hash_type(multisig_script.hash_type) .args(Bytes::from(value.hash160().as_bytes().to_vec()).pack()) .build() } diff --git a/src/util.rs b/src/util.rs index 6e9f79f1..4263572c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -162,7 +162,7 @@ pub fn convert_keccak256_hash(message: &[u8]) -> H256 { hasher.update(eth_prefix); hasher.update(message); let r = hasher.finalize(); - H256::from_slice(r.as_slice()).expect("convert_keccak256_hash") + H256::from_slice(&r).expect("convert_keccak256_hash") } #[cfg(all(test, feature = "test"))] @@ -207,10 +207,10 @@ mod tests { EpochNumberWithFraction::new(prepare_point.0, prepare_point.1, prepare_point.2); let expected = EpochNumberWithFraction::new(expected.0, expected.1, expected.2); let deposit_header = HeaderBuilder::default() - .epoch(deposit_point.full_value().pack()) + .epoch(deposit_point.full_value()) .build(); let prepare_header = HeaderBuilder::default() - .epoch(prepare_point.full_value().pack()) + .epoch(prepare_point.full_value()) .build(); let actual = minimal_unlock_point(&deposit_header, &prepare_header); assert_eq!( @@ -236,8 +236,8 @@ mod tests { let prepare_point = EpochNumberWithFraction::new(prepare_point.0, prepare_point.1, prepare_point.2); let deposit_header = HeaderBuilder::default() - .epoch(deposit_point.full_value().pack()) - .number(deposit_number.pack()) + .epoch(deposit_point.full_value()) + .number(deposit_number) .dao(pack_dao_data( 10_000_000_000_123_456, Default::default(), @@ -246,8 +246,8 @@ mod tests { )) .build(); let prepare_header = HeaderBuilder::default() - .epoch(prepare_point.full_value().pack()) - .number(prepare_number.pack()) + .epoch(prepare_point.full_value()) + .number(prepare_number) .dao(pack_dao_data( 10_000_000_001_123_456, Default::default(), @@ -281,11 +281,7 @@ mod tests { }); let tip_header: HeaderView = HeaderBuilder::default() - .epoch( - EpochNumberWithFraction::new(3, 200, 400) - .full_value() - .pack(), - ) + .epoch(EpochNumberWithFraction::new(3, 200, 400).full_value()) .build() .into(); server.mock(|when, then| { @@ -313,11 +309,7 @@ mod tests { }); let tip_header: HeaderView = HeaderBuilder::default() - .epoch( - EpochNumberWithFraction::new(3, 300, 600) - .full_value() - .pack(), - ) + .epoch(EpochNumberWithFraction::new(3, 300, 600).full_value()) .build() .into(); server.mock(|when, then| { @@ -359,11 +351,7 @@ mod tests { }); let tip_header: HeaderView = HeaderBuilder::default() - .epoch( - EpochNumberWithFraction::new(105, 300, 600) - .full_value() - .pack(), - ) + .epoch(EpochNumberWithFraction::new(105, 300, 600).full_value()) .build() .into(); server.mock(|when, then| {