Skip to content

Commit

Permalink
feat: add registry to actor
Browse files Browse the repository at this point in the history
  • Loading branch information
0xyaco committed Aug 6, 2024
1 parent 3035c57 commit 4178514
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/automated-dispute/src/eboActor.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { BlockNumberService } from "@ebo-agent/blocknumber";

import { EboRegistry } from "./eboRegistry.js";
import { RequestMismatch } from "./exceptions/requestMismatch.js";
import { ProtocolProvider } from "./protocolProvider.js";
import { EboEvent } from "./types/events.js";
import { Dispute, Response } from "./types/prophet.js";

export class EboActor {
private registry: EboRegistry;

constructor(
private readonly protocolProvider: ProtocolProvider,
private readonly blockNumberService: BlockNumberService,
private readonly requestId: string,
) {}
) {
this.registry = new EboRegistry();
}

public async onRequestCreated(event: EboEvent<"RequestCreated">): Promise<void> {
if (event.metadata.requestId != this.requestId)
throw new RequestMismatch(this.requestId, event.metadata.requestId);

// TODO: Update registry with the new event.metadata.request
this.registry.addRequest(event.metadata.requestId, event.metadata.request);

const { chainId } = event.metadata;
const { currentEpoch, currentEpochTimestamp } =
Expand Down
12 changes: 10 additions & 2 deletions packages/automated-dispute/src/eboRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { Dispute, Request, Response } from "./types/prophet.js";

class EboRegistry {
export class EboRegistry {
private requests: Map<string, Request>;
private responses: Map<string, Response>;
private dispute: Map<string, Dispute>;

constructor() {}
constructor() {
this.requests = new Map();
this.responses = new Map();
this.dispute = new Map();
}

public addRequest(requestId: string, request: Request) {
this.requests.set(requestId, request);
}
}
3 changes: 2 additions & 1 deletion packages/automated-dispute/src/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js";
import { Log } from "viem";

import { Dispute, Response } from "./prophet.js";
import { Dispute, Request, Response } from "./prophet.js";

export type EboEventName =
| "NewEpoch"
Expand All @@ -27,6 +27,7 @@ export interface ResponseProposed {
export interface RequestCreated {
epoch: bigint;
chainId: Caip2ChainId;
request: Request;
requestId: string;
}

Expand Down

0 comments on commit 4178514

Please sign in to comment.