Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
cdb_ipc_client_generated.cpp
Go to the documentation of this file.
1// AUTOGENERATED FILE - DO NOT EDIT
2
7
8#include <stdexcept>
9#include <tuple>
10
11namespace bb::cdb {
12
13CdbIpcClient::CdbIpcClient(const std::string& socket_path)
14 : client_(ipc::IpcClient::create_socket(socket_path))
15{
16 if (!client_->connect()) {
17 throw std::runtime_error("Failed to connect to server at " + socket_path);
18 }
19}
20
22{
23 if (client_) {
24 client_->close();
25 }
26}
27
28template <typename Cmd> typename Cmd::Response CdbIpcClient::send(Cmd&& cmd) const
29{
30 // Wrap command in CdbCommand NamedUnion, then in a 1-element tuple (matches server expectations)
31 CdbCommand command = std::forward<Cmd>(cmd);
32 auto wrapped = std::make_tuple(std::move(command));
33
34 // Serialize to msgpack
35 msgpack::sbuffer send_buffer;
36 msgpack::pack(send_buffer, wrapped);
37
38 // Send to server
39 constexpr uint64_t timeout_ns = 30'000'000'000ULL; // 30 seconds
40 if (!client_->send(send_buffer.data(), send_buffer.size(), timeout_ns)) {
41 throw std::runtime_error("Failed to send command to server");
42 }
43
44 // Receive response
45 auto response_span = client_->receive(timeout_ns);
46 if (response_span.empty()) {
47 throw std::runtime_error("Empty response from server");
48 }
49
50 // Deserialize response
51 auto unpacked = msgpack::unpack(reinterpret_cast<const char*>(response_span.data()), response_span.size());
52 auto response_obj = unpacked.get();
53
54 CdbCommandResponse response;
55 response_obj.convert(response);
56
57 // Release the receive buffer
58 client_->release(response_span.size());
59
60 // Check for error response
61 return std::move(response).visit([](auto&& resp) -> typename Cmd::Response {
62 using RespType = std::decay_t<decltype(resp)>;
63
65 throw std::runtime_error("Server error: " + resp.message);
68 } else {
69 throw std::runtime_error("Unexpected response type from server");
70 }
71 });
72}
73
78
83
88
93
98
103
108
113
118
123
128
133
135{
136 send(CdbShutdown{});
137}
138
139} // namespace bb::cdb
CdbCommand NamedUnion, CdbRequest context, and dispatch function.
A wrapper around std::variant that provides msgpack serialization based on type names.
decltype(auto) visit(Visitor &&vis) &&
CdbGetContractClass::Response get_contract_class(CdbGetContractClass cmd) const
CdbIpcClient(const std::string &socket_path)
void register_function_signatures(CdbRegisterFunctionSignatures cmd)
CdbGetContractClassIds::Response get_contract_class_ids() const
void commit_checkpoint(CdbCommitCheckpoint cmd)
void revert_checkpoint(CdbRevertCheckpoint cmd)
void add_contract_instance(CdbAddContractInstance cmd)
CdbGetBytecodeCommitment::Response get_bytecode_commitment(CdbGetBytecodeCommitment cmd)
void create_checkpoint(CdbCreateCheckpoint cmd)
std::unique_ptr< ipc::IpcClient > client_
void add_contracts(CdbAddContracts cmd)
void add_contract_class(CdbAddContractClass cmd)
CdbGetContractInstance::Response get_contract_instance(CdbGetContractInstance cmd) const
CdbGetDebugFunctionName::Response get_debug_function_name(CdbGetDebugFunctionName cmd) const
Cmd::Response send(Cmd &&cmd) const
ContractDBInterface adapter over the generated CDB IPC client.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13