Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: generic ebo events #17

Merged
merged 41 commits into from
Aug 5, 2024
Merged

refactor: generic ebo events #17

merged 41 commits into from
Aug 5, 2024

Conversation

0xyaco
Copy link
Collaborator

@0xyaco 0xyaco commented Jul 31, 2024

🤖 Linear

Closes GRT-79

Description

Refactors EBO events for strict type checking.

0xyaco added 30 commits July 18, 2024 18:18
Copy link

linear bot commented Jul 31, 2024

GRT-79 Wrap events with predefined structure

In order to have a consistent way to handle events and to be able to create "synthetic" events on our end we need a way to represent blockchain events in a normalized way.

Draft idea to wrap events coming from viem queries:

type EboEvent = "ResponseCreated" | "RequestCreated";
type EboEventData <EboEvent>  = EboEvent extends "ResponseCreated" ? ResponseCreated : RequestCreated;

interface ResponseCreated { 
    id: string;
    response: string;
    request_id: string;
}

type Event<T extends EboEvent> = {
    name: T;
    blocknumber: bigint;
    data: EventData<T>;
};

AC:

  • Protocol provider modified to use the new types for handling events
  • EBO actor uses new event wrap types.

@@ -73,7 +67,7 @@ export class ProtocolProvider {
};
}

async getEvents(_fromBlock: bigint, _toBlock: bigint): Promise<EboEvent[]> {
async getEvents(_fromBlock: bigint, _toBlock: bigint): Promise<AnyEboEvent[]> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only weird thing regarding this new approach, I had to declare a new type to be used with an array of EBO events.

There might be another way to do this that I don't know.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async getEvents(_fromBlock: bigint, _toBlock: bigint): Promise<AnyEboEvent[]> {
async getEvents(_fromBlock: bigint, _toBlock: bigint): Promise<EboEvent<EventName>[]> {

@0xyaco 0xyaco requested review from 0xkenj1 and 0xnigir1 July 31, 2024 21:49
Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

0xnigir1
0xnigir1 previously approved these changes Aug 1, 2024
Copy link
Collaborator

@0xnigir1 0xnigir1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

0xkenj1
0xkenj1 previously approved these changes Aug 1, 2024
@0xyaco 0xyaco force-pushed the feat/generic-ebo-events branch from a86b663 to c07b536 Compare August 2, 2024 14:16
Base automatically changed from feat/base-ebo-actor to dev August 2, 2024 16:22
@0xyaco 0xyaco dismissed stale reviews from 0xnigir1 and 0xkenj1 August 2, 2024 16:22

The base branch was changed.

@0xkenj1 0xkenj1 requested review from 0xkenj1 and 0xnigir1 August 5, 2024 19:59
@0xyaco 0xyaco merged commit 70dd4b6 into dev Aug 5, 2024
5 checks passed
@0xyaco 0xyaco deleted the feat/generic-ebo-events branch August 5, 2024 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants