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
77
91
104
115
126
144
155
158
159 GetLeafResponse() = default;
160 ~GetLeafResponse() = default;
161 GetLeafResponse(const GetLeafResponse& other) = default;
162 GetLeafResponse(GetLeafResponse&& other) noexcept = default;
163 GetLeafResponse& operator=(const GetLeafResponse& other) = default;
164 GetLeafResponse& operator=(GetLeafResponse&& other) noexcept = default;
165};
166
170
193
197
198 CommitResponse() = default;
199 ~CommitResponse() = default;
200 CommitResponse(const CommitResponse& other) = default;
201 CommitResponse(CommitResponse&& other) noexcept = default;
202 CommitResponse& operator=(const CommitResponse& other) = default;
203 CommitResponse& operator=(CommitResponse&& other) noexcept = default;
204};
205
209
210 UnwindResponse() = default;
211 ~UnwindResponse() = default;
212 UnwindResponse(const UnwindResponse& other) = default;
213 UnwindResponse(UnwindResponse&& other) noexcept = default;
214 UnwindResponse& operator=(const UnwindResponse& other) = default;
215 UnwindResponse& operator=(UnwindResponse&& other) noexcept = default;
216};
217
229
230template <typename ResponseType> struct TypedResponse {
231 ResponseType inner;
232 bool success{ true };
233 std::string message;
234
235 TypedResponse() = default;
236 ~TypedResponse() = default;
237 TypedResponse(const TypedResponse& other) = default;
238 TypedResponse(TypedResponse&& other) noexcept = default;
239 TypedResponse& operator=(const TypedResponse& other) = default;
240 TypedResponse& operator=(TypedResponse&& other) noexcept = default;
241};
242
243struct Response {
245 std::string message;
246
247 Response(bool s, std::string m)
248 : success(s)
249 , message(std::move(m))
250 {}
251 Response() = default;
252 ~Response() = default;
253 Response(const Response& other) = default;
254 Response(Response&& other) noexcept = default;
255 Response& operator=(const Response& other) = default;
256 Response& operator=(Response&& other) noexcept = default;
257};
258
259template <typename ResponseType>
260void execute_and_report(const std::function<void(TypedResponse<ResponseType>&)>& f,
261 const std::function<void(TypedResponse<ResponseType>&)>& on_completion)
262{
264 try {
265 f(response);
266 } catch (std::exception& e) {
267 response.success = false;
268 response.message = e.what();
269 // std::cout << "Response " << e.what() << std::endl;
270 }
271 try {
272 on_completion(response);
273 } catch (std::exception&) {
274 }
275}
276
277inline void execute_and_report(const std::function<void()>& f, const std::function<void(Response&)>& on_completion)
278{
279 Response response{ true, "" };
280 try {
281 f();
282 } catch (std::exception& e) {
283 response.success = false;
284 response.message = e.what();
285 // std::cout << "Response " << e.what() << std::endl;
286 }
287 try {
288 on_completion(response);
289 } catch (std::exception&) {
290 }
291}
292} // 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:260
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:82
std::shared_ptr< std::vector< std::pair< LeafValueType, size_t > > > sorted_leaves
Definition response.hpp:81
AddIndexedDataResponse & operator=(const AddIndexedDataResponse &other)=default
std::shared_ptr< std::vector< LeafUpdateWitnessData< LeafValueType > > > low_leaf_witness_data
Definition response.hpp:94
AddIndexedDataSequentiallyResponse(const AddIndexedDataSequentiallyResponse &other)=default
AddIndexedDataSequentiallyResponse & operator=(const AddIndexedDataSequentiallyResponse &other)=default
std::shared_ptr< std::vector< LeafUpdateWitnessData< LeafValueType > > > insertion_witness_data
Definition response.hpp:95
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:106
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:117
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:146
FindLeafPathResponse & operator=(FindLeafPathResponse &&other) noexcept=default
std::optional< IndexedLeaf< LeafValueType > > indexed_leaf
Definition response.hpp:168
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:177
bool operator==(const GetLowIndexedLeafResponse &other) const
Definition response.hpp:188
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
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:247
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:135
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