@aztec/pxe 0.79.0 → 0.81.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.
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +2 -1
- package/dest/pxe_oracle_interface/pxe_oracle_interface.d.ts +7 -6
- package/dest/pxe_oracle_interface/pxe_oracle_interface.d.ts.map +1 -1
- package/dest/pxe_oracle_interface/pxe_oracle_interface.js +44 -80
- package/dest/pxe_service/pxe_service.d.ts +1 -0
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +135 -100
- package/dest/storage/note_data_provider/note_dao.d.ts +9 -13
- package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_dao.js +11 -15
- package/dest/storage/note_data_provider/note_data_provider.d.ts +2 -2
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -1
- package/dest/storage/note_data_provider/note_data_provider.js +18 -19
- package/dest/synchronizer/synchronizer.js +1 -1
- package/package.json +15 -15
- package/src/config/index.ts +1 -0
- package/src/pxe_oracle_interface/pxe_oracle_interface.ts +55 -117
- package/src/pxe_service/pxe_service.ts +180 -134
- package/src/storage/note_data_provider/note_dao.ts +9 -18
- package/src/storage/note_data_provider/note_data_provider.ts +22 -28
- package/src/synchronizer/synchronizer.ts +1 -1
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +0 -11
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +0 -1
- package/dest/note_decryption_utils/add_public_values_to_payload.js +0 -47
- package/src/note_decryption_utils/add_public_values_to_payload.ts +0 -64
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
-
import type { Fr
|
|
2
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { toArray } from '@aztec/foundation/iterable';
|
|
4
4
|
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncMultiMap } from '@aztec/kv-store';
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
import type { InBlock } from '@aztec/stdlib/block';
|
|
7
|
-
import type { PublicKey } from '@aztec/stdlib/keys';
|
|
8
7
|
import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
|
|
9
8
|
|
|
10
9
|
import type { DataProvider } from '../data_provider.js';
|
|
@@ -22,7 +21,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
22
21
|
#nullifiedNotesByContract: AztecAsyncMultiMap<string, string>;
|
|
23
22
|
#nullifiedNotesByStorageSlot: AztecAsyncMultiMap<string, string>;
|
|
24
23
|
#nullifiedNotesByTxHash: AztecAsyncMultiMap<string, string>;
|
|
25
|
-
#
|
|
24
|
+
#nullifiedNotesByRecipient: AztecAsyncMultiMap<string, string>;
|
|
26
25
|
#nullifiedNotesByNullifier: AztecAsyncMap<string, string>;
|
|
27
26
|
|
|
28
27
|
#scopes: AztecAsyncMap<string, true>;
|
|
@@ -30,7 +29,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
30
29
|
#notesByContractAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
31
30
|
#notesByStorageSlotAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
32
31
|
#notesByTxHashAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
33
|
-
#
|
|
32
|
+
#notesByRecipientAndScope: Map<string, AztecAsyncMultiMap<string, string>>;
|
|
34
33
|
|
|
35
34
|
private constructor(store: AztecAsyncKVStore) {
|
|
36
35
|
this.#store = store;
|
|
@@ -43,7 +42,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
43
42
|
this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
|
|
44
43
|
this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
|
|
45
44
|
this.#nullifiedNotesByTxHash = store.openMultiMap('nullified_notes_by_tx_hash');
|
|
46
|
-
this.#
|
|
45
|
+
this.#nullifiedNotesByRecipient = store.openMultiMap('nullified_notes_by_recipient');
|
|
47
46
|
this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
|
|
48
47
|
|
|
49
48
|
this.#scopes = store.openMap('scopes');
|
|
@@ -51,7 +50,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
51
50
|
this.#notesByContractAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
52
51
|
this.#notesByStorageSlotAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
53
52
|
this.#notesByTxHashAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
54
|
-
this.#
|
|
53
|
+
this.#notesByRecipientAndScope = new Map<string, AztecAsyncMultiMap<string, string>>();
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
public static async create(store: AztecAsyncKVStore): Promise<NoteDataProvider> {
|
|
@@ -60,7 +59,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
60
59
|
pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
|
|
61
60
|
pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
|
|
62
61
|
pxeDB.#notesByTxHashAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_tx_hash`));
|
|
63
|
-
pxeDB.#
|
|
62
|
+
pxeDB.#notesByRecipientAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_recipient`));
|
|
64
63
|
}
|
|
65
64
|
return pxeDB;
|
|
66
65
|
}
|
|
@@ -76,10 +75,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
76
75
|
this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
|
|
77
76
|
this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
|
|
78
77
|
this.#notesByTxHashAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_tx_hash`));
|
|
79
|
-
this.#
|
|
80
|
-
scopeString,
|
|
81
|
-
this.#store.openMultiMap(`${scopeString}:notes_by_address_point`),
|
|
82
|
-
);
|
|
78
|
+
this.#notesByRecipientAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_recipient`));
|
|
83
79
|
|
|
84
80
|
return true;
|
|
85
81
|
}
|
|
@@ -103,7 +99,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
103
99
|
await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
|
|
104
100
|
await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
|
|
105
101
|
await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
|
|
106
|
-
await this.#
|
|
102
|
+
await this.#notesByRecipientAndScope.get(scope.toString())!.set(dao.recipient.toString(), noteIndex);
|
|
107
103
|
}
|
|
108
104
|
});
|
|
109
105
|
}
|
|
@@ -120,7 +116,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
120
116
|
await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
|
|
121
117
|
const scopes = await toArray(this.#scopes.keysAsync());
|
|
122
118
|
for (const scope of scopes) {
|
|
123
|
-
await this.#
|
|
119
|
+
await this.#notesByRecipientAndScope.get(scope)!.deleteValue(noteDao.recipient.toString(), noteIndex);
|
|
124
120
|
await this.#notesByTxHashAndScope.get(scope)!.deleteValue(noteDao.txHash.toString(), noteIndex);
|
|
125
121
|
await this.#notesByContractAndScope.get(scope)!.deleteValue(noteDao.contractAddress.toString(), noteIndex);
|
|
126
122
|
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(noteDao.storageSlot.toString(), noteIndex);
|
|
@@ -157,14 +153,14 @@ export class NoteDataProvider implements DataProvider {
|
|
|
157
153
|
let scopes = (await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex))) ?? [];
|
|
158
154
|
|
|
159
155
|
if (scopes.length === 0) {
|
|
160
|
-
scopes = [
|
|
156
|
+
scopes = [dao.recipient.toString()];
|
|
161
157
|
}
|
|
162
158
|
|
|
163
159
|
for (const scope of scopes) {
|
|
164
160
|
await this.#notesByContractAndScope.get(scope.toString())!.set(dao.contractAddress.toString(), noteIndex);
|
|
165
161
|
await this.#notesByStorageSlotAndScope.get(scope.toString())!.set(dao.storageSlot.toString(), noteIndex);
|
|
166
162
|
await this.#notesByTxHashAndScope.get(scope.toString())!.set(dao.txHash.toString(), noteIndex);
|
|
167
|
-
await this.#
|
|
163
|
+
await this.#notesByRecipientAndScope.get(scope.toString())!.set(dao.recipient.toString(), noteIndex);
|
|
168
164
|
await this.#notesToScope.set(noteIndex, scope);
|
|
169
165
|
}
|
|
170
166
|
|
|
@@ -174,15 +170,13 @@ export class NoteDataProvider implements DataProvider {
|
|
|
174
170
|
await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
|
|
175
171
|
await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
|
|
176
172
|
await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
|
|
177
|
-
await this.#
|
|
173
|
+
await this.#nullifiedNotesByRecipient.deleteValue(dao.recipient.toString(), noteIndex);
|
|
178
174
|
await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
|
|
179
175
|
}
|
|
180
176
|
});
|
|
181
177
|
}
|
|
182
178
|
|
|
183
179
|
async getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
184
|
-
const publicKey: PublicKey | undefined = filter.owner ? await filter.owner.toAddressPoint() : undefined;
|
|
185
|
-
|
|
186
180
|
filter.status = filter.status ?? NoteStatus.ACTIVE;
|
|
187
181
|
|
|
188
182
|
const candidateNoteSources = [];
|
|
@@ -200,9 +194,9 @@ export class NoteDataProvider implements DataProvider {
|
|
|
200
194
|
}
|
|
201
195
|
|
|
202
196
|
activeNoteIdsPerScope.push(
|
|
203
|
-
|
|
197
|
+
filter.recipient
|
|
204
198
|
? await toArray(
|
|
205
|
-
this.#
|
|
199
|
+
this.#notesByRecipientAndScope.get(formattedScopeString)!.getValuesAsync(filter.recipient.toString()),
|
|
206
200
|
)
|
|
207
201
|
: filter.txHash
|
|
208
202
|
? await toArray(
|
|
@@ -218,7 +212,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
218
212
|
? await toArray(
|
|
219
213
|
this.#notesByStorageSlotAndScope.get(formattedScopeString)!.getValuesAsync(filter.storageSlot.toString()),
|
|
220
214
|
)
|
|
221
|
-
: await toArray(this.#
|
|
215
|
+
: await toArray(this.#notesByRecipientAndScope.get(formattedScopeString)!.valuesAsync()),
|
|
222
216
|
);
|
|
223
217
|
}
|
|
224
218
|
|
|
@@ -229,8 +223,8 @@ export class NoteDataProvider implements DataProvider {
|
|
|
229
223
|
|
|
230
224
|
if (filter.status == NoteStatus.ACTIVE_OR_NULLIFIED) {
|
|
231
225
|
candidateNoteSources.push({
|
|
232
|
-
ids:
|
|
233
|
-
? await toArray(this.#
|
|
226
|
+
ids: filter.recipient
|
|
227
|
+
? await toArray(this.#nullifiedNotesByRecipient.getValuesAsync(filter.recipient.toString()))
|
|
234
228
|
: filter.txHash
|
|
235
229
|
? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString()))
|
|
236
230
|
: filter.contractAddress
|
|
@@ -263,7 +257,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
263
257
|
continue;
|
|
264
258
|
}
|
|
265
259
|
|
|
266
|
-
if (
|
|
260
|
+
if (filter.recipient && !note.recipient.equals(filter.recipient)) {
|
|
267
261
|
continue;
|
|
268
262
|
}
|
|
269
263
|
|
|
@@ -278,7 +272,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
278
272
|
return result;
|
|
279
273
|
}
|
|
280
274
|
|
|
281
|
-
removeNullifiedNotes(nullifiers: InBlock<Fr>[],
|
|
275
|
+
removeNullifiedNotes(nullifiers: InBlock<Fr>[], recipient: AztecAddress): Promise<NoteDao[]> {
|
|
282
276
|
if (nullifiers.length === 0) {
|
|
283
277
|
return Promise.resolve([]);
|
|
284
278
|
}
|
|
@@ -301,7 +295,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
301
295
|
}
|
|
302
296
|
const noteScopes = (await toArray(this.#notesToScope.getValuesAsync(noteIndex))) ?? [];
|
|
303
297
|
const note = NoteDao.fromBuffer(noteBuffer);
|
|
304
|
-
if (!note.
|
|
298
|
+
if (!note.recipient.equals(recipient)) {
|
|
305
299
|
// tried to nullify someone else's note
|
|
306
300
|
continue;
|
|
307
301
|
}
|
|
@@ -314,7 +308,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
314
308
|
const scopes = await toArray(this.#scopes.keysAsync());
|
|
315
309
|
|
|
316
310
|
for (const scope of scopes) {
|
|
317
|
-
await this.#
|
|
311
|
+
await this.#notesByRecipientAndScope.get(scope)!.deleteValue(note.recipient.toString(), noteIndex);
|
|
318
312
|
await this.#notesByTxHashAndScope.get(scope)!.deleteValue(note.txHash.toString(), noteIndex);
|
|
319
313
|
await this.#notesByContractAndScope.get(scope)!.deleteValue(note.contractAddress.toString(), noteIndex);
|
|
320
314
|
await this.#notesByStorageSlotAndScope.get(scope)!.deleteValue(note.storageSlot.toString(), noteIndex);
|
|
@@ -330,7 +324,7 @@ export class NoteDataProvider implements DataProvider {
|
|
|
330
324
|
await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
|
|
331
325
|
await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
|
|
332
326
|
await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
|
|
333
|
-
await this.#
|
|
327
|
+
await this.#nullifiedNotesByRecipient.set(note.recipient.toString(), noteIndex);
|
|
334
328
|
await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
|
|
335
329
|
|
|
336
330
|
await this.#nullifierToNoteId.delete(nullifier.toString());
|
|
@@ -49,7 +49,7 @@ export class Synchronizer implements L2BlockStreamEventHandler {
|
|
|
49
49
|
|
|
50
50
|
switch (event.type) {
|
|
51
51
|
case 'blocks-added': {
|
|
52
|
-
const lastBlock = event.blocks.at(-1)
|
|
52
|
+
const lastBlock = event.blocks.at(-1)!.block;
|
|
53
53
|
this.log.verbose(`Updated pxe last block to ${lastBlock.number}`, {
|
|
54
54
|
blockHash: lastBlock.hash(),
|
|
55
55
|
archive: lastBlock.archive.root.toString(),
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { L1NotePayload } from '@aztec/stdlib/logs';
|
|
2
|
-
import { Note } from '@aztec/stdlib/note';
|
|
3
|
-
import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
|
|
4
|
-
/**
|
|
5
|
-
* Merges privately and publicly delivered note values.
|
|
6
|
-
* @param db - PXE database used to fetch contract instance and artifact.
|
|
7
|
-
* @param payload - Payload corresponding to the note.
|
|
8
|
-
* @returns Note payload with public fields added.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getOrderedNoteItems(contractDataProvider: ContractDataProvider, { contractAddress, noteTypeId, privateNoteValues, publicNoteValues }: L1NotePayload): Promise<Note>;
|
|
11
|
-
//# sourceMappingURL=add_public_values_to_payload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"add_public_values_to_payload.d.ts","sourceRoot":"","sources":["../../src/note_decryption_utils/add_public_values_to_payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAC;AAExG;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,oBAAoB,EAAE,oBAAoB,EAC1C,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,EAAE,aAAa,GAClF,OAAO,CAAC,IAAI,CAAC,CAgDf"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ContractNotFoundError } from '@aztec/simulator/client';
|
|
2
|
-
import { Note } from '@aztec/stdlib/note';
|
|
3
|
-
/**
|
|
4
|
-
* Merges privately and publicly delivered note values.
|
|
5
|
-
* @param db - PXE database used to fetch contract instance and artifact.
|
|
6
|
-
* @param payload - Payload corresponding to the note.
|
|
7
|
-
* @returns Note payload with public fields added.
|
|
8
|
-
*/ export async function getOrderedNoteItems(contractDataProvider, { contractAddress, noteTypeId, privateNoteValues, publicNoteValues }) {
|
|
9
|
-
if (publicNoteValues.length === 0) {
|
|
10
|
-
return new Note(privateNoteValues);
|
|
11
|
-
}
|
|
12
|
-
const instance = await contractDataProvider.getContractInstance(contractAddress);
|
|
13
|
-
if (!instance) {
|
|
14
|
-
throw new ContractNotFoundError(`Could not find instance for ${contractAddress.toString()}. This should never happen here as the partial notes flow should be triggered only for non-deferred notes.`);
|
|
15
|
-
}
|
|
16
|
-
const artifact = await contractDataProvider.getContractArtifact(instance.currentContractClassId);
|
|
17
|
-
if (!artifact) {
|
|
18
|
-
throw new Error(`Could not find artifact for contract class ${instance.currentContractClassId.toString()}. This should never happen here as the partial notes flow should be triggered only for non-deferred notes.`);
|
|
19
|
-
}
|
|
20
|
-
const noteFields = Object.values(artifact.notes).find((note)=>note.id.equals(noteTypeId))?.fields;
|
|
21
|
-
if (!noteFields) {
|
|
22
|
-
throw new Error(`Could not find note fields for note type ${noteTypeId.toString()}.`);
|
|
23
|
-
}
|
|
24
|
-
// We sort note fields by index so that we can iterate over them in order.
|
|
25
|
-
noteFields.sort((a, b)=>a.index - b.index);
|
|
26
|
-
// Now we insert the public fields into the note based on its indices defined in the ABI.
|
|
27
|
-
const modifiedNoteItems = [
|
|
28
|
-
...privateNoteValues
|
|
29
|
-
];
|
|
30
|
-
let indexInPublicValues = 0;
|
|
31
|
-
for(let i = 0; i < noteFields.length; i++){
|
|
32
|
-
const noteField = noteFields[i];
|
|
33
|
-
if (noteField.nullable) {
|
|
34
|
-
if (i == noteFields.length - 1) {
|
|
35
|
-
// We are processing the last field so we simply insert the rest of the public fields at the end
|
|
36
|
-
modifiedNoteItems.push(...publicNoteValues.slice(indexInPublicValues));
|
|
37
|
-
} else {
|
|
38
|
-
const noteFieldLength = noteFields[i + 1].index - noteField.index;
|
|
39
|
-
const publicValuesToInsert = publicNoteValues.slice(indexInPublicValues, indexInPublicValues + noteFieldLength);
|
|
40
|
-
indexInPublicValues += noteFieldLength;
|
|
41
|
-
// Now we insert the public fields at the note field index
|
|
42
|
-
modifiedNoteItems.splice(noteField.index, 0, ...publicValuesToInsert);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return new Note(modifiedNoteItems);
|
|
47
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ContractNotFoundError } from '@aztec/simulator/client';
|
|
2
|
-
import type { L1NotePayload } from '@aztec/stdlib/logs';
|
|
3
|
-
import { Note } from '@aztec/stdlib/note';
|
|
4
|
-
|
|
5
|
-
import type { ContractDataProvider } from '../storage/contract_data_provider/contract_data_provider.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Merges privately and publicly delivered note values.
|
|
9
|
-
* @param db - PXE database used to fetch contract instance and artifact.
|
|
10
|
-
* @param payload - Payload corresponding to the note.
|
|
11
|
-
* @returns Note payload with public fields added.
|
|
12
|
-
*/
|
|
13
|
-
export async function getOrderedNoteItems(
|
|
14
|
-
contractDataProvider: ContractDataProvider,
|
|
15
|
-
{ contractAddress, noteTypeId, privateNoteValues, publicNoteValues }: L1NotePayload,
|
|
16
|
-
): Promise<Note> {
|
|
17
|
-
if (publicNoteValues.length === 0) {
|
|
18
|
-
return new Note(privateNoteValues);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const instance = await contractDataProvider.getContractInstance(contractAddress);
|
|
22
|
-
if (!instance) {
|
|
23
|
-
throw new ContractNotFoundError(
|
|
24
|
-
`Could not find instance for ${contractAddress.toString()}. This should never happen here as the partial notes flow should be triggered only for non-deferred notes.`,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const artifact = await contractDataProvider.getContractArtifact(instance.currentContractClassId);
|
|
29
|
-
if (!artifact) {
|
|
30
|
-
throw new Error(
|
|
31
|
-
`Could not find artifact for contract class ${instance.currentContractClassId.toString()}. This should never happen here as the partial notes flow should be triggered only for non-deferred notes.`,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const noteFields = Object.values(artifact.notes).find(note => note.id.equals(noteTypeId))?.fields;
|
|
36
|
-
|
|
37
|
-
if (!noteFields) {
|
|
38
|
-
throw new Error(`Could not find note fields for note type ${noteTypeId.toString()}.`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// We sort note fields by index so that we can iterate over them in order.
|
|
42
|
-
noteFields.sort((a, b) => a.index - b.index);
|
|
43
|
-
|
|
44
|
-
// Now we insert the public fields into the note based on its indices defined in the ABI.
|
|
45
|
-
const modifiedNoteItems = [...privateNoteValues];
|
|
46
|
-
let indexInPublicValues = 0;
|
|
47
|
-
for (let i = 0; i < noteFields.length; i++) {
|
|
48
|
-
const noteField = noteFields[i];
|
|
49
|
-
if (noteField.nullable) {
|
|
50
|
-
if (i == noteFields.length - 1) {
|
|
51
|
-
// We are processing the last field so we simply insert the rest of the public fields at the end
|
|
52
|
-
modifiedNoteItems.push(...publicNoteValues.slice(indexInPublicValues));
|
|
53
|
-
} else {
|
|
54
|
-
const noteFieldLength = noteFields[i + 1].index - noteField.index;
|
|
55
|
-
const publicValuesToInsert = publicNoteValues.slice(indexInPublicValues, indexInPublicValues + noteFieldLength);
|
|
56
|
-
indexInPublicValues += noteFieldLength;
|
|
57
|
-
// Now we insert the public fields at the note field index
|
|
58
|
-
modifiedNoteItems.splice(noteField.index, 0, ...publicValuesToInsert);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return new Note(modifiedNoteItems);
|
|
64
|
-
}
|