Skip to content

Commit

Permalink
it builds :)
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0x3 committed Nov 15, 2023
1 parent a0d1f27 commit f687459
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 236 deletions.
4 changes: 2 additions & 2 deletions docs/src/indexing-fuel-types/predicates.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
```rust,ignore
/// Standardized `Witness` data format for predicates.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Predicate {
pub struct IndexerPredicate {
/// Hash of associated predicate bytecode
template_id: Bytes32,
Expand Down Expand Up @@ -49,7 +49,7 @@ use fuel_indexer_utils::prelude::*;
#[indexer(manifest = "indexer.manifest.yaml")]
mod indexer_mod {
fn handle_spent_predicates(predicates: Vec<Predicate>) {
fn handle_spent_predicates(predicates: Vec<IndexerPredicate>) {
unimplemented!()
}
}
Expand Down
29 changes: 14 additions & 15 deletions packages/fuel-indexer-lib/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,30 @@ lazy_static! {
"Option<ID>",
"Option<Identity>",
"Option<Json>",
"Option<UID>",
"Option<String>",
"Option<UID>",
"String",
"UID",
"Vec<FtColumn>",
"String",
]);

/// Fuel-specific receipt-related type names.
pub static ref FUEL_PRIMITIVES: HashSet<&'static str> = HashSet::from([
"BlockData",
"Burn",
"Call",
"IndexerPredicate",
"Log",
"LogData",
"MessageOut",
"Mint",
"Panic",
"FooPredicate",
"Return",
"Revert",
"ScriptResult",
"Transfer",
"TransferOut",
"Mint",
"Burn",
"Predicate",
"PredicateIndex",
// "ConfigurablesIndex",
]);

/// Type names that are not allowed in GraphQL schema.
Expand Down Expand Up @@ -149,6 +148,7 @@ lazy_static! {
"FieldTxPointer",
"GasLimit",
"GasPrice",
"IndexerPredicate",
"Inputs",
"Log",
"Log",
Expand All @@ -160,8 +160,7 @@ lazy_static! {
"Mint",
"Outputs",
"Panic",
"Predicate",
"PredicateIndex",
"FooPredicate",
"ReceiptsRoot",
"Return",
"Revert",
Expand All @@ -187,18 +186,18 @@ lazy_static! {

/// Generic Sway ABI types.
pub static ref IGNORED_GENERIC_METADATA: HashSet<&'static str> = HashSet::from([
"generic T",
"generic E",
"enum Result",
"generic D",
"generic E",
"generic T",
"raw untyped ptr",
"struct RawVec",
"struct RawBytes",
"struct Bytes",
"enum Result"
"struct RawBytes",
"struct RawVec",
]);

pub static ref GENERIC_STRUCTS: HashSet<&'static str> = HashSet::from([
"Option",
"Vec",
"Option"
]);
}
4 changes: 2 additions & 2 deletions packages/fuel-indexer-lib/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use async_graphql_parser::{
},
Pos, Positioned,
};
use fuel_indexer_types::native::{GraphQLEntity, IndexMetadata, Predicate};
use fuel_indexer_types::native::{GraphQLEntity, IndexMetadata, IndexerPredicate};
use sha2::{Digest, Sha256};
use std::collections::{HashMap, HashSet};
use types::IdCol;
Expand All @@ -41,7 +41,7 @@ fn inject_native_entities_into_schema(schema: &str) -> String {
}

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

schema
Expand Down
5 changes: 2 additions & 3 deletions packages/fuel-indexer-macros/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,15 @@ impl Codegen for TypeDeclaration {
"bool" => quote! { bool },
"Burn" => quote! { Burn },
"Call" => quote! { Call },
// "ConfigurablesIndex" => quote! { ConfigurablesIndex },
"generic T" => quote! {},
"Identity" => quote! { Identity },
"IndexerPredicate" => quote! { IndexerPredicate },
"Log" => quote! { Log },
"LogData" => quote! { LogData },
"MessageOut" => quote! { MessageOut },
"Mint" => quote! { Mint },
"Panic" => quote! { Panic },
"Predicate" => quote! { Predicate },
"PredicateIndex" => quote! { PredicateIndex },
"FooPredicate" => quote! { FooPredicate },
"Return" => quote! { Return },
"Revert" => quote! { Revert },
"ScriptResult" => quote! { ScriptResult },
Expand Down
92 changes: 18 additions & 74 deletions packages/fuel-indexer-macros/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ fn process_fn_items(

let contract_abi = get_json_abi(contract_abi_path).unwrap_or_default();

// let predicate_abi = predicate_abi_paths
// .iter()
// .map(|p| get_json_abi(Some(p.to_string())).unwrap_or_default())
// .collect::<Vec<_>>();

let mut decoded_type_snippets = HashSet::new();
let mut decoded_log_match_arms = HashSet::new();
let mut decoded_type_fields = HashSet::new();
Expand All @@ -85,16 +80,6 @@ fn process_fn_items(
.map(|t| strip_callpath_from_type_field(t.clone()))
.collect::<Vec<TypeDeclaration>>();

// let predicate_abi_types = predicate_abi
// .iter()
// .flat_map(|abi| {
// abi.types
// .iter()
// .map(|c| (c.type_id, c.clone()))
// .collect::<Vec<_>>()
// })
// .collect::<HashMap<usize, TypeDeclaration>>();

let configurable_abi_types = manifest
.predicates()
.map(|p| {
Expand Down Expand Up @@ -843,6 +828,11 @@ fn process_fn_items(
Ok(())
}

// FIXME: Until SDK's Predicate is serializable, we can't use decode_type
pub fn decoder_predicate_type(&mut self, predicate: FooPredicate) {
self.foopredicate_decoded.push(predicate);
}

pub fn decode_logdata(&mut self, rb: usize, data: Vec<u8>) -> anyhow::Result<()> {
match rb {
#(#contract_log_type_decoders),*
Expand Down Expand Up @@ -873,7 +863,7 @@ fn process_fn_items(
}
};

let predicate_verification_toks = predicate_verification_tokens(&manifest);
let predicate_verification_toks = predicate_verification_tokens(manifest);

let predicate_tokens = quote! {
match &tx.transaction {
Expand All @@ -890,7 +880,7 @@ fn process_fn_items(
.map(|w| PredicateWitnessData::try_from(w.to_owned()))
.filter_map(Result::ok)
.map(|data| {
Predicate::from_signaled_witness_data(
IndexerPredicate::from_signaled_witness_data(
data.to_owned(),
tx_id,
outputs[data.output_index() as usize].to_owned(),
Expand All @@ -911,13 +901,13 @@ fn process_fn_items(
owner,
amount,
asset_id,
predicate,
predicate: predicate_code,
predicate_data,
..
} = coin;

// This could potentially be an InputCoin with no predicate data
if predicate.is_empty() || predicate_data.is_empty() {
if predicate_code.is_empty() || predicate_data.is_empty() {
return None;
}

Expand All @@ -932,65 +922,24 @@ fn process_fn_items(
});


let configurable = match pred {
Some(p) => {
let template_id = p.template_id().to_string();
let predicate_data = p.configurables().to_owned();
match pred {
Some(pred) => {
let template_id = pred.template_id().to_string();
let predicate_data = pred.configurables().to_owned();
let configurable = match template_id.as_str() {
#(#configurables_match)*
_ => panic!("Unknown predicate template ID; check ABI to make sure that predicate IDs are correct.")
};

Some(configurable)
}
None => None,
};

if let Some(configurable) = configurable {
match configurable {
#(#predicate_verification_toks)*
_ => panic!("Unrecognized configurable type."),
}
}

/**
if let Some(configurable) = configurable {
match configurable => {
ConfigurablesContainer::TestPredicate1IndexerConfigurables { field1, field2, .. } => {
let configurables = TestPredicate1Configurables::new()
.with_STRUCT(field1)
.with_enum(field2);
let predicate_data = TestPredicate1Encoder::encode_data(field1, field2, ..);
let mut predicate: Predicate = Predicate::from_code(chain_id, predicate_code)?
.with_data(predicate_data)
.with_configurables(configurables);
if *predicate.address() == coin_output.owner {
decoder.decode_type(predicate.type_id(), predicate);
}
match configurable {
#(#predicate_verification_toks)*
_ => panic!("Unrecognized configurable type."),
}
ConfigurablesContainer::TestPredicate2IndexerConfigurables { field2, field2, .. } => {
let configurables = TestPredicate2Configurables::new()
.with_STRUCT(field1)
.with_enum(field2);

let predicate_data = TestPredicate2Encoder::encode_data(field1, field2, .. );
let mut predicate: Predicate = Predicate::from_code(chain_id, predicate_code)?
.with_data(predicate_data)
.with_configurables(configurables);
if *predicate.address() == coin_output.owner {
decoder.decode_type(predicate.type_id(), predicate);
}
}
None
}
None => None,
}
*/

None
}
_ => {
debug!("Input type ignored for predicates.");
Expand Down Expand Up @@ -1333,11 +1282,6 @@ pub fn process_indexer_module(attrs: TokenStream, item: TokenStream) -> TokenStr

let indexer_configurables_tokens = indexer_configurables_tokens(&manifest);

// let predicate_abi_paths = predicate_abi_info
// .iter()
// .map(|(p, _n)| p.to_string())
// .collect::<Vec<_>>();

let (handler_block, fn_items) = process_fn_items(&manifest, indexer_module);
let handler_block = handler_block_wasm(handler_block);
let output = quote! {
Expand Down
Loading

0 comments on commit f687459

Please sign in to comment.