Skip to content

Commit

Permalink
feat: checking if origin is registered
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 3, 2023
1 parent 261032e commit 2b35709
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ContractFunctionInteraction {
throw new Error("Can't call `create` on an unconstrained function.");
}
if (!this.txRequest) {
const executionRequest = this.getExecutionRequest(this.contractAddress, options.origin);
const executionRequest = await this.getExecutionRequest(this.contractAddress, options.origin);
const nodeInfo = await this.wallet.getNodeInfo();
const txContext = TxContext.empty(new Fr(nodeInfo.chainId), new Fr(nodeInfo.version));
const txRequest = await this.wallet.createAuthenticatedTxRequest([executionRequest], txContext);
Expand All @@ -88,16 +88,22 @@ export class ContractFunctionInteraction {
* Returns an execution request that represents this operation. Useful as a building
* block for constructing batch requests.
* @param options - An optional object containing additional configuration for the transaction.
* @returns An execution request.
* @returns An execution request wrapped in promise.
*/
public request(options: SendMethodOptions = {}): ExecutionRequest {
public request(options: SendMethodOptions = {}): Promise<ExecutionRequest> {
return this.getExecutionRequest(this.contractAddress, options.origin);
}

protected getExecutionRequest(to: AztecAddress, from?: AztecAddress): ExecutionRequest {
protected async getExecutionRequest(to: AztecAddress, from?: AztecAddress): Promise<ExecutionRequest> {
const flatArgs = encodeArguments(this.functionDao, this.args);
from = from ?? this.wallet.getAddress();

const accounts = await this.wallet.getAccounts();
// Zero address is used during deployment and does not need to be in the wallet
if (!from.equals(AztecAddress.ZERO) && !accounts.some(acc => from!.equals(acc))) {
throw new Error(`The specified 'from' address ${from} is not in the wallet's accounts.`);
}

return {
args: flatArgs,
functionData: FunctionData.fromAbi(this.functionDao),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Con
);

const txContext = new TxContext(false, false, true, contractDeploymentData, new Fr(chainId), new Fr(version));
const executionRequest = this.getExecutionRequest(address, AztecAddress.ZERO);
const executionRequest = await this.getExecutionRequest(address, AztecAddress.ZERO);
const txRequest = await this.wallet.createAuthenticatedTxRequest([executionRequest], txContext);

this.txRequest = txRequest;
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_escrow_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ describe('e2e_escrow_contract', () => {
await expectBalance(owner, 50n);

const actions = [
zkTokenContract.methods.transfer(10, owner, recipient).request(),
escrowContract.methods.withdraw(zkTokenContract.address, 20, recipient).request(),
await zkTokenContract.methods.transfer(10, owner, recipient).request(),
await escrowContract.methods.withdraw(zkTokenContract.address, 20, recipient).request(),
];

// TODO: We need a nicer interface for batch actions
Expand Down

0 comments on commit 2b35709

Please sign in to comment.