Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
response.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Nishat], commit: 22d6fc368da0fbe5412f4f7b2890a052aa48d803 }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
16#include <exception>
17#include <functional>
18#include <memory>
19#include <optional>
20#include <string>
21#include <utility>
22
26
27 TreeMetaResponse() = default;
28 ~TreeMetaResponse() = default;
29 TreeMetaResponse(const TreeMetaResponse& other) = default;
30 TreeMetaResponse(TreeMetaResponse&& other) noexcept = default;
32 TreeMetaResponse& operator=(TreeMetaResponse&& other) noexcept = default;
33};
34
36 uint32_t depth;
37
38 CheckpointResponse() = default;
40 CheckpointResponse(const CheckpointResponse& other) = default;
41 CheckpointResponse(CheckpointResponse&& other) noexcept = default;
43 CheckpointResponse& operator=(CheckpointResponse&& other) noexcept = default;
44};
45
49
50 AddDataResponse() = default;
51 ~AddDataResponse() = default;
52 AddDataResponse(const AddDataResponse& other) = default;
53 AddDataResponse(AddDataResponse&& other) noexcept = default;
54 AddDataResponse& operator=(const AddDataResponse& other) = default;
55 AddDataResponse& operator=(AddDataResponse&& other) noexcept = default;
56};
57
68
89
103
116
127
138
156
167
170
171 GetLeafResponse() = default;
172 ~GetLeafResponse() = default;
173 GetLeafResponse(const GetLeafResponse& other) = default;
174 GetLeafResponse(GetLeafResponse&& other) noexcept = default;
175 GetLeafResponse& operator=(const GetLeafResponse& other) = default;
176 GetLeafResponse& operator=(GetLeafResponse&& other) noexcept = default;
177};
178
182
205
209
210 CommitResponse() = default;
211 ~CommitResponse() = default;
212 CommitResponse(const CommitResponse& other) = default;
213 CommitResponse(CommitResponse&& other) noexcept = default;
214 CommitResponse& operator=(const CommitResponse& other) = default;
215 CommitResponse& operator=(CommitResponse&& other) noexcept = default;
216};
217
221
222 UnwindResponse() = default;
223 ~UnwindResponse() = default;
224 UnwindResponse(const UnwindResponse& other) = default;
225 UnwindResponse(UnwindResponse&& other) noexcept = default;
226 UnwindResponse& operator=(const UnwindResponse& other) = default;
227 UnwindResponse& operator=(UnwindResponse&& other) noexcept = default;
228};
229
241
242template <typename ResponseType> struct TypedResponse {
243 ResponseType inner;
244 bool success{ true };
245 std::string message;
246
247 TypedResponse() = default;
248 ~TypedResponse() = default;
249 TypedResponse(const TypedResponse& other) = default;
250 TypedResponse(TypedResponse&& other) noexcept = default;
251 TypedResponse& operator=(const TypedResponse& other) = default;
252 TypedResponse& operator=(TypedResponse&& other) noexcept = default;
253};
254
255struct Response {
257 std::string message;
258
259 Response(bool s, std::string m)
260 : success(s)
261 , message(std::move(m))
262 {}
263 Response() = default;
264 ~Response() = default;
265 Response(const Response& other) = default;
266 Response(Response&& other) noexcept = default;
267 Response& operator=(const Response& other) = default;
268 Response& operator=(Response&& other) noexcept = default;
269};
270
271template <typename ResponseType>
272void execute_and_report(const std::function<void(TypedResponse<ResponseType>&)>& f,
273 const std::function<void(TypedResponse<ResponseType>&)>& on_completion)
274{
276 try {
277 f(response);
278 } catch (std::exception& e) {
279 response.success = false;
280 response.message = e.what();
281 // std::cout << "Response " << e.what() << std::endl;
282 }
283 try {
284 on_completion(response);
285 } catch (std::exception& e) {
286 std::cerr << "Completion callback threw: " << e.what() << std::endl;
287 std::abort();
288 }
289}
290
291inline void execute_and_report(const std::function<void()>& f, const std::function<void(Response&)>& on_completion)
292{
293 Response response{ true, "" };
294 try {
295 f();
296 } catch (std::exception& e) {
297 response.success = false;
298 response.message = e.what();
299 // std::cout << "Response " << e.what() << std::endl;
300 }
301 try {
302 on_completion(response);
303 } catch (std::exception& e) {
304 std::cerr << "Completion callback threw: " << e.what() << std::endl;
305 std::abort();
306 }
307}
308} // namespace bb::crypto::merkle_tree
void execute_and_report(const std::function< void(TypedResponse< ResponseType > &)> &f, const std::function< void(TypedResponse< ResponseType > &)> &on_completion)
Definition response.hpp:272
std::vector< fr > fr_sibling_path
Definition hash_path.hpp:14
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
AddDataResponse(AddDataResponse &&other) noexcept=default
AddDataResponse(const AddDataResponse &other)=default
AddDataResponse & operator=(AddDataResponse &&other) noexcept=default
AddDataResponse & operator=(const AddDataResponse &other)=default
AddIndexedDataResponse & operator=(AddIndexedDataResponse &&other) noexcept=default
AddIndexedDataResponse(AddIndexedDataResponse &&other) noexcept=default
AddIndexedDataResponse(const AddIndexedDataResponse &other)=default
std::shared_ptr< std::vector< LeafUpdateWitnessData< LeafValueType > > > low_leaf_witness_data
Definition response.hpp:94
AddIndexedDataResponse & operator=(const AddIndexedDataResponse &other)=default
std::shared_ptr< std::vector< std::pair< LeafValueType, index_t > > > sorted_leaves
Definition response.hpp:93
std::shared_ptr< std::vector< LeafUpdateWitnessData< LeafValueType > > > low_leaf_witness_data
Definition response.hpp:106
AddIndexedDataSequentiallyResponse(const AddIndexedDataSequentiallyResponse &other)=default
AddIndexedDataSequentiallyResponse & operator=(const AddIndexedDataSequentiallyResponse &other)=default
std::shared_ptr< std::vector< LeafUpdateWitnessData< LeafValueType > > > insertion_witness_data
Definition response.hpp:107
AddIndexedDataSequentiallyResponse(AddIndexedDataSequentiallyResponse &&other) noexcept=default
AddIndexedDataSequentiallyResponse & operator=(AddIndexedDataSequentiallyResponse &&other) noexcept=default
BlockForIndexResponse & operator=(BlockForIndexResponse &&other) noexcept=default
BlockForIndexResponse(const BlockForIndexResponse &other)=default
BlockForIndexResponse(BlockForIndexResponse &&other) noexcept=default
BlockForIndexResponse & operator=(const BlockForIndexResponse &other)=default
std::vector< std::optional< block_number_t > > blockNumbers
Definition response.hpp:118
CheckpointResponse & operator=(const CheckpointResponse &other)=default
CheckpointResponse(CheckpointResponse &&other) noexcept=default
CheckpointResponse & operator=(CheckpointResponse &&other) noexcept=default
CheckpointResponse(const CheckpointResponse &other)=default
CommitResponse & operator=(CommitResponse &&other) noexcept=default
CommitResponse(CommitResponse &&other) noexcept=default
CommitResponse(const CommitResponse &other)=default
CommitResponse & operator=(const CommitResponse &other)=default
std::vector< std::optional< index_t > > leaf_indices
Definition response.hpp:129
FindLeafIndexResponse & operator=(const FindLeafIndexResponse &other)=default
FindLeafIndexResponse(const FindLeafIndexResponse &other)=default
FindLeafIndexResponse(FindLeafIndexResponse &&other) noexcept=default
FindLeafIndexResponse & operator=(FindLeafIndexResponse &&other) noexcept=default
FindLeafPathResponse & operator=(const FindLeafPathResponse &other)=default
FindLeafPathResponse(const FindLeafPathResponse &other)=default
FindLeafPathResponse(FindLeafPathResponse &&other) noexcept=default
std::vector< std::optional< SiblingPathAndIndex > > leaf_paths
Definition response.hpp:158
FindLeafPathResponse & operator=(FindLeafPathResponse &&other) noexcept=default
std::optional< IndexedLeaf< LeafValueType > > indexed_leaf
Definition response.hpp:180
GetLeafResponse & operator=(GetLeafResponse &&other) noexcept=default
GetLeafResponse(GetLeafResponse &&other) noexcept=default
GetLeafResponse(const GetLeafResponse &other)=default
GetLeafResponse & operator=(const GetLeafResponse &other)=default
GetLowIndexedLeafResponse & operator=(GetLowIndexedLeafResponse &&other) noexcept=default
GetLowIndexedLeafResponse(const GetLowIndexedLeafResponse &other)=default
GetLowIndexedLeafResponse & operator=(const GetLowIndexedLeafResponse &other)=default
GetLowIndexedLeafResponse(bool p, const index_t &i)
Definition response.hpp:189
bool operator==(const GetLowIndexedLeafResponse &other) const
Definition response.hpp:200
GetLowIndexedLeafResponse(GetLowIndexedLeafResponse &&other) noexcept=default
GetSiblingPathResponse(const GetSiblingPathResponse &other)=default
GetSiblingPathResponse(GetSiblingPathResponse &&other) noexcept=default
GetSiblingPathResponse & operator=(const GetSiblingPathResponse &other)=default
GetSiblingPathResponse & operator=(GetSiblingPathResponse &&other) noexcept=default
LeafUpdateWitnessData(const LeafUpdateWitnessData &other)=default
LeafUpdateWitnessData(LeafUpdateWitnessData &&other) noexcept=default
bool operator==(const LeafUpdateWitnessData &other) const =default
LeafUpdateWitnessData(const IndexedLeaf< LeafType > &l, const index_t &i, fr_sibling_path p)
Definition response.hpp:74
LeafUpdateWitnessData & operator=(LeafUpdateWitnessData &&other) noexcept=default
LeafUpdateWitnessData & operator=(const LeafUpdateWitnessData &other)=default
RemoveHistoricResponse(RemoveHistoricResponse &&other) noexcept=default
RemoveHistoricResponse & operator=(RemoveHistoricResponse &&other) noexcept=default
RemoveHistoricResponse & operator=(const RemoveHistoricResponse &other)=default
RemoveHistoricResponse(const RemoveHistoricResponse &other)=default
Response(const Response &other)=default
Response(Response &&other) noexcept=default
Response(bool s, std::string m)
Definition response.hpp:259
Response & operator=(const Response &other)=default
Response & operator=(Response &&other) noexcept=default
SiblingPathAndIndex(SiblingPathAndIndex &&other) noexcept=default
SiblingPathAndIndex(index_t index, fr_sibling_path path)
Definition response.hpp:147
SiblingPathAndIndex & operator=(const SiblingPathAndIndex &other)=default
SiblingPathAndIndex & operator=(SiblingPathAndIndex &&other) noexcept=default
SiblingPathAndIndex(const SiblingPathAndIndex &other)=default
TreeMetaResponse(const TreeMetaResponse &other)=default
TreeMetaResponse & operator=(TreeMetaResponse &&other) noexcept=default
TreeMetaResponse(TreeMetaResponse &&other) noexcept=default
TreeMetaResponse & operator=(const TreeMetaResponse &other)=default
TypedResponse(TypedResponse &&other) noexcept=default
TypedResponse & operator=(const TypedResponse &other)=default
TypedResponse(const TypedResponse &other)=default
TypedResponse & operator=(TypedResponse &&other) noexcept=default
UnwindResponse & operator=(UnwindResponse &&other) noexcept=default
UnwindResponse & operator=(const UnwindResponse &other)=default
UnwindResponse(const UnwindResponse &other)=default
UnwindResponse(UnwindResponse &&other) noexcept=default