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

Commit

Permalink
update configurable decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0x3 committed Nov 10, 2023
1 parent 3944138 commit 07049a4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/fuel-indexer-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 16 additions & 9 deletions packages/fuel-indexer-macros/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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::<Vec<String>>()
.collect::<Vec<(String, String)>>()
})
.unwrap_or_default()
})
Expand All @@ -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,
});
Expand Down Expand Up @@ -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::<Vec<_>>();

// FIXME: do we have to load this twice?
Expand All @@ -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::<Vec<_>>();
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! {

Expand Down
15 changes: 9 additions & 6 deletions packages/fuel-indexer-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ pub(crate) fn configurables_tokens(

impl ConfigurableDecoder for #ident {
fn decode_type(&self, ty_id: usize, data: Vec<u8>) {

// Testing out predicate encoder stuff!!!!
// let predicate_data = Test1PredicateEncoder::encode_data(true);

match ty_id {
#(#config_set_decoders)*
_ => {
Expand All @@ -211,9 +207,16 @@ pub(crate) fn configurables_tokens(
impl TryFrom<Vec<u8>> for #ident {
type Error = bincode::Error;
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
// 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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 07049a4

Please sign in to comment.