@aztec/pxe 0.77.1 → 0.78.1
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/bin/index.js +1 -1
- package/dest/config/index.d.ts +1 -0
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +1 -0
- package/dest/entrypoints/client/bundle/index.d.ts +6 -0
- package/dest/entrypoints/client/bundle/index.d.ts.map +1 -0
- package/dest/entrypoints/client/bundle/index.js +5 -0
- package/dest/entrypoints/client/bundle/utils.d.ts +16 -0
- package/dest/entrypoints/client/bundle/utils.d.ts.map +1 -0
- package/dest/entrypoints/client/bundle/utils.js +30 -0
- package/dest/entrypoints/client/lazy/index.d.ts +6 -0
- package/dest/entrypoints/client/lazy/index.d.ts.map +1 -0
- package/dest/entrypoints/client/lazy/index.js +5 -0
- package/dest/entrypoints/client/lazy/utils.d.ts +15 -0
- package/dest/entrypoints/client/lazy/utils.d.ts.map +1 -0
- package/dest/entrypoints/client/lazy/utils.js +29 -0
- package/dest/entrypoints/client/pxe_creation_options.d.ts +11 -0
- package/dest/entrypoints/client/pxe_creation_options.d.ts.map +1 -0
- package/dest/entrypoints/server/index.d.ts +7 -0
- package/dest/entrypoints/server/index.d.ts.map +1 -0
- package/dest/entrypoints/server/index.js +6 -0
- package/dest/{utils/create_pxe_service.d.ts → entrypoints/server/utils.d.ts} +4 -4
- package/dest/entrypoints/server/utils.d.ts.map +1 -0
- package/dest/{utils/create_pxe_service.js → entrypoints/server/utils.js} +5 -11
- package/dest/kernel_oracle/index.d.ts +2 -1
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.js +0 -28
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts +2 -2
- package/dest/note_decryption_utils/add_public_values_to_payload.d.ts.map +1 -1
- package/dest/note_decryption_utils/add_public_values_to_payload.js +3 -3
- package/dest/{pxe_data_provider → pxe_oracle_interface}/index.d.ts +17 -9
- package/dest/pxe_oracle_interface/index.d.ts.map +1 -0
- package/dest/{pxe_data_provider → pxe_oracle_interface}/index.js +104 -61
- package/dest/pxe_oracle_interface/tagging_utils.d.ts.map +1 -0
- package/dest/pxe_service/error_enriching.d.ts +3 -4
- package/dest/pxe_service/error_enriching.d.ts.map +1 -1
- package/dest/pxe_service/error_enriching.js +4 -4
- package/dest/pxe_service/pxe_service.d.ts +18 -14
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +118 -65
- package/dest/storage/address_data_provider/address_data_provider.d.ts +13 -0
- package/dest/storage/address_data_provider/address_data_provider.d.ts.map +1 -0
- package/dest/storage/address_data_provider/address_data_provider.js +50 -0
- package/dest/storage/address_data_provider/index.d.ts +2 -0
- package/dest/storage/address_data_provider/index.d.ts.map +1 -0
- package/dest/storage/address_data_provider/index.js +1 -0
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts +11 -0
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.d.ts.map +1 -0
- package/dest/storage/auth_witness_data_provider/auth_witness_data_provider.js +20 -0
- package/dest/storage/auth_witness_data_provider/index.d.ts +2 -0
- package/dest/storage/auth_witness_data_provider/index.d.ts.map +1 -0
- package/dest/storage/auth_witness_data_provider/index.js +1 -0
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts +16 -0
- package/dest/storage/capsule_data_provider/capsule_data_provider.d.ts.map +1 -0
- package/dest/storage/capsule_data_provider/capsule_data_provider.js +57 -0
- package/dest/storage/capsule_data_provider/index.d.ts +2 -0
- package/dest/storage/capsule_data_provider/index.d.ts.map +1 -0
- package/dest/storage/capsule_data_provider/index.js +1 -0
- package/dest/{contract_data_provider → storage/contract_data_provider}/contract_data_provider.d.ts +38 -33
- package/dest/storage/contract_data_provider/contract_data_provider.d.ts.map +1 -0
- package/dest/{contract_data_provider → storage/contract_data_provider}/contract_data_provider.js +87 -42
- package/dest/storage/contract_data_provider/index.d.ts.map +1 -0
- package/dest/storage/contract_data_provider/private_functions_tree.d.ts.map +1 -0
- package/dest/storage/data_provider.d.ts +4 -0
- package/dest/storage/data_provider.d.ts.map +1 -0
- package/dest/storage/data_provider.js +1 -0
- package/dest/storage/index.d.ts +10 -0
- package/dest/storage/index.d.ts.map +1 -0
- package/dest/storage/index.js +9 -0
- package/dest/storage/note_data_provider/index.d.ts +3 -0
- package/dest/storage/note_data_provider/index.d.ts.map +1 -0
- package/dest/storage/note_data_provider/index.js +2 -0
- package/dest/storage/note_data_provider/note_dao.d.ts.map +1 -0
- package/dest/storage/note_data_provider/note_data_provider.d.ts +20 -0
- package/dest/storage/note_data_provider/note_data_provider.d.ts.map +1 -0
- package/dest/storage/note_data_provider/note_data_provider.js +249 -0
- package/dest/storage/sync_data_provider/index.d.ts +2 -0
- package/dest/storage/sync_data_provider/index.d.ts.map +1 -0
- package/dest/storage/sync_data_provider/index.js +1 -0
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts +12 -0
- package/dest/storage/sync_data_provider/sync_data_provider.d.ts.map +1 -0
- package/dest/storage/sync_data_provider/sync_data_provider.js +29 -0
- package/dest/storage/tagging_data_provider/index.d.ts +2 -0
- package/dest/storage/tagging_data_provider/index.d.ts.map +1 -0
- package/dest/storage/tagging_data_provider/index.js +1 -0
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts +18 -0
- package/dest/storage/tagging_data_provider/tagging_data_provider.d.ts.map +1 -0
- package/dest/storage/tagging_data_provider/tagging_data_provider.js +65 -0
- package/dest/synchronizer/synchronizer.d.ts +7 -3
- package/dest/synchronizer/synchronizer.d.ts.map +1 -1
- package/dest/synchronizer/synchronizer.js +16 -11
- package/dest/test/pxe_test_suite.d.ts.map +1 -0
- package/dest/{pxe_service/test → test}/pxe_test_suite.js +2 -6
- package/package.json +19 -26
- package/src/bin/index.ts +1 -1
- package/src/config/index.ts +2 -0
- package/src/entrypoints/client/bundle/index.ts +5 -0
- package/src/entrypoints/client/bundle/utils.ts +58 -0
- package/src/entrypoints/client/lazy/index.ts +5 -0
- package/src/entrypoints/client/lazy/utils.ts +53 -0
- package/src/entrypoints/client/pxe_creation_options.ts +7 -0
- package/src/entrypoints/server/index.ts +6 -0
- package/src/{utils/create_pxe_service.ts → entrypoints/server/utils.ts} +7 -18
- package/src/kernel_oracle/index.ts +1 -1
- package/src/kernel_prover/kernel_prover.ts +0 -51
- package/src/note_decryption_utils/add_public_values_to_payload.ts +4 -4
- package/src/{pxe_data_provider → pxe_oracle_interface}/index.ts +128 -96
- package/src/pxe_service/error_enriching.ts +8 -6
- package/src/pxe_service/pxe_service.ts +155 -89
- package/src/storage/address_data_provider/address_data_provider.ts +71 -0
- package/src/storage/address_data_provider/index.ts +1 -0
- package/src/storage/auth_witness_data_provider/auth_witness_data_provider.ts +34 -0
- package/src/storage/auth_witness_data_provider/index.ts +1 -0
- package/src/storage/capsule_data_provider/capsule_data_provider.ts +80 -0
- package/src/storage/capsule_data_provider/index.ts +1 -0
- package/src/{contract_data_provider → storage/contract_data_provider}/contract_data_provider.ts +128 -48
- package/src/storage/data_provider.ts +3 -0
- package/src/storage/index.ts +10 -0
- package/src/storage/note_data_provider/index.ts +2 -0
- package/src/storage/note_data_provider/note_data_provider.ts +345 -0
- package/src/storage/sync_data_provider/index.ts +1 -0
- package/src/storage/sync_data_provider/sync_data_provider.ts +40 -0
- package/src/storage/tagging_data_provider/index.ts +1 -0
- package/src/storage/tagging_data_provider/tagging_data_provider.ts +92 -0
- package/src/synchronizer/synchronizer.ts +15 -10
- package/src/{pxe_service/test → test}/pxe_test_suite.ts +2 -9
- package/dest/contract_data_provider/contract_data_provider.d.ts.map +0 -1
- package/dest/contract_data_provider/index.d.ts.map +0 -1
- package/dest/contract_data_provider/private_functions_tree.d.ts.map +0 -1
- package/dest/database/index.d.ts +0 -3
- package/dest/database/index.d.ts.map +0 -1
- package/dest/database/index.js +0 -2
- package/dest/database/interfaces/contract_artifact_db.d.ts +0 -20
- package/dest/database/interfaces/contract_artifact_db.d.ts.map +0 -1
- package/dest/database/interfaces/contract_artifact_db.js +0 -3
- package/dest/database/interfaces/contract_instance_db.d.ts +0 -20
- package/dest/database/interfaces/contract_instance_db.d.ts.map +0 -1
- package/dest/database/interfaces/contract_instance_db.js +0 -3
- package/dest/database/interfaces/index.d.ts +0 -4
- package/dest/database/interfaces/index.d.ts.map +0 -1
- package/dest/database/interfaces/pxe_database.d.ts +0 -211
- package/dest/database/interfaces/pxe_database.d.ts.map +0 -1
- package/dest/database/interfaces/pxe_database.js +0 -4
- package/dest/database/interfaces/pxe_database_test_suite.d.ts +0 -7
- package/dest/database/interfaces/pxe_database_test_suite.d.ts.map +0 -1
- package/dest/database/interfaces/pxe_database_test_suite.js +0 -557
- package/dest/database/kv_pxe_database.d.ts +0 -58
- package/dest/database/kv_pxe_database.d.ts.map +0 -1
- package/dest/database/kv_pxe_database.js +0 -480
- package/dest/database/note_dao.d.ts.map +0 -1
- package/dest/index.d.ts +0 -9
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -8
- package/dest/pxe_data_provider/index.d.ts.map +0 -1
- package/dest/pxe_data_provider/tagging_utils.d.ts.map +0 -1
- package/dest/pxe_service/test/pxe_test_suite.d.ts.map +0 -1
- package/dest/utils/create_pxe_service.d.ts.map +0 -1
- package/src/database/index.ts +0 -2
- package/src/database/interfaces/contract_artifact_db.ts +0 -20
- package/src/database/interfaces/contract_instance_db.ts +0 -21
- package/src/database/interfaces/index.ts +0 -3
- package/src/database/interfaces/pxe_database.ts +0 -240
- package/src/database/interfaces/pxe_database_test_suite.ts +0 -558
- package/src/database/kv_pxe_database.ts +0 -670
- package/src/index.ts +0 -9
- /package/dest/{database/interfaces/index.js → entrypoints/client/pxe_creation_options.js} +0 -0
- /package/dest/{pxe_data_provider → pxe_oracle_interface}/tagging_utils.d.ts +0 -0
- /package/dest/{pxe_data_provider → pxe_oracle_interface}/tagging_utils.js +0 -0
- /package/dest/{contract_data_provider → storage/contract_data_provider}/index.d.ts +0 -0
- /package/dest/{contract_data_provider → storage/contract_data_provider}/index.js +0 -0
- /package/dest/{contract_data_provider → storage/contract_data_provider}/private_functions_tree.d.ts +0 -0
- /package/dest/{contract_data_provider → storage/contract_data_provider}/private_functions_tree.js +0 -0
- /package/dest/{database → storage/note_data_provider}/note_dao.d.ts +0 -0
- /package/dest/{database → storage/note_data_provider}/note_dao.js +0 -0
- /package/dest/{pxe_service/test → test}/pxe_test_suite.d.ts +0 -0
- /package/src/{pxe_data_provider → pxe_oracle_interface}/tagging_utils.ts +0 -0
- /package/src/{contract_data_provider → storage/contract_data_provider}/index.ts +0 -0
- /package/src/{contract_data_provider → storage/contract_data_provider}/private_functions_tree.ts +0 -0
- /package/src/{database → storage/note_data_provider}/note_dao.ts +0 -0
package/dest/{contract_data_provider → storage/contract_data_provider}/contract_data_provider.d.ts
RENAMED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import type { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import type { MembershipWitness } from '@aztec/foundation/trees';
|
|
5
|
-
import
|
|
6
|
-
import type
|
|
7
|
-
import
|
|
8
|
-
import type
|
|
9
|
-
import type {
|
|
5
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
6
|
+
import { type ContractArtifact, type FunctionArtifact, type FunctionDebugMetadata, FunctionSelector } from '@aztec/stdlib/abi';
|
|
7
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
+
import { type ContractClass, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
9
|
+
import type { DataProvider } from '../data_provider.js';
|
|
10
10
|
/**
|
|
11
11
|
* ContractDataProvider serves as a data manager and retriever for Aztec.nr contracts.
|
|
12
12
|
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
|
|
@@ -14,16 +14,42 @@ import type { ContractInstanceDatabase } from '../database/interfaces/contract_i
|
|
|
14
14
|
* to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
|
|
15
15
|
* the required information and facilitate cryptographic proof generation.
|
|
16
16
|
*/
|
|
17
|
-
export declare class ContractDataProvider {
|
|
18
|
-
private
|
|
17
|
+
export declare class ContractDataProvider implements DataProvider {
|
|
18
|
+
#private;
|
|
19
19
|
/** Map from contract class id to private function tree. */
|
|
20
|
-
private
|
|
21
|
-
constructor(
|
|
20
|
+
private contractClassesCache;
|
|
21
|
+
constructor(store: AztecAsyncKVStore);
|
|
22
|
+
addContractArtifact(id: Fr, contract: ContractArtifact): Promise<void>;
|
|
23
|
+
addContractInstance(contract: ContractInstanceWithAddress): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
26
|
+
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
27
|
+
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
28
|
+
* and added to the cache before returning.
|
|
29
|
+
*
|
|
30
|
+
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
31
|
+
* @returns A ContractTree instance associated with the specified contract address.
|
|
32
|
+
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
33
|
+
*/
|
|
34
|
+
private getTreeForClassId;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieve or create a ContractTree instance based on the provided AztecAddress.
|
|
37
|
+
* If an existing tree with the same contract address is found in the cache, it will be returned.
|
|
38
|
+
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
39
|
+
* and added to the cache before returning.
|
|
40
|
+
*
|
|
41
|
+
* @param contractAddress - The AztecAddress of the contract for which the ContractTree is required.
|
|
42
|
+
* @returns A ContractTree instance associated with the specified contract address.
|
|
43
|
+
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
44
|
+
*/
|
|
45
|
+
private getTreeForAddress;
|
|
46
|
+
getContractsAddresses(): Promise<AztecAddress[]>;
|
|
22
47
|
/** Returns a contract instance for a given address. Throws if not found. */
|
|
23
|
-
getContractInstance(contractAddress: AztecAddress): Promise<
|
|
48
|
+
getContractInstance(contractAddress: AztecAddress): Promise<ContractInstanceWithAddress>;
|
|
49
|
+
getContractArtifact(contractClassId: Fr): Promise<ContractArtifact>;
|
|
24
50
|
/** Returns a contract class for a given class id. Throws if not found. */
|
|
25
51
|
getContractClass(contractClassId: Fr): Promise<ContractClass>;
|
|
26
|
-
|
|
52
|
+
getContract(address: AztecAddress): Promise<(ContractInstanceWithAddress & ContractArtifact) | undefined>;
|
|
27
53
|
/**
|
|
28
54
|
* Retrieves the artifact of a specified function within a given contract.
|
|
29
55
|
* The function is identified by its selector, which is a unique code generated from the function's signature.
|
|
@@ -78,27 +104,6 @@ export declare class ContractDataProvider {
|
|
|
78
104
|
getFunctionMembershipWitness(contractClassId: Fr, selector: FunctionSelector): Promise<MembershipWitness<5>>;
|
|
79
105
|
getDebugContractName(contractAddress: AztecAddress): Promise<string>;
|
|
80
106
|
getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string>;
|
|
81
|
-
|
|
82
|
-
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
83
|
-
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
84
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
85
|
-
* and added to the cache before returning.
|
|
86
|
-
*
|
|
87
|
-
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
88
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
89
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
90
|
-
*/
|
|
91
|
-
private getTreeForClassId;
|
|
92
|
-
/**
|
|
93
|
-
* Retrieve or create a ContractTree instance based on the provided AztecAddress.
|
|
94
|
-
* If an existing tree with the same contract address is found in the cache, it will be returned.
|
|
95
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
96
|
-
* and added to the cache before returning.
|
|
97
|
-
*
|
|
98
|
-
* @param contractAddress - The AztecAddress of the contract for which the ContractTree is required.
|
|
99
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
100
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
101
|
-
*/
|
|
102
|
-
private getTreeForAddress;
|
|
107
|
+
getSize(): Promise<number>;
|
|
103
108
|
}
|
|
104
109
|
//# sourceMappingURL=contract_data_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract_data_provider.d.ts","sourceRoot":"","sources":["../../../src/storage/contract_data_provider/contract_data_provider.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AAExE,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,gBAAgB,EAKjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,2BAA2B,EAEjC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;;;;;GAMG;AACH,qBAAa,oBAAqB,YAAW,YAAY;;IACvD,2DAA2D;IAC3D,OAAO,CAAC,oBAAoB,CAAgD;gBAKhE,KAAK,EAAE,iBAAiB;IAOvB,mBAAmB,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB7E,mBAAmB,CAAC,QAAQ,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB/E;;;;;;;;;OASG;YACW,iBAAiB;IAY/B;;;;;;;;;OASG;YACW,iBAAiB;IAOzB,qBAAqB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAKtD,4EAA4E;IAC/D,mBAAmB,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAQxF,mBAAmB,CAAC,eAAe,EAAE,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAKhF,0EAA0E;IAC7D,gBAAgB,CAAC,eAAe,EAAE,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAK7D,WAAW,CACtB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,CAAC,2BAA2B,GAAG,gBAAgB,CAAC,GAAG,SAAS,CAAC;IASxE;;;;;;;;OAQG;IACU,mBAAmB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;IAK1F;;;;;;;;OAQG;IACU,yBAAyB,CACpC,eAAe,EAAE,YAAY,EAC7B,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAKxC;;;;;;;;;OASG;IACU,wBAAwB,CACnC,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAM7C;;;;;;;;;OASG;IACU,WAAW,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;IAKlF;;;;;;;;OAQG;IACU,4BAA4B,CACvC,eAAe,EAAE,EAAE,EACnB,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAKnB,oBAAoB,CAAC,eAAe,EAAE,YAAY;IAKlD,oBAAoB,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;IAO9E,OAAO;CAKrB"}
|
package/dest/{contract_data_provider → storage/contract_data_provider}/contract_data_provider.js
RENAMED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
1
2
|
import { ContractClassNotFoundError, ContractNotFoundError } from '@aztec/simulator/client';
|
|
2
|
-
import { getFunctionDebugMetadata } from '@aztec/stdlib/abi';
|
|
3
|
+
import { FunctionSelector, FunctionType, contractArtifactFromBuffer, contractArtifactToBuffer, getFunctionDebugMetadata } from '@aztec/stdlib/abi';
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import { SerializableContractInstance } from '@aztec/stdlib/contract';
|
|
3
6
|
import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
4
7
|
/**
|
|
5
8
|
* ContractDataProvider serves as a data manager and retriever for Aztec.nr contracts.
|
|
@@ -8,26 +11,98 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
8
11
|
* to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
|
|
9
12
|
* the required information and facilitate cryptographic proof generation.
|
|
10
13
|
*/ export class ContractDataProvider {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this
|
|
14
|
+
/** Map from contract class id to private function tree. */ contractClassesCache = new Map();
|
|
15
|
+
#contractArtifacts;
|
|
16
|
+
#contractInstances;
|
|
17
|
+
constructor(store){
|
|
18
|
+
this.#contractArtifacts = store.openMap('contract_artifacts');
|
|
19
|
+
this.#contractInstances = store.openMap('contracts_instances');
|
|
20
|
+
}
|
|
21
|
+
// Setters
|
|
22
|
+
async addContractArtifact(id, contract) {
|
|
23
|
+
const privateFunctions = contract.functions.filter((functionArtifact)=>functionArtifact.functionType === FunctionType.PRIVATE);
|
|
24
|
+
const privateSelectors = await Promise.all(privateFunctions.map(async (privateFunctionArtifact)=>(await FunctionSelector.fromNameAndParameters(privateFunctionArtifact.name, privateFunctionArtifact.parameters)).toString()));
|
|
25
|
+
if (privateSelectors.length !== new Set(privateSelectors).size) {
|
|
26
|
+
throw new Error('Repeated function selectors of private functions');
|
|
27
|
+
}
|
|
28
|
+
await this.#contractArtifacts.set(id.toString(), contractArtifactToBuffer(contract));
|
|
29
|
+
}
|
|
30
|
+
async addContractInstance(contract) {
|
|
31
|
+
await this.#contractInstances.set(contract.address.toString(), new SerializableContractInstance(contract).toBuffer());
|
|
32
|
+
}
|
|
33
|
+
// Private getters
|
|
34
|
+
async #getContractInstance(address) {
|
|
35
|
+
const contract = await this.#contractInstances.getAsync(address.toString());
|
|
36
|
+
return contract && SerializableContractInstance.fromBuffer(contract).withAddress(address);
|
|
37
|
+
}
|
|
38
|
+
async #getContractArtifact(id) {
|
|
39
|
+
const contract = await this.#contractArtifacts.getAsync(id.toString());
|
|
40
|
+
// TODO(@spalladino): AztecAsyncMap lies and returns Uint8Arrays instead of Buffers, hence the extra Buffer.from.
|
|
41
|
+
return contract && contractArtifactFromBuffer(Buffer.from(contract));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Retrieve or create a ContractTree instance based on the provided class id.
|
|
45
|
+
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
46
|
+
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
47
|
+
* and added to the cache before returning.
|
|
48
|
+
*
|
|
49
|
+
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
50
|
+
* @returns A ContractTree instance associated with the specified contract address.
|
|
51
|
+
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
52
|
+
*/ async getTreeForClassId(classId) {
|
|
53
|
+
if (!this.contractClassesCache.has(classId.toString())) {
|
|
54
|
+
const artifact = await this.#getContractArtifact(classId);
|
|
55
|
+
if (!artifact) {
|
|
56
|
+
throw new ContractClassNotFoundError(classId.toString());
|
|
57
|
+
}
|
|
58
|
+
const tree = await PrivateFunctionsTree.create(artifact);
|
|
59
|
+
this.contractClassesCache.set(classId.toString(), tree);
|
|
60
|
+
}
|
|
61
|
+
return this.contractClassesCache.get(classId.toString());
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieve or create a ContractTree instance based on the provided AztecAddress.
|
|
65
|
+
* If an existing tree with the same contract address is found in the cache, it will be returned.
|
|
66
|
+
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
67
|
+
* and added to the cache before returning.
|
|
68
|
+
*
|
|
69
|
+
* @param contractAddress - The AztecAddress of the contract for which the ContractTree is required.
|
|
70
|
+
* @returns A ContractTree instance associated with the specified contract address.
|
|
71
|
+
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
72
|
+
*/ async getTreeForAddress(contractAddress) {
|
|
73
|
+
const instance = await this.getContractInstance(contractAddress);
|
|
74
|
+
return this.getTreeForClassId(instance.currentContractClassId);
|
|
75
|
+
}
|
|
76
|
+
// Public getters
|
|
77
|
+
async getContractsAddresses() {
|
|
78
|
+
const keys = await toArray(this.#contractInstances.keysAsync());
|
|
79
|
+
return keys.map(AztecAddress.fromString);
|
|
16
80
|
}
|
|
17
81
|
/** Returns a contract instance for a given address. Throws if not found. */ async getContractInstance(contractAddress) {
|
|
18
|
-
const instance = await this
|
|
82
|
+
const instance = await this.#getContractInstance(contractAddress);
|
|
19
83
|
if (!instance) {
|
|
20
84
|
throw new ContractNotFoundError(contractAddress.toString());
|
|
21
85
|
}
|
|
22
86
|
return instance;
|
|
23
87
|
}
|
|
88
|
+
async getContractArtifact(contractClassId) {
|
|
89
|
+
const tree = await this.getTreeForClassId(contractClassId);
|
|
90
|
+
return tree.getArtifact();
|
|
91
|
+
}
|
|
24
92
|
/** Returns a contract class for a given class id. Throws if not found. */ async getContractClass(contractClassId) {
|
|
25
93
|
const tree = await this.getTreeForClassId(contractClassId);
|
|
26
94
|
return tree.getContractClass();
|
|
27
95
|
}
|
|
28
|
-
async
|
|
29
|
-
const
|
|
30
|
-
|
|
96
|
+
async getContract(address) {
|
|
97
|
+
const instance = await this.getContractInstance(address);
|
|
98
|
+
const artifact = instance && await this.getContractArtifact(instance?.currentContractClassId);
|
|
99
|
+
if (!instance || !artifact) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
...instance,
|
|
104
|
+
...artifact
|
|
105
|
+
};
|
|
31
106
|
}
|
|
32
107
|
/**
|
|
33
108
|
* Retrieves the artifact of a specified function within a given contract.
|
|
@@ -102,37 +177,7 @@ import { PrivateFunctionsTree } from './private_functions_tree.js';
|
|
|
102
177
|
const { name: functionName } = await tree.getFunctionArtifact(selector);
|
|
103
178
|
return `${contractName}:${functionName}`;
|
|
104
179
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* If an existing tree with the same class id is found in the cache, it will be returned.
|
|
108
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
109
|
-
* and added to the cache before returning.
|
|
110
|
-
*
|
|
111
|
-
* @param classId - The class id of the contract for which the ContractTree is required.
|
|
112
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
113
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
114
|
-
*/ async getTreeForClassId(classId) {
|
|
115
|
-
if (!this.contractClasses.has(classId.toString())) {
|
|
116
|
-
const artifact = await this.db.getContractArtifact(classId);
|
|
117
|
-
if (!artifact) {
|
|
118
|
-
throw new ContractClassNotFoundError(classId.toString());
|
|
119
|
-
}
|
|
120
|
-
const tree = await PrivateFunctionsTree.create(artifact);
|
|
121
|
-
this.contractClasses.set(classId.toString(), tree);
|
|
122
|
-
}
|
|
123
|
-
return this.contractClasses.get(classId.toString());
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Retrieve or create a ContractTree instance based on the provided AztecAddress.
|
|
127
|
-
* If an existing tree with the same contract address is found in the cache, it will be returned.
|
|
128
|
-
* Otherwise, a new ContractTree instance will be created using the contract data from the database
|
|
129
|
-
* and added to the cache before returning.
|
|
130
|
-
*
|
|
131
|
-
* @param contractAddress - The AztecAddress of the contract for which the ContractTree is required.
|
|
132
|
-
* @returns A ContractTree instance associated with the specified contract address.
|
|
133
|
-
* @throws An Error if the contract is not found in the ContractDatabase.
|
|
134
|
-
*/ async getTreeForAddress(contractAddress) {
|
|
135
|
-
const instance = await this.getContractInstance(contractAddress);
|
|
136
|
-
return this.getTreeForClassId(instance.currentContractClassId);
|
|
180
|
+
async getSize() {
|
|
181
|
+
return (await toArray(this.#contractInstances.valuesAsync())).concat(await toArray(this.#contractArtifacts.valuesAsync())).reduce((sum, value)=>sum + value.length, 0);
|
|
137
182
|
}
|
|
138
183
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/contract_data_provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private_functions_tree.d.ts","sourceRoot":"","sources":["../../../src/storage/contract_data_provider/private_functions_tree.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EACL,KAAK,mBAAmB,EAIzB,MAAM,wBAAwB,CAAC;AAEhC;;;;;GAKG;AACH,qBAAa,oBAAoB;IAGX,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAAoB,OAAO,CAAC,aAAa;IAFtF,OAAO,CAAC,IAAI,CAAC,CAAa;IAE1B,OAAO;WAEM,MAAM,CAAC,QAAQ,EAAE,gBAAgB;IAK9C;;;;;;;OAOG;IACU,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB;IAkB3D;;;;;;;OAOG;IACU,WAAW,CAAC,QAAQ,EAAE,gBAAgB;IAKnD;;;;;;OAMG;IACI,mBAAmB;IAI1B,yCAAyC;IAClC,gBAAgB;IAIvB,qCAAqC;IAC9B,WAAW;IAIlB;;OAEG;IACI,kBAAkB;IAIzB;;;;;;;;OAQG;IACU,4BAA4B,CACvC,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,iBAAiB,CAAC,OAAO,oBAAoB,CAAC,CAAC;YAiB5C,OAAO;CAOtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data_provider.d.ts","sourceRoot":"","sources":["../../src/storage/data_provider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './address_data_provider/index.js';
|
|
2
|
+
export * from './auth_witness_data_provider/index.js';
|
|
3
|
+
export * from './capsule_data_provider/index.js';
|
|
4
|
+
export * from './contract_data_provider/index.js';
|
|
5
|
+
export * from './note_data_provider/index.js';
|
|
6
|
+
export * from './sync_data_provider/index.js';
|
|
7
|
+
export * from './tagging_data_provider/index.js';
|
|
8
|
+
export * from './data_provider.js';
|
|
9
|
+
export declare const PXE_DATA_SCHEMA_VERSION = 2;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,uCAAuC,CAAC;AACtD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,oBAAoB,CAAC;AAEnC,eAAO,MAAM,uBAAuB,IAAI,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './address_data_provider/index.js';
|
|
2
|
+
export * from './auth_witness_data_provider/index.js';
|
|
3
|
+
export * from './capsule_data_provider/index.js';
|
|
4
|
+
export * from './contract_data_provider/index.js';
|
|
5
|
+
export * from './note_data_provider/index.js';
|
|
6
|
+
export * from './sync_data_provider/index.js';
|
|
7
|
+
export * from './tagging_data_provider/index.js';
|
|
8
|
+
export * from './data_provider.js';
|
|
9
|
+
export const PXE_DATA_SCHEMA_VERSION = 2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/note_data_provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"note_dao.d.ts","sourceRoot":"","sources":["../../../src/storage/note_data_provider/note_dao.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,EAAE,EAAS,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C;;;GAGG;AACH,qBAAa,OAAQ,YAAW,QAAQ;IAIpC,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC;;;SAGK;IACE,WAAW,EAAE,EAAE;IACtB,qFAAqF;IAC9E,KAAK,EAAE,EAAE;IAGhB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,MAAM;IAC5B;gBACY;IACL,WAAW,EAAE,MAAM;IAC1B,+EAA+E;IACxE,KAAK,EAAE,MAAM;IACpB,4EAA4E;IACrE,YAAY,EAAE,SAAS;IAE9B;;OAEG;IACI,UAAU,EAAE,YAAY;;IA3C/B,kFAAkF;IAC3E,IAAI,EAAE,IAAI;IACjB,8GAA8G;IACvG,eAAe,EAAE,YAAY;IACpC;;;SAGK;IACE,WAAW,EAAE,EAAE;IACtB,qFAAqF;IAC9E,KAAK,EAAE,EAAE;IAGhB;;;OAGG;IACI,QAAQ,EAAE,EAAE;IACnB;;;OAGG;IACI,eAAe,EAAE,EAAE;IAG1B;;OAEG;IACI,MAAM,EAAE,MAAM;IACrB;gBACY;IACL,aAAa,EAAE,MAAM;IAC5B;gBACY;IACL,WAAW,EAAE,MAAM;IAC1B,+EAA+E;IACxE,KAAK,EAAE,MAAM;IACpB,4EAA4E;IACrE,YAAY,EAAE,SAAS;IAE9B;;OAEG;IACI,UAAU,EAAE,YAAY;IAGjC,QAAQ,IAAI,MAAM;IAiBlB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAgC/C,QAAQ;IAIR,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM;IAK7B;;;OAGG;IACI,OAAO;WAMD,MAAM,CAAC,EAClB,IAAoB,EACpB,eAA2B,EAC3B,WAAyB,EACzB,KAAmB,EACnB,QAAsB,EACtB,eAA6B,EAC7B,MAAwB,EACxB,aAAgD,EAChD,WAAoC,EACpC,KAA8B,EAC9B,YAAwB,EACxB,UAAkC,GACnC,GAAE,OAAO,CAAC,OAAO,CAAM;CAgBzB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Fr, Point } from '@aztec/foundation/fields';
|
|
2
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { InBlock } from '@aztec/stdlib/block';
|
|
5
|
+
import { type NotesFilter } from '@aztec/stdlib/note';
|
|
6
|
+
import type { DataProvider } from '../data_provider.js';
|
|
7
|
+
import { NoteDao } from './note_dao.js';
|
|
8
|
+
export declare class NoteDataProvider implements DataProvider {
|
|
9
|
+
#private;
|
|
10
|
+
private constructor();
|
|
11
|
+
static create(store: AztecAsyncKVStore): Promise<NoteDataProvider>;
|
|
12
|
+
addScope(scope: AztecAddress): Promise<boolean>;
|
|
13
|
+
addNotes(notes: NoteDao[], scope?: AztecAddress): Promise<void>;
|
|
14
|
+
removeNotesAfter(blockNumber: number): Promise<void>;
|
|
15
|
+
unnullifyNotesAfter(blockNumber: number, synchedBlockNumber?: number): Promise<void>;
|
|
16
|
+
getNotes(filter: NotesFilter): Promise<NoteDao[]>;
|
|
17
|
+
removeNullifiedNotes(nullifiers: InBlock<Fr>[], accountAddressPoint: Point): Promise<NoteDao[]>;
|
|
18
|
+
getSize(): Promise<number>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=note_data_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"note_data_provider.d.ts","sourceRoot":"","sources":["../../../src/storage/note_data_provider/note_data_provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,qBAAa,gBAAiB,YAAW,YAAY;;IAsBnD,OAAO;WAsBa,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAWlE,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAmBtD,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,GAAE,YAAgC,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBjF,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB9C,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkD3F,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAkGvD,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,mBAAmB,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IA6DzF,OAAO;CAGd"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
2
|
+
import { toArray } from '@aztec/foundation/iterable';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { NoteStatus } from '@aztec/stdlib/note';
|
|
5
|
+
import { NoteDao } from './note_dao.js';
|
|
6
|
+
export class NoteDataProvider {
|
|
7
|
+
#store;
|
|
8
|
+
#notes;
|
|
9
|
+
#nullifiedNotes;
|
|
10
|
+
#nullifierToNoteId;
|
|
11
|
+
#nullifiersByBlockNumber;
|
|
12
|
+
#nullifiedNotesToScope;
|
|
13
|
+
#nullifiedNotesByContract;
|
|
14
|
+
#nullifiedNotesByStorageSlot;
|
|
15
|
+
#nullifiedNotesByTxHash;
|
|
16
|
+
#nullifiedNotesByAddressPoint;
|
|
17
|
+
#nullifiedNotesByNullifier;
|
|
18
|
+
#scopes;
|
|
19
|
+
#notesToScope;
|
|
20
|
+
#notesByContractAndScope;
|
|
21
|
+
#notesByStorageSlotAndScope;
|
|
22
|
+
#notesByTxHashAndScope;
|
|
23
|
+
#notesByAddressPointAndScope;
|
|
24
|
+
constructor(store){
|
|
25
|
+
this.#store = store;
|
|
26
|
+
this.#notes = store.openMap('notes');
|
|
27
|
+
this.#nullifiedNotes = store.openMap('nullified_notes');
|
|
28
|
+
this.#nullifierToNoteId = store.openMap('nullifier_to_note');
|
|
29
|
+
this.#nullifiersByBlockNumber = store.openMultiMap('nullifier_to_block_number');
|
|
30
|
+
this.#nullifiedNotesToScope = store.openMultiMap('nullified_notes_to_scope');
|
|
31
|
+
this.#nullifiedNotesByContract = store.openMultiMap('nullified_notes_by_contract');
|
|
32
|
+
this.#nullifiedNotesByStorageSlot = store.openMultiMap('nullified_notes_by_storage_slot');
|
|
33
|
+
this.#nullifiedNotesByTxHash = store.openMultiMap('nullified_notes_by_tx_hash');
|
|
34
|
+
this.#nullifiedNotesByAddressPoint = store.openMultiMap('nullified_notes_by_address_point');
|
|
35
|
+
this.#nullifiedNotesByNullifier = store.openMap('nullified_notes_by_nullifier');
|
|
36
|
+
this.#scopes = store.openMap('scopes');
|
|
37
|
+
this.#notesToScope = store.openMultiMap('notes_to_scope');
|
|
38
|
+
this.#notesByContractAndScope = new Map();
|
|
39
|
+
this.#notesByStorageSlotAndScope = new Map();
|
|
40
|
+
this.#notesByTxHashAndScope = new Map();
|
|
41
|
+
this.#notesByAddressPointAndScope = new Map();
|
|
42
|
+
}
|
|
43
|
+
static async create(store) {
|
|
44
|
+
const pxeDB = new NoteDataProvider(store);
|
|
45
|
+
for await (const scope of pxeDB.#scopes.keysAsync()){
|
|
46
|
+
pxeDB.#notesByContractAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_contract`));
|
|
47
|
+
pxeDB.#notesByStorageSlotAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_storage_slot`));
|
|
48
|
+
pxeDB.#notesByTxHashAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_tx_hash`));
|
|
49
|
+
pxeDB.#notesByAddressPointAndScope.set(scope, store.openMultiMap(`${scope}:notes_by_address_point`));
|
|
50
|
+
}
|
|
51
|
+
return pxeDB;
|
|
52
|
+
}
|
|
53
|
+
async addScope(scope) {
|
|
54
|
+
const scopeString = scope.toString();
|
|
55
|
+
if (await this.#scopes.hasAsync(scopeString)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
await this.#scopes.set(scopeString, true);
|
|
59
|
+
this.#notesByContractAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_contract`));
|
|
60
|
+
this.#notesByStorageSlotAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_storage_slot`));
|
|
61
|
+
this.#notesByTxHashAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_tx_hash`));
|
|
62
|
+
this.#notesByAddressPointAndScope.set(scopeString, this.#store.openMultiMap(`${scopeString}:notes_by_address_point`));
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
async addNotes(notes, scope = AztecAddress.ZERO) {
|
|
66
|
+
if (!await this.#scopes.hasAsync(scope.toString())) {
|
|
67
|
+
await this.addScope(scope);
|
|
68
|
+
}
|
|
69
|
+
return this.#store.transactionAsync(async ()=>{
|
|
70
|
+
for (const dao of notes){
|
|
71
|
+
// store notes by their index in the notes hash tree
|
|
72
|
+
// this provides the uniqueness we need to store individual notes
|
|
73
|
+
// and should also return notes in the order that they were created.
|
|
74
|
+
// Had we stored them by their nullifier, they would be returned in random order
|
|
75
|
+
const noteIndex = toBufferBE(dao.index, 32).toString('hex');
|
|
76
|
+
await this.#notes.set(noteIndex, dao.toBuffer());
|
|
77
|
+
await this.#notesToScope.set(noteIndex, scope.toString());
|
|
78
|
+
await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
|
|
79
|
+
await this.#notesByContractAndScope.get(scope.toString()).set(dao.contractAddress.toString(), noteIndex);
|
|
80
|
+
await this.#notesByStorageSlotAndScope.get(scope.toString()).set(dao.storageSlot.toString(), noteIndex);
|
|
81
|
+
await this.#notesByTxHashAndScope.get(scope.toString()).set(dao.txHash.toString(), noteIndex);
|
|
82
|
+
await this.#notesByAddressPointAndScope.get(scope.toString()).set(dao.addressPoint.toString(), noteIndex);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
removeNotesAfter(blockNumber) {
|
|
87
|
+
return this.#store.transactionAsync(async ()=>{
|
|
88
|
+
const notes = await toArray(this.#notes.valuesAsync());
|
|
89
|
+
for (const note of notes){
|
|
90
|
+
const noteDao = NoteDao.fromBuffer(note);
|
|
91
|
+
if (noteDao.l2BlockNumber > blockNumber) {
|
|
92
|
+
const noteIndex = toBufferBE(noteDao.index, 32).toString('hex');
|
|
93
|
+
await this.#notes.delete(noteIndex);
|
|
94
|
+
await this.#notesToScope.delete(noteIndex);
|
|
95
|
+
await this.#nullifierToNoteId.delete(noteDao.siloedNullifier.toString());
|
|
96
|
+
const scopes = await toArray(this.#scopes.keysAsync());
|
|
97
|
+
for (const scope of scopes){
|
|
98
|
+
await this.#notesByAddressPointAndScope.get(scope).deleteValue(noteDao.addressPoint.toString(), noteIndex);
|
|
99
|
+
await this.#notesByTxHashAndScope.get(scope).deleteValue(noteDao.txHash.toString(), noteIndex);
|
|
100
|
+
await this.#notesByContractAndScope.get(scope).deleteValue(noteDao.contractAddress.toString(), noteIndex);
|
|
101
|
+
await this.#notesByStorageSlotAndScope.get(scope).deleteValue(noteDao.storageSlot.toString(), noteIndex);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async unnullifyNotesAfter(blockNumber, synchedBlockNumber) {
|
|
108
|
+
const nullifiersToUndo = [];
|
|
109
|
+
const currentBlockNumber = blockNumber + 1;
|
|
110
|
+
const maxBlockNumber = synchedBlockNumber ?? currentBlockNumber;
|
|
111
|
+
for(let i = currentBlockNumber; i <= maxBlockNumber; i++){
|
|
112
|
+
nullifiersToUndo.push(...await toArray(this.#nullifiersByBlockNumber.getValuesAsync(i)));
|
|
113
|
+
}
|
|
114
|
+
const notesIndexesToReinsert = await Promise.all(nullifiersToUndo.map((nullifier)=>this.#nullifiedNotesByNullifier.getAsync(nullifier)));
|
|
115
|
+
const notNullNoteIndexes = notesIndexesToReinsert.filter((noteIndex)=>noteIndex != undefined);
|
|
116
|
+
const nullifiedNoteBuffers = await Promise.all(notNullNoteIndexes.map((noteIndex)=>this.#nullifiedNotes.getAsync(noteIndex)));
|
|
117
|
+
const noteDaos = nullifiedNoteBuffers.filter((buffer)=>buffer != undefined).map((buffer)=>NoteDao.fromBuffer(buffer));
|
|
118
|
+
await this.#store.transactionAsync(async ()=>{
|
|
119
|
+
for (const dao of noteDaos){
|
|
120
|
+
const noteIndex = toBufferBE(dao.index, 32).toString('hex');
|
|
121
|
+
await this.#notes.set(noteIndex, dao.toBuffer());
|
|
122
|
+
await this.#nullifierToNoteId.set(dao.siloedNullifier.toString(), noteIndex);
|
|
123
|
+
let scopes = await toArray(this.#nullifiedNotesToScope.getValuesAsync(noteIndex)) ?? [];
|
|
124
|
+
if (scopes.length === 0) {
|
|
125
|
+
scopes = [
|
|
126
|
+
new AztecAddress(dao.addressPoint.x).toString()
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
for (const scope of scopes){
|
|
130
|
+
await this.#notesByContractAndScope.get(scope.toString()).set(dao.contractAddress.toString(), noteIndex);
|
|
131
|
+
await this.#notesByStorageSlotAndScope.get(scope.toString()).set(dao.storageSlot.toString(), noteIndex);
|
|
132
|
+
await this.#notesByTxHashAndScope.get(scope.toString()).set(dao.txHash.toString(), noteIndex);
|
|
133
|
+
await this.#notesByAddressPointAndScope.get(scope.toString()).set(dao.addressPoint.toString(), noteIndex);
|
|
134
|
+
await this.#notesToScope.set(noteIndex, scope);
|
|
135
|
+
}
|
|
136
|
+
await this.#nullifiedNotes.delete(noteIndex);
|
|
137
|
+
await this.#nullifiedNotesToScope.delete(noteIndex);
|
|
138
|
+
await this.#nullifiersByBlockNumber.deleteValue(dao.l2BlockNumber, dao.siloedNullifier.toString());
|
|
139
|
+
await this.#nullifiedNotesByContract.deleteValue(dao.contractAddress.toString(), noteIndex);
|
|
140
|
+
await this.#nullifiedNotesByStorageSlot.deleteValue(dao.storageSlot.toString(), noteIndex);
|
|
141
|
+
await this.#nullifiedNotesByTxHash.deleteValue(dao.txHash.toString(), noteIndex);
|
|
142
|
+
await this.#nullifiedNotesByAddressPoint.deleteValue(dao.addressPoint.toString(), noteIndex);
|
|
143
|
+
await this.#nullifiedNotesByNullifier.delete(dao.siloedNullifier.toString());
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async getNotes(filter) {
|
|
148
|
+
const publicKey = filter.owner ? await filter.owner.toAddressPoint() : undefined;
|
|
149
|
+
filter.status = filter.status ?? NoteStatus.ACTIVE;
|
|
150
|
+
const candidateNoteSources = [];
|
|
151
|
+
filter.scopes ??= (await toArray(this.#scopes.keysAsync())).map((addressString)=>AztecAddress.fromString(addressString));
|
|
152
|
+
const activeNoteIdsPerScope = [];
|
|
153
|
+
for (const scope of new Set(filter.scopes)){
|
|
154
|
+
const formattedScopeString = scope.toString();
|
|
155
|
+
if (!await this.#scopes.hasAsync(formattedScopeString)) {
|
|
156
|
+
throw new Error('Trying to get incoming notes of an scope that is not in the PXE database');
|
|
157
|
+
}
|
|
158
|
+
activeNoteIdsPerScope.push(publicKey ? await toArray(this.#notesByAddressPointAndScope.get(formattedScopeString).getValuesAsync(publicKey.toString())) : filter.txHash ? await toArray(this.#notesByTxHashAndScope.get(formattedScopeString).getValuesAsync(filter.txHash.toString())) : filter.contractAddress ? await toArray(this.#notesByContractAndScope.get(formattedScopeString).getValuesAsync(filter.contractAddress.toString())) : filter.storageSlot ? await toArray(this.#notesByStorageSlotAndScope.get(formattedScopeString).getValuesAsync(filter.storageSlot.toString())) : await toArray(this.#notesByAddressPointAndScope.get(formattedScopeString).valuesAsync()));
|
|
159
|
+
}
|
|
160
|
+
candidateNoteSources.push({
|
|
161
|
+
ids: new Set(activeNoteIdsPerScope.flat()),
|
|
162
|
+
notes: this.#notes
|
|
163
|
+
});
|
|
164
|
+
if (filter.status == NoteStatus.ACTIVE_OR_NULLIFIED) {
|
|
165
|
+
candidateNoteSources.push({
|
|
166
|
+
ids: publicKey ? await toArray(this.#nullifiedNotesByAddressPoint.getValuesAsync(publicKey.toString())) : filter.txHash ? await toArray(this.#nullifiedNotesByTxHash.getValuesAsync(filter.txHash.toString())) : filter.contractAddress ? await toArray(this.#nullifiedNotesByContract.getValuesAsync(filter.contractAddress.toString())) : filter.storageSlot ? await toArray(this.#nullifiedNotesByStorageSlot.getValuesAsync(filter.storageSlot.toString())) : await toArray(this.#nullifiedNotes.keysAsync()),
|
|
167
|
+
notes: this.#nullifiedNotes
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const result = [];
|
|
171
|
+
for (const { ids, notes } of candidateNoteSources){
|
|
172
|
+
for (const id of ids){
|
|
173
|
+
const serializedNote = await notes.getAsync(id);
|
|
174
|
+
if (!serializedNote) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const note = NoteDao.fromBuffer(serializedNote);
|
|
178
|
+
if (filter.contractAddress && !note.contractAddress.equals(filter.contractAddress)) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (filter.txHash && !note.txHash.equals(filter.txHash)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (publicKey && !note.addressPoint.equals(publicKey)) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (filter.siloedNullifier && !note.siloedNullifier.equals(filter.siloedNullifier)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
result.push(note);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
removeNullifiedNotes(nullifiers, accountAddressPoint) {
|
|
199
|
+
if (nullifiers.length === 0) {
|
|
200
|
+
return Promise.resolve([]);
|
|
201
|
+
}
|
|
202
|
+
return this.#store.transactionAsync(async ()=>{
|
|
203
|
+
const nullifiedNotes = [];
|
|
204
|
+
for (const blockScopedNullifier of nullifiers){
|
|
205
|
+
const { data: nullifier, l2BlockNumber: blockNumber } = blockScopedNullifier;
|
|
206
|
+
const noteIndex = await this.#nullifierToNoteId.getAsync(nullifier.toString());
|
|
207
|
+
if (!noteIndex) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const noteBuffer = noteIndex ? await this.#notes.getAsync(noteIndex) : undefined;
|
|
211
|
+
if (!noteBuffer) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const noteScopes = await toArray(this.#notesToScope.getValuesAsync(noteIndex)) ?? [];
|
|
215
|
+
const note = NoteDao.fromBuffer(noteBuffer);
|
|
216
|
+
if (!note.addressPoint.equals(accountAddressPoint)) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
nullifiedNotes.push(note);
|
|
220
|
+
await this.#notes.delete(noteIndex);
|
|
221
|
+
await this.#notesToScope.delete(noteIndex);
|
|
222
|
+
const scopes = await toArray(this.#scopes.keysAsync());
|
|
223
|
+
for (const scope of scopes){
|
|
224
|
+
await this.#notesByAddressPointAndScope.get(scope).deleteValue(accountAddressPoint.toString(), noteIndex);
|
|
225
|
+
await this.#notesByTxHashAndScope.get(scope).deleteValue(note.txHash.toString(), noteIndex);
|
|
226
|
+
await this.#notesByContractAndScope.get(scope).deleteValue(note.contractAddress.toString(), noteIndex);
|
|
227
|
+
await this.#notesByStorageSlotAndScope.get(scope).deleteValue(note.storageSlot.toString(), noteIndex);
|
|
228
|
+
}
|
|
229
|
+
if (noteScopes !== undefined) {
|
|
230
|
+
for (const scope of noteScopes){
|
|
231
|
+
await this.#nullifiedNotesToScope.set(noteIndex, scope);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
await this.#nullifiedNotes.set(noteIndex, note.toBuffer());
|
|
235
|
+
await this.#nullifiersByBlockNumber.set(blockNumber, nullifier.toString());
|
|
236
|
+
await this.#nullifiedNotesByContract.set(note.contractAddress.toString(), noteIndex);
|
|
237
|
+
await this.#nullifiedNotesByStorageSlot.set(note.storageSlot.toString(), noteIndex);
|
|
238
|
+
await this.#nullifiedNotesByTxHash.set(note.txHash.toString(), noteIndex);
|
|
239
|
+
await this.#nullifiedNotesByAddressPoint.set(note.addressPoint.toString(), noteIndex);
|
|
240
|
+
await this.#nullifiedNotesByNullifier.set(nullifier.toString(), noteIndex);
|
|
241
|
+
await this.#nullifierToNoteId.delete(nullifier.toString());
|
|
242
|
+
}
|
|
243
|
+
return nullifiedNotes;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
async getSize() {
|
|
247
|
+
return (await this.getNotes({})).reduce((sum, note)=>sum + note.getSize(), 0);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/sync_data_provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SyncDataProvider } from './sync_data_provider.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
|
+
import { BlockHeader } from '@aztec/stdlib/tx';
|
|
3
|
+
import type { DataProvider } from '../data_provider.js';
|
|
4
|
+
export declare class SyncDataProvider implements DataProvider {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(store: AztecAsyncKVStore);
|
|
7
|
+
setHeader(header: BlockHeader): Promise<void>;
|
|
8
|
+
getBlockNumber(): Promise<number | undefined>;
|
|
9
|
+
getBlockHeader(): Promise<BlockHeader>;
|
|
10
|
+
getSize(): Promise<number>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=sync_data_provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync_data_provider.d.ts","sourceRoot":"","sources":["../../../src/storage/sync_data_provider/sync_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,qBAAa,gBAAiB,YAAW,YAAY;;gBAIvC,KAAK,EAAE,iBAAiB;IAK9B,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,cAAc,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAS7C,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAStC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CAGjC"}
|