@aztec/pxe 0.28.1 → 0.30.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/contract_data_oracle/index.d.ts +23 -9
- package/dest/contract_data_oracle/index.d.ts.map +1 -1
- package/dest/contract_data_oracle/index.js +55 -39
- package/dest/contract_data_oracle/private_functions_tree.d.ts +7 -15
- package/dest/contract_data_oracle/private_functions_tree.d.ts.map +1 -1
- package/dest/contract_data_oracle/private_functions_tree.js +10 -15
- package/dest/database/contracts/contract_instance_db.d.ts +2 -0
- package/dest/database/contracts/contract_instance_db.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.d.ts +3 -4
- package/dest/database/kv_pxe_database.d.ts.map +1 -1
- package/dest/database/kv_pxe_database.js +16 -17
- package/dest/database/pxe_database.d.ts +5 -2
- package/dest/database/pxe_database.d.ts.map +1 -1
- package/dest/kernel_oracle/index.d.ts +1 -0
- package/dest/kernel_oracle/index.d.ts.map +1 -1
- package/dest/kernel_prover/kernel_prover.js +4 -4
- package/dest/pxe_http/pxe_http_server.d.ts.map +1 -1
- package/dest/pxe_http/pxe_http_server.js +2 -4
- package/dest/pxe_service/create_pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/create_pxe_service.js +8 -2
- package/dest/pxe_service/pxe_service.d.ts +8 -6
- package/dest/pxe_service/pxe_service.d.ts.map +1 -1
- package/dest/pxe_service/pxe_service.js +36 -37
- package/dest/pxe_service/test/pxe_test_suite.d.ts.map +1 -1
- package/dest/pxe_service/test/pxe_test_suite.js +26 -6
- package/dest/simulator_oracle/index.d.ts +1 -1
- package/dest/simulator_oracle/index.d.ts.map +1 -1
- package/dest/simulator_oracle/index.js +11 -14
- package/package.json +12 -12
- package/src/contract_data_oracle/index.ts +63 -50
- package/src/contract_data_oracle/private_functions_tree.ts +12 -17
- package/src/database/contracts/contract_instance_db.ts +3 -0
- package/src/database/kv_pxe_database.ts +17 -17
- package/src/database/pxe_database.ts +6 -2
- package/src/kernel_prover/kernel_prover.ts +3 -3
- package/src/pxe_http/pxe_http_server.ts +0 -4
- package/src/pxe_service/create_pxe_service.ts +7 -1
- package/src/pxe_service/pxe_service.ts +42 -40
- package/src/pxe_service/test/pxe_test_suite.ts +37 -6
- package/src/simulator_oracle/index.ts +10 -15
- package/dest/contract_database/index.d.ts +0 -2
- package/dest/contract_database/index.d.ts.map +0 -1
- package/dest/contract_database/index.js +0 -2
- package/dest/contract_database/memory_contract_database.d.ts +0 -43
- package/dest/contract_database/memory_contract_database.d.ts.map +0 -1
- package/dest/contract_database/memory_contract_database.js +0 -51
- package/src/contract_database/index.ts +0 -1
- package/src/contract_database/memory_contract_database.ts +0 -58
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthWitness,
|
|
3
3
|
AztecNode,
|
|
4
|
-
ContractDao,
|
|
5
|
-
ContractData,
|
|
6
|
-
DeployedContract,
|
|
7
|
-
ExtendedContractData,
|
|
8
4
|
ExtendedNote,
|
|
9
5
|
FunctionCall,
|
|
10
6
|
GetUnencryptedLogsResponse,
|
|
@@ -35,12 +31,11 @@ import {
|
|
|
35
31
|
PartialAddress,
|
|
36
32
|
PrivateKernelTailCircuitPublicInputs,
|
|
37
33
|
PublicCallRequest,
|
|
38
|
-
computeArtifactHash,
|
|
39
34
|
computeContractClassId,
|
|
40
35
|
getContractClassFromArtifact,
|
|
41
36
|
} from '@aztec/circuits.js';
|
|
42
37
|
import { computeCommitmentNonce, siloNullifier } from '@aztec/circuits.js/hash';
|
|
43
|
-
import { DecodedReturn, encodeArguments } from '@aztec/foundation/abi';
|
|
38
|
+
import { ContractArtifact, DecodedReturn, FunctionSelector, encodeArguments } from '@aztec/foundation/abi';
|
|
44
39
|
import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
|
|
45
40
|
import { Fr } from '@aztec/foundation/fields';
|
|
46
41
|
import { SerialQueue } from '@aztec/foundation/fifo';
|
|
@@ -218,36 +213,46 @@ export class PXEService implements PXE {
|
|
|
218
213
|
return Promise.resolve(recipient);
|
|
219
214
|
}
|
|
220
215
|
|
|
221
|
-
public async
|
|
222
|
-
const
|
|
223
|
-
await
|
|
224
|
-
|
|
225
|
-
for (const contract of contractDaos) {
|
|
226
|
-
const instance = contract.instance;
|
|
227
|
-
const contractAztecAddress = instance.address;
|
|
228
|
-
const hasPortal = instance.portalContractAddress && !instance.portalContractAddress.isZero();
|
|
229
|
-
const portalInfo = hasPortal ? ` with portal ${instance.portalContractAddress.toChecksumString()}` : '';
|
|
230
|
-
this.log.info(`Added contract ${contract.name} at ${contractAztecAddress}${portalInfo}`);
|
|
231
|
-
await this.synchronizer.reprocessDeferredNotesForContract(contractAztecAddress);
|
|
232
|
-
}
|
|
216
|
+
public async registerContractClass(artifact: ContractArtifact): Promise<void> {
|
|
217
|
+
const contractClassId = computeContractClassId(getContractClassFromArtifact(artifact));
|
|
218
|
+
await this.db.addContractArtifact(contractClassId, artifact);
|
|
219
|
+
this.log.info(`Added contract class ${artifact.name} with id ${contractClassId}`);
|
|
233
220
|
}
|
|
234
221
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
public async registerContract(contract: { instance: ContractInstanceWithAddress; artifact?: ContractArtifact }) {
|
|
223
|
+
const { instance } = contract;
|
|
224
|
+
let { artifact } = contract;
|
|
225
|
+
|
|
226
|
+
if (artifact) {
|
|
227
|
+
// If the user provides an artifact, validate it against the expected class id and register it
|
|
228
|
+
const contractClassId = computeContractClassId(getContractClassFromArtifact(artifact));
|
|
229
|
+
if (!contractClassId.equals(instance.contractClassId)) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.contractClassId})`,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
240
234
|
await this.db.addContractArtifact(contractClassId, artifact);
|
|
241
|
-
|
|
235
|
+
} else {
|
|
236
|
+
// Otherwise, make sure there is an artifact already registered for that class id
|
|
237
|
+
artifact = await this.db.getContractArtifact(instance.contractClassId);
|
|
238
|
+
if (!artifact) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`Missing contract artifact for class id ${instance.contractClassId} for contract ${instance.address}`,
|
|
241
|
+
);
|
|
242
|
+
}
|
|
242
243
|
}
|
|
244
|
+
|
|
245
|
+
this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()}`);
|
|
246
|
+
await this.db.addContractInstance(instance);
|
|
247
|
+
await this.synchronizer.reprocessDeferredNotesForContract(instance.address);
|
|
243
248
|
}
|
|
244
249
|
|
|
245
|
-
public
|
|
246
|
-
return
|
|
250
|
+
public getContracts(): Promise<AztecAddress[]> {
|
|
251
|
+
return this.db.getContractsAddresses();
|
|
247
252
|
}
|
|
248
253
|
|
|
249
254
|
public async getPublicStorageAt(contract: AztecAddress, slot: Fr) {
|
|
250
|
-
if ((await this.
|
|
255
|
+
if (!(await this.getContractInstance(contract))) {
|
|
251
256
|
throw new Error(`Contract ${contract.toString()} is not deployed`);
|
|
252
257
|
}
|
|
253
258
|
return await this.node.getPublicStorageAt(contract, slot);
|
|
@@ -382,9 +387,6 @@ export class PXEService implements PXE {
|
|
|
382
387
|
if (!txRequest.functionData.isPrivate) {
|
|
383
388
|
throw new Error(`Public entrypoints are not allowed`);
|
|
384
389
|
}
|
|
385
|
-
if (txRequest.functionData.isInternal === undefined) {
|
|
386
|
-
throw new Error(`Unspecified internal are not allowed`);
|
|
387
|
-
}
|
|
388
390
|
|
|
389
391
|
// all simulations must be serialized w.r.t. the synchronizer
|
|
390
392
|
return await this.jobQueue.put(async () => {
|
|
@@ -443,14 +445,6 @@ export class PXEService implements PXE {
|
|
|
443
445
|
return await this.node.getBlockNumber();
|
|
444
446
|
}
|
|
445
447
|
|
|
446
|
-
public async getExtendedContractData(contractAddress: AztecAddress): Promise<ExtendedContractData | undefined> {
|
|
447
|
-
return await this.node.getExtendedContractData(contractAddress);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
public async getContractData(contractAddress: AztecAddress): Promise<ContractData | undefined> {
|
|
451
|
-
return await this.node.getContractData(contractAddress);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
448
|
/**
|
|
455
449
|
* Gets unencrypted logs based on the provided filter.
|
|
456
450
|
* @param filter - The filter to apply to the logs.
|
|
@@ -657,9 +651,13 @@ export class PXEService implements PXE {
|
|
|
657
651
|
if (contract) {
|
|
658
652
|
err.enrichWithContractName(parsedContractAddress, contract.name);
|
|
659
653
|
selectors.forEach(selector => {
|
|
660
|
-
const functionArtifact = contract.functions.find(f =>
|
|
654
|
+
const functionArtifact = contract.functions.find(f => FunctionSelector.fromString(selector).equals(f));
|
|
661
655
|
if (functionArtifact) {
|
|
662
|
-
err.enrichWithFunctionName(
|
|
656
|
+
err.enrichWithFunctionName(
|
|
657
|
+
parsedContractAddress,
|
|
658
|
+
FunctionSelector.fromNameAndParameters(functionArtifact),
|
|
659
|
+
functionArtifact.name,
|
|
660
|
+
);
|
|
663
661
|
}
|
|
664
662
|
});
|
|
665
663
|
}
|
|
@@ -749,4 +747,8 @@ export class PXEService implements PXE {
|
|
|
749
747
|
public async isContractClassPubliclyRegistered(id: Fr): Promise<boolean> {
|
|
750
748
|
return !!(await this.node.getContractClass(id));
|
|
751
749
|
}
|
|
750
|
+
|
|
751
|
+
public async isContractPubliclyDeployed(address: AztecAddress): Promise<boolean> {
|
|
752
|
+
return !!(await this.node.getContract(address));
|
|
753
|
+
}
|
|
752
754
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
PXE,
|
|
3
|
+
TxExecutionRequest,
|
|
4
|
+
randomContractArtifact,
|
|
5
|
+
randomContractInstanceWithAddress,
|
|
6
|
+
randomDeployedContract,
|
|
7
|
+
} from '@aztec/circuit-types';
|
|
2
8
|
import {
|
|
3
9
|
AztecAddress,
|
|
4
10
|
CompleteAddress,
|
|
@@ -7,6 +13,7 @@ import {
|
|
|
7
13
|
INITIAL_L2_BLOCK_NUM,
|
|
8
14
|
Point,
|
|
9
15
|
TxContext,
|
|
16
|
+
getContractClassFromArtifact,
|
|
10
17
|
} from '@aztec/circuits.js';
|
|
11
18
|
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
|
|
12
19
|
import { ConstantKeyPair } from '@aztec/key-store';
|
|
@@ -82,16 +89,40 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
|
|
|
82
89
|
});
|
|
83
90
|
|
|
84
91
|
it('successfully adds a contract', async () => {
|
|
85
|
-
const contracts
|
|
86
|
-
|
|
92
|
+
const contracts = [randomDeployedContract(), randomDeployedContract()];
|
|
93
|
+
for (const contract of contracts) {
|
|
94
|
+
await pxe.registerContract(contract);
|
|
95
|
+
}
|
|
87
96
|
|
|
88
97
|
const expectedContractAddresses = contracts.map(contract => contract.instance.address);
|
|
89
98
|
const contractAddresses = await pxe.getContracts();
|
|
90
|
-
|
|
91
|
-
// check if all the contracts were returned
|
|
92
99
|
expect(contractAddresses).toEqual(expect.arrayContaining(expectedContractAddresses));
|
|
93
100
|
});
|
|
94
101
|
|
|
102
|
+
it('registers a class and adds a contract for it', async () => {
|
|
103
|
+
const artifact = randomContractArtifact();
|
|
104
|
+
const contractClass = getContractClassFromArtifact(artifact);
|
|
105
|
+
const contractClassId = contractClass.id;
|
|
106
|
+
const instance = randomContractInstanceWithAddress({ contractClassId });
|
|
107
|
+
|
|
108
|
+
await pxe.registerContractClass(artifact);
|
|
109
|
+
expect(await pxe.getContractClass(contractClassId)).toEqual(contractClass);
|
|
110
|
+
|
|
111
|
+
await pxe.registerContract({ instance });
|
|
112
|
+
expect(await pxe.getContractInstance(instance.address)).toEqual(instance);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('refuses to register a contract with a class that has not been registered', async () => {
|
|
116
|
+
const instance = randomContractInstanceWithAddress();
|
|
117
|
+
await expect(pxe.registerContract({ instance })).rejects.toThrow(/Missing contract artifact/i);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('refuses to register a contract with an artifact with mismatching class id', async () => {
|
|
121
|
+
const artifact = randomContractArtifact();
|
|
122
|
+
const instance = randomContractInstanceWithAddress();
|
|
123
|
+
await expect(pxe.registerContract({ instance, artifact })).rejects.toThrow(/Artifact does not match/i);
|
|
124
|
+
});
|
|
125
|
+
|
|
95
126
|
it('throws when simulating a tx targeting public entrypoint', async () => {
|
|
96
127
|
const functionData = FunctionData.empty();
|
|
97
128
|
functionData.isPrivate = false;
|
|
@@ -119,7 +150,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise<PXE>) =>
|
|
|
119
150
|
);
|
|
120
151
|
});
|
|
121
152
|
|
|
122
|
-
// Note: Not testing `
|
|
153
|
+
// Note: Not testing `getContractData` and `getUnencryptedLogs` here as these
|
|
123
154
|
// functions only call AztecNode and these methods are frequently used by the e2e tests.
|
|
124
155
|
|
|
125
156
|
it('successfully gets a block number', async () => {
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
Header,
|
|
17
17
|
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
18
18
|
} from '@aztec/circuits.js';
|
|
19
|
-
import { FunctionArtifactWithDebugMetadata } from '@aztec/foundation/abi';
|
|
19
|
+
import { FunctionArtifactWithDebugMetadata, getFunctionArtifactWithDebugMetadata } from '@aztec/foundation/abi';
|
|
20
20
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
21
21
|
import { DBOracle, KeyPair, MessageLoadOracleInputs } from '@aztec/simulator';
|
|
22
22
|
import { ContractInstance } from '@aztec/types/contracts';
|
|
@@ -111,16 +111,9 @@ export class SimulatorOracle implements DBOracle {
|
|
|
111
111
|
contractAddress: AztecAddress,
|
|
112
112
|
functionName: string,
|
|
113
113
|
): Promise<FunctionArtifactWithDebugMetadata | undefined> {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const debug = await this.contractDataOracle.getFunctionDebugMetadata(contractAddress, artifact.selector);
|
|
120
|
-
return {
|
|
121
|
-
...artifact,
|
|
122
|
-
debug,
|
|
123
|
-
};
|
|
114
|
+
const instance = await this.contractDataOracle.getContractInstance(contractAddress);
|
|
115
|
+
const artifact = await this.contractDataOracle.getContractArtifact(instance.contractClassId);
|
|
116
|
+
return artifact && getFunctionArtifactWithDebugMetadata(artifact, functionName);
|
|
124
117
|
}
|
|
125
118
|
|
|
126
119
|
async getPortalContractAddress(contractAddress: AztecAddress): Promise<EthAddress> {
|
|
@@ -129,16 +122,18 @@ export class SimulatorOracle implements DBOracle {
|
|
|
129
122
|
|
|
130
123
|
/**
|
|
131
124
|
* Retrieves the L1ToL2Message associated with a specific entry key
|
|
132
|
-
* Throws an error if the entry key is not found
|
|
133
125
|
*
|
|
126
|
+
* @throws If the entry key is not found
|
|
134
127
|
* @param entryKey - The key of the message to be retrieved
|
|
135
128
|
* @returns A promise that resolves to the message data, a sibling path and the
|
|
136
129
|
* index of the message in the l1ToL2MessageTree
|
|
137
130
|
*/
|
|
138
131
|
async getL1ToL2MembershipWitness(entryKey: Fr): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>> {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
const response = await this.aztecNode.getL1ToL2MessageMembershipWitness('latest', entryKey);
|
|
133
|
+
if (!response) {
|
|
134
|
+
throw new Error(`No L1 to L2 message found for entry key ${entryKey.toString()}`);
|
|
135
|
+
}
|
|
136
|
+
const [index, siblingPath] = response;
|
|
142
137
|
return new MessageLoadOracleInputs(index, siblingPath);
|
|
143
138
|
}
|
|
144
139
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contract_database/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export * from './memory_contract_database.js';
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3RfZGF0YWJhc2UvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYywrQkFBK0IsQ0FBQyJ9
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { ContractDao, ContractDatabase } from '@aztec/circuit-types';
|
|
2
|
-
import { FunctionSelector } from '@aztec/circuits.js';
|
|
3
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
|
-
import { DebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
/**
|
|
6
|
-
* The MemoryContractDatabase class serves as an in-memory implementation of the ContractDatabase interface.
|
|
7
|
-
* It allows for storing and retrieving contract data, such as ContractDao objects and associated function bytecodes,
|
|
8
|
-
* within a contracts array. This class is particularly useful for testing and development purposes where a
|
|
9
|
-
* persistent storage may not be required.
|
|
10
|
-
*/
|
|
11
|
-
export declare class MemoryContractDatabase implements ContractDatabase {
|
|
12
|
-
protected log: DebugLogger;
|
|
13
|
-
private contracts;
|
|
14
|
-
constructor(log: DebugLogger);
|
|
15
|
-
/**
|
|
16
|
-
* Adds a new ContractDao instance to the memory-based contract database.
|
|
17
|
-
* The function stores the contract in an array and returns a resolved promise indicating successful addition.
|
|
18
|
-
*
|
|
19
|
-
* @param contract - The ContractDao instance to be added to the memory database.
|
|
20
|
-
* @returns A Promise that resolves when the contract is successfully added.
|
|
21
|
-
*/
|
|
22
|
-
addContract(contract: ContractDao): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Retrieve a ContractDao instance with the specified AztecAddress from the in-memory contracts list.
|
|
25
|
-
* Returns the first match found or undefined if no contract with the given address is found.
|
|
26
|
-
*
|
|
27
|
-
* @param address - The AztecAddress to search for in the stored contracts.
|
|
28
|
-
* @returns A Promise resolving to the ContractDao instance matching the given address or undefined.
|
|
29
|
-
*/
|
|
30
|
-
getContract(address: AztecAddress): Promise<ContractDao | undefined>;
|
|
31
|
-
getContracts(): Promise<ContractDao[]>;
|
|
32
|
-
/**
|
|
33
|
-
* Retrieve the bytecode associated with a given contract address and function selector.
|
|
34
|
-
* This function searches through the stored contracts to find a matching contract and function,
|
|
35
|
-
* then returns the corresponding bytecode. If no match is found, it returns undefined.
|
|
36
|
-
*
|
|
37
|
-
* @param contractAddress - The AztecAddress representing the contract address to look for.
|
|
38
|
-
* @param selector - The function selector.
|
|
39
|
-
* @returns A Promise that resolves to the bytecode of the matching function or undefined if not found.
|
|
40
|
-
*/
|
|
41
|
-
getCode(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=memory_contract_database.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory_contract_database.d.ts","sourceRoot":"","sources":["../../src/contract_database/memory_contract_database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,gBAAgB;IAGjD,SAAS,CAAC,GAAG,EAAE,WAAW;IAFtC,OAAO,CAAC,SAAS,CAAqB;gBAEhB,GAAG,EAAE,WAAW;IAEtC;;;;;;OAMG;IACI,WAAW,CAAC,QAAQ,EAAE,WAAW;IAMxC;;;;;;OAMG;IACI,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAIpE,YAAY,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAI7C;;;;;;;;OAQG;IACU,OAAO,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB;CAI/E"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The MemoryContractDatabase class serves as an in-memory implementation of the ContractDatabase interface.
|
|
3
|
-
* It allows for storing and retrieving contract data, such as ContractDao objects and associated function bytecodes,
|
|
4
|
-
* within a contracts array. This class is particularly useful for testing and development purposes where a
|
|
5
|
-
* persistent storage may not be required.
|
|
6
|
-
*/
|
|
7
|
-
export class MemoryContractDatabase {
|
|
8
|
-
constructor(log) {
|
|
9
|
-
this.log = log;
|
|
10
|
-
this.contracts = [];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Adds a new ContractDao instance to the memory-based contract database.
|
|
14
|
-
* The function stores the contract in an array and returns a resolved promise indicating successful addition.
|
|
15
|
-
*
|
|
16
|
-
* @param contract - The ContractDao instance to be added to the memory database.
|
|
17
|
-
* @returns A Promise that resolves when the contract is successfully added.
|
|
18
|
-
*/
|
|
19
|
-
addContract(contract) {
|
|
20
|
-
this.log(`Adding contract ${contract.instance.address.toString()}`);
|
|
21
|
-
this.contracts.push(contract);
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Retrieve a ContractDao instance with the specified AztecAddress from the in-memory contracts list.
|
|
26
|
-
* Returns the first match found or undefined if no contract with the given address is found.
|
|
27
|
-
*
|
|
28
|
-
* @param address - The AztecAddress to search for in the stored contracts.
|
|
29
|
-
* @returns A Promise resolving to the ContractDao instance matching the given address or undefined.
|
|
30
|
-
*/
|
|
31
|
-
getContract(address) {
|
|
32
|
-
return Promise.resolve(this.contracts.find(c => c.instance.address.equals(address)));
|
|
33
|
-
}
|
|
34
|
-
getContracts() {
|
|
35
|
-
return Promise.resolve(this.contracts);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Retrieve the bytecode associated with a given contract address and function selector.
|
|
39
|
-
* This function searches through the stored contracts to find a matching contract and function,
|
|
40
|
-
* then returns the corresponding bytecode. If no match is found, it returns undefined.
|
|
41
|
-
*
|
|
42
|
-
* @param contractAddress - The AztecAddress representing the contract address to look for.
|
|
43
|
-
* @param selector - The function selector.
|
|
44
|
-
* @returns A Promise that resolves to the bytecode of the matching function or undefined if not found.
|
|
45
|
-
*/
|
|
46
|
-
async getCode(contractAddress, selector) {
|
|
47
|
-
const contract = await this.getContract(contractAddress);
|
|
48
|
-
return contract?.functions.find(f => f.selector.equals(selector))?.bytecode;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVtb3J5X2NvbnRyYWN0X2RhdGFiYXNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbnRyYWN0X2RhdGFiYXNlL21lbW9yeV9jb250cmFjdF9kYXRhYmFzZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLQTs7Ozs7R0FLRztBQUNILE1BQU0sT0FBTyxzQkFBc0I7SUFHakMsWUFBc0IsR0FBZ0I7UUFBaEIsUUFBRyxHQUFILEdBQUcsQ0FBYTtRQUY5QixjQUFTLEdBQWtCLEVBQUUsQ0FBQztJQUVHLENBQUM7SUFFMUM7Ozs7OztPQU1HO0lBQ0ksV0FBVyxDQUFDLFFBQXFCO1FBQ3RDLElBQUksQ0FBQyxHQUFHLENBQUMsbUJBQW1CLFFBQVEsQ0FBQyxRQUFRLENBQUMsT0FBTyxDQUFDLFFBQVEsRUFBRSxFQUFFLENBQUMsQ0FBQztRQUNwRSxJQUFJLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsQ0FBQztRQUM5QixPQUFPLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQztJQUMzQixDQUFDO0lBRUQ7Ozs7OztPQU1HO0lBQ0ksV0FBVyxDQUFDLE9BQXFCO1FBQ3RDLE9BQU8sT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLENBQUMsQ0FBQyxRQUFRLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxPQUFPLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDdkYsQ0FBQztJQUVNLFlBQVk7UUFDakIsT0FBTyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQztJQUN6QyxDQUFDO0lBRUQ7Ozs7Ozs7O09BUUc7SUFDSSxLQUFLLENBQUMsT0FBTyxDQUFDLGVBQTZCLEVBQUUsUUFBMEI7UUFDNUUsTUFBTSxRQUFRLEdBQUcsTUFBTSxJQUFJLENBQUMsV0FBVyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1FBQ3pELE9BQU8sUUFBUSxFQUFFLFNBQVMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxFQUFFLFFBQVEsQ0FBQztJQUM5RSxDQUFDO0NBQ0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './memory_contract_database.js';
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ContractDao, ContractDatabase } from '@aztec/circuit-types';
|
|
2
|
-
import { FunctionSelector } from '@aztec/circuits.js';
|
|
3
|
-
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
4
|
-
import { DebugLogger } from '@aztec/foundation/log';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The MemoryContractDatabase class serves as an in-memory implementation of the ContractDatabase interface.
|
|
8
|
-
* It allows for storing and retrieving contract data, such as ContractDao objects and associated function bytecodes,
|
|
9
|
-
* within a contracts array. This class is particularly useful for testing and development purposes where a
|
|
10
|
-
* persistent storage may not be required.
|
|
11
|
-
*/
|
|
12
|
-
export class MemoryContractDatabase implements ContractDatabase {
|
|
13
|
-
private contracts: ContractDao[] = [];
|
|
14
|
-
|
|
15
|
-
constructor(protected log: DebugLogger) {}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Adds a new ContractDao instance to the memory-based contract database.
|
|
19
|
-
* The function stores the contract in an array and returns a resolved promise indicating successful addition.
|
|
20
|
-
*
|
|
21
|
-
* @param contract - The ContractDao instance to be added to the memory database.
|
|
22
|
-
* @returns A Promise that resolves when the contract is successfully added.
|
|
23
|
-
*/
|
|
24
|
-
public addContract(contract: ContractDao) {
|
|
25
|
-
this.log(`Adding contract ${contract.instance.address.toString()}`);
|
|
26
|
-
this.contracts.push(contract);
|
|
27
|
-
return Promise.resolve();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Retrieve a ContractDao instance with the specified AztecAddress from the in-memory contracts list.
|
|
32
|
-
* Returns the first match found or undefined if no contract with the given address is found.
|
|
33
|
-
*
|
|
34
|
-
* @param address - The AztecAddress to search for in the stored contracts.
|
|
35
|
-
* @returns A Promise resolving to the ContractDao instance matching the given address or undefined.
|
|
36
|
-
*/
|
|
37
|
-
public getContract(address: AztecAddress): Promise<ContractDao | undefined> {
|
|
38
|
-
return Promise.resolve(this.contracts.find(c => c.instance.address.equals(address)));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public getContracts(): Promise<ContractDao[]> {
|
|
42
|
-
return Promise.resolve(this.contracts);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Retrieve the bytecode associated with a given contract address and function selector.
|
|
47
|
-
* This function searches through the stored contracts to find a matching contract and function,
|
|
48
|
-
* then returns the corresponding bytecode. If no match is found, it returns undefined.
|
|
49
|
-
*
|
|
50
|
-
* @param contractAddress - The AztecAddress representing the contract address to look for.
|
|
51
|
-
* @param selector - The function selector.
|
|
52
|
-
* @returns A Promise that resolves to the bytecode of the matching function or undefined if not found.
|
|
53
|
-
*/
|
|
54
|
-
public async getCode(contractAddress: AztecAddress, selector: FunctionSelector) {
|
|
55
|
-
const contract = await this.getContract(contractAddress);
|
|
56
|
-
return contract?.functions.find(f => f.selector.equals(selector))?.bytecode;
|
|
57
|
-
}
|
|
58
|
-
}
|