|
| 1 | +/** |
| 2 | + * Copyright (c) 2011-2026 libbitcoin developers (see AUTHORS) |
| 3 | + * |
| 4 | + * This file is part of libbitcoin. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Affero General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Affero General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | +#ifndef LIBBITCOIN_DATABASE_QUERY_WIRE_IPP |
| 20 | +#define LIBBITCOIN_DATABASE_QUERY_WIRE_IPP |
| 21 | + |
| 22 | +#include <algorithm> |
| 23 | +#include <utility> |
| 24 | +#include <bitcoin/database/define.hpp> |
| 25 | + |
| 26 | +namespace libbitcoin { |
| 27 | +namespace database { |
| 28 | + |
| 29 | +// Wire serialized objects. |
| 30 | +// ---------------------------------------------------------------------------- |
| 31 | + |
| 32 | +TEMPLATE |
| 33 | +bool CLASS::get_wire_header(byteflipper& flipper, |
| 34 | + const header_link& link) const NOEXCEPT |
| 35 | +{ |
| 36 | + const auto start = flipper.get_write_position(); |
| 37 | + table::header::wire_header header{ {}, flipper }; |
| 38 | + if (!store_.header.get(link, header)) |
| 39 | + { |
| 40 | + flipper.invalidate(); |
| 41 | + return false; |
| 42 | + } |
| 43 | + |
| 44 | + // Genesis header parent is defaulted, others must be looked up. |
| 45 | + if (header.parent_fk != schema::header::link::terminal) |
| 46 | + { |
| 47 | + flipper.set_position(start); |
| 48 | + table::header::wire_key key{ {}, flipper }; |
| 49 | + if (!store_.header.get(header.parent_fk, key)) |
| 50 | + { |
| 51 | + flipper.invalidate(); |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + flipper.set_position(start + system::chain::header::serialized_size()); |
| 56 | + } |
| 57 | + |
| 58 | + return true; |
| 59 | +} |
| 60 | + |
| 61 | +TEMPLATE |
| 62 | +bool CLASS::get_wire_tx(byteflipper& , const tx_link& , |
| 63 | + bool ) const NOEXCEPT |
| 64 | +{ |
| 65 | + return {}; |
| 66 | +} |
| 67 | + |
| 68 | +TEMPLATE |
| 69 | +bool CLASS::get_wire_block(byteflipper& , const header_link& , |
| 70 | + bool ) const NOEXCEPT |
| 71 | +{ |
| 72 | + return {}; |
| 73 | +} |
| 74 | + |
| 75 | +TEMPLATE |
| 76 | +data_chunk CLASS::get_wire_header(const header_link& link) const NOEXCEPT |
| 77 | +{ |
| 78 | + using namespace system; |
| 79 | + data_chunk data(chain::header::serialized_size()); |
| 80 | + stream::flip::fast ostream(data); |
| 81 | + flip::bytes::fast out(ostream); |
| 82 | + if (!get_wire_header(out, link) || !out) |
| 83 | + data.clear(); |
| 84 | + |
| 85 | + return data; |
| 86 | +} |
| 87 | + |
| 88 | +TEMPLATE |
| 89 | +data_chunk CLASS::get_wire_tx(const tx_link& , bool ) const NOEXCEPT |
| 90 | +{ |
| 91 | + return {}; |
| 92 | +} |
| 93 | + |
| 94 | +TEMPLATE |
| 95 | +data_chunk CLASS::get_wire_block(const header_link& , bool ) const NOEXCEPT |
| 96 | +{ |
| 97 | + return {}; |
| 98 | +} |
| 99 | + |
| 100 | +} // namespace database |
| 101 | +} // namespace libbitcoin |
| 102 | + |
| 103 | +#endif |
0 commit comments