Skip to content

Commit

Permalink
Refactor DeployMethod request method to cache result
Browse files Browse the repository at this point in the history
The method was not idempotent as it was pushing capsules, which broke other calls that depended on capsules. Unclear why this popped up only now.
  • Loading branch information
spalladino committed Mar 13, 2024
1 parent 9d95634 commit fb2d7d7
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions yarn-project/aztec.js/src/contract/deploy_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
/** Constructor function to call. */
private constructorArtifact: FunctionArtifact | undefined;

/** Cached call to request() */
private functionCalls: FunctionCall[] | undefined;

private log = createDebugLogger('aztec:js:deploy_method');

constructor(
Expand Down Expand Up @@ -103,18 +106,21 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
* it returns a promise for an array instead of a function call directly.
*/
public async request(options: DeployOptions = {}): Promise<FunctionCall[]> {
const { address } = this.getInstance(options);
const calls = await this.getDeploymentFunctionCalls(options);
if (this.constructorArtifact && !options.skipInitialization) {
const constructorCall = new ContractFunctionInteraction(
this.wallet,
address,
this.constructorArtifact,
this.args,
);
calls.push(constructorCall.request());
if (!this.functionCalls) {
const { address } = this.getInstance(options);
const calls = await this.getDeploymentFunctionCalls(options);
if (this.constructorArtifact && !options.skipInitialization) {
const constructorCall = new ContractFunctionInteraction(
this.wallet,
address,
this.constructorArtifact,
this.args,
);
calls.push(constructorCall.request());
}
this.functionCalls = calls;
}
return calls;
return this.functionCalls;
}

/**
Expand Down

0 comments on commit fb2d7d7

Please sign in to comment.