forked from libbitcoin/libbitcoin-node
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprotocol_explore.hpp
More file actions
180 lines (158 loc) · 7.85 KB
/
protocol_explore.hpp
File metadata and controls
180 lines (158 loc) · 7.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_EXPLORE_HPP
#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_EXPLORE_HPP
#include <atomic>
#include <memory>
#include <optional>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/protocols/protocol_html.hpp>
namespace libbitcoin {
namespace node {
class BCN_API protocol_explore
: public node::protocol_html,
protected network::tracker<protocol_explore>
{
public:
typedef std::shared_ptr<protocol_explore> ptr;
using interface = network::rpc::interface::explore;
using dispatcher = network::rpc::dispatcher<interface>;
protocol_explore(const auto& session,
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
: node::protocol_html(session, channel, options),
network::tracker<protocol_explore>(session->log)
{
}
void start() NOEXCEPT override;
void stopping(const code& ec) NOEXCEPT override;
protected:
template <class Derived, typename Method, typename... Args>
inline void subscribe(Method&& method, Args&&... args) NOEXCEPT
{
dispatcher_.subscribe(BIND_SHARED(method, args));
}
/// Dispatch.
bool try_dispatch_object(
const network::http::request& request) NOEXCEPT override;
/// REST interface handlers.
bool handle_get_top(const code& ec, interface::top,
uint8_t version, uint8_t media) NOEXCEPT;
bool handle_get_block(const code& ec, interface::block,
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height, bool witness) NOEXCEPT;
bool handle_get_block_header(const code& ec, interface::block_header,
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_block_txs(const code& ec, interface::block_txs,
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_block_fees(const code& ec, interface::block_fees,
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_block_filter(const code& ec, interface::block_filter,
uint8_t version, uint8_t media, uint8_t type,
std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_block_filter_hash(const code& ec,
interface::block_filter_hash, uint8_t version, uint8_t media,
uint8_t type, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_block_filter_header(const code& ec,
interface::block_filter_header, uint8_t version, uint8_t media,
uint8_t type, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_block_tx(const code& ec, interface::block_tx,
uint8_t version, uint8_t media, uint32_t position,
std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height, bool witness) NOEXCEPT;
bool handle_get_tx(const code& ec, interface::tx,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
bool witness) NOEXCEPT;
bool handle_get_tx_header(const code& ec, interface::tx_header,
uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
bool handle_get_tx_fee(const code& ec, interface::tx_fee,
uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
bool handle_get_inputs(const code& ec, interface::inputs,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
bool witness) NOEXCEPT;
bool handle_get_input(const code& ec, interface::input,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index, bool witness) NOEXCEPT;
bool handle_get_input_script(const code& ec, interface::input_script,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_input_witness(const code& ec, interface::input_witness,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_outputs(const code& ec, interface::outputs,
uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
bool handle_get_output(const code& ec, interface::output,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_output_script(const code& ec, interface::output_script,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_output_spender(const code& ec, interface::output_spender,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_output_spenders(const code& ec, interface::output_spenders,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_address(const code& ec, interface::address,
uint8_t version, uint8_t media,
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
bool handle_get_address_confirmed(const code& ec,
interface::address_confirmed, uint8_t version, uint8_t media,
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
bool handle_get_address_unconfirmed(const code& ec,
interface::address_unconfirmed, uint8_t version, uint8_t media,
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
bool handle_get_address_balance(const code& ec,
interface::address_balance, uint8_t version, uint8_t media,
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
private:
using balance_handler = std::function<void(code, uint8_t, uint64_t)>;
using address_handler = std::function<void(code, uint8_t,
database::outpoints&&)>;
void do_get_address(uint8_t media, bool turbo,
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
void do_get_address_confirmed(uint8_t media, bool turbo,
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
void do_get_address_unconfirmed(uint8_t media, bool turbo,
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
void complete_get_address(const code& ec, uint8_t media,
const database::outpoints& set) NOEXCEPT;
void do_get_address_balance(uint8_t media, bool turbo,
const system::hash_cptr& hash, const balance_handler& handler) NOEXCEPT;
void complete_get_address_balance(const code& ec, uint8_t media,
const uint64_t balance) NOEXCEPT;
void inject(boost::json::value& out, std::optional<uint32_t> height,
const database::header_link& link) const NOEXCEPT;
database::header_link to_header(const std::optional<uint32_t>& height,
const std::optional<system::hash_cptr>& hash) NOEXCEPT;
dispatcher dispatcher_{};
std::atomic_bool stopping_{};
};
} // namespace node
} // namespace libbitcoin
#endif