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

fix: support contract JSON ABI with callpaths #1354

Merged
merged 4 commits into from
Sep 19, 2023
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
25 changes: 25 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,31 @@ 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`.
///
/// It is possible that the type field for a `TypeDeclaration` contains a
/// fully-qualified path (e.g. `std::address::Address` as opposed to `Address`).
/// Path separators are not allowed to be used as part of an identifier, so this
/// function removes the qualifying path while keeping the type keyword.
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()))
deekerno marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading