Skip to content

Commit

Permalink
Fix overly broad tuple ignore check; add unit type to non-decodables
Browse files Browse the repository at this point in the history
  • Loading branch information
deekerno committed Aug 30, 2023
1 parent 68cf538 commit 2c87dd4
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/fuel-indexer-macros/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ pub fn unwrap_or_default_for_external_type(
}
}

/// Whether or not a `TypeDeclaration` is tuple type
pub fn is_tuple_type(typ: &TypeDeclaration) -> bool {
typ.type_field.as_str().starts_with('(')
}

/// Extract tokens from JSON ABI file
pub fn get_json_abi(abi_path: Option<String>) -> Option<ProgramABI> {
match abi_path {
Expand Down Expand Up @@ -78,7 +73,23 @@ pub fn get_json_abi(abi_path: Option<String>) -> Option<ProgramABI> {
}
}

/// Whether this TypeDeclaration should be used in the codgen
/// Whether a `TypeDeclaration` is tuple type
pub fn is_tuple_type(typ: &TypeDeclaration) -> bool {
let mut type_field_chars = typ.type_field.chars();

type_field_chars.nth(0).is_some_and(|c| c == '(')
&& type_field_chars.nth(0).is_some_and(|c| c != ')')
}

/// Whether a `TypeDeclaration` is a unit type
pub fn is_unit_type(typ: &TypeDeclaration) -> bool {
let mut type_field_chars = typ.type_field.chars();

type_field_chars.nth(0).is_some_and(|c| c == '(')
&& type_field_chars.nth(0).is_some_and(|c| c == ')')
}

/// Whether this TypeDeclaration should be used in the codegen
pub fn is_ignored_type(typ: &TypeDeclaration) -> bool {
is_tuple_type(typ)
}
Expand All @@ -93,6 +104,10 @@ pub fn is_non_decodable_type(typ: &TypeDeclaration) -> bool {
return true;
}

if is_unit_type(typ) {
return true;
}

false
}

Expand Down

0 comments on commit 2c87dd4

Please sign in to comment.