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

enhancement: implement find on entity #1446

Merged
merged 18 commits into from
Nov 20, 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
1,031 changes: 578 additions & 453 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions examples/greetings/contracts/greeting/Forc.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[[package]]
name = 'core'
source = 'path+from-root-63B5D95B29B128A3'
name = "core"
source = "path+from-root-AD80769CAE44474A"

[[package]]
name = 'greeting'
source = 'member'
dependencies = ['std']
name = "greeting"
source = "member"
dependencies = ["std"]

[[package]]
name = 'std'
source = 'git+https://github.com/fuellabs/sway?tag=v0.45.0#92dc9f361a9508a940c0d0708130f26fa044f6b3'
dependencies = ['core']
name = "std"
source = "git+https://github.com/fuellabs/sway?tag=v0.46.0#e75f14b03636bc96751a6760304a1a6d3eb5937d"
dependencies = ["core"]
4 changes: 4 additions & 0 deletions packages/fuel-indexer-api-server/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub(crate) fn check_wasm_toolchain_version(data: Vec<u8>) -> anyhow::Result<Stri
"ff_get_object".to_string(),
Function::new_typed(&mut store, |_: i64, _: i32, _: i32| 0i32),
);
exports.insert(
"ff_single_select".to_string(),
Function::new_typed(&mut store, |_: i64, _: i32, _: i32| 0i32),
);
exports.insert(
"ff_early_exit".to_string(),
Function::new_typed(&mut store, |_: i32| {}),
Expand Down
1 change: 1 addition & 0 deletions packages/fuel-indexer-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proc-macro = true
[dependencies]
async-graphql-parser = "5.0"
async-graphql-value = "5.0"
convert_case = "0.6"
fuel-abi-types = "0.3"
fuel-indexer-database-types = { workspace = true }
fuel-indexer-lib = { workspace = true, default-features = true }
Expand Down
38 changes: 38 additions & 0 deletions packages/fuel-indexer-macros/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub struct ImplementationDecoder {
/// Token stream of struct fields.
struct_fields: TokenStream,

/// Token stream used to generate `T::struct_field()` `Field<F>` or
/// `OptionField<F>` which are the used to construct `Constraint<T>` for use
/// with `T::find()`
pub field_selectors: Vec<TokenStream>,

/// `TypeDefinition`.
typdef: TypeDefinition,

Expand All @@ -50,6 +55,7 @@ impl Default for ImplementationDecoder {
parameters: quote! {},
hasher: quote! {},
struct_fields: quote! {},
field_selectors: vec![],
typdef: TypeDefinition {
description: None,
extend: false,
Expand All @@ -74,6 +80,7 @@ impl Decoder for ImplementationDecoder {
let obj_name = typ.name.to_string();

let mut struct_fields = quote! {};
let mut field_selectors = vec![];
let mut parameters = quote! {};
let mut hasher = quote! { Sha256::new() };

Expand Down Expand Up @@ -141,12 +148,37 @@ impl Decoder for ImplementationDecoder {
#field_name_ident,
};
}

let ident = format_ident!("{obj_name}");
let field_name_ident_string = field_name_ident.to_string();

// Skip generics
if processed_type_result.inner_type_ident.is_none()
&& !processed_type_result.nullable
{
field_selectors.push(quote! {
pub fn #field_name_ident () -> Field<#ident, #field_type_tokens> {
Field::new(#field_name_ident_string .to_string())
}
});
}

if processed_type_result.nullable
&& processed_type_result.field_type_ident != "Array"
{
field_selectors.push(quote! {
pub fn #field_name_ident () -> OptionField<#ident, #field_type_ident> {
OptionField::new(#field_name_ident_string .to_string())
}
});
}
}

ImplementationDecoder {
parameters,
hasher,
struct_fields,
field_selectors,
typdef: typ.clone(),
parsed: parsed.clone(),
}
Expand Down Expand Up @@ -240,6 +272,7 @@ impl From<ImplementationDecoder> for TokenStream {
struct_fields,
typdef,
parsed,
field_selectors,
} = decoder;

let typdef_name = typdef.name.to_string();
Expand Down Expand Up @@ -296,10 +329,13 @@ impl From<ImplementationDecoder> for TokenStream {
}
}

#(#field_selectors)*

#impl_get_or_create
}
}
}

TypeKind::Union(u) => {
let union_name = typdef.name.to_string();

Expand All @@ -309,6 +345,8 @@ impl From<ImplementationDecoder> for TokenStream {
} else {
quote! {
impl #ident {
#(#field_selectors)*

#impl_get_or_create
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/fuel-indexer-macros/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ impl Codegen for TypeDeclaration {
"u32" => quote! { u32 },
"u64" => quote! { u64 },
"u8" => quote! { u8 },
"str" => quote! { String },
o if o.starts_with("str[") => quote! { String },
o => {
proc_macro_error::abort_call_site!(
Expand Down
1 change: 1 addition & 0 deletions packages/fuel-indexer-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ hex = "0.4"
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = { version = "0.10" }
sqlparser = { version = "0.39" }
Loading
Loading