Skip to content

Commit

Permalink
Fix jobs with Pre-Defined callback handler
Browse files Browse the repository at this point in the history
  • Loading branch information
polipaul committed Jul 18, 2023
1 parent d10c8e5 commit 886372e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/agents/AbstractAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export abstract class AbstractAgent implements IAgent {
* @private
*/
private async resyncAllJobs(): Promise<number> {
const latestBock = await this.network.getLatestBlockNumber();
const latestBock = this.network.getLatestBlockNumber();
// 1. init jobs
let newJobs = new Map<string, RandaoJob | LightJob>();
newJobs = await this.dataSource.getRegisteredJobs(this);
Expand Down Expand Up @@ -543,7 +543,6 @@ export abstract class AbstractAgent implements IAgent {

const job = this.jobs.get(jobKey);
job.applyJobCreditsDeposit(BigNumber.from(amount));
job.finalizeInitialization();
job.watch();
});

Expand Down Expand Up @@ -573,7 +572,6 @@ export abstract class AbstractAgent implements IAgent {

if (this.ownerJobs.has(jobOwner)) {
for (const jobKey of this.ownerJobs.get(jobOwner)) {
this.jobs.get(jobKey).finalizeInitialization();
this.jobs.get(jobKey).watch();
}
}
Expand Down Expand Up @@ -628,6 +626,18 @@ export abstract class AbstractAgent implements IAgent {
job.watch();
});

this.contract.on('SetJobPreDefinedCalldata', event => {
const { jobKey, preDefinedCalldata } = event.args;

this.clog(
`'SetJobPreDefinedCalldata' event: (block=${event.blockNumber},jobKey=${jobKey},preDefinedCalldata=${preDefinedCalldata})`,
);

const job = this.jobs.get(jobKey);
job.applyPreDefinedCalldata(preDefinedCalldata);
job.watch();
});

this.contract.on('SetJobResolver', event => {
const { jobKey, resolverAddress, resolverCalldata } = event.args;

Expand Down
1 change: 1 addition & 0 deletions app/agents/Agent.2.3.0.randao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class AgentRandao_2_3_0 extends AbstractAgent implements IRandaoAgent {
this.clog('Updating binJob to', binJob);
job.applyBinJobData(binJob);
}
job.finalizeInitialization();
job.watch();
});

Expand Down
6 changes: 6 additions & 0 deletions app/jobs/AbstractJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export abstract class AbstractJob {
protected config: ParsedJobConfig;
private jobLevelMinKeeperCvp: BigNumber;
protected resolver: Resolver;
protected preDefinedCalldata: string;

private averageBlockTimeSeconds: number;
private network: Network;
Expand Down Expand Up @@ -175,6 +176,7 @@ export abstract class AbstractJob {

public applyJob(job: GetJobResponse): boolean {
this.resolver = { resolverAddress: job.resolver.resolverAddress, resolverCalldata: job.resolver.resolverCalldata };
this.preDefinedCalldata = job.preDefinedCalldata;

if (typeof job.details !== 'object') {
throw this.err(`applyJob(): job.details is not an object: ${job.details}`);
Expand Down Expand Up @@ -255,6 +257,10 @@ export abstract class AbstractJob {
this.resolver = { resolverAddress, resolverCalldata };
}

public applyPreDefinedCalldata(preDefinedCalldata: string) {
this.preDefinedCalldata = preDefinedCalldata;
}

public applyConfig(isActive: boolean, useJobOwnerCredits: boolean, assertResolverSelector: boolean) {
this.config.isActive = isActive;
this.config.useJobOwnerCredits = useJobOwnerCredits;
Expand Down

0 comments on commit 886372e

Please sign in to comment.