-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathdefault_entrypoint.ts
More file actions
48 lines (40 loc) · 1.59 KB
/
default_entrypoint.ts
File metadata and controls
48 lines (40 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { FunctionType } from '@aztec/stdlib/abi';
import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
import type { EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js';
import type { ExecutionPayload } from './payload.js';
/**
* Default implementation of the entrypoint interface. It calls a function on a contract directly
*/
export class DefaultEntrypoint implements EntrypointInterface {
constructor(private chainId: number, private rollupVersion: number) {}
async createTxExecutionRequest(
exec: ExecutionPayload,
fee: FeeOptions,
options: TxExecutionOptions,
): Promise<TxExecutionRequest> {
if (options.nonce || options.cancellable !== undefined) {
throw new Error('TxExecutionOptions are not supported in DefaultEntrypoint');
}
// Initial request with calls, authWitnesses and capsules
const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
if (calls.length > 1) {
throw new Error(`Expected a single call, got ${calls.length}`);
}
const call = calls[0];
// Hash the arguments for the function call
const hashedArguments = [await HashedValues.fromArgs(call.args)];
if (call.type !== FunctionType.PRIVATE) {
throw new Error('Public entrypoints are not allowed');
}
// Assemble the tx request
return new TxExecutionRequest(
call.to,
call.selector,
hashedArguments[0].hash,
new TxContext(this.chainId, this.rollupVersion, fee.gasSettings),
[...hashedArguments, ...extraHashedArgs],
authWitnesses,
capsules,
);
}
}