@aztec/archiver 0.23.0 → 0.24.0

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.
@@ -0,0 +1,164 @@
1
+ import { INITIAL_L2_BLOCK_NUM, L2Block, L2Tx, TxHash } from '@aztec/circuit-types';
2
+ import { AztecAddress } from '@aztec/circuits.js';
3
+ import { createDebugLogger } from '@aztec/foundation/log';
4
+ import { AztecKVStore, AztecMap, Range } from '@aztec/kv-store';
5
+
6
+ type BlockIndexValue = [blockNumber: number, index: number];
7
+
8
+ type BlockContext = {
9
+ blockNumber: number;
10
+ l1BlockNumber: bigint;
11
+ block: Buffer;
12
+ };
13
+
14
+ /**
15
+ * LMDB implementation of the ArchiverDataStore interface.
16
+ */
17
+ export class BlockStore {
18
+ /** Map block number to block data */
19
+ #blocks: AztecMap<number, BlockContext>;
20
+
21
+ /** Index mapping transaction hash (as a string) to its location in a block */
22
+ #txIndex: AztecMap<string, BlockIndexValue>;
23
+
24
+ /** Index mapping a contract's address (as a string) to its location in a block */
25
+ #contractIndex: AztecMap<string, BlockIndexValue>;
26
+
27
+ #log = createDebugLogger('aztec:archiver:block_store');
28
+
29
+ constructor(private db: AztecKVStore) {
30
+ this.#blocks = db.openMap('archiver_blocks');
31
+
32
+ this.#txIndex = db.openMap('archiver_tx_index');
33
+ this.#contractIndex = db.openMap('archiver_contract_index');
34
+ }
35
+
36
+ /**
37
+ * Append new blocks to the store's list.
38
+ * @param blocks - The L2 blocks to be added to the store.
39
+ * @returns True if the operation is successful.
40
+ */
41
+ addBlocks(blocks: L2Block[]): Promise<boolean> {
42
+ return this.db.transaction(() => {
43
+ for (const block of blocks) {
44
+ void this.#blocks.set(block.number, {
45
+ blockNumber: block.number,
46
+ block: block.toBuffer(),
47
+ l1BlockNumber: block.getL1BlockNumber(),
48
+ });
49
+
50
+ for (const [i, tx] of block.getTxs().entries()) {
51
+ if (tx.txHash.isZero()) {
52
+ continue;
53
+ }
54
+ void this.#txIndex.set(tx.txHash.toString(), [block.number, i]);
55
+ }
56
+
57
+ for (const [i, contractData] of block.newContractData.entries()) {
58
+ if (contractData.contractAddress.isZero()) {
59
+ continue;
60
+ }
61
+
62
+ void this.#contractIndex.set(contractData.contractAddress.toString(), [block.number, i]);
63
+ }
64
+ }
65
+
66
+ return true;
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Gets up to `limit` amount of L2 blocks starting from `from`.
72
+ * @param start - Number of the first block to return (inclusive).
73
+ * @param limit - The number of blocks to return.
74
+ * @returns The requested L2 blocks, without logs attached
75
+ */
76
+ *getBlocks(start: number, limit: number): IterableIterator<L2Block> {
77
+ for (const blockCtx of this.#blocks.values(this.#computeBlockRange(start, limit))) {
78
+ yield L2Block.fromBuffer(blockCtx.block);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Gets an L2 block.
84
+ * @param blockNumber - The number of the block to return.
85
+ * @returns The requested L2 block, without logs attached
86
+ */
87
+ getBlock(blockNumber: number): L2Block | undefined {
88
+ const blockCtx = this.#blocks.get(blockNumber);
89
+ if (!blockCtx || !blockCtx.block) {
90
+ return undefined;
91
+ }
92
+
93
+ return L2Block.fromBuffer(blockCtx.block);
94
+ }
95
+
96
+ /**
97
+ * Gets an l2 tx.
98
+ * @param txHash - The txHash of the l2 tx.
99
+ * @returns The requested L2 tx.
100
+ */
101
+ getL2Tx(txHash: TxHash): L2Tx | undefined {
102
+ const [blockNumber, txIndex] = this.getL2TxLocation(txHash) ?? [];
103
+ if (typeof blockNumber !== 'number' || typeof txIndex !== 'number') {
104
+ return undefined;
105
+ }
106
+
107
+ const block = this.getBlock(blockNumber);
108
+ return block?.getTx(txIndex);
109
+ }
110
+
111
+ /**
112
+ * Looks up which block included the requested L2 tx.
113
+ * @param txHash - The txHash of the l2 tx.
114
+ * @returns The block number and index of the tx.
115
+ */
116
+ getL2TxLocation(txHash: TxHash): [blockNumber: number, txIndex: number] | undefined {
117
+ return this.#txIndex.get(txHash.toString());
118
+ }
119
+
120
+ /**
121
+ * Looks up which block deployed a particular contract.
122
+ * @param contractAddress - The address of the contract to look up.
123
+ * @returns The block number and index of the contract.
124
+ */
125
+ getContractLocation(contractAddress: AztecAddress): [blockNumber: number, index: number] | undefined {
126
+ return this.#contractIndex.get(contractAddress.toString());
127
+ }
128
+
129
+ /**
130
+ * Gets the number of the latest L2 block processed.
131
+ * @returns The number of the latest L2 block processed.
132
+ */
133
+ getBlockNumber(): number {
134
+ const [lastBlockNumber] = this.#blocks.keys({ reverse: true, limit: 1 });
135
+ return typeof lastBlockNumber === 'number' ? lastBlockNumber : INITIAL_L2_BLOCK_NUM - 1;
136
+ }
137
+
138
+ /**
139
+ * Gets the most recent L1 block processed.
140
+ * @returns The L1 block that published the latest L2 block
141
+ */
142
+ getL1BlockNumber(): bigint {
143
+ const [lastBlock] = this.#blocks.values({ reverse: true, limit: 1 });
144
+ if (!lastBlock) {
145
+ return 0n;
146
+ } else {
147
+ return lastBlock.l1BlockNumber;
148
+ }
149
+ }
150
+
151
+ #computeBlockRange(start: number, limit: number): Required<Pick<Range<number>, 'start' | 'end'>> {
152
+ if (limit < 1) {
153
+ throw new Error(`Invalid limit: ${limit}`);
154
+ }
155
+
156
+ if (start < INITIAL_L2_BLOCK_NUM) {
157
+ this.#log(`Clamping start block ${start} to ${INITIAL_L2_BLOCK_NUM}`);
158
+ start = INITIAL_L2_BLOCK_NUM;
159
+ }
160
+
161
+ const end = start + limit;
162
+ return { start, end };
163
+ }
164
+ }
@@ -0,0 +1,64 @@
1
+ import { Fr, FunctionSelector } from '@aztec/circuits.js';
2
+ import { BufferReader, numToUInt8, serializeToBuffer } from '@aztec/foundation/serialize';
3
+ import { AztecKVStore, AztecMap } from '@aztec/kv-store';
4
+ import { ContractClassPublic } from '@aztec/types/contracts';
5
+
6
+ /**
7
+ * LMDB implementation of the ArchiverDataStore interface.
8
+ */
9
+ export class ContractClassStore {
10
+ #contractClasses: AztecMap<string, Buffer>;
11
+
12
+ constructor(db: AztecKVStore) {
13
+ this.#contractClasses = db.openMap('archiver_contract_classes');
14
+ }
15
+
16
+ addContractClass(contractClass: ContractClassPublic): Promise<boolean> {
17
+ return this.#contractClasses.set(contractClass.id.toString(), serializeContractClassPublic(contractClass));
18
+ }
19
+
20
+ getContractClass(id: Fr): ContractClassPublic | undefined {
21
+ const contractClass = this.#contractClasses.get(id.toString());
22
+ return contractClass && { ...deserializeContractClassPublic(contractClass), id };
23
+ }
24
+ }
25
+
26
+ export function serializeContractClassPublic(contractClass: ContractClassPublic): Buffer {
27
+ return serializeToBuffer(
28
+ numToUInt8(contractClass.version),
29
+ contractClass.artifactHash,
30
+ contractClass.privateFunctions?.length ?? 0,
31
+ contractClass.privateFunctions?.map(f => serializeToBuffer(f.selector, f.vkHash, f.isInternal)) ?? [],
32
+ contractClass.publicFunctions.length,
33
+ contractClass.publicFunctions?.map(f =>
34
+ serializeToBuffer(f.selector, f.bytecode.length, f.bytecode, f.isInternal),
35
+ ) ?? [],
36
+ contractClass.packedBytecode.length,
37
+ contractClass.packedBytecode,
38
+ contractClass.privateFunctionsRoot,
39
+ );
40
+ }
41
+
42
+ export function deserializeContractClassPublic(buffer: Buffer): Omit<ContractClassPublic, 'id'> {
43
+ const reader = BufferReader.asReader(buffer);
44
+ return {
45
+ version: reader.readUInt8() as 1,
46
+ artifactHash: reader.readObject(Fr),
47
+ privateFunctions: reader.readVector({
48
+ fromBuffer: reader => ({
49
+ selector: reader.readObject(FunctionSelector),
50
+ vkHash: reader.readObject(Fr),
51
+ isInternal: reader.readBoolean(),
52
+ }),
53
+ }),
54
+ publicFunctions: reader.readVector({
55
+ fromBuffer: reader => ({
56
+ selector: reader.readObject(FunctionSelector),
57
+ bytecode: reader.readBuffer(),
58
+ isInternal: reader.readBoolean(),
59
+ }),
60
+ }),
61
+ packedBytecode: reader.readBuffer(),
62
+ privateFunctionsRoot: reader.readObject(Fr),
63
+ };
64
+ }
@@ -0,0 +1,26 @@
1
+ import { AztecAddress } from '@aztec/circuits.js';
2
+ import { AztecKVStore, AztecMap } from '@aztec/kv-store';
3
+ import { ContractInstanceWithAddress, SerializableContractInstance } from '@aztec/types/contracts';
4
+
5
+ /**
6
+ * LMDB implementation of the ArchiverDataStore interface.
7
+ */
8
+ export class ContractInstanceStore {
9
+ #contractInstances: AztecMap<string, Buffer>;
10
+
11
+ constructor(db: AztecKVStore) {
12
+ this.#contractInstances = db.openMap('archiver_contract_instances');
13
+ }
14
+
15
+ addContractInstance(contractInstance: ContractInstanceWithAddress): Promise<boolean> {
16
+ return this.#contractInstances.set(
17
+ contractInstance.address.toString(),
18
+ new SerializableContractInstance(contractInstance).toBuffer(),
19
+ );
20
+ }
21
+
22
+ getContractInstance(address: AztecAddress): ContractInstanceWithAddress | undefined {
23
+ const contractInstance = this.#contractInstances.get(address.toString());
24
+ return contractInstance && SerializableContractInstance.fromBuffer(contractInstance).withAddress(address);
25
+ }
26
+ }
@@ -0,0 +1,93 @@
1
+ import { ContractData, ExtendedContractData } from '@aztec/circuit-types';
2
+ import { AztecAddress } from '@aztec/foundation/aztec-address';
3
+ import { createDebugLogger } from '@aztec/foundation/log';
4
+ import { AztecKVStore, AztecMap } from '@aztec/kv-store';
5
+
6
+ import { BlockStore } from './block_store.js';
7
+
8
+ /**
9
+ * LMDB implementation of the ArchiverDataStore interface.
10
+ */
11
+ export class ContractStore {
12
+ #blockStore: BlockStore;
13
+ #extendedContractData: AztecMap<number, Buffer[]>;
14
+ #log = createDebugLogger('aztec:archiver:contract_store');
15
+
16
+ constructor(private db: AztecKVStore, blockStore: BlockStore) {
17
+ this.#extendedContractData = db.openMap('archiver_extended_contract_data');
18
+ this.#blockStore = blockStore;
19
+ }
20
+
21
+ /**
22
+ * Add new extended contract data from an L2 block to the store's list.
23
+ * @param data - List of contracts' data to be added.
24
+ * @param blockNum - Number of the L2 block the contract data was deployed in.
25
+ * @returns True if the operation is successful.
26
+ */
27
+ addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean> {
28
+ return this.#extendedContractData.swap(blockNum, (existingData = []) => {
29
+ existingData.push(...data.map(d => d.toBuffer()));
30
+ return existingData;
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Get the extended contract data for this contract.
36
+ * @param contractAddress - The contract data address.
37
+ * @returns The extended contract data or undefined if not found.
38
+ */
39
+ getExtendedContractData(contractAddress: AztecAddress): ExtendedContractData | undefined {
40
+ const [blockNumber, _] = this.#blockStore.getContractLocation(contractAddress) ?? [];
41
+
42
+ if (typeof blockNumber !== 'number') {
43
+ return undefined;
44
+ }
45
+
46
+ for (const contract of this.#extendedContractData.get(blockNumber) ?? []) {
47
+ const extendedContractData = ExtendedContractData.fromBuffer(contract);
48
+ if (extendedContractData.contractData.contractAddress.equals(contractAddress)) {
49
+ return extendedContractData;
50
+ }
51
+ }
52
+
53
+ return undefined;
54
+ }
55
+
56
+ /**
57
+ * Lookup all extended contract data in an L2 block.
58
+ * @param blockNumber - The block number to get all contract data from.
59
+ * @returns All extended contract data in the block (if found).
60
+ */
61
+ getExtendedContractDataInBlock(blockNumber: number): Array<ExtendedContractData> {
62
+ return (this.#extendedContractData.get(blockNumber) ?? []).map(contract =>
63
+ ExtendedContractData.fromBuffer(contract),
64
+ );
65
+ }
66
+
67
+ /**
68
+ * Get basic info for an L2 contract.
69
+ * Contains contract address & the ethereum portal address.
70
+ * @param contractAddress - The contract data address.
71
+ * @returns ContractData with the portal address (if we didn't throw an error).
72
+ */
73
+ getContractData(contractAddress: AztecAddress): ContractData | undefined {
74
+ const [blockNumber, index] = this.#blockStore.getContractLocation(contractAddress) ?? [];
75
+ if (typeof blockNumber !== 'number' || typeof index !== 'number') {
76
+ return undefined;
77
+ }
78
+
79
+ const block = this.#blockStore.getBlock(blockNumber);
80
+ return block?.newContractData[index];
81
+ }
82
+
83
+ /**
84
+ * Get basic info for an all L2 contracts deployed in a block.
85
+ * Contains contract address & the ethereum portal address.
86
+ * @param blockNumber - Number of the L2 block where contracts were deployed.
87
+ * @returns ContractData with the portal address (if we didn't throw an error).
88
+ */
89
+ getContractDataInBlock(blockNumber: number): ContractData[] {
90
+ const block = this.#blockStore.getBlock(blockNumber);
91
+ return block?.newContractData ?? [];
92
+ }
93
+ }
@@ -0,0 +1,264 @@
1
+ import {
2
+ ContractData,
3
+ ExtendedContractData,
4
+ GetUnencryptedLogsResponse,
5
+ L1ToL2Message,
6
+ L2Block,
7
+ L2BlockL2Logs,
8
+ L2Tx,
9
+ LogFilter,
10
+ LogType,
11
+ TxHash,
12
+ } from '@aztec/circuit-types';
13
+ import { Fr } from '@aztec/circuits.js';
14
+ import { AztecAddress } from '@aztec/foundation/aztec-address';
15
+ import { createDebugLogger } from '@aztec/foundation/log';
16
+ import { AztecKVStore } from '@aztec/kv-store';
17
+ import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';
18
+
19
+ import { ArchiverDataStore, ArchiverL1SynchPoint } from '../archiver_store.js';
20
+ import { BlockStore } from './block_store.js';
21
+ import { ContractClassStore } from './contract_class_store.js';
22
+ import { ContractInstanceStore } from './contract_instance_store.js';
23
+ import { ContractStore } from './contract_store.js';
24
+ import { LogStore } from './log_store.js';
25
+ import { MessageStore } from './message_store.js';
26
+
27
+ /**
28
+ * LMDB implementation of the ArchiverDataStore interface.
29
+ */
30
+ export class KVArchiverDataStore implements ArchiverDataStore {
31
+ #blockStore: BlockStore;
32
+ #logStore: LogStore;
33
+ #contractStore: ContractStore;
34
+ #messageStore: MessageStore;
35
+ #contractClassStore: ContractClassStore;
36
+ #contractInstanceStore: ContractInstanceStore;
37
+
38
+ #log = createDebugLogger('aztec:archiver:data-store');
39
+
40
+ constructor(db: AztecKVStore, logsMaxPageSize: number = 1000) {
41
+ this.#blockStore = new BlockStore(db);
42
+ this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize);
43
+ this.#contractStore = new ContractStore(db, this.#blockStore);
44
+ this.#messageStore = new MessageStore(db);
45
+ this.#contractClassStore = new ContractClassStore(db);
46
+ this.#contractInstanceStore = new ContractInstanceStore(db);
47
+ }
48
+
49
+ getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
50
+ return Promise.resolve(this.#contractClassStore.getContractClass(id));
51
+ }
52
+
53
+ getContractInstance(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
54
+ return Promise.resolve(this.#contractInstanceStore.getContractInstance(address));
55
+ }
56
+
57
+ async addContractClasses(data: ContractClassPublic[], _blockNumber: number): Promise<boolean> {
58
+ return (await Promise.all(data.map(c => this.#contractClassStore.addContractClass(c)))).every(Boolean);
59
+ }
60
+
61
+ async addContractInstances(data: ContractInstanceWithAddress[], _blockNumber: number): Promise<boolean> {
62
+ return (await Promise.all(data.map(c => this.#contractInstanceStore.addContractInstance(c)))).every(Boolean);
63
+ }
64
+
65
+ /**
66
+ * Append new blocks to the store's list.
67
+ * @param blocks - The L2 blocks to be added to the store.
68
+ * @returns True if the operation is successful.
69
+ */
70
+ addBlocks(blocks: L2Block[]): Promise<boolean> {
71
+ return this.#blockStore.addBlocks(blocks);
72
+ }
73
+
74
+ /**
75
+ * Gets up to `limit` amount of L2 blocks starting from `from`.
76
+ * The blocks returned do not contain any logs.
77
+ *
78
+ * @param start - Number of the first block to return (inclusive).
79
+ * @param limit - The number of blocks to return.
80
+ * @returns The requested L2 blocks, without any logs attached
81
+ */
82
+ getBlocks(start: number, limit: number): Promise<L2Block[]> {
83
+ try {
84
+ return Promise.resolve(Array.from(this.#blockStore.getBlocks(start, limit)));
85
+ } catch (err) {
86
+ // this function is sync so if any errors are thrown we need to make sure they're passed on as rejected Promises
87
+ return Promise.reject(err);
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Gets an l2 tx.
93
+ * @param txHash - The txHash of the l2 tx.
94
+ * @returns The requested L2 tx.
95
+ */
96
+ getL2Tx(txHash: TxHash): Promise<L2Tx | undefined> {
97
+ return Promise.resolve(this.#blockStore.getL2Tx(txHash));
98
+ }
99
+
100
+ /**
101
+ * Append new logs to the store's list.
102
+ * @param encryptedLogs - The logs to be added to the store.
103
+ * @param unencryptedLogs - The type of the logs to be added to the store.
104
+ * @param blockNumber - The block for which to add the logs.
105
+ * @returns True if the operation is successful.
106
+ */
107
+ addLogs(
108
+ encryptedLogs: L2BlockL2Logs | undefined,
109
+ unencryptedLogs: L2BlockL2Logs | undefined,
110
+ blockNumber: number,
111
+ ): Promise<boolean> {
112
+ return this.#logStore.addLogs(encryptedLogs, unencryptedLogs, blockNumber);
113
+ }
114
+
115
+ /**
116
+ * Append new pending L1 to L2 messages to the store.
117
+ * @param messages - The L1 to L2 messages to be added to the store.
118
+ * @param l1BlockNumber - The L1 block number for which to add the messages.
119
+ * @returns True if the operation is successful.
120
+ */
121
+ addPendingL1ToL2Messages(messages: L1ToL2Message[], l1BlockNumber: bigint): Promise<boolean> {
122
+ return Promise.resolve(this.#messageStore.addPendingMessages(messages, l1BlockNumber));
123
+ }
124
+
125
+ /**
126
+ * Remove pending L1 to L2 messages from the store (if they were cancelled).
127
+ * @param messages - The message keys to be removed from the store.
128
+ * @param l1BlockNumber - The L1 block number for which to remove the messages.
129
+ * @returns True if the operation is successful.
130
+ */
131
+ cancelPendingL1ToL2Messages(messages: Fr[], l1BlockNumber: bigint): Promise<boolean> {
132
+ return Promise.resolve(this.#messageStore.cancelPendingMessages(messages, l1BlockNumber));
133
+ }
134
+
135
+ /**
136
+ * Messages that have been published in an L2 block are confirmed.
137
+ * Add them to the confirmed store, also remove them from the pending store.
138
+ * @param entryKeys - The message keys to be removed from the store.
139
+ * @param blockNumber - The block for which to add the messages.
140
+ * @returns True if the operation is successful.
141
+ */
142
+ confirmL1ToL2Messages(entryKeys: Fr[]): Promise<boolean> {
143
+ return this.#messageStore.confirmPendingMessages(entryKeys);
144
+ }
145
+
146
+ /**
147
+ * Gets up to `limit` amount of pending L1 to L2 messages, sorted by fee
148
+ * @param limit - The number of messages to return (by default NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).
149
+ * @returns The requested L1 to L2 message keys.
150
+ */
151
+ getPendingL1ToL2MessageKeys(limit: number): Promise<Fr[]> {
152
+ return Promise.resolve(this.#messageStore.getPendingMessageKeysByFee(limit));
153
+ }
154
+
155
+ /**
156
+ * Gets the confirmed L1 to L2 message corresponding to the given message key.
157
+ * @param messageKey - The message key to look up.
158
+ * @returns The requested L1 to L2 message or throws if not found.
159
+ */
160
+ getConfirmedL1ToL2Message(messageKey: Fr): Promise<L1ToL2Message> {
161
+ try {
162
+ return Promise.resolve(this.#messageStore.getConfirmedMessage(messageKey));
163
+ } catch (err) {
164
+ return Promise.reject(err);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Gets up to `limit` amount of logs starting from `from`.
170
+ * @param start - Number of the L2 block to which corresponds the first logs to be returned.
171
+ * @param limit - The number of logs to return.
172
+ * @param logType - Specifies whether to return encrypted or unencrypted logs.
173
+ * @returns The requested logs.
174
+ */
175
+ getLogs(start: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]> {
176
+ try {
177
+ return Promise.resolve(Array.from(this.#logStore.getLogs(start, limit, logType)));
178
+ } catch (err) {
179
+ return Promise.reject(err);
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Gets unencrypted logs based on the provided filter.
185
+ * @param filter - The filter to apply to the logs.
186
+ * @returns The requested logs.
187
+ */
188
+ getUnencryptedLogs(filter: LogFilter): Promise<GetUnencryptedLogsResponse> {
189
+ try {
190
+ return Promise.resolve(this.#logStore.getUnencryptedLogs(filter));
191
+ } catch (err) {
192
+ return Promise.reject(err);
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Add new extended contract data from an L2 block to the store's list.
198
+ * @param data - List of contracts' data to be added.
199
+ * @param blockNum - Number of the L2 block the contract data was deployed in.
200
+ * @returns True if the operation is successful.
201
+ */
202
+ addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise<boolean> {
203
+ return this.#contractStore.addExtendedContractData(data, blockNum);
204
+ }
205
+
206
+ /**
207
+ * Get the extended contract data for this contract.
208
+ * @param contractAddress - The contract data address.
209
+ * @returns The extended contract data or undefined if not found.
210
+ */
211
+ getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
212
+ return Promise.resolve(this.#contractStore.getExtendedContractData(contractAddress));
213
+ }
214
+
215
+ /**
216
+ * Lookup all extended contract data in an L2 block.
217
+ * @param blockNumber - The block number to get all contract data from.
218
+ * @returns All extended contract data in the block (if found).
219
+ */
220
+ getExtendedContractDataInBlock(blockNumber: number): Promise<ExtendedContractData[]> {
221
+ return Promise.resolve(Array.from(this.#contractStore.getExtendedContractDataInBlock(blockNumber)));
222
+ }
223
+
224
+ /**
225
+ * Get basic info for an L2 contract.
226
+ * Contains contract address & the ethereum portal address.
227
+ * @param contractAddress - The contract data address.
228
+ * @returns ContractData with the portal address (if we didn't throw an error).
229
+ */
230
+ getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
231
+ return Promise.resolve(this.#contractStore.getContractData(contractAddress));
232
+ }
233
+
234
+ /**
235
+ * Get basic info for an all L2 contracts deployed in a block.
236
+ * Contains contract address & the ethereum portal address.
237
+ * @param blockNumber - Number of the L2 block where contracts were deployed.
238
+ * @returns ContractData with the portal address (if we didn't throw an error).
239
+ */
240
+ getContractDataInBlock(blockNumber: number): Promise<ContractData[]> {
241
+ return Promise.resolve(Array.from(this.#contractStore.getContractDataInBlock(blockNumber)));
242
+ }
243
+
244
+ /**
245
+ * Gets the number of the latest L2 block processed.
246
+ * @returns The number of the latest L2 block processed.
247
+ */
248
+ getBlockNumber(): Promise<number> {
249
+ return Promise.resolve(this.#blockStore.getBlockNumber());
250
+ }
251
+
252
+ /**
253
+ * Gets the last L1 block number processed by the archiver
254
+ */
255
+ getL1BlockNumber(): Promise<ArchiverL1SynchPoint> {
256
+ const addedBlock = this.#blockStore.getL1BlockNumber();
257
+ const { addedMessages, cancelledMessages } = this.#messageStore.getL1BlockNumber();
258
+ return Promise.resolve({
259
+ addedBlock,
260
+ addedMessages,
261
+ cancelledMessages,
262
+ });
263
+ }
264
+ }