Skip to content

Commit dd76173

Browse files
JonoPrestDZakhJasoonS
authored
V2 (#35)
* Update rescript version and clean up HyperSync client * Update scenarios and remove -with-deps * Refactor context types using unified type Remove line Remove double definition * Remove unused ethers type and converters * Fix broken tests and remove not useful ones * Remove all references to required_entities * Run formatter * Refactor in memory store Remove additional entityName definition * Add entityId to entityUpdate record to remove need for passing id * Apply review comments * Fix genType errors * Fix tests * Initial implementation of v2 * Fix testing frame work Remove hardcoding of async getters * Add node util inspect for debugging * Fix dynamic contract registration flow * Migrate test_codegen handlers to v2 and fix tests Fix big decimal test * Remove Event Contract and Entity suffixes from codegen names * Rename loadLayer type and constructor * Rename enum type to t and unify enum logic * Rename preLoader to loader * Remove fn from register types and add more register apis * Update api to contractRegister with separate function * Update all evm templates for V2 * Remove contract suffix from templates * Remove entity suffix from types in templates * Update swap and dynamic contract handlers * Do not rely on api keys for contract verifycation but keep them as a fallback * Completely remove API tokens - allow users to add their own api tokens if the have one. * Neaten up contract import templates * Dz/merge v1.3 (#44) * [V1] Remove EventSummary from init template (#34) * Remove EventSummary from init template * Revert the code which I shouldn't remove * Do not rely on api keys for contract verifycation but keep them as a fallback * Completely remove API tokens - allow users to add their own api tokens if the have one. * Dz/fuel contract import 5 (#43) * Prompt to get a single fuel contract * A semi-working contract import for Fuel * Fix contract import templates for Fuel * Vendor Fuel abi * Fix evm indexer * Fix rescript_types tests * Human readable names for Fuel logs * Support setting only one log_id per event * Events selection * Add shared_prompts mod * Prompt multiple contracts for Fuel * Refactor prompt_to_continue_adding to reuse for multiple ecosystems * Fix event_name index * Add first non-etherscan contract verification * Remove unused block * Remove Addresses import from Test file --------- Co-authored-by: Jason <[email protected]> --------- Co-authored-by: Jason <[email protected]> * Allow creating an index on 'db_write_timestamp' to allow polling queries to be quicker * Sync fuel fork changes (#46) * Sync Fuel fork changes * Update fuel fork version * Apply latest fuel fork changes * Update Greeter on Fuel template --------- Co-authored-by: Dmitry Zakharov <[email protected]> Co-authored-by: Jason <[email protected]>
1 parent e960fe9 commit dd76173

File tree

100 files changed

+3092
-4239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+3092
-4239
lines changed

codegenerator/cli/src/cli_args/init_config.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ pub mod evm {
5656
.into_iter()
5757
.map(|event| EventConfig {
5858
event: EventConfig::event_string_from_abi_event(&event),
59-
required_entities: None,
60-
is_async: None,
6159
})
6260
.collect();
6361

@@ -291,8 +289,6 @@ pub mod fuel {
291289
.iter()
292290
.map(|selected_log| human_config::evm::EventConfig {
293291
event: format!("{}()", selected_log.event_name),
294-
is_async: None,
295-
required_entities: None,
296292
})
297293
.collect(),
298294
}),

codegenerator/cli/src/cli_args/interactive_init/evm_prompts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ impl LocalImportArgs {
271271
))?;
272272

273273
let abi: ethers::abi::Contract = serde_json::from_str(&abi_file).context(format!(
274-
"Failed to deserialize ABI at {:?} - Please ensure the ABI file is formatted correctly \
275-
or contact the team.",
274+
"Failed to deserialize ABI at {:?} - Please ensure the ABI file is formatted \
275+
correctly or contact the team.",
276276
abi_path
277277
))?;
278278

codegenerator/cli/src/cli_args/interactive_init/fuel_prompts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::PathBuf;
2+
13
use crate::{
24
clap_definitions::fuel::{
35
ContractImportArgs, InitFlow as ClapInitFlow, LocalImportArgs, LocalOrExplorerImport,
@@ -57,7 +59,7 @@ fn get_abi_path_string(local_import_args: &LocalImportArgs) -> Result<String> {
5759
match &local_import_args.abi_file {
5860
Some(p) => Ok(p.clone()),
5961
None => prompt_abi_file_path(|path| {
60-
let maybe_parsed_abi = Abi::parse(&path.to_string());
62+
let maybe_parsed_abi = Abi::parse(PathBuf::from(&path));
6163
match maybe_parsed_abi {
6264
Ok(_) => Validation::Valid,
6365
Err(e) => Validation::Invalid(e.into()),
@@ -116,7 +118,7 @@ async fn get_contract_import_selection(args: ContractImportArgs) -> Result<Selec
116118

117119
let abi_path_string =
118120
get_abi_path_string(&local_import_args).context("Failed getting Fuel ABI path")?;
119-
let abi = Abi::parse(&abi_path_string).context("Failed parsing Fuel ABI")?;
121+
let abi = Abi::parse(PathBuf::from(&abi_path_string)).context("Failed parsing Fuel ABI")?;
120122

121123
let mut selected_logs = abi.get_logs();
122124
if !args.all_events {

codegenerator/cli/src/commands.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub mod rescript {
3535
use std::path::PathBuf;
3636

3737
pub async fn clean(path: &PathBuf) -> Result<std::process::ExitStatus> {
38-
let args = vec!["rescript", "clean", "-with-deps"];
38+
let args = vec!["rescript", "clean"];
3939
execute_command("pnpm", args, path).await
4040
}
4141

@@ -44,7 +44,7 @@ pub mod rescript {
4444
execute_command("pnpm", args, path).await
4545
}
4646
pub async fn build(path: &PathBuf) -> Result<std::process::ExitStatus> {
47-
let args = vec!["rescript", "build", "-with-deps"];
47+
let args = vec!["rescript"];
4848
execute_command("pnpm", args, path).await
4949
}
5050
}
@@ -226,7 +226,10 @@ pub mod start {
226226
"Indexer has failed to run. Please see error logs for more details"
227227
));
228228
}
229-
println!("\nIndexer has successfully finished processing all events on all chains. Exiting process.");
229+
println!(
230+
"\nIndexer has successfully finished processing all events on all chains. Exiting \
231+
process."
232+
);
230233
Ok(())
231234
}
232235
}

codegenerator/cli/src/config_parsing/entity_parsing.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,10 @@ impl Entity {
334334
.map(|multi_field_index| {
335335
multi_field_index
336336
.validate_no_duplicates(&fields)?
337-
.validate_field_name_exists(&fields)?
337+
.validate_field_name_exists_or_is_allowed(
338+
&fields,
339+
&vec!["db_write_timestamp".to_string()],
340+
)?
338341
.validate_no_index_on_derived_field(&fields)?
339342
.validate_no_index_on_id_field()
340343
})
@@ -446,7 +449,7 @@ impl Entity {
446449
&'a self,
447450
schema: &'a Schema,
448451
) -> anyhow::Result<Vec<(&'a Field, &'a Self)>> {
449-
let required_entities_with_field = self
452+
let related_entities_with_field = self
450453
.get_fields()
451454
.into_iter()
452455
.filter_map(|field| {
@@ -465,7 +468,7 @@ impl Entity {
465468
})
466469
.collect::<anyhow::Result<_>>()?;
467470

468-
Ok(required_entities_with_field)
471+
Ok(related_entities_with_field)
469472
}
470473

471474
/// Validate each field type in an the given entity
@@ -719,12 +722,16 @@ impl MultiFieldIndex {
719722
}
720723
}
721724

722-
fn validate_field_name_exists(self, fields: &HashMap<String, Field>) -> anyhow::Result<Self> {
725+
fn validate_field_name_exists_or_is_allowed(
726+
self,
727+
fields: &HashMap<String, Field>,
728+
allowed_names: &Vec<String>,
729+
) -> anyhow::Result<Self> {
723730
for field_name in &self.0 {
724-
if let None = fields.get(field_name) {
731+
if !fields.contains_key(field_name) && !allowed_names.contains(field_name) {
725732
return Err(anyhow!(
726733
"Index error: Field '{}' does not exist in entity, please remove it from the \
727-
`@index` directive.",
734+
`@index` directive.",
728735
field_name,
729736
));
730737
}
@@ -856,7 +863,7 @@ impl RescriptType {
856863
.join(", ");
857864
format!("({})", inner_types_str)
858865
}
859-
RescriptType::EnumVariant(enum_name) => format!("Enums.{}", &enum_name.uncapitalized),
866+
RescriptType::EnumVariant(enum_name) => format!("Enums.{}.t", &enum_name.capitalized),
860867
}
861868
}
862869

@@ -888,7 +895,7 @@ impl RescriptType {
888895
format!("S.tuple((. s) => ({}))", inner_str)
889896
}
890897
RescriptType::EnumVariant(enum_name) => {
891-
format!("Enums.{}Schema", &enum_name.uncapitalized)
898+
format!("Enums.{}.schema", &enum_name.capitalized)
892899
}
893900
}
894901
}
@@ -906,7 +913,7 @@ impl RescriptType {
906913
RescriptType::Array(_) => "[]".to_string(),
907914
RescriptType::Option(_) => "None".to_string(),
908915
RescriptType::EnumVariant(enum_name) => {
909-
format!("Enums.{}Default", &enum_name.uncapitalized)
916+
format!("Enums.{}.default", &enum_name.capitalized)
910917
}
911918
RescriptType::Tuple(inner_types) => {
912919
let inner_types_str = inner_types
@@ -1702,7 +1709,7 @@ type TestEntity {
17021709

17031710
assert_eq!(
17041711
rescript_type.to_string(),
1705-
"option<Enums.testEnum>".to_owned()
1712+
"option<Enums.TestEnum.t>".to_owned()
17061713
);
17071714
}
17081715

codegenerator/cli/src/config_parsing/graph_migration/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,6 @@ pub async fn generate_config_from_subgraph_id(
343343
.collect::<String>();
344344
let event = EventConfig {
345345
event: event_name.to_string(),
346-
required_entities: Some(vec![]),
347-
is_async: None,
348346
};
349347

350348
Ok(event)

codegenerator/cli/src/config_parsing/human_config.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct NetworkContract<T> {
2424
}
2525

2626
pub mod evm {
27-
use super::{GlobalContract, NetworkContract, NetworkId, RequiredEntity};
27+
use super::{GlobalContract, NetworkContract, NetworkId};
2828
use serde::{Deserialize, Serialize};
2929

3030
#[derive(Debug, Serialize, Deserialize, PartialEq)]
@@ -125,10 +125,6 @@ pub mod evm {
125125
#[serde(rename_all = "camelCase")]
126126
pub struct EventConfig {
127127
pub event: String,
128-
#[serde(skip_serializing_if = "Option::is_none")]
129-
pub is_async: Option<bool>,
130-
#[serde(skip_serializing_if = "Option::is_none")]
131-
pub required_entities: Option<Vec<RequiredEntity>>,
132128
}
133129

134130
impl EventConfig {
@@ -207,16 +203,6 @@ pub mod fuel {
207203
}
208204
}
209205

210-
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
211-
#[serde(rename_all = "camelCase")]
212-
pub struct RequiredEntity {
213-
pub name: String,
214-
#[serde(skip_serializing_if = "Option::is_none")]
215-
pub labels: Option<Vec<String>>,
216-
#[serde(skip_serializing_if = "Option::is_none")]
217-
pub array_labels: Option<Vec<String>>,
218-
}
219-
220206
fn strip_to_letters(string: &str) -> String {
221207
let mut pg_friendly_name = String::new();
222208
for c in string.chars() {

codegenerator/cli/src/config_parsing/system_config.rs

Lines changed: 16 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use super::{
22
chain_helpers::get_confirmed_block_threshold_from_id,
33
entity_parsing::{Entity, GraphQLEnum, Schema},
4-
human_config::{
5-
self,
6-
evm::{
7-
EventConfig, EventDecoder, HumanConfig, HypersyncConfig as HumanHypersyncConfig,
8-
Network as HumanNetwork, RpcConfig as HumanRpcConfig, SyncSourceConfig,
9-
},
4+
human_config::evm::{
5+
EventConfig, EventDecoder, HumanConfig, HypersyncConfig as HumanHypersyncConfig,
6+
Network as HumanNetwork, RpcConfig as HumanRpcConfig, SyncSourceConfig,
107
},
118
hypersync_endpoints,
129
validation::validate_names_not_reserved,
@@ -17,8 +14,6 @@ use crate::{
1714
};
1815
use anyhow::{anyhow, Context, Result};
1916
use ethers::abi::{ethabi::Event as EthAbiEvent, EventParam, HumanReadableParser};
20-
21-
use itertools::Itertools;
2217
use serde::Serialize;
2318
use std::{
2419
collections::{HashMap, HashSet},
@@ -173,7 +168,7 @@ impl SystemConfig {
173168
.events
174169
.iter()
175170
.cloned()
176-
.map(|e| Event::try_from_config_event(e, &abi_from_file, &schema))
171+
.map(|e| Event::try_from_config_event(e, &abi_from_file))
177172
.collect::<Result<Vec<_>>>()
178173
.context(format!(
179174
"Failed parsing abi types for events in global contract {}",
@@ -207,20 +202,22 @@ impl SystemConfig {
207202
.events
208203
.iter()
209204
.cloned()
210-
.map(|e| Event::try_from_config_event(e, &abi_from_file, &schema))
205+
.map(|e| Event::try_from_config_event(e, &abi_from_file))
211206
.collect::<Result<Vec<_>>>()?;
212207

213208
let contract =
214209
Contract::new(contract.name, l_contract.handler, events, abi_from_file)
215210
.context(format!(
216-
"Failed parsing locally defined network contract at network id {}",
217-
network.id
218-
))?;
211+
"Failed parsing locally defined network contract at network \
212+
id {}",
213+
network.id
214+
))?;
219215

220216
//Check if contract exists
221217
unique_hashmap::try_insert(&mut contracts, contract.name.clone(), contract)
222218
.context(format!(
223-
"Failed inserting locally defined network contract at network id {}",
219+
"Failed inserting locally defined network contract at network id \
220+
{}",
224221
network.id,
225222
))?;
226223
}
@@ -493,7 +490,6 @@ impl Contract {
493490
let mut events_abi = ethers::abi::Contract::default();
494491

495492
let mut event_names = Vec::new();
496-
let mut entity_and_label_names = Vec::new();
497493
for event in &events {
498494
events_abi
499495
.events
@@ -502,18 +498,6 @@ impl Contract {
502498
.push(event.get_event().clone());
503499

504500
event_names.push(event.event.0.name.clone());
505-
506-
for entity in &event.required_entities {
507-
entity_and_label_names.push(entity.name.clone());
508-
if let Some(labels) = &entity.labels {
509-
entity_and_label_names.extend(labels.clone());
510-
}
511-
if let Some(array_labels) = &entity.array_labels {
512-
entity_and_label_names.extend(array_labels.clone());
513-
}
514-
}
515-
// Checking that entity names do not include any reserved words
516-
validate_names_not_reserved(&entity_and_label_names, "Required Entities".to_string())?;
517501
}
518502
// Checking that event names do not include any reserved words
519503
validate_names_not_reserved(&event_names, "Events".to_string())?;
@@ -557,7 +541,6 @@ impl Contract {
557541
#[derive(Debug, Clone, PartialEq)]
558542
pub struct Event {
559543
event: NormalizedEthAbiEvent,
560-
pub required_entities: Vec<human_config::RequiredEntity>,
561544
pub is_async: bool,
562545
}
563546

@@ -568,7 +551,7 @@ impl Event {
568551
Ok(event) => Ok(event),
569552
Err(err) => Err(anyhow!(
570553
"EE103: Unable to parse event signature {} due to the following error: {}. \
571-
Please refer to our docs on how to correctly define a human readable ABI.",
554+
Please refer to our docs on how to correctly define a human readable ABI.",
572555
sig,
573556
err
574557
)),
@@ -599,30 +582,12 @@ impl Event {
599582
pub fn try_from_config_event(
600583
human_cfg_event: EventConfig,
601584
opt_abi: &Option<EvmAbi>,
602-
schema: &Schema,
603585
) -> Result<Self> {
604586
let event = Event::get_abi_event(&human_cfg_event.event, opt_abi)?.into();
605587

606-
let required_entities = human_cfg_event.required_entities.unwrap_or_else(|| {
607-
// If no required entities are specified, we assume all entities are required
608-
schema
609-
.entities
610-
.values()
611-
.sorted_by_key(|v| &v.name)
612-
.cloned()
613-
.map(|entity| human_config::RequiredEntity {
614-
name: entity.name,
615-
labels: None,
616-
array_labels: None,
617-
})
618-
.collect()
619-
});
620-
let is_async = human_cfg_event.is_async.unwrap_or_else(|| false);
621-
622588
Ok(Event {
623589
event,
624-
required_entities,
625-
is_async,
590+
is_async: false,
626591
})
627592
}
628593

@@ -658,22 +623,6 @@ impl From<EthAbiEvent> for NormalizedEthAbiEvent {
658623
}
659624
}
660625

661-
#[derive(Debug, Clone, PartialEq)]
662-
struct RequiredEntity {
663-
pub name: String,
664-
pub labels: Vec<String>,
665-
pub array_labels: Vec<String>,
666-
}
667-
impl From<human_config::RequiredEntity> for RequiredEntity {
668-
fn from(r: human_config::RequiredEntity) -> Self {
669-
RequiredEntity {
670-
name: r.name,
671-
labels: r.labels.unwrap_or_else(|| vec![]),
672-
array_labels: r.array_labels.unwrap_or_else(|| vec![]),
673-
}
674-
}
675-
}
676-
677626
#[cfg(test)]
678627
mod test {
679628
use super::SystemConfig;
@@ -822,7 +771,9 @@ mod test {
822771
Event::get_abi_event(&event_string, &None)
823772
.unwrap_err()
824773
.to_string(),
825-
"EE103: Unable to parse event signature event MyEvent(uint69 myArg) due to the following error: UnrecognisedToken 14:20 `uint69`. Please refer to our docs on how to correctly define a human readable ABI."
774+
"EE103: Unable to parse event signature event MyEvent(uint69 myArg) due to the \
775+
following error: UnrecognisedToken 14:20 `uint69`. Please refer to our docs on how \
776+
to correctly define a human readable ABI."
826777
);
827778
}
828779

0 commit comments

Comments
 (0)