Skip to content

Commit

Permalink
fix make clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan committed Jul 25, 2023
1 parent cd392ce commit 335a9c6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
6 changes: 1 addition & 5 deletions util/gen-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ default = ["std"]
calc-hash = ["blake2b-ref"]
check-data = []
serialized-size = ["calc-hash"]
std = [
"calc-hash",
"check-data",
"serialized-size",
"molecule/std", "ckb-fixed-hash", "numext-fixed-uint", "ckb-error", "ckb-occupied-capacity", "ckb-hash" ]
std = ["calc-hash", "check-data", "serialized-size", "molecule/std", "ckb-fixed-hash", "numext-fixed-uint", "ckb-error", "ckb-occupied-capacity", "ckb-hash"]

[dependencies]
molecule = { version = "0.7.5", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions util/gen-types/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The essential rust types for CKB contracts.

#![allow(clippy::from_over_into)]

#[cfg(feature = "std")]
Expand All @@ -7,8 +9,6 @@ pub use std_env::*;

use crate::packed;

pub(crate) type BlockNumber = u64;

/// Specifies how the script `code_hash` is used to match the script code and how to run the code.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum ScriptHashType {
Expand Down
11 changes: 4 additions & 7 deletions util/gen-types/src/extension/shortcut.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use crate::{
bytes,
core::{self, BlockNumber},
generated::packed,
prelude::*,
vec::Vec,
};
use crate::{bytes, core, generated::packed, prelude::*, vec::Vec};

type BlockNumber = u64;

impl packed::Byte32 {
/// Creates a new `Bytes32` whose bits are all zeros.
Expand Down Expand Up @@ -293,6 +289,7 @@ impl AsRef<[u8]> for packed::TransactionKey {
}

impl packed::HeaderDigest {
/// Checks if the `HeaderDigest` is the default value.
pub fn is_default(&self) -> bool {
let default = Self::default();
self.as_slice() == default.as_slice()
Expand Down
3 changes: 2 additions & 1 deletion util/gen-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ extern crate alloc;

mod conversion;
pub mod core;
pub mod extension;
mod extension;
mod generated;
pub mod prelude;
pub use generated::packed;
#[allow(missing_docs)]
pub mod util;

//re-exports
Expand Down
35 changes: 35 additions & 0 deletions util/types/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,97 @@ pub use ckb_gen_types::prelude::*;

use std::collections::HashSet;

/// Trait for converting types into `TransactionView`.
pub trait IntoTransactionView {
/// Converts the implementing type into a `TransactionView`.
fn into_view(self) -> TransactionView;
}

/// Trait for converting types into `HeaderView`.
pub trait IntoHeaderView {
/// Converts the implementing type into a `HeaderView`.
fn into_view(self) -> HeaderView;
}

/// Trait for converting types into `UncleBlockView`.
pub trait IntoUncleBlockView {
/// Converts the implementing type into an `UncleBlockView`.
fn into_view(self) -> UncleBlockView;
}

/// Trait for converting types into `BlockView`.
pub trait IntoBlockView {
/// Converts the implementing type into a `BlockView` without resetting the header.
fn into_view_without_reset_header(self) -> BlockView;

/// Converts the implementing type into a `BlockView`.
fn into_view(self) -> BlockView;

/// Converts a packed block and associated data into a `BlockView`.
fn block_into_view_internal(
block: packed::Block,
tx_hashes: Vec<packed::Byte32>,
tx_witness_hashes: Vec<packed::Byte32>,
) -> BlockView;
}

/// Trait for obtaining an advanced builder for `BlockView`.
pub trait AsBlockBuilder {
/// Creates a new advanced builder for `BlockView`.
fn new_advanced_builder() -> BlockBuilder;

/// Gets an advanced builder from the implementing type.
fn as_advanced_builder(&self) -> BlockBuilder;
}

/// Trait for obtaining an advanced builder for `TransactionView`.
pub trait AsTransactionBuilder {
/// Gets an advanced builder for `TransactionView` from the implementing type.
fn as_advanced_builder(&self) -> TransactionBuilder;
}

/// Trait for obtaining an advanced builder for `HeaderView`.
pub trait AsHeaderBuilder {
/// Gets an advanced builder for `HeaderView` from the implementing type.
fn as_advanced_builder(&self) -> HeaderBuilder;
}

/// Trait for calculating difficulty.
pub trait Difficulty {
/// Calculates and returns the difficulty value as a `U256`.
fn difficulty(&self) -> U256;
}

/// Trait for building a compact block from a `BlockView`.
pub trait BuildCompactBlock {
/// Builds a compact block from a `BlockView` and a set of prefilled transaction indexes.
fn build_from_block(
block: &BlockView,
prefilled_transactions_indexes: &HashSet<usize>,
) -> packed::CompactBlock;

/// Returns the short IDs of the transactions in the compact block.
fn block_short_ids(&self) -> Vec<Option<packed::ProposalShortId>>;

/// Returns the indexes of the short IDs in the compact block.
fn short_id_indexes(&self) -> Vec<usize>;
}

/// Trait for resetting the header of a packed block.
pub trait ResetBlock {
/// Resets the header of the packed block.
fn reset_header(self) -> packed::Block;

/// Resets the header of the packed block with given transaction hashes and witness hashes.
fn reset_header_with_hashes(
self,
tx_hashes: &[packed::Byte32],
tx_witness_hashes: &[packed::Byte32],
) -> packed::Block;
}

/// Trait for calculating the extra hash of a block.
pub trait CalcExtraHash {
/// Calculates and returns the extra hash of the block as an `ExtraHashView`.
fn calc_extra_hash(&self) -> ExtraHashView;
}
2 changes: 2 additions & 0 deletions util/types/src/utilities/merkle_mountain_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ impl core::HeaderView {
}
}

/// Trait for representing a header digest.
pub trait HeaderDigest {
/// Verify the header digest
fn verify(&self) -> Result<(), String>;
}

Expand Down

0 comments on commit 335a9c6

Please sign in to comment.