Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Support contract ABI with callpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
deekerno committed Sep 15, 2023
1 parent 1b345b0 commit 3b5026d
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 110 deletions.
20 changes: 20 additions & 0 deletions packages/fuel-indexer-macros/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,26 @@ pub fn can_derive_id(field_set: &HashSet<String>, field_name: &str) -> bool {
&& field_name != IdCol::to_lowercase_str()
}

/// Strip the call path from the type field of a `TypeDeclaration`.
pub fn strip_callpath_from_type_field(mut typ: TypeDeclaration) -> TypeDeclaration {
if is_non_decodable_type(&typ) {
return typ;
}

let mut s = typ.type_field.split_whitespace();
typ.type_field =
if let (Some(keyword), Some(fully_qualified_type_path)) = (s.next(), s.last()) {
if let Some(slug) = fully_qualified_type_path.split("::").last() {
[keyword, slug].join(" ")
} else {
unreachable!("All types should be formed with a keyword and call path")
}
} else {
typ.type_field
};
typ
}

/// Simply represents a value for a generic type.
#[derive(Debug)]
pub enum GenericType {
Expand Down
7 changes: 6 additions & 1 deletion packages/fuel-indexer-macros/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ fn process_fn_items(
let mut abi_dispatchers = Vec::new();

let funcs = abi.clone().functions;
let abi_types = abi.clone().types;
let abi_types: Vec<TypeDeclaration> = abi
.clone()
.types
.iter()
.map(|t| strip_callpath_from_type_field(t.clone()))
.collect();
let abi_log_types = abi.clone().logged_types.unwrap_or_default();
let abi_msg_types = abi.clone().messages_types.unwrap_or_default();
let fuel_types = FUEL_PRIMITIVES
Expand Down
Loading

0 comments on commit 3b5026d

Please sign in to comment.