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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
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
38
39 AddDataResponse() = default;
40 ~AddDataResponse() = default;
41 AddDataResponse(const AddDataResponse& other) = default;
42 AddDataResponse(AddDataResponse&& other) noexcept = default;
43 AddDataResponse& operator=(const AddDataResponse& other) = default;
44 AddDataResponse& operator=(AddDataResponse&& other) noexcept = default;
45};
46
57
78
92
105
116
127
145
156
159
160 GetLeafResponse() = default;
161 ~GetLeafResponse() = default;
162 GetLeafResponse(const GetLeafResponse& other) = default;
163 GetLeafResponse(GetLeafResponse&& other) noexcept = default;
164 GetLeafResponse& operator=(const GetLeafResponse& other) = default;
165 GetLeafResponse& operator=(GetLeafResponse&& other) noexcept = default;
166};
167
171
194
198
199 CommitResponse() = default;
200 ~CommitResponse() = default;
201 CommitResponse(const CommitResponse& other) = default;
202 CommitResponse(CommitResponse&& other) noexcept = default;
203 CommitResponse& operator=(const CommitResponse& other) = default;
204 CommitResponse& operator=(CommitResponse&& other) noexcept = default;
205};
206
210
211 UnwindResponse() = default;
212 ~UnwindResponse() = default;
213 UnwindResponse(const UnwindResponse& other) = default;
214 UnwindResponse(UnwindResponse&& other) noexcept = default;
215 UnwindResponse& operator=(const UnwindResponse& other) = default;
216 UnwindResponse& operator=(UnwindResponse&& other) noexcept = default;
217};
218
230
231template <typename ResponseType> struct TypedResponse {
232 ResponseType inner;
233 bool success{ true };
234 std::string message;
235
236 TypedResponse() = default;
237 ~TypedResponse() = default;
238 TypedResponse(const TypedResponse& other) = default;
239 TypedResponse(TypedResponse&& other) noexcept = default;
240 TypedResponse& operator=(const TypedResponse& other) = default;
241 TypedResponse& operator=(TypedResponse&& other) noexcept = default;
242};
243
244struct Response {
246 std::string message;
247
248 Response(bool s, std::string m)
249 : success(s)
250 , message(std::move(m))
251 {}
252 Response() = default;
253 ~Response() = default;
254 Response(const Response& other) = default;
255 Response(Response&& other) noexcept = default;
256 Response& operator=(const Response& other) = default;
257 Response& operator=(Response&& other) noexcept = default;
258};
259
260template <typename ResponseType>
261void execute_and_report(const std::function<void(TypedResponse<ResponseType>&)>& f,
262 const std::function<void(TypedResponse<ResponseType>&)>& on_completion)
263{
265 try {
266 f(response);
267 } catch (std::exception& e) {
268 response.success = false;
269 response.message = e.what();
270 // std::cout << "Response " << e.what() << std::endl;
271 }
272 try {
273 on_completion(response);
274 } catch (std::exception&) {
275 }
276}
277
278inline void execute_and_report(const std::function<void()>& f, const std::function<void(Response&)>& on_completion)
279{
280 Response response{ true, "" };
281 try {
282 f();
283 } catch (std::exception& e) {
284 response.success = false;
285 response.message = e.what();
286 // std::cout << "Response " << e.what() << std::endl;
287 }
288 try {
289 on_completion(response);
290 } catch (std::exception&) {
291 }
292}
293} // 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:261
std::vector< fr > fr_sibling_path
Definition hash_path.hpp:16
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:83
AddIndexedDataResponse & operator=(const AddIndexedDataResponse &other)=default
std::shared_ptr< std::vector< std::pair< LeafValueType, index_t > > > sorted_leaves
Definition response.hpp:82
std::shared_ptr< std::vector< LeafUpdateWitnessData< LeafValueType > > > low_leaf_witness_data
Definition response.hpp:95
AddIndexedDataSequentiallyResponse(const AddIndexedDataSequentiallyResponse &other)=default
AddIndexedDataSequentiallyResponse & operator=(const AddIndexedDataSequentiallyResponse &other)=default
std::shared_ptr< std::vector< LeafUpdateWitnessData< LeafValueType > > > insertion_witness_data
Definition response.hpp:96
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:107
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:118
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:147
FindLeafPathResponse & operator=(FindLeafPathResponse &&other) noexcept=default
std::optional< IndexedLeaf< LeafValueType > > indexed_leaf
Definition response.hpp:169
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:178
bool operator==(const GetLowIndexedLeafResponse &other) const
Definition response.hpp:189
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:63
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:248
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:136
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