veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
mempool_result.hpp
1// Copyright (c) 2019-2022 Xenios SEZC
2// https://www.veriblock.org
3// Distributed under the MIT software license, see the accompanying
4// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef VERIBLOCK_POP_CPP_MEMPOOL_RESULT_HPP
7#define VERIBLOCK_POP_CPP_MEMPOOL_RESULT_HPP
8
9#include "entities/atv.hpp"
10#include "entities/vbkblock.hpp"
11#include "entities/vtb.hpp"
12#include "validation_state.hpp"
13
14namespace altintegration {
15
20 std::vector<std::pair<VbkBlock::id_t, ValidationState>> context;
21 std::vector<std::pair<VTB::id_t, ValidationState>> vtbs;
22 std::vector<std::pair<ATV::id_t, ValidationState>> atvs;
23};
24
26namespace detail {
27
29template <typename JsonValue, typename ID>
30JsonValue putArrayOfPairs(
31 JsonValue& obj,
32 std::string key,
33 const std::vector<std::pair<ID, ValidationState>>& pairs) {
34 auto arr = json::makeEmptyArray<JsonValue>();
35 for (auto& v : pairs) {
36 auto o = json::makeEmptyObject<JsonValue>();
37 json::putStringKV(o, "id", HexStr(v.first));
38 auto state = ToJSON<JsonValue>(v.second);
39 json::putKV(o, "validity", state);
40 json::arrayPushBack(arr, o);
41 }
42
43 json::putKV(obj, key, arr);
44 return obj;
45}
46
47} // namespace detail
48
50template <typename JsonValue>
51JsonValue ToJSON(const MempoolResult& r) {
52 auto obj = json::makeEmptyObject<JsonValue>();
53 detail::putArrayOfPairs(obj, "vbkblocks", r.context);
54 detail::putArrayOfPairs(obj, "vtbs", r.vtbs);
55 detail::putArrayOfPairs(obj, "atvs", r.atvs);
56 return obj;
57}
58
59} // namespace altintegration
60
61#endif // VERIBLOCK_POP_CPP_MEMPOOL_RESULT_HPP
Defines logging helpers.
Definition: block.hpp:14
std::string HexStr(const T itbegin, const T itend)
Convert bytes to hex.
Definition: strutil.hpp:44
An entity which is returned from MemPool on call to submitAll.