-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[V1] Remove EventSummary from init template (#34)
* Remove EventSummary from init template * Revert the code which I shouldn't remove
- Loading branch information
Showing
10 changed files
with
92 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 2 additions & 14 deletions
16
codegenerator/cli/templates/dynamic/contract_import_templates/shared/schema.graphql.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
type EventsSummary { | ||
id: ID! | ||
{{#each imported_contracts as |contract|}} | ||
{{#each contract.imported_events as |event|}} | ||
{{contract.name.uncapitalized}}_{{event.name.capitalized | ||
}}: [{{contract.name.capitalized}}_{{event.name.capitalized | ||
}}!]! @derivedFrom(field: "eventsSummary") | ||
{{contract.name.uncapitalized}}_{{event.name.capitalized}}Count: BigInt! | ||
{{/each}} | ||
{{/each}} | ||
} | ||
{{#each imported_contracts as |contract|}} | ||
{{#each contract.imported_events as |event|}} | ||
|
||
type {{contract.name.capitalized}}_{{event.name.capitalized}} { | ||
id: ID! | ||
{{#each event.params as |param|}} | ||
{{param.entity_key.uncapitalized}}: {{param.graphql_type}} | ||
{{/each}} | ||
eventsSummary: String! | ||
} | ||
|
||
{{/each}} | ||
{{/each}} | ||
{{/each}} |
68 changes: 14 additions & 54 deletions
68
...rator/cli/templates/dynamic/contract_import_templates/typescript/src/EventHandlers.ts.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,32 @@ | ||
/* | ||
*Please refer to https://docs.envio.dev for a thorough guide on all Envio indexer features* | ||
* Please refer to https://docs.envio.dev for a thorough guide on all Envio indexer features | ||
*/ | ||
import { | ||
{{#each imported_contracts as |contract|}} | ||
{{contract.name.capitalized}}Contract, | ||
{{#each contract.imported_events as |event|}} | ||
{{contract.name.capitalized}}_{{event.name.capitalized}}Entity, | ||
{{/each}} | ||
{{#each contract.imported_events as |event|}} | ||
{{contract.name.capitalized}}_{{event.name.capitalized}}Entity, | ||
{{/each}} | ||
EventsSummaryEntity | ||
} from "generated"; | ||
|
||
export const GLOBAL_EVENTS_SUMMARY_KEY = "GlobalEventsSummary"; | ||
|
||
const INITIAL_EVENTS_SUMMARY: EventsSummaryEntity = { | ||
id: GLOBAL_EVENTS_SUMMARY_KEY, | ||
{{#each imported_contracts as |contract|}} | ||
{{#each contract.imported_events as |event|}} | ||
{{contract.name.uncapitalized}}_{{event.name.capitalized}}Count: BigInt(0), | ||
{{/each}} | ||
{{/each}} | ||
}; | ||
|
||
} from "generated"; | ||
{{#each imported_contracts as |contract|}} | ||
{{#each contract.imported_events as |event|}} | ||
{{contract.name.capitalized}}Contract.{{event.name.capitalized | ||
}}.loader(({ event, context }) => { | ||
context.EventsSummary.load(GLOBAL_EVENTS_SUMMARY_KEY); | ||
}); | ||
|
||
{{contract.name.capitalized}}Contract.{{event.name.capitalized | ||
}}.handler(({ event, context }) => { | ||
const summary = context.EventsSummary.get(GLOBAL_EVENTS_SUMMARY_KEY); | ||
|
||
const currentSummaryEntity: EventsSummaryEntity = | ||
summary ?? INITIAL_EVENTS_SUMMARY; | ||
|
||
const nextSummaryEntity = { | ||
...currentSummaryEntity, | ||
{{contract.name.uncapitalized}}_{{event.name.capitalized | ||
}}Count: currentSummaryEntity.{{contract.name.uncapitalized | ||
}}_{{event.name.capitalized | ||
}}Count + BigInt(1), | ||
}; | ||
|
||
const {{contract.name.uncapitalized | ||
}}_{{event.name.capitalized}}Entity: {{contract.name.capitalized | ||
}}_{{event.name.capitalized | ||
}}Entity = { | ||
{{contract.name.capitalized}}Contract.{{event.name.capitalized}}.handler(({ event, context }) => { | ||
const entity: {{contract.name.capitalized}}_{{event.name.capitalized}}Entity = { | ||
id: event.transactionHash + event.logIndex.toString(), | ||
{{#each event.params as |param|}} | ||
{{param.entity_key.uncapitalized | ||
}}: event.params.{{param.event_key.uncapitalized}}{{#if | ||
param.tuple_param_accessor_indexes | ||
}} | ||
{{#each param.tuple_param_accessor_indexes as |index|}} | ||
[{{index}}] | ||
{{/each}} | ||
{{/if}} | ||
, | ||
{{param.entity_key.uncapitalized}}: event.params.{{param.event_key.uncapitalized}}{{#if | ||
param.tuple_param_accessor_indexes | ||
}} | ||
{{#each param.tuple_param_accessor_indexes as |index|}} | ||
[{{index}}] | ||
{{/each}} | ||
{{/if}}, | ||
{{/each}} | ||
eventsSummary: GLOBAL_EVENTS_SUMMARY_KEY, | ||
}; | ||
|
||
context.EventsSummary.set(nextSummaryEntity); | ||
context.{{contract.name.capitalized | ||
}}_{{event.name.capitalized}}.set({{contract.name.uncapitalized | ||
}}_{{event.name.capitalized}}Entity); | ||
context.{{contract.name.capitalized}}_{{event.name.capitalized}}.set(entity); | ||
}); | ||
{{/each}} | ||
{{/each}} |
Oops, something went wrong.