From 07049a4538551953279e2bcf6f0d9fe0968f3816 Mon Sep 17 00:00:00 2001 From: ra0x3 Date: Fri, 10 Nov 2023 11:30:36 -0500 Subject: [PATCH] update configurable decoding --- packages/fuel-indexer-lib/src/lib.rs | 3 ++- packages/fuel-indexer-macros/src/indexer.rs | 25 ++++++++++++------- packages/fuel-indexer-macros/src/lib.rs | 15 ++++++----- .../indexers/fuel-indexer-test/src/lib.rs | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/packages/fuel-indexer-lib/src/lib.rs b/packages/fuel-indexer-lib/src/lib.rs index 59110c589..ab0750c3a 100644 --- a/packages/fuel-indexer-lib/src/lib.rs +++ b/packages/fuel-indexer-lib/src/lib.rs @@ -116,7 +116,8 @@ pub fn fully_qualified_namespace(namespace: &str, identifier: &str) -> String { pub fn configurables_name(template_name: &str) -> String { let name = to_pascal_case(template_name); - format!("{}Configurables", name) + // FIXME: Rename this + format!("{}InnerConfigurables", name) } /// Return the name of the join table for the given entities. diff --git a/packages/fuel-indexer-macros/src/indexer.rs b/packages/fuel-indexer-macros/src/indexer.rs index 1037198ad..7430015ab 100644 --- a/packages/fuel-indexer-macros/src/indexer.rs +++ b/packages/fuel-indexer-macros/src/indexer.rs @@ -1254,7 +1254,7 @@ pub fn process_indexer_module(attrs: TokenStream, item: TokenStream) -> TokenStr // .unwrap_or_default() // }) // .unwrap_or_default(); - let predicate_abis = manifest + let predicate_abi_info = manifest .predicates() .map(|p| { p.templates() @@ -1265,9 +1265,13 @@ pub fn process_indexer_module(attrs: TokenStream, item: TokenStream) -> TokenStr Some(&t.abi), manifest.graphql_schema(), ); - predicate_abi + + if let Some(predicate_abi) = predicate_abi { + return Some((predicate_abi, t.name.to_string())); + } + None }) - .collect::>() + .collect::>() }) .unwrap_or_default() }) @@ -1284,10 +1288,9 @@ pub fn process_indexer_module(attrs: TokenStream, item: TokenStream) -> TokenStr }); } - predicate_abis.iter().for_each(|abi_path| { + predicate_abi_info.iter().for_each(|(abi_path, name)| { targets.push(AbigenTarget { - // TODO: Change these to the actual predicate name - name: manifest.namespace().to_string(), + name: name.to_string(), abi: abi_path.to_string(), program_type: ProgramType::Predicate, }); @@ -1315,9 +1318,9 @@ pub fn process_indexer_module(attrs: TokenStream, item: TokenStream) -> TokenStr let predicate_impl_tokens = predicate_tokens(); // FIXME: do we have to load this twice? - let predicate_abi = predicate_abis + let predicate_abi = predicate_abi_info .iter() - .map(|p| get_json_abi(Some(p.to_string())).unwrap_or_default()) + .map(|(p, _n)| get_json_abi(Some(p.to_string())).unwrap_or_default()) .collect::>(); // FIXME: do we have to load this twice? @@ -1334,8 +1337,12 @@ pub fn process_indexer_module(attrs: TokenStream, item: TokenStream) -> TokenStr let configurables_tokens = configurables_tokens(manifest.predicates(), &predicate_abi); + let predicate_abi = predicate_abi_info + .iter() + .map(|(p, _n)| p.to_string()) + .collect::>(); let (handler_block, fn_items) = - process_fn_items(&manifest, contract_abi, predicate_abis, indexer_module); + process_fn_items(&manifest, contract_abi, predicate_abi, indexer_module); let handler_block = handler_block_wasm(handler_block, &manifest); let output = quote! { diff --git a/packages/fuel-indexer-macros/src/lib.rs b/packages/fuel-indexer-macros/src/lib.rs index 4344b7ce6..8efd53663 100644 --- a/packages/fuel-indexer-macros/src/lib.rs +++ b/packages/fuel-indexer-macros/src/lib.rs @@ -189,10 +189,6 @@ pub(crate) fn configurables_tokens( impl ConfigurableDecoder for #ident { fn decode_type(&self, ty_id: usize, data: Vec) { - - // Testing out predicate encoder stuff!!!! - // let predicate_data = Test1PredicateEncoder::encode_data(true); - match ty_id { #(#config_set_decoders)* _ => { @@ -211,9 +207,16 @@ pub(crate) fn configurables_tokens( impl TryFrom> for #ident { type Error = bincode::Error; fn try_from(bytes: Vec) -> Result { - // TODO: Chunk and decode each piece of the bytearray let obj = Self::default(); - // obj.decode_type(ty_id, data); + let mut left = 0; + let right = bytes.len(); + while left < right { + let ty_id = u32::from_le_bytes(bytes[0..4].try_into().unwrap()); + let len = u32::from_le_bytes(bytes[4..8].try_into().unwrap()); + let arr = bytes[8 .. len as usize].to_vec(); + obj.decode_type(ty_id as usize, arr); + left = 8 + len as usize; + } Ok(obj) } } diff --git a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs index f0e4847e9..61fe4bd72 100644 --- a/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs +++ b/packages/fuel-indexer-tests/indexers/fuel-indexer-test/src/lib.rs @@ -586,7 +586,7 @@ mod fuel_indexer_test { #[predicate] fn fuel_indexer_test_predicates( predicates: PredicateIndex, - configurables: TestPredicate1Configurables, + configurables: TestPredicate1InnerConfigurables, ) { info!("fuel_indexer_test_predicates handling trigger_predicates event"); }