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

Commit

Permalink
rename configurables to inpputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0x3 committed Nov 17, 2023
1 parent 423586f commit 5409045
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 41 deletions.
11 changes: 9 additions & 2 deletions packages/fuel-indexer-macros/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,13 @@ fn process_fn_items(
let type_tokens = typ.rust_tokens();
let name = typ.decoder_field_ident();
let ty_id = typ.type_id;

// NOTE: This decoding is used to derive the indexer configurable so that we can push the configurable
// to the `Decoder` (as we do for all other types passed to indexer handlers).
Some(quote! {
#ty_id => {
let obj = #type_tokens::try_from(data).expect("Could not deserialize configurables.");
// FIXME: Are we supposed to be decoding the witness data to indexer configurables? Or raw predicate data?
let obj = #type_tokens::new(data);
self.#name.push(obj);
}
})
Expand Down Expand Up @@ -739,9 +743,12 @@ fn process_fn_items(
let name = indexer_configurables_name(&t.name);
let ident = format_ident! { "{}", name };

// NOTE: This decoding is used to derive the indexer configurable so that we can further use it
// before we move to the predicate verification process.
quote! {
#template_id => {
let obj = #ident::try_from(predicate_data).expect("Failed to decode configurable");
// FIXME: Are we supposed to be decoding the witness data to indexer configurables? Or raw predicate data?
let obj = #ident::new(predicate_data);
ConfigurablesContainer::#ident(obj)
},
}
Expand Down
58 changes: 33 additions & 25 deletions packages/fuel-indexer-macros/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,10 @@ pub fn transaction_predicate_tokens(
match pred {
Some(pred) => {
let template_id = pred.template_id().to_string();
let predicate_data = pred.configurables().to_owned();

// FIXME: What is the difference between these inputs, and the inputs in `predicate_data` from the TX?
// Why do we keep this twice?
let predicate_data = pred.inputs().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.")
Expand Down Expand Up @@ -607,6 +610,31 @@ pub fn indexer_configurables_tokens(manifest: &Manifest) -> TokenStream {
#(#predicate_input_fields),*
}

impl #ident {

// TODO: Should document the standardization of predicate witness data

pub fn new(data: Vec<u8>) -> Self {
let mut ty_ids: Vec<u32> = Vec::new();
let mut indices: Vec<u32> = Vec::new();
let mut lens: Vec<u32> = Vec::new();

let mut left = 0;
let right = data.len();
while left < right {
let ty_id = u32::from_le_bytes(data[left..4].try_into().unwrap());
let len = u32::from_le_bytes(data[left + 4..8].try_into().unwrap());
let arr = data[left + 4 + 8 .. len as usize].to_vec();
ty_ids.push(ty_id);
indices.push(left as u32);
lens.push(len);
left = 8 + len as usize;
}

todo!("Finish!")
}
}

impl ConfigurableDecoder for #ident {
fn decode_type(&self, ty_id: usize, data: Vec<u8>) {
match ty_id {
Expand All @@ -623,26 +651,6 @@ pub fn indexer_configurables_tokens(manifest: &Manifest) -> TokenStream {
type_id(FUEL_TYPES_NAMESPACE, #name) as usize
}
}

// TODO: Should document the standardization of predicate witness data

impl TryFrom<Vec<u8>> for #ident {
type Error = bincode::Error;
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
// let obj = Self::default();
// 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)
todo!()
}
}
}
});

Expand Down Expand Up @@ -670,14 +678,14 @@ pub fn predicate_tokens() -> TokenStream {
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 inputs = p.inputs();
let template_id = p.template_id();
let output_index = p.output_index();

let coin_output = bincode::serialize(&coin_output).expect("Could not serialize CoinOutput.");

Self::new(
configurables.to_owned(),
inputs.to_owned(),
template_id.to_owned(),
output_index.to_owned(),
coin_output,
Expand All @@ -690,7 +698,7 @@ pub fn predicate_tokens() -> TokenStream {
impl From<PredicateEntity> for IndexerPredicate {
fn from(entity: PredicateEntity) -> Self {
let PredicateEntity {
configurables,
inputs,
unspent_tx_id,
spent_tx_id,
coin_output,
Expand All @@ -701,7 +709,7 @@ pub fn predicate_tokens() -> TokenStream {

Self::from_entity(
output_index,
configurables.to_vec(),
inputs.to_vec(),
template_id,
coin_output,
unspent_tx_id,
Expand Down
28 changes: 14 additions & 14 deletions packages/fuel-indexer-types/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub struct PredicateWitnessData {
/// Configurable constants in predicates.
output_index: u64,

/// Configurables passed to predicate.
configurables: Vec<u8>,
/// Predicate inputs.
inputs: Vec<u8>,
}

impl PredicateWitnessData {
Expand All @@ -71,8 +71,8 @@ impl PredicateWitnessData {
}

/// Return the configuration schema of the associated predicate.
pub fn configurables(&self) -> &Vec<u8> {
&self.configurables
pub fn inputs(&self) -> &Vec<u8> {
&self.inputs
}
}
impl TryFrom<Witness> for PredicateWitnessData {
Expand All @@ -86,11 +86,11 @@ impl TryFrom<Witness> for PredicateWitnessData {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct IndexerPredicate {
/// Hash of associated predicate bytecode
/// Hash of associated predicate bytecode.
template_id: Bytes32,

/// Configurable constants in predicates.
configurables: Vec<u8>,
/// Inputs to the predicate.
inputs: Vec<u8>,

/// Relevant TX output indices of predicates that need to be watched.
output_index: u64,
Expand All @@ -109,7 +109,7 @@ impl IndexerPredicate {
/// Create a new `IndexerPredicate`.
pub fn from_entity(
output_index: u64,
configurables: Vec<u8>,
inputs: Vec<u8>,
template_id: Bytes32,
coin_output: Vec<u8>,
unspent_tx_id: Bytes32,
Expand All @@ -119,7 +119,7 @@ impl IndexerPredicate {
.expect("Could not deserialize coin output.");
Self {
template_id,
configurables,
inputs,
output_index,
coin_output,
unspent_tx_id,
Expand All @@ -133,8 +133,8 @@ impl IndexerPredicate {
}

/// Get the configuration schema of the predicate.
pub fn configurables(&self) -> &Vec<u8> {
&self.configurables
pub fn inputs(&self) -> &Vec<u8> {
&self.inputs
}

/// Get the predicate data output index.
Expand Down Expand Up @@ -172,12 +172,12 @@ impl IndexerPredicate {
let PredicateWitnessData {
template_id,
output_index,
configurables,
inputs,
} = data;

Self {
template_id,
configurables,
inputs,
output_index,
coin_output,
unspent_tx_id: tx_id,
Expand All @@ -201,7 +201,7 @@ impl GraphQLEntity for IndexerPredicate {
r#"
type PredicateEntity @entity {
id: ID!
configurables: Bytes!
inputs: Bytes!
template_id: Bytes32!
output_index: U64!
coin_output: Bytes!
Expand Down

0 comments on commit 5409045

Please sign in to comment.