Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Jun 18, 2024
1 parent 7f62a90 commit 91a5ba4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/api/abi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
export { type ContractArtifact, type FunctionArtifact, EventSelector, FunctionSelector } from '@aztec/foundation/abi';
export { loadContractArtifact, contractArtifactToBuffer, contractArtifactFromBuffer } from '@aztec/types/abi';
export { type NoirCompiledContract } from '@aztec/types/noir';
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export {
CheatCodes,
EthAddressLike,
EthCheatCodes,
EventSelectorLike,
FieldLike,
FunctionSelectorLike,
WrappedFieldLike,
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/aztec.js/src/utils/abi_types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type AztecAddress, type EthAddress, type Fr, type FunctionSelector } from '@aztec/circuits.js';
import { type AztecAddress, type EthAddress, type Fr, type FunctionSelector, type EventSelector } from '@aztec/circuits.js';

/** Any type that can be converted into a field for a contract call. */
export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr };
Expand All @@ -9,8 +9,11 @@ export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | Eth
/** Any type that can be converted into an AztecAddress Aztec.nr struct. */
export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress;

/** Any type that can be converted into an FunctionSelector Aztec.nr struct. */
/** Any type that can be converted into a FunctionSelector Aztec.nr struct. */
export type FunctionSelectorLike = FieldLike | FunctionSelector;

/** Any type that can be converted into an EventSelector Aztec.nr struct. */
export type EventSelectorLike = FieldLike | EventSelector;

/** Any type that can be converted into a struct with a single `inner` field. */
export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike;
15 changes: 8 additions & 7 deletions yarn-project/builder/src/contract-interface-gen/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ function generateEvents(events: any[] | undefined) {
`;

const fieldNames = event.fields.map((field: any) => `"${field.name}"`);
const eventType = `${eventName}: {decode: (payload: L1EventPayload | undefined) => ${eventName} | undefined, functionSelector: FunctionSelector, fieldNames: string[] }`;
const eventType = `${eventName}: {decode: (payload: L1EventPayload | undefined) => ${eventName} | undefined, eventSelector: EventSelector, fieldNames: string[] }`;

const eventImpl = `${eventName}: {
decode: this.decodeEvent(${event.fields.length}, FunctionSelector.fromSignature('${eventName}(${event.fields
decode: this.decodeEvent(${event.fields.length}, EventSelector.fromSignature('${eventName}(${event.fields
.map(() => 'Field')
.join(',')})'), [${fieldNames}]),
functionSelector: FunctionSelector.fromSignature('${eventName}(${event.fields.map(() => 'Field').join(',')})'),
eventSelector: EventSelector.fromSignature('${eventName}(${event.fields.map(() => 'Field').join(',')})'),
fieldNames: [${fieldNames}],
}`;

Expand All @@ -276,21 +276,21 @@ function generateEvents(events: any[] | undefined) {
eventDefs: eventsMetadata.map(({ eventDef }) => eventDef).join('\n'),
events: `
// Partial application is chosen is to avoid the duplication of so much codegen.
private static decodeEvent<T>(fieldsLength: number, functionSelector: FunctionSelector, fields: string[]): (payload: L1EventPayload | undefined) => T | undefined {
private static decodeEvent<T>(fieldsLength: number, eventSelector: EventSelector, fields: string[]): (payload: L1EventPayload | undefined) => T | undefined {
return (payload: L1EventPayload | undefined): T | undefined => {
if (payload === undefined) {
return undefined;
}
if (
!functionSelector.equals(
FunctionSelector.fromField(payload.eventTypeId),
!eventSelector.equals(
EventSelector.fromField(payload.eventTypeId),
)
) {
return undefined;
}
if (payload.event.items.length !== fieldsLength) {
throw new Error(
'Something is weird here, we have matching FunctionSelectors, but the actual payload has mismatched length',
'Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length',
);
}
Expand Down Expand Up @@ -351,6 +351,7 @@ import {
EthAddressLike,
FieldLike,
Fr,
EventSelector,
FunctionSelector,
FunctionSelectorLike,
L1EventPayload,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuit-types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
type PartialAddress,
type Point,
} from '@aztec/circuits.js';
import { type ContractArtifact, type FunctionSelector } from '@aztec/foundation/abi';
import { type EventSelector, type ContractArtifact } from '@aztec/foundation/abi';
import {
type ContractClassWithId,
type ContractInstanceWithAddress,
Expand Down Expand Up @@ -397,7 +397,7 @@ export interface PXE {
*/
export interface EventMetadata<T> {
decode(payload: L1EventPayload): T | undefined;
functionSelector: FunctionSelector;
eventSelector: EventSelector;
fieldNames: string[];
}

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/structs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ export * from './tx_request.js';
export * from './validation_requests.js';
export * from './verification_key.js';

export { FunctionSelector } from '@aztec/foundation/abi';
export { EventSelector, FunctionSelector } from '@aztec/foundation/abi';
export * from '@aztec/foundation/aztec-address';
export * from '@aztec/foundation/fields';
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
getContractClassFromArtifact,
} from '@aztec/circuits.js';
import { computeNoteHashNonce, siloNullifier } from '@aztec/circuits.js/hash';
import { type ContractArtifact, type DecodedReturn, FunctionSelector, encodeArguments } from '@aztec/foundation/abi';
import { type ContractArtifact, type DecodedReturn, EventSelector, FunctionSelector, encodeArguments } from '@aztec/foundation/abi';
import { type Fq, Fr, type Point } from '@aztec/foundation/fields';
import { SerialQueue } from '@aztec/foundation/fifo';
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
Expand Down Expand Up @@ -853,7 +853,7 @@ export class PXEService implements PXE {
if (visibleEvent.payload === undefined) {
return undefined;
}
if (!FunctionSelector.fromField(visibleEvent.payload.eventTypeId).equals(eventMetadata.functionSelector)) {
if (!EventSelector.fromField(visibleEvent.payload.eventTypeId).equals(eventMetadata.eventSelector)) {
return undefined;
}
if (visibleEvent.payload.event.items.length !== eventMetadata.fieldNames.length) {
Expand Down

0 comments on commit 91a5ba4

Please sign in to comment.