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

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0x3 committed Nov 27, 2023
1 parent 01fd53f commit 285b1d9
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 135 deletions.
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.73.0"
2 changes: 1 addition & 1 deletion packages/fuel-indexer-lib/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ lazy_static! {
/// Set of internal indexer entities.
pub static ref INTERNAL_INDEXER_ENTITIES: HashSet<&'static str> = HashSet::from([
"IndexMetadataEntity",
"PredicateEntity",
"IndexerPredicateEntity",
]);

/// Set of types that implement `AsRef<[u8]>`.
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-lib/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn inject_native_entities_into_schema(schema: &str) -> String {
schema = format!("{}{}", schema, PredicateCoinOutput::schema_fragment())
}

if !schema.contains("type PredicateEntity") {
if !schema.contains("type IndexerPredicateEntity") {
schema = format!("{}{}", schema, IndexerPredicate::schema_fragment())
}

Expand Down
25 changes: 11 additions & 14 deletions packages/fuel-indexer-macros/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use fuel_indexer_lib::{
graphql::{list_field_type_name, types::IdCol, ParsedGraphQLSchema},
manifest::Manifest,
};
use fuel_indexer_types::{indexer::Predicates, type_id, TypeId, FUEL_TYPES_NAMESPACE};
use fuel_indexer_types::{type_id, FUEL_TYPES_NAMESPACE};
use fuels_code_gen::utils::Source;
use inflections::case::to_pascal_case;
use proc_macro2::TokenStream;
Expand Down Expand Up @@ -190,6 +190,10 @@ pub fn is_generic_type(typ: &TypeDeclaration) -> bool {
matches!(gt, GenericType::Vec | GenericType::Option)
}

pub fn is_predicate_primitive(typ: &TypeDeclaration) -> bool {
typ.type_field.as_str() == "Predicate" || typ.type_field.as_str() == "Predicates"
}

/// Given a `TokenStream` representing this `TypeDeclaration`'s fully typed path,
/// return the associated `match` arm for decoding this type in the `Decoder`.
pub fn decode_snippet(
Expand All @@ -203,12 +207,10 @@ pub fn decode_snippet(
if is_fuel_primitive(typ) {
// Since predicates are contained in the container `Predicates`, their decoding works a bit
// differently than the typical Fuel primitive.
if ty_id == Predicates::type_id() {
if is_predicate_primitive(typ) {
quote! {
#ty_id => {
// FIXME: Inject template ID here!!!
let obj: Predicate = bincode::deserialize(&data).expect("Bad bincode.");
self.#name.add("123".to_string(), obj);
Logger::warn("Skipping predicate decoder.");
}
}
} else {
Expand Down Expand Up @@ -1265,7 +1267,7 @@ pub fn configurable_fn_type_name(configurable: &Configurable) -> Option<String>
}

/// Derive a mapping of input type IDs to their corresponding names for a given set of predicates.
pub fn predicate_inputs_names_map(manifest: &Manifest) -> HashMap<usize, String> {
pub fn indexer_configurables_names_map(manifest: &Manifest) -> HashMap<usize, String> {
let mut output = HashMap::new();
if let Some(predicate) = manifest.predicates() {
if predicate.is_empty() {
Expand All @@ -1291,17 +1293,12 @@ pub fn predicate_inputs_names_map(manifest: &Manifest) -> HashMap<usize, String>
output
}

/// Derive the name of the set of inputs for this predicate template.
pub fn predicate_inputs_name(template_name: &str) -> String {
format!("{}Inputs", to_pascal_case(template_name))
/// Derive the name of the set of indexer-specific configurables for this predicate template.
pub fn indexer_configurables_name(template_name: &str) -> String {
format!("{}IndexerConfigurables", to_pascal_case(template_name))
}

/// Derive the name of the set of configurables for this predicate template.
pub fn sdk_configurables_name(template_name: &str) -> String {
format!("{}Configurables", to_pascal_case(template_name))
}

/// Given a template name, derive the name of the corresponding `fuels-rs` `Configurables` encoder type.
pub fn sdk_configurables_encoder_name(template_name: &str) -> String {
format!("{}Encoder", to_pascal_case(template_name))
}
2 changes: 1 addition & 1 deletion packages/fuel-indexer-macros/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn process_fn_items(
t.iter()
.map(|t| {
let ty_id = type_id(FUEL_TYPES_NAMESPACE, &t.name()) as usize;
let name = predicate_inputs_name(&t.name());
let name = indexer_configurables_name(&t.name());
TypeDeclaration {
type_id: ty_id,
type_field: name,
Expand Down
Loading

0 comments on commit 285b1d9

Please sign in to comment.