Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ts_callback_contract_db.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <napi.h>
5#include <optional>
6
9
10namespace bb::nodejs {
11
28 public:
49 TsCallbackContractDB(Napi::ThreadSafeFunction instanceCallback,
50 Napi::ThreadSafeFunction classCallback,
51 Napi::ThreadSafeFunction addContractsCallback,
52 Napi::ThreadSafeFunction bytecodeCommitmentCallback,
53 Napi::ThreadSafeFunction debugNameCallback,
54 Napi::ThreadSafeFunction createCheckpointCallback,
55 Napi::ThreadSafeFunction commitCheckpointCallback,
56 Napi::ThreadSafeFunction revertCheckpointCallback);
57
68 const bb::avm2::AztecAddress& address) const override;
69
80
86 void add_contracts(const bb::avm2::ContractDeploymentData& contract_deployment_data) override;
87
95
104 const bb::avm2::FF& selector) const override;
105
111 void create_checkpoint() override;
112
118 void commit_checkpoint() override;
119
125 void revert_checkpoint() override;
126
133 void release();
134
135 private:
136 Napi::ThreadSafeFunction contract_instance_callback_;
137 Napi::ThreadSafeFunction contract_class_callback_;
138 Napi::ThreadSafeFunction add_contracts_callback_;
139 Napi::ThreadSafeFunction bytecode_commitment_callback_;
140 Napi::ThreadSafeFunction debug_name_callback_;
141 Napi::ThreadSafeFunction create_checkpoint_callback_;
142 Napi::ThreadSafeFunction commit_checkpoint_callback_;
143 Napi::ThreadSafeFunction revert_checkpoint_callback_;
144
145 // Track whether TSFNs have been released to avoid double-release
146 mutable bool released_ = false;
147};
148
149} // namespace bb::nodejs
std::shared_ptr< Napi::ThreadSafeFunction > add_contracts
Implementation of ContractDBInterface that uses NAPI callbacks to TypeScript.
std::optional< bb::avm2::ContractClass > get_contract_class(const bb::avm2::ContractClassId &class_id) const override
Fetches a contract class by class ID.
void revert_checkpoint() override
Reverts the current checkpoint.
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 commit_checkpoint() override
Commits the current checkpoint.
std::optional< bb::avm2::ContractInstance > get_contract_instance(const bb::avm2::AztecAddress &address) const override
Fetches a contract instance by address.
Napi::ThreadSafeFunction create_checkpoint_callback_
Napi::ThreadSafeFunction bytecode_commitment_callback_
std::optional< bb::avm2::FF > get_bytecode_commitment(const bb::avm2::ContractClassId &class_id) const override
Fetches bytecode commitment for a contract class.
void release()
Releases the thread-safe function handles.
Napi::ThreadSafeFunction contract_class_callback_
Napi::ThreadSafeFunction revert_checkpoint_callback_
void create_checkpoint() override
Creates a new checkpoint.
Napi::ThreadSafeFunction add_contracts_callback_
Napi::ThreadSafeFunction commit_checkpoint_callback_
Napi::ThreadSafeFunction contract_instance_callback_
FF ContractClassId
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13