@aztec/aztec-node 0.1.0-alpha23 → 0.1.0-alpha40
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.
- package/.tsbuildinfo +1 -1
- package/dest/aztec-node/config.d.ts +1 -1
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +4 -2
- package/dest/aztec-node/http-node.d.ts +26 -16
- package/dest/aztec-node/http-node.d.ts.map +1 -1
- package/dest/aztec-node/http-node.js +53 -29
- package/dest/aztec-node/http-node.test.js +75 -37
- package/dest/aztec-node/server.d.ts +29 -14
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +46 -24
- package/dest/index.d.ts +0 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/package.json +10 -10
- package/src/aztec-node/config.ts +3 -1
- package/src/aztec-node/http-node.test.ts +94 -37
- package/src/aztec-node/http-node.ts +59 -29
- package/src/aztec-node/server.ts +65 -25
- package/src/index.ts +0 -1
- package/dest/aztec-node/aztec-node.d.ts +0 -126
- package/dest/aztec-node/aztec-node.d.ts.map +0 -1
- package/dest/aztec-node/aztec-node.js +0 -2
- package/src/aztec-node/aztec-node.ts +0 -153
package/dest/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export * from './aztec-node/aztec-node.js';
|
|
2
1
|
export * from './aztec-node/config.js';
|
|
3
2
|
export * from './aztec-node/server.js';
|
|
4
3
|
export * from './aztec-node/http-node.js';
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyx3QkFBd0IsQ0FBQztBQUN2QyxjQUFjLHdCQUF3QixDQUFDO0FBQ3ZDLGNBQWMsMkJBQTJCLENBQUMifQ==
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/aztec-node",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-alpha40",
|
|
4
4
|
"exports": "./dest/index.js",
|
|
5
5
|
"main": "dest/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@aztec/archiver": "0.1.0-
|
|
9
|
-
"@aztec/circuits.js": "0.1.0-
|
|
10
|
-
"@aztec/foundation": "0.1.0-
|
|
11
|
-
"@aztec/l1-artifacts": "0.1.0-
|
|
12
|
-
"@aztec/merkle-tree": "0.1.0-
|
|
13
|
-
"@aztec/p2p": "0.1.0-
|
|
14
|
-
"@aztec/sequencer-client": "0.1.0-
|
|
15
|
-
"@aztec/types": "0.1.0-
|
|
16
|
-
"@aztec/world-state": "0.1.0-
|
|
8
|
+
"@aztec/archiver": "0.1.0-alpha40",
|
|
9
|
+
"@aztec/circuits.js": "0.1.0-alpha40",
|
|
10
|
+
"@aztec/foundation": "0.1.0-alpha40",
|
|
11
|
+
"@aztec/l1-artifacts": "0.1.0-alpha40",
|
|
12
|
+
"@aztec/merkle-tree": "0.1.0-alpha40",
|
|
13
|
+
"@aztec/p2p": "0.1.0-alpha40",
|
|
14
|
+
"@aztec/sequencer-client": "0.1.0-alpha40",
|
|
15
|
+
"@aztec/types": "0.1.0-alpha40",
|
|
16
|
+
"@aztec/world-state": "0.1.0-alpha40",
|
|
17
17
|
"tslib": "^2.4.0"
|
|
18
18
|
}
|
|
19
19
|
}
|
package/src/aztec-node/config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ArchiverConfig, getConfigEnvVars as getArchiverVars } from '@aztec/archiver';
|
|
2
|
-
import { SequencerClientConfig, getConfigEnvVars as getSequencerVars } from '@aztec/sequencer-client';
|
|
3
2
|
import { P2PConfig, getP2PConfigEnvVars } from '@aztec/p2p';
|
|
3
|
+
import { SequencerClientConfig, getConfigEnvVars as getSequencerVars } from '@aztec/sequencer-client';
|
|
4
|
+
import { getConfigEnvVars as getWorldStateVars } from '@aztec/world-state';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The configuration the aztec node.
|
|
@@ -16,6 +17,7 @@ export function getConfigEnvVars(): AztecNodeConfig {
|
|
|
16
17
|
...getSequencerVars(),
|
|
17
18
|
...getArchiverVars(),
|
|
18
19
|
...getP2PConfigEnvVars(),
|
|
20
|
+
...getWorldStateVars(),
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
return allEnvVars;
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { AztecAddress, CircuitsWasm, Fr } from '@aztec/circuits.js';
|
|
1
|
+
import { AztecAddress, CircuitsWasm, EthAddress, Fr, HistoricBlockData } from '@aztec/circuits.js';
|
|
2
2
|
import { randomBytes } from '@aztec/foundation/crypto';
|
|
3
|
-
import { Pedersen
|
|
3
|
+
import { Pedersen } from '@aztec/merkle-tree';
|
|
4
4
|
import {
|
|
5
5
|
ContractData,
|
|
6
|
-
|
|
6
|
+
ContractDataAndBytecode,
|
|
7
7
|
L1ToL2Message,
|
|
8
8
|
L2Block,
|
|
9
9
|
L2BlockL2Logs,
|
|
10
10
|
LogType,
|
|
11
11
|
MerkleTreeId,
|
|
12
|
-
|
|
12
|
+
SiblingPath,
|
|
13
13
|
TxHash,
|
|
14
|
+
mockTx,
|
|
14
15
|
} from '@aztec/types';
|
|
16
|
+
|
|
15
17
|
import { jest } from '@jest/globals';
|
|
18
|
+
|
|
16
19
|
import { HttpNode } from './http-node.js';
|
|
17
20
|
|
|
18
21
|
const TEST_URL = 'http://aztec-node-url.com/';
|
|
@@ -66,7 +69,7 @@ describe('HttpNode', () => {
|
|
|
66
69
|
|
|
67
70
|
const result = await httpNode.getBlocks(0, 3);
|
|
68
71
|
|
|
69
|
-
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-blocks?from=0&
|
|
72
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-blocks?from=0&limit=3`);
|
|
70
73
|
expect(result).toEqual([block1, block2]);
|
|
71
74
|
});
|
|
72
75
|
|
|
@@ -76,11 +79,36 @@ describe('HttpNode', () => {
|
|
|
76
79
|
|
|
77
80
|
const result = await httpNode.getBlocks(0, 2);
|
|
78
81
|
|
|
79
|
-
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-blocks?from=0&
|
|
82
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-blocks?from=0&limit=2`);
|
|
80
83
|
expect(result).toEqual([]);
|
|
81
84
|
});
|
|
82
85
|
});
|
|
83
86
|
|
|
87
|
+
describe('getBlock', () => {
|
|
88
|
+
it('should fetch and parse a block', async () => {
|
|
89
|
+
const block1 = L2Block.random(1);
|
|
90
|
+
const response = {
|
|
91
|
+
block: block1.encode(),
|
|
92
|
+
};
|
|
93
|
+
setFetchMock(response);
|
|
94
|
+
|
|
95
|
+
const result = await httpNode.getBlock(1);
|
|
96
|
+
|
|
97
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-block?number=1`);
|
|
98
|
+
expect(result).toEqual(block1);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should return undefined if the block is not available', async () => {
|
|
102
|
+
const response = { block: undefined };
|
|
103
|
+
setFetchMock(response);
|
|
104
|
+
|
|
105
|
+
const result = await httpNode.getBlock(2);
|
|
106
|
+
|
|
107
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-block?number=2`);
|
|
108
|
+
expect(result).toEqual(undefined);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
84
112
|
describe('getBlockHeight', () => {
|
|
85
113
|
it('should fetch and return the block height', async () => {
|
|
86
114
|
const response = { blockHeight: 100 };
|
|
@@ -117,21 +145,34 @@ describe('HttpNode', () => {
|
|
|
117
145
|
});
|
|
118
146
|
});
|
|
119
147
|
|
|
120
|
-
describe('
|
|
148
|
+
describe('getRollupAddress', () => {
|
|
149
|
+
it('should fetch and return the rollup address', async () => {
|
|
150
|
+
const addr = EthAddress.random();
|
|
151
|
+
const response = { rollupAddress: addr.toString() };
|
|
152
|
+
setFetchMock(response);
|
|
153
|
+
|
|
154
|
+
const result = await httpNode.getRollupAddress();
|
|
155
|
+
|
|
156
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-rollup-address`);
|
|
157
|
+
expect(result).toEqual(addr);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('getContractDataAndBytecode', () => {
|
|
121
162
|
it('should fetch and return contract public data', async () => {
|
|
122
|
-
const
|
|
163
|
+
const contractDataAndBytecode = ContractDataAndBytecode.random();
|
|
123
164
|
const response = {
|
|
124
|
-
contractData:
|
|
165
|
+
contractData: contractDataAndBytecode.toBuffer(),
|
|
125
166
|
};
|
|
126
167
|
|
|
127
168
|
setFetchMock(response);
|
|
128
169
|
|
|
129
|
-
const result = await httpNode.
|
|
170
|
+
const result = await httpNode.getContractDataAndBytecode(contractDataAndBytecode.contractData.contractAddress);
|
|
130
171
|
|
|
131
172
|
expect(fetch).toHaveBeenCalledWith(
|
|
132
|
-
`${TEST_URL}contract-data?address=${
|
|
173
|
+
`${TEST_URL}contract-data-and-bytecode?address=${contractDataAndBytecode.contractData.contractAddress.toString()}`,
|
|
133
174
|
);
|
|
134
|
-
expect(result).toEqual(
|
|
175
|
+
expect(result).toEqual(contractDataAndBytecode);
|
|
135
176
|
});
|
|
136
177
|
|
|
137
178
|
it('should return undefined if contract data is not available', async () => {
|
|
@@ -142,9 +183,9 @@ describe('HttpNode', () => {
|
|
|
142
183
|
|
|
143
184
|
const randomAddress = AztecAddress.random();
|
|
144
185
|
|
|
145
|
-
const result = await httpNode.
|
|
186
|
+
const result = await httpNode.getContractDataAndBytecode(randomAddress);
|
|
146
187
|
|
|
147
|
-
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}contract-data?address=${randomAddress.toString()}`);
|
|
188
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}contract-data-and-bytecode?address=${randomAddress.toString()}`);
|
|
148
189
|
expect(result).toEqual(undefined);
|
|
149
190
|
});
|
|
150
191
|
});
|
|
@@ -154,7 +195,7 @@ describe('HttpNode', () => {
|
|
|
154
195
|
const processedLogType = logType === 'encrypted' ? LogType.ENCRYPTED : LogType.UNENCRYPTED;
|
|
155
196
|
|
|
156
197
|
const from = 0;
|
|
157
|
-
const
|
|
198
|
+
const limit = 3;
|
|
158
199
|
const log1 = L2BlockL2Logs.random(2, 3, 4);
|
|
159
200
|
const log2 = L2BlockL2Logs.random(1, 5, 2);
|
|
160
201
|
const response = {
|
|
@@ -162,9 +203,9 @@ describe('HttpNode', () => {
|
|
|
162
203
|
};
|
|
163
204
|
setFetchMock(response);
|
|
164
205
|
|
|
165
|
-
const result = await httpNode.getLogs(from,
|
|
206
|
+
const result = await httpNode.getLogs(from, limit, processedLogType);
|
|
166
207
|
|
|
167
|
-
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-logs?from=${from}&
|
|
208
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}get-logs?from=${from}&limit=${limit}&logType=${processedLogType}`);
|
|
168
209
|
expect(result).toEqual([log1, log2]);
|
|
169
210
|
});
|
|
170
211
|
|
|
@@ -174,43 +215,45 @@ describe('HttpNode', () => {
|
|
|
174
215
|
const processedLogType = logType === 'encrypted' ? LogType.ENCRYPTED : LogType.UNENCRYPTED;
|
|
175
216
|
|
|
176
217
|
const from = 0;
|
|
177
|
-
const
|
|
218
|
+
const limit = 2;
|
|
178
219
|
const response = {};
|
|
179
220
|
setFetchMock(response);
|
|
180
221
|
|
|
181
|
-
const result = await httpNode.getLogs(from,
|
|
222
|
+
const result = await httpNode.getLogs(from, limit, processedLogType);
|
|
182
223
|
|
|
183
|
-
expect(fetch).toHaveBeenCalledWith(
|
|
224
|
+
expect(fetch).toHaveBeenCalledWith(
|
|
225
|
+
`${TEST_URL}get-logs?from=${from}&limit=${limit}&logType=${processedLogType}`,
|
|
226
|
+
);
|
|
184
227
|
expect(result).toEqual([]);
|
|
185
228
|
},
|
|
186
229
|
);
|
|
187
230
|
});
|
|
188
231
|
|
|
189
|
-
describe('
|
|
232
|
+
describe('getContractData', () => {
|
|
190
233
|
it('should fetch and return contract data', async () => {
|
|
191
|
-
const
|
|
234
|
+
const contractData = ContractData.random();
|
|
192
235
|
const response = {
|
|
193
|
-
|
|
236
|
+
contractData: contractData.toBuffer(),
|
|
194
237
|
};
|
|
195
238
|
setFetchMock(response);
|
|
196
239
|
|
|
197
|
-
const result = await httpNode.
|
|
240
|
+
const result = await httpNode.getContractData(contractData.contractAddress);
|
|
198
241
|
|
|
199
|
-
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}contract-
|
|
200
|
-
expect(result).toEqual(
|
|
242
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}contract-data?address=${contractData.contractAddress.toString()}`);
|
|
243
|
+
expect(result).toEqual(contractData);
|
|
201
244
|
});
|
|
202
245
|
|
|
203
246
|
it('should return undefined if contract data is not available', async () => {
|
|
204
247
|
const response = {
|
|
205
|
-
|
|
248
|
+
contractData: undefined,
|
|
206
249
|
};
|
|
207
250
|
setFetchMock(response);
|
|
208
251
|
|
|
209
252
|
const randomAddress = AztecAddress.random();
|
|
210
253
|
|
|
211
|
-
const result = await httpNode.
|
|
254
|
+
const result = await httpNode.getContractData(randomAddress);
|
|
212
255
|
|
|
213
|
-
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}contract-
|
|
256
|
+
expect(fetch).toHaveBeenCalledWith(`${TEST_URL}contract-data?address=${randomAddress.toString()}`);
|
|
214
257
|
expect(result).toBeUndefined();
|
|
215
258
|
});
|
|
216
259
|
});
|
|
@@ -369,7 +412,7 @@ describe('HttpNode', () => {
|
|
|
369
412
|
});
|
|
370
413
|
});
|
|
371
414
|
|
|
372
|
-
describe('
|
|
415
|
+
describe('getPublicStorageAt', () => {
|
|
373
416
|
it('should fetch and return the storage value at the given contract slot', async () => {
|
|
374
417
|
const contractAddress = AztecAddress.random();
|
|
375
418
|
const slot = BigInt(789);
|
|
@@ -377,9 +420,9 @@ describe('HttpNode', () => {
|
|
|
377
420
|
const response = { value: storageValue.toString('hex') };
|
|
378
421
|
setFetchMock(response);
|
|
379
422
|
|
|
380
|
-
const result = await httpNode.
|
|
423
|
+
const result = await httpNode.getPublicStorageAt(contractAddress, slot);
|
|
381
424
|
|
|
382
|
-
const url = `${TEST_URL}storage-at?address=${contractAddress}&slot=${slot.toString()}`;
|
|
425
|
+
const url = `${TEST_URL}public-storage-at?address=${contractAddress}&slot=${slot.toString()}`;
|
|
383
426
|
expect(fetch).toHaveBeenCalledWith(url);
|
|
384
427
|
expect(result).toEqual(storageValue);
|
|
385
428
|
});
|
|
@@ -390,9 +433,9 @@ describe('HttpNode', () => {
|
|
|
390
433
|
const response = {};
|
|
391
434
|
setFetchMock(response);
|
|
392
435
|
|
|
393
|
-
const result = await httpNode.
|
|
436
|
+
const result = await httpNode.getPublicStorageAt(contractAddress, slot);
|
|
394
437
|
|
|
395
|
-
const url = `${TEST_URL}storage-at?address=${contractAddress}&slot=${slot.toString()}`;
|
|
438
|
+
const url = `${TEST_URL}public-storage-at?address=${contractAddress}&slot=${slot.toString()}`;
|
|
396
439
|
expect(fetch).toHaveBeenCalledWith(url);
|
|
397
440
|
expect(result).toBeUndefined();
|
|
398
441
|
});
|
|
@@ -406,9 +449,7 @@ describe('HttpNode', () => {
|
|
|
406
449
|
[MerkleTreeId.NULLIFIER_TREE]: Fr.random(),
|
|
407
450
|
[MerkleTreeId.PUBLIC_DATA_TREE]: Fr.random(),
|
|
408
451
|
[MerkleTreeId.L1_TO_L2_MESSAGES_TREE]: Fr.random(),
|
|
409
|
-
[MerkleTreeId.
|
|
410
|
-
[MerkleTreeId.CONTRACT_TREE_ROOTS_TREE]: Fr.random(),
|
|
411
|
-
[MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE]: Fr.random(),
|
|
452
|
+
[MerkleTreeId.BLOCKS_TREE]: Fr.random(),
|
|
412
453
|
};
|
|
413
454
|
|
|
414
455
|
const rootsInResponse: Record<MerkleTreeId, string> = Object.fromEntries(
|
|
@@ -425,4 +466,20 @@ describe('HttpNode', () => {
|
|
|
425
466
|
expect(result).toEqual(roots);
|
|
426
467
|
});
|
|
427
468
|
});
|
|
469
|
+
|
|
470
|
+
describe('getHistoricBlockData', () => {
|
|
471
|
+
it('should fetch and return the current committed roots for the data trees', async () => {
|
|
472
|
+
const blockData = HistoricBlockData.random();
|
|
473
|
+
|
|
474
|
+
const response = { blockData };
|
|
475
|
+
|
|
476
|
+
setFetchMock(response);
|
|
477
|
+
|
|
478
|
+
const result = await httpNode.getHistoricBlockData();
|
|
479
|
+
|
|
480
|
+
const url = `${TEST_URL}historic-block-data`;
|
|
481
|
+
expect(fetch).toHaveBeenCalledWith(url);
|
|
482
|
+
expect(result).toEqual(blockData);
|
|
483
|
+
});
|
|
484
|
+
});
|
|
428
485
|
});
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { AztecNode } from '@aztec/aztec-node';
|
|
2
1
|
import {
|
|
3
2
|
AztecAddress,
|
|
4
3
|
CONTRACT_TREE_HEIGHT,
|
|
4
|
+
EthAddress,
|
|
5
5
|
Fr,
|
|
6
|
+
HistoricBlockData,
|
|
6
7
|
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
7
8
|
PRIVATE_DATA_TREE_HEIGHT,
|
|
8
9
|
} from '@aztec/circuits.js';
|
|
9
|
-
import {
|
|
10
|
-
import { SiblingPath } from '@aztec/merkle-tree';
|
|
10
|
+
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
11
11
|
import {
|
|
12
|
+
AztecNode,
|
|
12
13
|
ContractData,
|
|
13
|
-
|
|
14
|
+
ContractDataAndBytecode,
|
|
14
15
|
L1ToL2Message,
|
|
15
16
|
L1ToL2MessageAndIndex,
|
|
16
17
|
L2Block,
|
|
17
18
|
L2BlockL2Logs,
|
|
18
19
|
LogType,
|
|
19
20
|
MerkleTreeId,
|
|
21
|
+
SiblingPath,
|
|
20
22
|
Tx,
|
|
21
23
|
TxHash,
|
|
22
24
|
} from '@aztec/types';
|
|
@@ -26,9 +28,9 @@ import {
|
|
|
26
28
|
*/
|
|
27
29
|
export class HttpNode implements AztecNode {
|
|
28
30
|
private baseUrl: string;
|
|
29
|
-
private log:
|
|
31
|
+
private log: DebugLogger;
|
|
30
32
|
|
|
31
|
-
constructor(baseUrl: string, log =
|
|
33
|
+
constructor(baseUrl: string, log = createDebugLogger('aztec:http-node')) {
|
|
32
34
|
this.baseUrl = baseUrl.toString().replace(/\/$/, '');
|
|
33
35
|
this.log = log;
|
|
34
36
|
}
|
|
@@ -43,17 +45,30 @@ export class HttpNode implements AztecNode {
|
|
|
43
45
|
return respJson.isReady;
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Method to request a block at the provided block number.
|
|
50
|
+
* @param number - The block number to request.
|
|
51
|
+
* @returns The block requested. Or undefined if it does not exist.
|
|
52
|
+
*/
|
|
53
|
+
async getBlock(number: number): Promise<L2Block | undefined> {
|
|
54
|
+
const url = new URL(`${this.baseUrl}/get-block`);
|
|
55
|
+
url.searchParams.append('number', number.toString());
|
|
56
|
+
const response = await (await fetch(url.toString())).json();
|
|
57
|
+
const { block } = response;
|
|
58
|
+
return Promise.resolve(block ? L2Block.decode(Buffer.from(block, 'hex')) : block);
|
|
59
|
+
}
|
|
60
|
+
|
|
46
61
|
/**
|
|
47
62
|
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
48
63
|
* @param from - The start of the range of blocks to return.
|
|
49
|
-
* @param
|
|
64
|
+
* @param limit - Maximum number of blocks to obtain.
|
|
50
65
|
* @returns The blocks requested.
|
|
51
66
|
*/
|
|
52
|
-
async getBlocks(from: number,
|
|
67
|
+
async getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
53
68
|
const url = new URL(`${this.baseUrl}/get-blocks`);
|
|
54
69
|
url.searchParams.append('from', from.toString());
|
|
55
|
-
if (
|
|
56
|
-
url.searchParams.append('
|
|
70
|
+
if (limit !== undefined) {
|
|
71
|
+
url.searchParams.append('limit', limit.toString());
|
|
57
72
|
}
|
|
58
73
|
const response = await (await fetch(url.toString())).json();
|
|
59
74
|
const blocks = response.blocks as string[];
|
|
@@ -85,6 +100,13 @@ export class HttpNode implements AztecNode {
|
|
|
85
100
|
return respJson.version;
|
|
86
101
|
}
|
|
87
102
|
|
|
103
|
+
public async getRollupAddress(): Promise<EthAddress> {
|
|
104
|
+
const url = new URL(`${this.baseUrl}/get-rollup-address`);
|
|
105
|
+
const response = await fetch(url.toString());
|
|
106
|
+
const respJson = await response.json();
|
|
107
|
+
return EthAddress.fromString(respJson.rollupAddress);
|
|
108
|
+
}
|
|
109
|
+
|
|
88
110
|
/**
|
|
89
111
|
* Method to fetch the chain id of the base-layer for the rollup.
|
|
90
112
|
* @returns The chain id.
|
|
@@ -97,34 +119,34 @@ export class HttpNode implements AztecNode {
|
|
|
97
119
|
}
|
|
98
120
|
|
|
99
121
|
/**
|
|
100
|
-
* Lookup the
|
|
122
|
+
* Lookup the contract data for this contract.
|
|
101
123
|
* Contains the ethereum portal address and bytecode.
|
|
102
124
|
* @param contractAddress - The contract data address.
|
|
103
125
|
* @returns The complete contract data including portal address & bytecode (if we didn't throw an error).
|
|
104
126
|
*/
|
|
105
|
-
async
|
|
106
|
-
const url = new URL(`${this.baseUrl}/contract-data`);
|
|
127
|
+
async getContractDataAndBytecode(contractAddress: AztecAddress): Promise<ContractDataAndBytecode | undefined> {
|
|
128
|
+
const url = new URL(`${this.baseUrl}/contract-data-and-bytecode`);
|
|
107
129
|
url.searchParams.append('address', contractAddress.toString());
|
|
108
130
|
const response = await (await fetch(url.toString())).json();
|
|
109
131
|
if (!response || !response.contractData) {
|
|
110
132
|
return undefined;
|
|
111
133
|
}
|
|
112
134
|
const contract = response.contractData as string;
|
|
113
|
-
return Promise.resolve(
|
|
135
|
+
return Promise.resolve(ContractDataAndBytecode.fromBuffer(Buffer.from(contract, 'hex')));
|
|
114
136
|
}
|
|
115
137
|
|
|
116
138
|
/**
|
|
117
|
-
* Gets
|
|
139
|
+
* Gets up to `limit` amount of logs starting from `from`.
|
|
118
140
|
* @param from - Number of the L2 block to which corresponds the first logs to be returned.
|
|
119
|
-
* @param
|
|
141
|
+
* @param limit - The maximum number of logs to return.
|
|
120
142
|
* @param logType - Specifies whether to return encrypted or unencrypted logs.
|
|
121
143
|
* @returns The requested logs.
|
|
122
144
|
*/
|
|
123
|
-
public async getLogs(from: number,
|
|
145
|
+
public async getLogs(from: number, limit: number, logType: LogType): Promise<L2BlockL2Logs[]> {
|
|
124
146
|
const url = new URL(`${this.baseUrl}/get-logs`);
|
|
125
147
|
|
|
126
148
|
url.searchParams.append('from', from.toString());
|
|
127
|
-
url.searchParams.append('
|
|
149
|
+
url.searchParams.append('limit', limit.toString());
|
|
128
150
|
url.searchParams.append('logType', logType.toString());
|
|
129
151
|
|
|
130
152
|
const response = await (await fetch(url.toString())).json();
|
|
@@ -137,19 +159,19 @@ export class HttpNode implements AztecNode {
|
|
|
137
159
|
}
|
|
138
160
|
|
|
139
161
|
/**
|
|
140
|
-
* Lookup the
|
|
162
|
+
* Lookup the contract data for this contract.
|
|
141
163
|
* Contains the ethereum portal address.
|
|
142
164
|
* @param contractAddress - The contract data address.
|
|
143
165
|
* @returns The contract's address & portal address.
|
|
144
166
|
*/
|
|
145
|
-
async
|
|
146
|
-
const url = new URL(`${this.baseUrl}/contract-
|
|
167
|
+
async getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
|
|
168
|
+
const url = new URL(`${this.baseUrl}/contract-data`);
|
|
147
169
|
url.searchParams.append('address', contractAddress.toString());
|
|
148
170
|
const response = await (await fetch(url.toString())).json();
|
|
149
|
-
if (!response || !response.
|
|
171
|
+
if (!response || !response.contractData) {
|
|
150
172
|
return undefined;
|
|
151
173
|
}
|
|
152
|
-
const contract = response.
|
|
174
|
+
const contract = response.contractData as string;
|
|
153
175
|
return Promise.resolve(ContractData.fromBuffer(Buffer.from(contract, 'hex')));
|
|
154
176
|
}
|
|
155
177
|
|
|
@@ -183,7 +205,7 @@ export class HttpNode implements AztecNode {
|
|
|
183
205
|
url.searchParams.append('hash', txHash.toString());
|
|
184
206
|
const response = await fetch(url.toString());
|
|
185
207
|
if (response.status === 404) {
|
|
186
|
-
this.log(`Tx ${txHash.toString()} not found`);
|
|
208
|
+
this.log.info(`Tx ${txHash.toString()} not found`);
|
|
187
209
|
return undefined;
|
|
188
210
|
}
|
|
189
211
|
const txBuffer = Buffer.from(await (await fetch(url.toString())).arrayBuffer());
|
|
@@ -284,8 +306,8 @@ export class HttpNode implements AztecNode {
|
|
|
284
306
|
* @returns Storage value at the given contract slot (or undefined if not found).
|
|
285
307
|
* Note: Aztec's version of `eth_getStorageAt`.
|
|
286
308
|
*/
|
|
287
|
-
async
|
|
288
|
-
const url = new URL(`${this.baseUrl}/storage-at`);
|
|
309
|
+
async getPublicStorageAt(contract: AztecAddress, slot: bigint): Promise<Buffer | undefined> {
|
|
310
|
+
const url = new URL(`${this.baseUrl}/public-storage-at`);
|
|
289
311
|
url.searchParams.append('address', contract.toString());
|
|
290
312
|
url.searchParams.append('slot', slot.toString());
|
|
291
313
|
const response = await (await fetch(url.toString())).json();
|
|
@@ -316,9 +338,17 @@ export class HttpNode implements AztecNode {
|
|
|
316
338
|
[MerkleTreeId.NULLIFIER_TREE]: extractRoot(MerkleTreeId.NULLIFIER_TREE),
|
|
317
339
|
[MerkleTreeId.PUBLIC_DATA_TREE]: extractRoot(MerkleTreeId.PUBLIC_DATA_TREE),
|
|
318
340
|
[MerkleTreeId.L1_TO_L2_MESSAGES_TREE]: extractRoot(MerkleTreeId.L1_TO_L2_MESSAGES_TREE),
|
|
319
|
-
[MerkleTreeId.
|
|
320
|
-
[MerkleTreeId.CONTRACT_TREE_ROOTS_TREE]: extractRoot(MerkleTreeId.CONTRACT_TREE_ROOTS_TREE),
|
|
321
|
-
[MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE]: extractRoot(MerkleTreeId.PRIVATE_DATA_TREE_ROOTS_TREE),
|
|
341
|
+
[MerkleTreeId.BLOCKS_TREE]: extractRoot(MerkleTreeId.BLOCKS_TREE),
|
|
322
342
|
};
|
|
323
343
|
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Returns the currently committed historic block data.
|
|
347
|
+
* @returns The current committed block data.
|
|
348
|
+
*/
|
|
349
|
+
public async getHistoricBlockData(): Promise<HistoricBlockData> {
|
|
350
|
+
const url = new URL(`${this.baseUrl}/historic-block-data`);
|
|
351
|
+
const response = await (await fetch(url.toString())).json();
|
|
352
|
+
return response.blockData;
|
|
353
|
+
}
|
|
324
354
|
}
|