|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
Implementation of ContractDBInterface that uses NAPI callbacks to TypeScript. More...
#include <ts_callback_contract_db.hpp>
Public Member Functions | |
| TsCallbackContractDB (Napi::ThreadSafeFunction instanceCallback, Napi::ThreadSafeFunction classCallback, Napi::ThreadSafeFunction addContractsCallback, Napi::ThreadSafeFunction bytecodeCommitmentCallback, Napi::ThreadSafeFunction debugNameCallback, Napi::ThreadSafeFunction createCheckpointCallback, Napi::ThreadSafeFunction commitCheckpointCallback, Napi::ThreadSafeFunction revertCheckpointCallback) | |
| Constructs a callback-based contracts database. | |
| std::optional< bb::avm2::ContractInstance > | get_contract_instance (const bb::avm2::AztecAddress &address) const override |
| Fetches a contract instance by address. | |
| std::optional< bb::avm2::ContractClass > | get_contract_class (const bb::avm2::ContractClassId &class_id) const override |
| Fetches a contract class by class ID. | |
| void | add_contracts (const bb::avm2::ContractDeploymentData &contract_deployment_data) override |
| Adds contracts from deployment data. | |
| std::optional< bb::avm2::FF > | get_bytecode_commitment (const bb::avm2::ContractClassId &class_id) const override |
| Fetches bytecode commitment for a contract class. | |
| std::optional< std::string > | get_debug_function_name (const bb::avm2::AztecAddress &address, const bb::avm2::FF &selector) const override |
| Fetches debug function name for a contract function. | |
| void | create_checkpoint () override |
| Creates a new checkpoint. | |
| void | commit_checkpoint () override |
| Commits the current checkpoint. | |
| void | revert_checkpoint () override |
| Reverts the current checkpoint. | |
| void | release () |
| Releases the thread-safe function handles. | |
Public Member Functions inherited from bb::avm2::simulation::ContractDBInterface | |
| virtual | ~ContractDBInterface ()=default |
| virtual std::optional< ContractInstance > | get_contract_instance (const AztecAddress &address) const =0 |
| virtual std::optional< ContractClass > | get_contract_class (const ContractClassId &class_id) const =0 |
| virtual std::optional< FF > | get_bytecode_commitment (const ContractClassId &class_id) const =0 |
| virtual std::optional< std::string > | get_debug_function_name (const AztecAddress &address, const FunctionSelector &selector) const =0 |
Private Attributes | |
| Napi::ThreadSafeFunction | contract_instance_callback_ |
| Napi::ThreadSafeFunction | contract_class_callback_ |
| Napi::ThreadSafeFunction | add_contracts_callback_ |
| Napi::ThreadSafeFunction | bytecode_commitment_callback_ |
| Napi::ThreadSafeFunction | debug_name_callback_ |
| Napi::ThreadSafeFunction | create_checkpoint_callback_ |
| Napi::ThreadSafeFunction | commit_checkpoint_callback_ |
| Napi::ThreadSafeFunction | revert_checkpoint_callback_ |
| bool | released_ = false |
Implementation of ContractDBInterface that uses NAPI callbacks to TypeScript.
This class bridges C++ contract data queries to TypeScript's PublicContractsDB. During simulation, when C++ needs contract instances or classes, it calls back to TypeScript through thread-safe NAPI functions.
Thread Safety:
Lifecycle:
Definition at line 27 of file ts_callback_contract_db.hpp.
| bb::nodejs::TsCallbackContractDB::TsCallbackContractDB | ( | Napi::ThreadSafeFunction | instanceCallback, |
| Napi::ThreadSafeFunction | classCallback, | ||
| Napi::ThreadSafeFunction | addContractsCallback, | ||
| Napi::ThreadSafeFunction | bytecodeCommitmentCallback, | ||
| Napi::ThreadSafeFunction | debugNameCallback, | ||
| Napi::ThreadSafeFunction | createCheckpointCallback, | ||
| Napi::ThreadSafeFunction | commitCheckpointCallback, | ||
| Napi::ThreadSafeFunction | revertCheckpointCallback | ||
| ) |
Constructs a callback-based contracts database.
| instanceCallback | Thread-safe function to fetch contract instances from TypeScript Expected signature: (address: string) => Promise<Buffer | undefined> |
| classCallback | Thread-safe function to fetch contract classes from TypeScript Expected signature: (classId: string) => Promise<Buffer | undefined> |
| addContractsCallback | Thread-safe function to add contracts Expected signature: (contractDeploymentData: Buffer) => Promise<void> |
| bytecodeCommitmentCallback | Thread-safe function to fetch bytecode commitments Expected signature: (classId: string) => Promise<Buffer | undefined> |
| debugNameCallback | Thread-safe function to fetch debug function names Expected signature: (address: string, selector: string) => Promise<string | undefined> |
| createCheckpointCallback | Thread-safe function to create a checkpoint Expected signature: () => Promise<void> |
| commitCheckpointCallback | Thread-safe function to commit a checkpoint Expected signature: () => Promise<void> |
| revertCheckpointCallback | Thread-safe function to revert a checkpoint Expected signature: () => Promise<void> |
Definition at line 11 of file ts_callback_contract_db.cpp.
|
overridevirtual |
Adds contracts from deployment data.
| contract_deployment_data | The contract deployment data |
Implements bb::avm2::simulation::ContractDBInterface.
Definition at line 80 of file ts_callback_contract_db.cpp.
|
overridevirtual |
Commits the current checkpoint.
Accepts the current checkpoint's state as latest.
Implements bb::avm2::simulation::ContractDBInterface.
Definition at line 181 of file ts_callback_contract_db.cpp.
|
overridevirtual |
Creates a new checkpoint.
Creates a checkpoint in the TypeScript contracts DB, enabling rollbacks to current state.
Implements bb::avm2::simulation::ContractDBInterface.
Definition at line 149 of file ts_callback_contract_db.cpp.
|
override |
Fetches bytecode commitment for a contract class.
| class_id | The contract class ID |
Definition at line 96 of file ts_callback_contract_db.cpp.
|
override |
Fetches a contract class by class ID.
Calls back to TypeScript to retrieve the contract class. The TypeScript callback should return a msgpack-serialized ContractClassHint buffer, or undefined if not found.
| class_id | The contract class ID to lookup |
Definition at line 55 of file ts_callback_contract_db.cpp.
|
override |
Fetches a contract instance by address.
Calls back to TypeScript to retrieve the contract instance. The TypeScript callback should return a msgpack-serialized ContractInstanceHint buffer, or undefined if not found.
| address | The contract address to lookup |
Definition at line 29 of file ts_callback_contract_db.cpp.
|
override |
Fetches debug function name for a contract function.
| address | The contract address |
| selector | The function selector |
Definition at line 122 of file ts_callback_contract_db.cpp.
| void bb::nodejs::TsCallbackContractDB::release | ( | ) |
Releases the thread-safe function handles.
Must be called before destruction to properly clean up NAPI resources. This tells Node.js that the C++ side is done with the callbacks.
Definition at line 245 of file ts_callback_contract_db.cpp.
|
overridevirtual |
Reverts the current checkpoint.
Discards the current checkpoint's state and rolls back to the previous checkpoint.
Implements bb::avm2::simulation::ContractDBInterface.
Definition at line 213 of file ts_callback_contract_db.cpp.
|
private |
Definition at line 138 of file ts_callback_contract_db.hpp.
|
private |
Definition at line 139 of file ts_callback_contract_db.hpp.
|
private |
Definition at line 142 of file ts_callback_contract_db.hpp.
|
private |
Definition at line 137 of file ts_callback_contract_db.hpp.
|
private |
Definition at line 136 of file ts_callback_contract_db.hpp.
|
private |
Definition at line 141 of file ts_callback_contract_db.hpp.
|
private |
Definition at line 140 of file ts_callback_contract_db.hpp.
|
mutableprivate |
Definition at line 146 of file ts_callback_contract_db.hpp.
|
private |
Definition at line 143 of file ts_callback_contract_db.hpp.