forked from libbitcoin/libbitcoin-node
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprotocol_electrum_version.hpp
More file actions
89 lines (75 loc) · 3.28 KB
/
protocol_electrum_version.hpp
File metadata and controls
89 lines (75 loc) · 3.28 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
/**
* 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_ELECTRUM_VERSION_HPP
#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_ELECTRUM_VERSION_HPP
#include <memory>
#include <unordered_map>
#include <bitcoin/node/channels/channels.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/interfaces/interfaces.hpp>
#include <bitcoin/node/parsers/parsers.hpp>
#include <bitcoin/node/protocols/protocol_rpc.hpp>
namespace libbitcoin {
namespace node {
class BCN_API protocol_electrum_version
: public node::protocol_rpc<channel_electrum>,
protected network::tracker<protocol_electrum_version>
{
public:
typedef std::shared_ptr<protocol_electrum_version> ptr;
using rpc_interface = interface::electrum;
inline protocol_electrum_version(const auto& session,
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
: node::protocol_rpc<channel_electrum>(session, channel, options),
channel_(std::dynamic_pointer_cast<channel_t>(channel)),
network::tracker<protocol_electrum_version>(session->log)
{
}
virtual void shake(network::result_handler&& handler) NOEXCEPT;
virtual void complete(const code& ec, const code& shake) NOEXCEPT;
protected:
static constexpr electrum_version minimum = electrum_version::v1_4;
static constexpr electrum_version maximum = electrum_version::v1_4_2;
static constexpr size_t max_client_name_length = 1024;
void handle_server_version(const code& ec,
rpc_interface::server_version, const std::string& client_name,
const interface::value_t& protocol_version) NOEXCEPT;
electrum_version version() const NOEXCEPT;
std::string_view negotiated_version() const NOEXCEPT;
bool set_version(const interface::value_t& version) NOEXCEPT;
bool get_versions(electrum_version& min, electrum_version& max,
const interface::value_t& version) NOEXCEPT;
std::string_view server_name() const NOEXCEPT;
std::string_view client_name() const NOEXCEPT;
std::string escape_client(const std::string& in) NOEXCEPT;
bool set_client(const std::string& name) NOEXCEPT;
private:
static std::string_view version_to_string(
electrum_version version) NOEXCEPT;
static electrum_version version_from_string(
const std::string_view& version) NOEXCEPT;
// This is mostly thread safe, and used in a thread safe manner.
const channel_t::ptr channel_;
// This is protected by strand.
std::shared_ptr<network::result_handler> handler_{};
};
} // namespace node
} // namespace libbitcoin
#endif