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

Commit

Permalink
pending verification step
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0x3 committed Oct 23, 2023
1 parent 0bcbbb1 commit b25ad2f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 34 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 44 additions & 2 deletions packages/fuel-indexer-macros/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,49 @@ fn process_fn_items(
})
.collect::<Vec<_>>();

// 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
Expand Down Expand Up @@ -1064,7 +1106,7 @@ pub fn process_indexer_module(attrs: TokenStream, item: TokenStream) -> TokenStr

#configurables_tokens

// #predicate_impl_tokens
#predicate_impl_tokens

#handler_block

Expand Down
31 changes: 19 additions & 12 deletions packages/fuel-indexer-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ pub(crate) fn predicate_tokens(
) -> proc_macro2::TokenStream {
quote! {
impl From<Predicate> 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())
}
}

Expand All @@ -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)
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/fuel-indexer-types/src/fuel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ impl From<ClientInput> 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) => {
Expand All @@ -241,8 +241,8 @@ impl From<ClientInput> 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,
Expand All @@ -269,9 +269,9 @@ impl From<ClientInput> 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) => {
Expand All @@ -281,7 +281,7 @@ impl From<ClientInput> 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,
})
Expand Down

0 comments on commit b25ad2f

Please sign in to comment.