forked from libbitcoin/libbitcoin-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprotocol_electrum.hpp
More file actions
169 lines (150 loc) · 6.85 KB
/
protocol_electrum.hpp
File metadata and controls
169 lines (150 loc) · 6.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
/**
* Copyright (c) 2011-2026 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_SERVER_PROTOCOLS_PROTOCOL_ELECTRUM_HPP
#define LIBBITCOIN_SERVER_PROTOCOLS_PROTOCOL_ELECTRUM_HPP
#include <memory>
#include <unordered_map>
#include <bitcoin/server/channels/channels.hpp>
#include <bitcoin/server/define.hpp>
#include <bitcoin/server/interfaces/interfaces.hpp>
#include <bitcoin/server/parsers/parsers.hpp>
#include <bitcoin/server/protocols/protocol_electrum_version.hpp>
#include <bitcoin/server/protocols/protocol_rpc.hpp>
namespace libbitcoin {
namespace server {
class BCS_API protocol_electrum
: public protocol_rpc<channel_electrum>,
protected network::tracker<protocol_electrum>
{
public:
typedef std::shared_ptr<protocol_electrum> ptr;
using rpc_interface = interface::electrum;
inline protocol_electrum(const auto& session,
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
: protocol_rpc<channel_electrum>(session, channel, options),
options_(options),
channel_(std::dynamic_pointer_cast<channel_t>(channel)),
network::tracker<protocol_electrum>(session->log)
{
}
void start() NOEXCEPT override;
void stopping(const code& ec) NOEXCEPT override;
protected:
/// Handlers (event subscription).
bool handle_event(const code&, node::chase event_,
node::event_value) NOEXCEPT;
/// Handlers (blockchain).
void handle_blockchain_block_header(const code& ec,
rpc_interface::blockchain_block_header, double height,
double cp_height) NOEXCEPT;
void handle_blockchain_block_headers(const code& ec,
rpc_interface::blockchain_block_headers, double start_height,
double count, double cp_height) NOEXCEPT;
void handle_blockchain_headers_subscribe(const code& ec,
rpc_interface::blockchain_headers_subscribe) NOEXCEPT;
void handle_blockchain_estimate_fee(const code& ec,
rpc_interface::blockchain_estimate_fee, double number,
const std::string& mode) NOEXCEPT;
void handle_blockchain_relay_fee(const code& ec,
rpc_interface::blockchain_relay_fee) NOEXCEPT;
void handle_blockchain_scripthash_get_balance(const code& ec,
rpc_interface::blockchain_scripthash_get_balance,
const std::string& scripthash) NOEXCEPT;
void handle_blockchain_scripthash_get_history(const code& ec,
rpc_interface::blockchain_scripthash_get_history,
const std::string& scripthash) NOEXCEPT;
void handle_blockchain_scripthash_get_mempool(const code& ec,
rpc_interface::blockchain_scripthash_get_mempool,
const std::string& scripthash) NOEXCEPT;
void handle_blockchain_scripthash_list_unspent(const code& ec,
rpc_interface::blockchain_scripthash_list_unspent,
const std::string& scripthash) NOEXCEPT;
void handle_blockchain_scripthash_subscribe(const code& ec,
rpc_interface::blockchain_scripthash_subscribe,
const std::string& scripthash) NOEXCEPT;
void handle_blockchain_scripthash_unsubscribe(const code& ec,
rpc_interface::blockchain_scripthash_unsubscribe,
const std::string& scripthash) NOEXCEPT;
void handle_blockchain_transaction_broadcast(const code& ec,
rpc_interface::blockchain_transaction_broadcast,
const std::string& raw_tx) NOEXCEPT;
void handle_blockchain_transaction_broadcast_package(const code& ec,
rpc_interface::blockchain_transaction_broadcast_package,
const std::string& raw_txs, bool verbose) NOEXCEPT;
void handle_blockchain_transaction_get(const code& ec,
rpc_interface::blockchain_transaction_get, const std::string& tx_hash,
bool verbose) NOEXCEPT;
void handle_blockchain_transaction_get_merkle(const code& ec,
rpc_interface::blockchain_transaction_get_merkle,
const std::string& tx_hash, double height) NOEXCEPT;
void handle_blockchain_transaction_id_from_pos(const code& ec,
rpc_interface::blockchain_transaction_id_from_pos, double height,
double tx_pos, bool merkle) NOEXCEPT;
/// Handlers (server).
void handle_server_add_peer(const code& ec,
rpc_interface::server_add_peer,
const interface::object_t& features) NOEXCEPT;
void handle_server_banner(const code& ec,
rpc_interface::server_banner) NOEXCEPT;
void handle_server_donation_address(const code& ec,
rpc_interface::server_donation_address) NOEXCEPT;
void handle_server_features(const code& ec,
rpc_interface::server_features) NOEXCEPT;
void handle_server_peers_subscribe(const code& ec,
rpc_interface::server_peers_subscribe) NOEXCEPT;
void handle_server_ping(const code& ec,
rpc_interface::server_ping) NOEXCEPT;
////void handle_server_version(const code& ec,
//// rpc_interface::server_version, const std::string& client_name,
//// const interface::value_t& protocol_version) NOEXCEPT;
/// Handlers (mempool).
void handle_mempool_get_fee_histogram(const code& ec,
rpc_interface::mempool_get_fee_histogram) NOEXCEPT;
void handle_mempool_get_info(const code& ec,
rpc_interface::mempool_get_info) NOEXCEPT;
protected:
/// Common implementation for block_header/s.
void blockchain_block_headers(size_t starting, size_t quantity,
size_t waypoint, bool multiplicity) NOEXCEPT;
/// Notify client of new header.
void do_header(node::header_t link) NOEXCEPT;
inline bool at_least(server::electrum::version version) const NOEXCEPT
{
return channel_->version() >= version;
}
inline const options_t& options() const NOEXCEPT
{
return options_;
}
private:
using version_t = protocol_electrum_version;
static constexpr electrum::version minimum = version_t::minimum;
static constexpr electrum::version maximum = version_t::maximum;
// Compute server.features.hosts value from config.
network::rpc::object_t advertised_hosts() const NOEXCEPT;
// These are thread safe.
const options_t& options_;
std::atomic_bool subscribed_{};
// This is mostly thread safe, and used in a thread safe manner.
const channel_t::ptr channel_;
};
} // namespace server
} // namespace libbitcoin
#endif