@aztec/archiver 0.1.0-alpha20 → 0.1.0-alpha21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ import {
5
5
  ContractData,
6
6
  L1ToL2Message,
7
7
  L2BlockL2Logs,
8
+ LogType,
8
9
  } from '@aztec/types';
9
10
  import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
10
11
  import { AztecAddress } from '@aztec/foundation/aztec-address';
@@ -31,18 +32,12 @@ export interface ArchiverDataStore {
31
32
  getL2Blocks(from: number, take: number): Promise<L2Block[]>;
32
33
 
33
34
  /**
34
- * Append new encrypted logs to the store's list.
35
- * @param data - The encrypted logs to be added to the store.
35
+ * Append new logs to the store's list.
36
+ * @param data - The logs to be added to the store.
37
+ * @param logType - The type of the logs to be added to the store.
36
38
  * @returns True if the operation is successful.
37
39
  */
38
- addEncryptedLogs(data: L2BlockL2Logs[]): Promise<boolean>;
39
-
40
- /**
41
- * Append new unencrypted logs to the store's list.
42
- * @param data - The unencrypted logs to be added to the store.
43
- * @returns True if the operation is successful.
44
- */
45
- addUnencryptedLogs(data: L2BlockL2Logs[]): Promise<boolean>;
40
+ addLogs(data: L2BlockL2Logs[], logType: LogType): Promise<boolean>;
46
41
 
47
42
  /**
48
43
  * Append new pending L1 to L2 messages to the store.
@@ -81,20 +76,13 @@ export interface ArchiverDataStore {
81
76
  getConfirmedL1ToL2Message(messageKey: Fr): Promise<L1ToL2Message>;
82
77
 
83
78
  /**
84
- * Gets the `take` amount of encrypted logs starting from `from`.
85
- * @param from - Number of the L2 block to which corresponds the first `encryptedLogs` to be returned.
86
- * @param take - The number of encrypted logs to return.
87
- * @returns The requested encrypted logs.
88
- */
89
- getEncryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]>;
90
-
91
- /**
92
- * Gets the `take` amount of unencrypted logs starting from `from`.
93
- * @param from - Number of the L2 block to which corresponds the first `unencryptedLogs` to be returned.
94
- * @param take - The number of unencrypted logs to return.
95
- * @returns The requested unencrypted logs.
79
+ * Gets the `take` amount of logs starting from `from`.
80
+ * @param from - Number of the L2 block to which corresponds the first logs to be returned.
81
+ * @param take - The number of logs to return.
82
+ * @param logType - Specifies whether to return encrypted or unencrypted logs.
83
+ * @returns The requested logs.
96
84
  */
97
- getUnencryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]>;
85
+ getLogs(from: number, take: number, logType: LogType): Promise<L2BlockL2Logs[]>;
98
86
 
99
87
  /**
100
88
  * Store new Contract Public Data from an L2 block to the store's list.
@@ -197,22 +185,13 @@ export class MemoryArchiverStore implements ArchiverDataStore {
197
185
  }
198
186
 
199
187
  /**
200
- * Append new encrypted logs data to the store's list.
201
- * @param data - The encrypted logs to be added to the store.
202
- * @returns True if the operation is successful (always in this implementation).
203
- */
204
- public addEncryptedLogs(data: L2BlockL2Logs[]): Promise<boolean> {
205
- this.encryptedLogs.push(...data);
206
- return Promise.resolve(true);
207
- }
208
-
209
- /**
210
- * Append new unencrypted logs data to the store's list.
211
- * @param data - The unencrypted logs to be added to the store.
212
- * @returns True if the operation is successful (always in this implementation).
188
+ * Append new logs to the store's list.
189
+ * @param data - The logs to be added to the store.
190
+ * @param logType - The type of the logs to be added to the store.
191
+ * @returns True if the operation is successful.
213
192
  */
214
- public addUnencryptedLogs(data: L2BlockL2Logs[]): Promise<boolean> {
215
- this.unencryptedLogs.push(...data);
193
+ addLogs(data: L2BlockL2Logs[], logType: LogType): Promise<boolean> {
194
+ logType === LogType.ENCRYPTED ? this.encryptedLogs.push(...data) : this.unencryptedLogs.push(...data);
216
195
  return Promise.resolve(true);
217
196
  }
218
197
 
@@ -310,39 +289,23 @@ export class MemoryArchiverStore implements ArchiverDataStore {
310
289
  }
311
290
 
312
291
  /**
313
- * Gets the `take` amount of encrypted logs starting from `from`.
314
- * @param from - Number of the L2 block to which corresponds the first encrypted logs to be returned.
315
- * @param take - The number of encrypted logs to return.
316
- * @returns The requested encrypted logs.
317
- */
318
- public getEncryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]> {
319
- if (from < INITIAL_L2_BLOCK_NUM) {
320
- throw new Error(`Invalid block range ${from}`);
321
- }
322
- if (from > this.encryptedLogs.length) {
323
- return Promise.resolve([]);
324
- }
325
- const startIndex = from - INITIAL_L2_BLOCK_NUM;
326
- const endIndex = from + take;
327
- return Promise.resolve(this.encryptedLogs.slice(startIndex, endIndex));
328
- }
329
-
330
- /**
331
- * Gets the 'take' amount of unencrypted logs starting from 'from'.
332
- * @param from - Number of the L2 block to which corresponds the first unencrypted logs to be returned.
333
- * @param take - The number of unencrypted logs to return.
334
- * @returns The requested unencrypted logs.
292
+ * Gets the `take` amount of logs starting from `from`.
293
+ * @param from - Number of the L2 block to which corresponds the first logs to be returned.
294
+ * @param take - The number of logs to return.
295
+ * @param logType - Specifies whether to return encrypted or unencrypted logs.
296
+ * @returns The requested logs.
335
297
  */
336
- public getUnencryptedLogs(from: number, take: number): Promise<L2BlockL2Logs[]> {
298
+ getLogs(from: number, take: number, logType: LogType): Promise<L2BlockL2Logs[]> {
337
299
  if (from < INITIAL_L2_BLOCK_NUM) {
338
300
  throw new Error(`Invalid block range ${from}`);
339
301
  }
340
- if (from > this.unencryptedLogs.length) {
302
+ const logs = logType === LogType.ENCRYPTED ? this.encryptedLogs : this.unencryptedLogs;
303
+ if (from > logs.length) {
341
304
  return Promise.resolve([]);
342
305
  }
343
306
  const startIndex = from - INITIAL_L2_BLOCK_NUM;
344
307
  const endIndex = from + take;
345
- return Promise.resolve(this.unencryptedLogs.slice(startIndex, endIndex));
308
+ return Promise.resolve(logs.slice(startIndex, endIndex));
346
309
  }
347
310
 
348
311
  /**