|
20 | 20 | #define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_ELECTRUM_HPP |
21 | 21 |
|
22 | 22 | #include <memory> |
| 23 | +#include <unordered_map> |
23 | 24 | #include <bitcoin/node/channels/channels.hpp> |
24 | 25 | #include <bitcoin/node/define.hpp> |
25 | 26 | #include <bitcoin/node/interfaces/interfaces.hpp> |
@@ -48,70 +49,138 @@ class BCN_API protocol_electrum |
48 | 49 |
|
49 | 50 | protected: |
50 | 51 | /// Handlers (blockchain). |
51 | | - bool handle_blockchain_block_header(const code& ec, |
| 52 | + void handle_blockchain_block_header(const code& ec, |
52 | 53 | rpc_interface::blockchain_block_header, double height, |
53 | 54 | double cp_height) NOEXCEPT; |
54 | | - bool handle_blockchain_block_headers(const code& ec, |
| 55 | + void handle_blockchain_block_headers(const code& ec, |
55 | 56 | rpc_interface::blockchain_block_headers, double start_height, |
56 | 57 | double count, double cp_height) NOEXCEPT; |
57 | | - bool handle_blockchain_headers_subscribe(const code& ec, |
| 58 | + void handle_blockchain_headers_subscribe(const code& ec, |
58 | 59 | rpc_interface::blockchain_headers_subscribe) NOEXCEPT; |
59 | | - bool handle_blockchain_estimatefee(const code& ec, |
| 60 | + void handle_blockchain_estimatefee(const code& ec, |
60 | 61 | rpc_interface::blockchain_estimatefee, double) NOEXCEPT; |
61 | | - bool handle_blockchain_relayfee(const code& ec, |
| 62 | + void handle_blockchain_relayfee(const code& ec, |
62 | 63 | rpc_interface::blockchain_relayfee) NOEXCEPT; |
63 | | - bool handle_blockchain_scripthash_get_balance(const code& ec, |
| 64 | + void handle_blockchain_scripthash_get_balance(const code& ec, |
64 | 65 | rpc_interface::blockchain_scripthash_get_balance, |
65 | 66 | const std::string& scripthash) NOEXCEPT; |
66 | | - bool handle_blockchain_scripthash_get_history(const code& ec, |
| 67 | + void handle_blockchain_scripthash_get_history(const code& ec, |
67 | 68 | rpc_interface::blockchain_scripthash_get_history, |
68 | 69 | const std::string& scripthash) NOEXCEPT; |
69 | | - bool handle_blockchain_scripthash_get_mempool(const code& ec, |
| 70 | + void handle_blockchain_scripthash_get_mempool(const code& ec, |
70 | 71 | rpc_interface::blockchain_scripthash_get_mempool, |
71 | 72 | const std::string& scripthash) NOEXCEPT; |
72 | | - bool handle_blockchain_scripthash_listunspent(const code& ec, |
| 73 | + void handle_blockchain_scripthash_listunspent(const code& ec, |
73 | 74 | rpc_interface::blockchain_scripthash_listunspent, |
74 | 75 | const std::string& scripthash) NOEXCEPT; |
75 | | - bool handle_blockchain_scripthash_subscribe(const code& ec, |
| 76 | + void handle_blockchain_scripthash_subscribe(const code& ec, |
76 | 77 | rpc_interface::blockchain_scripthash_subscribe, |
77 | 78 | const std::string& scripthash) NOEXCEPT; |
78 | | - bool handle_blockchain_scripthash_unsubscribe(const code& ec, |
| 79 | + void handle_blockchain_scripthash_unsubscribe(const code& ec, |
79 | 80 | rpc_interface::blockchain_scripthash_unsubscribe, |
80 | 81 | const std::string& scripthash) NOEXCEPT; |
81 | | - bool handle_blockchain_transaction_broadcast(const code& ec, |
| 82 | + void handle_blockchain_transaction_broadcast(const code& ec, |
82 | 83 | rpc_interface::blockchain_transaction_broadcast, |
83 | 84 | const std::string& raw_tx) NOEXCEPT; |
84 | | - bool handle_blockchain_transaction_get(const code& ec, |
| 85 | + void handle_blockchain_transaction_get(const code& ec, |
85 | 86 | rpc_interface::blockchain_transaction_get, const std::string& tx_hash, |
86 | 87 | bool verbose) NOEXCEPT; |
87 | | - bool handle_blockchain_transaction_get_merkle(const code& ec, |
| 88 | + void handle_blockchain_transaction_get_merkle(const code& ec, |
88 | 89 | rpc_interface::blockchain_transaction_get_merkle, |
89 | 90 | const std::string& tx_hash, double height) NOEXCEPT; |
90 | | - bool handle_blockchain_transaction_id_from_pos(const code& ec, |
| 91 | + void handle_blockchain_transaction_id_from_pos(const code& ec, |
91 | 92 | rpc_interface::blockchain_transaction_id_from_pos, double height, |
92 | 93 | double tx_pos, bool merkle) NOEXCEPT; |
93 | 94 |
|
94 | 95 | /// Handlers (server). |
95 | | - bool handle_server_add_peer(const code& ec, |
| 96 | + void handle_server_add_peer(const code& ec, |
96 | 97 | rpc_interface::server_add_peer, |
97 | | - const network::rpc::object_t& features) NOEXCEPT; |
98 | | - bool handle_server_banner(const code& ec, |
| 98 | + const interface::object_t& features) NOEXCEPT; |
| 99 | + void handle_server_banner(const code& ec, |
99 | 100 | rpc_interface::server_banner) NOEXCEPT; |
100 | | - bool handle_server_donation_address(const code& ec, |
| 101 | + void handle_server_donation_address(const code& ec, |
101 | 102 | rpc_interface::server_donation_address) NOEXCEPT; |
102 | | - bool handle_server_features(const code& ec, |
| 103 | + void handle_server_features(const code& ec, |
103 | 104 | rpc_interface::server_features) NOEXCEPT; |
104 | | - bool handle_server_peers_subscribe(const code& ec, |
| 105 | + void handle_server_peers_subscribe(const code& ec, |
105 | 106 | rpc_interface::server_peers_subscribe) NOEXCEPT; |
106 | | - bool handle_server_ping(const code& ec, |
| 107 | + void handle_server_ping(const code& ec, |
107 | 108 | rpc_interface::server_ping) NOEXCEPT; |
108 | | - bool handle_server_version(const code& ec, |
| 109 | + void handle_server_version(const code& ec, |
109 | 110 | rpc_interface::server_version, const std::string& client_name, |
110 | | - const network::rpc::value_t& protocol_version) NOEXCEPT; |
| 111 | + const interface::value_t& protocol_version) NOEXCEPT; |
111 | 112 |
|
112 | 113 | /// Handlers (mempool). |
113 | | - bool handle_mempool_get_fee_histogram(const code& ec, |
| 114 | + void handle_mempool_get_fee_histogram(const code& ec, |
114 | 115 | rpc_interface::mempool_get_fee_histogram) NOEXCEPT; |
| 116 | + |
| 117 | +protected: |
| 118 | + enum class protocol_version |
| 119 | + { |
| 120 | + /// Invalid version. |
| 121 | + v0_0, |
| 122 | + |
| 123 | + /// 2011, initial protocol negotiation. |
| 124 | + v0_6, |
| 125 | + |
| 126 | + /// 2012, enhanced protocol negotiation. |
| 127 | + v0_8, |
| 128 | + |
| 129 | + /// 2012, added pruning limits and transport indicators. |
| 130 | + v0_9, |
| 131 | + |
| 132 | + /// 2013, baseline for core methods in the official specification. |
| 133 | + v0_10, |
| 134 | + |
| 135 | + /// 2014, 1.x series, deprecations of utxo and block number methods. |
| 136 | + v1_0, |
| 137 | + |
| 138 | + /// 2015, updated version response and introduced scripthash methods. |
| 139 | + v1_1, |
| 140 | + |
| 141 | + /// 2017, added optional parameters for transactions and headers. |
| 142 | + v1_2, |
| 143 | + |
| 144 | + /// 2018, defaulted raw headers and introduced new block methods. |
| 145 | + v1_3, |
| 146 | + |
| 147 | + /// 2019, removed deserialized headers and added merkle proof features. |
| 148 | + v1_4, |
| 149 | + |
| 150 | + /// 2019, modifications for auxiliary proof-of-work handling. |
| 151 | + v1_4_1, |
| 152 | + |
| 153 | + /// 2020, added scripthash unsubscribe functionality. |
| 154 | + v1_4_2, |
| 155 | + |
| 156 | + /// 2022, updated response formats and added fee estimation modes. |
| 157 | + v1_6 |
| 158 | + }; |
| 159 | + |
| 160 | + static constexpr protocol_version minimum = protocol_version::v1_4; |
| 161 | + static constexpr protocol_version maximum = protocol_version::v1_4_2; |
| 162 | + |
| 163 | + protocol_version version() const NOEXCEPT; |
| 164 | + std::string_view get_version() const NOEXCEPT; |
| 165 | + bool is_version(protocol_version version) const NOEXCEPT; |
| 166 | + bool set_version(const interface::value_t& version) NOEXCEPT; |
| 167 | + bool get_versions(protocol_version& min, protocol_version& max, |
| 168 | + const interface::value_t& version) NOEXCEPT; |
| 169 | + |
| 170 | + static std::string_view get_server() NOEXCEPT; |
| 171 | + std::string_view get_client() const NOEXCEPT; |
| 172 | + std::string escape_client(const std::string& in) NOEXCEPT; |
| 173 | + bool set_client(const std::string& name) NOEXCEPT; |
| 174 | + |
| 175 | +private: |
| 176 | + static std::string_view version_to_string( |
| 177 | + protocol_version version) NOEXCEPT; |
| 178 | + static protocol_version version_from_string( |
| 179 | + const std::string_view& version) NOEXCEPT; |
| 180 | + |
| 181 | + // These are protected by strand. |
| 182 | + protocol_version version_{ protocol_version::v0_0 }; |
| 183 | + std::string name_{}; |
115 | 184 | }; |
116 | 185 |
|
117 | 186 | } // namespace node |
|
0 commit comments