Skip to content

Commit cd892e9

Browse files
committed
typing LogRetrievalRequest
1 parent eecee60 commit cd892e9

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

yarn-project/pxe/src/contract_function_simulator/noir-structs/log_retrieval_request.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ describe('LogRetrievalRequest', () => {
1313
const request = LogRetrievalRequest.fromFields(serialized);
1414

1515
expect(request.contractAddress).toEqual(AztecAddress.fromBigInt(1n));
16-
expect(request.unsiloedTag).toEqual(new Fr(2));
16+
expect(request.tag).toEqual(new Fr(2));
1717
});
1818
});

yarn-project/pxe/src/contract_function_simulator/noir-structs/log_retrieval_request.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Fr } from '@aztec/foundation/curves/bn254';
22
import { FieldReader } from '@aztec/foundation/serialize';
33
import { AztecAddress } from '@aztec/stdlib/aztec-address';
4+
import { Tag } from '@aztec/stdlib/logs';
45

56
/**
67
* Intermediate struct used to perform batch log retrieval by PXE. The `utilityBulkRetrieveLogs` oracle expects values of this
@@ -9,18 +10,18 @@ import { AztecAddress } from '@aztec/stdlib/aztec-address';
910
export class LogRetrievalRequest {
1011
constructor(
1112
public contractAddress: AztecAddress,
12-
public unsiloedTag: Fr,
13+
public tag: Tag,
1314
) {}
1415

1516
toFields(): Fr[] {
16-
return [this.contractAddress.toField(), this.unsiloedTag];
17+
return [this.contractAddress.toField(), this.tag.value];
1718
}
1819

1920
static fromFields(fields: Fr[] | FieldReader): LogRetrievalRequest {
2021
const reader = FieldReader.asReader(fields);
2122

2223
const contractAddress = AztecAddress.fromField(reader.readField());
23-
const unsiloedTag = reader.readField();
24+
const unsiloedTag = new Tag(reader.readField());
2425

2526
return new LogRetrievalRequest(contractAddress, unsiloedTag);
2627
}

yarn-project/pxe/src/logs/log_service.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ describe('LogService', () => {
429429
});
430430

431431
describe('bulkRetrieveLogs', () => {
432-
const unsiloedTag = Fr.random();
432+
const unsiloedTag = new Tag(Fr.random());
433433

434434
beforeEach(() => {
435435
aztecNode.getPrivateLogsByTags.mockReset();
@@ -458,7 +458,7 @@ describe('LogService', () => {
458458
txHash.equals(scopedLog.txHash) ? Promise.resolve(indexedTxEffect) : Promise.resolve(undefined),
459459
);
460460

461-
const request = new LogRetrievalRequest(contractAddress, scopedLog.log.fields[0]);
461+
const request = new LogRetrievalRequest(contractAddress, new Tag(scopedLog.log.fields[0]));
462462

463463
const responses = await logService.bulkRetrieveLogs([request]);
464464

@@ -478,7 +478,7 @@ describe('LogService', () => {
478478
txHash.equals(scopedLog.txHash) ? Promise.resolve(indexedTxEffect) : Promise.resolve(undefined),
479479
);
480480

481-
const request = new LogRetrievalRequest(contractAddress, scopedLog.log.fields[0]);
481+
const request = new LogRetrievalRequest(contractAddress, new Tag(scopedLog.log.fields[0]));
482482

483483
const responses = await logService.bulkRetrieveLogs([request]);
484484

@@ -488,7 +488,7 @@ describe('LogService', () => {
488488
});
489489

490490
describe('getPublicLogByTag', () => {
491-
const tag = Fr.random();
491+
const tag = new Tag(Fr.random());
492492

493493
beforeEach(() => {
494494
aztecNode.getPublicLogsByTagsFromContract.mockReset();
@@ -519,7 +519,7 @@ describe('LogService', () => {
519519
expect(result.txHash).toEqual(scopedLog.txHash);
520520
expect(result.firstNullifierInTx).toEqual(indexedTxEffect.data.nullifiers[0]);
521521

522-
expect(aztecNode.getPublicLogsByTagsFromContract).toHaveBeenCalledWith(logContractAddress, [new Tag(tag)]);
522+
expect(aztecNode.getPublicLogsByTagsFromContract).toHaveBeenCalledWith(logContractAddress, [tag]);
523523
expect(aztecNode.getTxEffect).toHaveBeenCalledWith(scopedLog.txHash);
524524
});
525525

@@ -545,7 +545,7 @@ describe('LogService', () => {
545545
it('returns log fields that are actually emitted', async () => {
546546
const logContractAddress = await AztecAddress.random();
547547
const logPlaintext = [Fr.random()];
548-
const logContent = [tag, ...logPlaintext];
548+
const logContent = [tag.value, ...logPlaintext];
549549

550550
const log = PublicLog.from({
551551
contractAddress: logContractAddress,

yarn-project/pxe/src/logs/log_service.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ export class LogService {
3737
logRetrievalRequests.map(async request => {
3838
// TODO(#14555): remove these internal functions and have node endpoints that do this instead
3939
const [publicLog, privateLog] = await Promise.all([
40-
this.getPublicLogByTag(request.unsiloedTag, request.contractAddress),
41-
this.getPrivateLogByTag(await SiloedTag.compute(new Tag(request.unsiloedTag), request.contractAddress)),
40+
this.getPublicLogByTag(request.tag, request.contractAddress),
41+
this.getPrivateLogByTag(await SiloedTag.compute(request.tag, request.contractAddress)),
4242
]);
4343

4444
if (publicLog !== null) {
4545
if (privateLog !== null) {
4646
throw new Error(
47-
`Found both a public and private log when searching for tag ${request.unsiloedTag} from contract ${request.contractAddress}`,
47+
`Found both a public and private log when searching for tag ${request.tag} from contract ${request.contractAddress}`,
4848
);
4949
}
5050

@@ -69,9 +69,8 @@ export class LogService {
6969
}
7070

7171
// TODO(#14555): delete this function and implement this behavior in the node instead
72-
public async getPublicLogByTag(tag: Fr, contractAddress: AztecAddress): Promise<PublicLogWithTxData | null> {
73-
const tagObject = new Tag(tag);
74-
const logs = await this.aztecNode.getPublicLogsByTagsFromContract(contractAddress, [tagObject]);
72+
public async getPublicLogByTag(tag: Tag, contractAddress: AztecAddress): Promise<PublicLogWithTxData | null> {
73+
const logs = await this.aztecNode.getPublicLogsByTagsFromContract(contractAddress, [tag]);
7574
const logsForTag = logs[0];
7675

7776
if (logsForTag.length == 0) {

yarn-project/stdlib/src/logs/tag.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type { PreTag } from './pre_tag.js';
1010
* with a contract address by kernels before being included in the final log.
1111
*/
1212
export class Tag {
13-
// TODO(#14555): Make this constructor private again
1413
constructor(public readonly value: Fr) {}
1514

1615
static async compute(preTag: PreTag): Promise<Tag> {
@@ -22,6 +21,10 @@ export class Tag {
2221
return schemas.Fr.transform((fr: Fr) => new Tag(fr));
2322
}
2423

24+
toString(): string {
25+
return this.value.toString();
26+
}
27+
2528
toJSON(): string {
2629
return this.value.toString();
2730
}

0 commit comments

Comments
 (0)