From b25ad2f254cba94f97cfe4644f1067f3f0c229ea Mon Sep 17 00:00:00 2001 From: ra0x3 Date: Mon, 23 Oct 2023 15:31:24 -0400 Subject: [PATCH] pending verification step --- Cargo.lock | 11 ----- Cargo.toml | 2 +- packages/fuel-indexer-macros/src/indexer.rs | 46 ++++++++++++++++++++- packages/fuel-indexer-macros/src/lib.rs | 31 ++++++++------ packages/fuel-indexer-types/src/fuel.rs | 16 +++---- 5 files changed, 72 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c31aa7fb4..2b7a81f9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4111,17 +4111,6 @@ dependencies = [ "serde", ] -[[package]] -name = "greetings_native_indexer" -version = "0.0.0" -dependencies = [ - "async-trait", - "fuel-indexer", - "fuel-indexer-utils", - "fuels", - "serde", -] - [[package]] name = "group" version = "0.12.1" diff --git a/Cargo.toml b/Cargo.toml index 28233807a..fd6507583 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" members = [ "examples/fuel-explorer/fuel-explorer", - "examples/greetings-native/greetings-native-indexer", + # "examples/greetings-native/greetings-native-indexer", "examples/greetings/greetings-data", "examples/greetings/greetings-fuel-client", "examples/greetings/greetings-indexer", diff --git a/packages/fuel-indexer-macros/src/indexer.rs b/packages/fuel-indexer-macros/src/indexer.rs index 92616dfe4..e4b468170 100644 --- a/packages/fuel-indexer-macros/src/indexer.rs +++ b/packages/fuel-indexer-macros/src/indexer.rs @@ -717,7 +717,49 @@ fn process_fn_items( }) .collect::>(); - // let foo = signaled_predicates.iter().map(|p| ) + // Cache signaled predicates + signaled_predicates.iter().for_each(|p| { + let _p = PredicateEntity::from(p.to_owned()).get_or_create(); + }); + + let verifiable_predicates = inputs.iter().filter(|i| { + match i { + + fuel::Input::Coin(coin) => { + let fuel::InputCoin { + utxo_id, + owner, + amount, + asset_id, + predicate, + predicate_data, + .. + } = coin; + + // This could potentially be an InputCoin with no predicate data + if predicate.is_empty() || predicate_data.is_empty() { + return false; + } + + signaled_predicates.iter().any(|p| { + let utxo = p.coin_output(); + utxo.to == *owner + }) + } + _ => { + warn!("This input type is not handled yet."); + false + } + } + }); + + // 1. do the verification + + + + // 2a. for verified predicates, add them to predicateindex + // 2b. for verified predicates, derive their #identConfigurables and add them to the ConfigurablesIndex + // - Predicate.configurables has the predicate data for a single predicate and set of configurables @@ -1064,7 +1106,7 @@ pub fn process_indexer_module(attrs: TokenStream, item: TokenStream) -> TokenStr #configurables_tokens - // #predicate_impl_tokens + #predicate_impl_tokens #handler_block diff --git a/packages/fuel-indexer-macros/src/lib.rs b/packages/fuel-indexer-macros/src/lib.rs index 21e1e83ef..98cb37fec 100644 --- a/packages/fuel-indexer-macros/src/lib.rs +++ b/packages/fuel-indexer-macros/src/lib.rs @@ -37,15 +37,23 @@ pub(crate) fn predicate_tokens( ) -> proc_macro2::TokenStream { quote! { impl From for PredicateEntity { - fn from(predicate: Predicate) -> Self { - let coin_output = predicate.coin_output(); - let witness_data = predicate.witness_data(); - let spent_tx_id = predicate.spent_tx_id(); - let unspent_tx_id = predicate.unspent_tx_id(); - let configurables = predicate.configurables(); - let predicate_id = predicate.predicate_id(); - - Self::new(configurables, predicate_id, witness_data.output_index(), coin_output, unspent_tx_id, spent_tx_id) + fn from(p: Predicate) -> Self { + let coin_output = p.coin_output(); + let spent_tx_id = p.spent_tx_id(); + let unspent_tx_id = p.unspent_tx_id(); + let configurables = p.configurables(); + let predicate_id = p.predicate_id(); + let output_index = p.output_index(); + + let coin_output = bincode::serialize(&coin_output).expect("Could not serialize CoinOutput."); + + Self::new( + configurables.to_owned(), + predicate_id.to_owned(), + output_index.to_owned(), + coin_output, + unspent_tx_id.to_owned(), + spent_tx_id.to_owned()) } } @@ -58,11 +66,10 @@ pub(crate) fn predicate_tokens( coin_output, predicate_id, output_index, + .. } = entity; - let coin_output: fuel::CoinOutput = bincode::deserialize(coin_output).unwrap(); - - Self { predicate_id, output_index, coin_output, unspent_tx_id, spent_tx_id, configurables } + Self::from_entity(output_index, configurables.to_vec(), predicate_id, coin_output, unspent_tx_id, spent_tx_id) } } } diff --git a/packages/fuel-indexer-types/src/fuel.rs b/packages/fuel-indexer-types/src/fuel.rs index dcb072c9e..1921f4667 100644 --- a/packages/fuel-indexer-types/src/fuel.rs +++ b/packages/fuel-indexer-types/src/fuel.rs @@ -215,8 +215,8 @@ impl From for Input { nonce: message_signed.nonce, witness_index: message_signed.witness_index, data: message_signed.data, - predicate: "".into(), - predicate_data: "".into(), + predicate: Bytes::new(), + predicate_data: Bytes::new(), }) } ClientInput::MessageDataPredicate(message_predicate) => { @@ -241,8 +241,8 @@ impl From for Input { tx_pointer: coin_signed.tx_pointer.into(), witness_index: coin_signed.witness_index, maturity: coin_signed.maturity, - predicate: "".into(), - predicate_data: "".into(), + predicate: Bytes::new(), + predicate_data: Bytes::new(), }), ClientInput::CoinPredicate(coin_predicate) => Input::Coin(InputCoin { utxo_id: coin_predicate.utxo_id, @@ -269,9 +269,9 @@ impl From for Input { amount: message_coin.amount, nonce: message_coin.nonce, witness_index: message_coin.witness_index, - data: "".into(), - predicate: "".into(), - predicate_data: "".into(), + data: Bytes::new(), + predicate: Bytes::new(), + predicate_data: Bytes::new(), }) } ClientInput::MessageCoinPredicate(message_coin) => { @@ -281,7 +281,7 @@ impl From for Input { amount: message_coin.amount, nonce: message_coin.nonce, witness_index: 0, - data: "".into(), + data: Bytes::new(), predicate: message_coin.predicate, predicate_data: message_coin.predicate_data, })