Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enum tuple struct #2925

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions script/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ impl LazyData {

#[derive(Debug, PartialEq, Eq, Clone)]
enum Binaries {
Unique((Byte32, LazyData)),
Duplicate((Byte32, LazyData)),
Unique(Byte32, LazyData),
Duplicate(Byte32, LazyData),
Multiple,
}

impl Binaries {
fn new(data_hash: Byte32, data: LazyData) -> Self {
Self::Unique((data_hash, data))
Self::Unique(data_hash, data)
}

fn merge(&mut self, data_hash: &Byte32) {
match self {
Self::Unique(ref old) | Self::Duplicate(ref old) => {
if old.0 != *data_hash {
Self::Unique(ref hash, data) | Self::Duplicate(ref hash, data) => {
if hash != data_hash {
*self = Self::Multiple;
} else {
*self = Self::Duplicate(old.to_owned());
*self = Self::Duplicate(hash.to_owned(), data.to_owned());
}
}
Self::Multiple => {
zhangsoledad marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -376,8 +376,8 @@ impl<'a, DL: CellDataProvider + HeaderProvider> TransactionScriptsVerifier<'a, D
ScriptHashType::Type => {
if let Some(ref bin) = self.binaries_by_type_hash.get(&script.code_hash()) {
match bin {
Binaries::Unique((_, ref lazy)) => Ok(lazy.access(self.data_loader)),
Binaries::Duplicate((_, ref lazy)) => {
Binaries::Unique(_, ref lazy) => Ok(lazy.access(self.data_loader)),
Binaries::Duplicate(_, ref lazy) => {
let proposal_window = self.consensus.tx_proposal_window();
let epoch_number = self.tx_env.epoch_number(proposal_window);
if self
Expand Down
21 changes: 12 additions & 9 deletions util/types/src/core/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum ResolvedDep {
/// TODO(doc): @quake
Cell(CellMeta),
/// TODO(doc): @quake
Group((CellMeta, Vec<CellMeta>)),
Group(CellMeta, Vec<CellMeta>),
}

/// type alias system cells map
Expand Down Expand Up @@ -307,7 +307,7 @@ impl ResolvedTransaction {
.build();

let dep_group = system_cell.get(&cell_dep);
if let Some(ResolvedDep::Group((_, cell_deps))) = dep_group {
if let Some(ResolvedDep::Group(_, cell_deps)) = dep_group {
resolved_system_deps.extend(cell_deps.iter().map(|dep| &dep.out_point));
} else {
check_cell(&cell_meta.out_point)?;
Expand Down Expand Up @@ -848,8 +848,7 @@ fn resolve_transaction_deps_with_system_cell_cache<
.checked_sub(1)
.ok_or(OutPointError::OverMaxDepExpansionLimit { ban })?;
}
ResolvedDep::Group(group) => {
let (dep_group, cell_deps) = group;
ResolvedDep::Group(dep_group, cell_deps) => {
resolved_dep_groups.push(dep_group.clone());
resolved_cell_deps.extend(cell_deps.clone());
remaining_dep_slots = remaining_dep_slots
Expand Down Expand Up @@ -989,16 +988,20 @@ pub fn setup_system_cell_cache<CP: CellProvider>(
build_cell_meta_from_out_point(cell_provider, out_point)
};

let secp_group_dep_cell = resolve_dep_group(&secp_group_dep.out_point(), resolve_cell, true)
.expect("resolve secp_group_dep_cell");
cell_deps.insert(secp_group_dep, ResolvedDep::Group(secp_group_dep_cell));
let (secp_dep_group, secp_group_cells) =
resolve_dep_group(&secp_group_dep.out_point(), resolve_cell, true)
.expect("resolve secp_group_dep_cell");
cell_deps.insert(
secp_group_dep,
ResolvedDep::Group(secp_dep_group, secp_group_cells),
);

let multi_sign_secp_group_cell =
let (multi_sign_dep_group, multi_sign_group_cells) =
resolve_dep_group(&multi_sign_secp_group.out_point(), resolve_cell, true)
.expect("resolve multi_sign_secp_group");
cell_deps.insert(
multi_sign_secp_group,
ResolvedDep::Group(multi_sign_secp_group_cell),
ResolvedDep::Group(multi_sign_dep_group, multi_sign_group_cells),
);

SYSTEM_CELL.set(cell_deps)
Expand Down