Skip to content

Commit

Permalink
V2 (#35)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent e960fe9 commit dd76173
Show file tree
Hide file tree
Showing 100 changed files with 3,092 additions and 4,239 deletions.
4 changes: 0 additions & 4 deletions codegenerator/cli/src/cli_args/init_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ pub mod evm {
.into_iter()
.map(|event| EventConfig {
event: EventConfig::event_string_from_abi_event(&event),
required_entities: None,
is_async: None,
})
.collect();

Expand Down Expand Up @@ -291,8 +289,6 @@ pub mod fuel {
.iter()
.map(|selected_log| human_config::evm::EventConfig {
event: format!("{}()", selected_log.event_name),
is_async: None,
required_entities: None,
})
.collect(),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ impl LocalImportArgs {
))?;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use crate::{
clap_definitions::fuel::{
ContractImportArgs, InitFlow as ClapInitFlow, LocalImportArgs, LocalOrExplorerImport,
Expand Down Expand Up @@ -57,7 +59,7 @@ fn get_abi_path_string(local_import_args: &LocalImportArgs) -> Result<String> {
match &local_import_args.abi_file {
Some(p) => Ok(p.clone()),
None => prompt_abi_file_path(|path| {
let maybe_parsed_abi = Abi::parse(&path.to_string());
let maybe_parsed_abi = Abi::parse(PathBuf::from(&path));
match maybe_parsed_abi {
Ok(_) => Validation::Valid,
Err(e) => Validation::Invalid(e.into()),
Expand Down Expand Up @@ -116,7 +118,7 @@ async fn get_contract_import_selection(args: ContractImportArgs) -> Result<Selec

let abi_path_string =
get_abi_path_string(&local_import_args).context("Failed getting Fuel ABI path")?;
let abi = Abi::parse(&abi_path_string).context("Failed parsing Fuel ABI")?;
let abi = Abi::parse(PathBuf::from(&abi_path_string)).context("Failed parsing Fuel ABI")?;

let mut selected_logs = abi.get_logs();
if !args.all_events {
Expand Down
9 changes: 6 additions & 3 deletions codegenerator/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub mod rescript {
use std::path::PathBuf;

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

Expand All @@ -44,7 +44,7 @@ pub mod rescript {
execute_command("pnpm", args, path).await
}
pub async fn build(path: &PathBuf) -> Result<std::process::ExitStatus> {
let args = vec!["rescript", "build", "-with-deps"];
let args = vec!["rescript"];
execute_command("pnpm", args, path).await
}
}
Expand Down Expand Up @@ -226,7 +226,10 @@ pub mod start {
"Indexer has failed to run. Please see error logs for more details"
));
}
println!("\nIndexer has successfully finished processing all events on all chains. Exiting process.");
println!(
"\nIndexer has successfully finished processing all events on all chains. Exiting \
process."
);
Ok(())
}
}
Expand Down
27 changes: 17 additions & 10 deletions codegenerator/cli/src/config_parsing/entity_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ impl Entity {
.map(|multi_field_index| {
multi_field_index
.validate_no_duplicates(&fields)?
.validate_field_name_exists(&fields)?
.validate_field_name_exists_or_is_allowed(
&fields,
&vec!["db_write_timestamp".to_string()],
)?
.validate_no_index_on_derived_field(&fields)?
.validate_no_index_on_id_field()
})
Expand Down Expand Up @@ -446,7 +449,7 @@ impl Entity {
&'a self,
schema: &'a Schema,
) -> anyhow::Result<Vec<(&'a Field, &'a Self)>> {
let required_entities_with_field = self
let related_entities_with_field = self
.get_fields()
.into_iter()
.filter_map(|field| {
Expand All @@ -465,7 +468,7 @@ impl Entity {
})
.collect::<anyhow::Result<_>>()?;

Ok(required_entities_with_field)
Ok(related_entities_with_field)
}

/// Validate each field type in an the given entity
Expand Down Expand Up @@ -719,12 +722,16 @@ impl MultiFieldIndex {
}
}

fn validate_field_name_exists(self, fields: &HashMap<String, Field>) -> anyhow::Result<Self> {
fn validate_field_name_exists_or_is_allowed(
self,
fields: &HashMap<String, Field>,
allowed_names: &Vec<String>,
) -> anyhow::Result<Self> {
for field_name in &self.0 {
if let None = fields.get(field_name) {
if !fields.contains_key(field_name) && !allowed_names.contains(field_name) {
return Err(anyhow!(
"Index error: Field '{}' does not exist in entity, please remove it from the \
`@index` directive.",
`@index` directive.",
field_name,
));
}
Expand Down Expand Up @@ -856,7 +863,7 @@ impl RescriptType {
.join(", ");
format!("({})", inner_types_str)
}
RescriptType::EnumVariant(enum_name) => format!("Enums.{}", &enum_name.uncapitalized),
RescriptType::EnumVariant(enum_name) => format!("Enums.{}.t", &enum_name.capitalized),
}
}

Expand Down Expand Up @@ -888,7 +895,7 @@ impl RescriptType {
format!("S.tuple((. s) => ({}))", inner_str)
}
RescriptType::EnumVariant(enum_name) => {
format!("Enums.{}Schema", &enum_name.uncapitalized)
format!("Enums.{}.schema", &enum_name.capitalized)
}
}
}
Expand All @@ -906,7 +913,7 @@ impl RescriptType {
RescriptType::Array(_) => "[]".to_string(),
RescriptType::Option(_) => "None".to_string(),
RescriptType::EnumVariant(enum_name) => {
format!("Enums.{}Default", &enum_name.uncapitalized)
format!("Enums.{}.default", &enum_name.capitalized)
}
RescriptType::Tuple(inner_types) => {
let inner_types_str = inner_types
Expand Down Expand Up @@ -1702,7 +1709,7 @@ type TestEntity {

assert_eq!(
rescript_type.to_string(),
"option<Enums.testEnum>".to_owned()
"option<Enums.TestEnum.t>".to_owned()
);
}

Expand Down
2 changes: 0 additions & 2 deletions codegenerator/cli/src/config_parsing/graph_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ pub async fn generate_config_from_subgraph_id(
.collect::<String>();
let event = EventConfig {
event: event_name.to_string(),
required_entities: Some(vec![]),
is_async: None,
};

Ok(event)
Expand Down
16 changes: 1 addition & 15 deletions codegenerator/cli/src/config_parsing/human_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct NetworkContract<T> {
}

pub mod evm {
use super::{GlobalContract, NetworkContract, NetworkId, RequiredEntity};
use super::{GlobalContract, NetworkContract, NetworkId};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -125,10 +125,6 @@ pub mod evm {
#[serde(rename_all = "camelCase")]
pub struct EventConfig {
pub event: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_async: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub required_entities: Option<Vec<RequiredEntity>>,
}

impl EventConfig {
Expand Down Expand Up @@ -207,16 +203,6 @@ pub mod fuel {
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RequiredEntity {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub labels: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub array_labels: Option<Vec<String>>,
}

fn strip_to_letters(string: &str) -> String {
let mut pg_friendly_name = String::new();
for c in string.chars() {
Expand Down
81 changes: 16 additions & 65 deletions codegenerator/cli/src/config_parsing/system_config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use super::{
chain_helpers::get_confirmed_block_threshold_from_id,
entity_parsing::{Entity, GraphQLEnum, Schema},
human_config::{
self,
evm::{
EventConfig, EventDecoder, HumanConfig, HypersyncConfig as HumanHypersyncConfig,
Network as HumanNetwork, RpcConfig as HumanRpcConfig, SyncSourceConfig,
},
human_config::evm::{
EventConfig, EventDecoder, HumanConfig, HypersyncConfig as HumanHypersyncConfig,
Network as HumanNetwork, RpcConfig as HumanRpcConfig, SyncSourceConfig,
},
hypersync_endpoints,
validation::validate_names_not_reserved,
Expand All @@ -17,8 +14,6 @@ use crate::{
};
use anyhow::{anyhow, Context, Result};
use ethers::abi::{ethabi::Event as EthAbiEvent, EventParam, HumanReadableParser};

use itertools::Itertools;
use serde::Serialize;
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -173,7 +168,7 @@ impl SystemConfig {
.events
.iter()
.cloned()
.map(|e| Event::try_from_config_event(e, &abi_from_file, &schema))
.map(|e| Event::try_from_config_event(e, &abi_from_file))
.collect::<Result<Vec<_>>>()
.context(format!(
"Failed parsing abi types for events in global contract {}",
Expand Down Expand Up @@ -207,20 +202,22 @@ impl SystemConfig {
.events
.iter()
.cloned()
.map(|e| Event::try_from_config_event(e, &abi_from_file, &schema))
.map(|e| Event::try_from_config_event(e, &abi_from_file))
.collect::<Result<Vec<_>>>()?;

let contract =
Contract::new(contract.name, l_contract.handler, events, abi_from_file)
.context(format!(
"Failed parsing locally defined network contract at network id {}",
network.id
))?;
"Failed parsing locally defined network contract at network \
id {}",
network.id
))?;

//Check if contract exists
unique_hashmap::try_insert(&mut contracts, contract.name.clone(), contract)
.context(format!(
"Failed inserting locally defined network contract at network id {}",
"Failed inserting locally defined network contract at network id \
{}",
network.id,
))?;
}
Expand Down Expand Up @@ -493,7 +490,6 @@ impl Contract {
let mut events_abi = ethers::abi::Contract::default();

let mut event_names = Vec::new();
let mut entity_and_label_names = Vec::new();
for event in &events {
events_abi
.events
Expand All @@ -502,18 +498,6 @@ impl Contract {
.push(event.get_event().clone());

event_names.push(event.event.0.name.clone());

for entity in &event.required_entities {
entity_and_label_names.push(entity.name.clone());
if let Some(labels) = &entity.labels {
entity_and_label_names.extend(labels.clone());
}
if let Some(array_labels) = &entity.array_labels {
entity_and_label_names.extend(array_labels.clone());
}
}
// Checking that entity names do not include any reserved words
validate_names_not_reserved(&entity_and_label_names, "Required Entities".to_string())?;
}
// Checking that event names do not include any reserved words
validate_names_not_reserved(&event_names, "Events".to_string())?;
Expand Down Expand Up @@ -557,7 +541,6 @@ impl Contract {
#[derive(Debug, Clone, PartialEq)]
pub struct Event {
event: NormalizedEthAbiEvent,
pub required_entities: Vec<human_config::RequiredEntity>,
pub is_async: bool,
}

Expand All @@ -568,7 +551,7 @@ impl Event {
Ok(event) => Ok(event),
Err(err) => Err(anyhow!(
"EE103: Unable to parse event signature {} due to the following error: {}. \
Please refer to our docs on how to correctly define a human readable ABI.",
Please refer to our docs on how to correctly define a human readable ABI.",
sig,
err
)),
Expand Down Expand Up @@ -599,30 +582,12 @@ impl Event {
pub fn try_from_config_event(
human_cfg_event: EventConfig,
opt_abi: &Option<EvmAbi>,
schema: &Schema,
) -> Result<Self> {
let event = Event::get_abi_event(&human_cfg_event.event, opt_abi)?.into();

let required_entities = human_cfg_event.required_entities.unwrap_or_else(|| {
// If no required entities are specified, we assume all entities are required
schema
.entities
.values()
.sorted_by_key(|v| &v.name)
.cloned()
.map(|entity| human_config::RequiredEntity {
name: entity.name,
labels: None,
array_labels: None,
})
.collect()
});
let is_async = human_cfg_event.is_async.unwrap_or_else(|| false);

Ok(Event {
event,
required_entities,
is_async,
is_async: false,
})
}

Expand Down Expand Up @@ -658,22 +623,6 @@ impl From<EthAbiEvent> for NormalizedEthAbiEvent {
}
}

#[derive(Debug, Clone, PartialEq)]
struct RequiredEntity {
pub name: String,
pub labels: Vec<String>,
pub array_labels: Vec<String>,
}
impl From<human_config::RequiredEntity> for RequiredEntity {
fn from(r: human_config::RequiredEntity) -> Self {
RequiredEntity {
name: r.name,
labels: r.labels.unwrap_or_else(|| vec![]),
array_labels: r.array_labels.unwrap_or_else(|| vec![]),
}
}
}

#[cfg(test)]
mod test {
use super::SystemConfig;
Expand Down Expand Up @@ -822,7 +771,9 @@ mod test {
Event::get_abi_event(&event_string, &None)
.unwrap_err()
.to_string(),
"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."
"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."
);
}

Expand Down
Loading

0 comments on commit dd76173

Please sign in to comment.