Skip to content

Commit 26ee76e

Browse files
committed
Add electrum method versions, refactor test exception safety.
1 parent 74b7f82 commit 26ee76e

16 files changed

Lines changed: 907 additions & 409 deletions

include/bitcoin/server/interfaces/electrum.hpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct electrum_methods
4444
method<"blockchain.scripthash.subscribe", string_t>{ "scripthash" },
4545
method<"blockchain.scripthash.unsubscribe", string_t>{ "scripthash" },
4646
method<"blockchain.transaction.broadcast", string_t>{ "raw_tx" },
47+
method<"blockchain.transaction.broadcast_package", string_t, optional<true>>{ "raw_txs", "verbose" },
4748
method<"blockchain.transaction.get", string_t, boolean_t>{ "tx_hash", "verbose" },
4849
method<"blockchain.transaction.get_merkle", string_t, number_t>{ "tx_hash", "height" },
4950
method<"blockchain.transaction.id_from_pos", number_t, number_t, optional<false>>{ "height", "tx_pos", "merkle" },
@@ -58,7 +59,8 @@ struct electrum_methods
5859
method<"server.version", string_t, optional<empty::value>>{ "client_name", "protocol_version" },
5960

6061
/// Mempool methods.
61-
method<"mempool.get_fee_histogram">{}
62+
method<"mempool.get_fee_histogram">{},
63+
method<"mempool.get_info">{}
6264
};
6365

6466
template <typename... Args>
@@ -80,17 +82,19 @@ struct electrum_methods
8082
using blockchain_scripthash_subscribe = at<9>;
8183
using blockchain_scripthash_unsubscribe = at<10>;
8284
using blockchain_transaction_broadcast = at<11>;
83-
using blockchain_transaction_get = at<12>;
84-
using blockchain_transaction_get_merkle = at<13>;
85-
using blockchain_transaction_id_from_pos = at<14>;
86-
using server_add_peer = at<15>;
87-
using server_banner = at<16>;
88-
using server_donation_address = at<17>;
89-
using server_features = at<18>;
90-
using server_peers_subscribe = at<19>;
91-
using server_ping = at<20>;
92-
using server_version = at<21>;
93-
using mempool_get_fee_histogram = at<22>;
85+
using blockchain_transaction_broadcast_package = at<12>;
86+
using blockchain_transaction_get = at<13>;
87+
using blockchain_transaction_get_merkle = at<14>;
88+
using blockchain_transaction_id_from_pos = at<15>;
89+
using server_add_peer = at<16>;
90+
using server_banner = at<17>;
91+
using server_donation_address = at<18>;
92+
using server_features = at<19>;
93+
using server_peers_subscribe = at<20>;
94+
using server_ping = at<21>;
95+
using server_version = at<22>;
96+
using mempool_get_fee_histogram = at<23>;
97+
using mempool_get_info = at<24>;
9498
};
9599

96100
} // namespace interface

include/bitcoin/server/parsers/electrum_version.hpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ enum class version
3131
/// Invalid version.
3232
v0_0,
3333

34-
/// 2011, initial protocol negotiation.
34+
/// 2011, initial protocol negotiation (usupported).
3535
v0_6,
3636

37-
/// 2012, enhanced protocol negotiation.
37+
/// 2012, enhanced protocol negotiation (usupported).
3838
v0_8,
3939

40-
/// 2012, added pruning limits and transport indicators.
40+
/// 2012, added pruning limits and transport indicators (usupported).
4141
v0_9,
4242

43-
/// 2013, baseline for core methods in the official specification.
43+
/// 2013, baseline for core methods in official specification (usupported).
4444
v0_10,
4545

46-
/// 2014, 1.x series, deprecations of utxo and block number methods.
46+
/// 2014, deprecations of utxo and block number methods (minimum).
4747
v1_0,
4848

4949
/// 2015, updated version response and introduced scripthash methods.
@@ -64,8 +64,14 @@ enum class version
6464
/// 2020, added scripthash unsubscribe functionality.
6565
v1_4_2,
6666

67-
/// 2022, updated response formats and added fee estimation modes.
68-
v1_6
67+
/// There is no v1.5 release (skipped).
68+
//v1_5,
69+
70+
/// 2022, updated response formats, added fee estimation modes (maximum).
71+
v1_6,
72+
73+
/// Not valid, just defined for out of bounds testing.
74+
v1_7
6975
};
7076

7177
std::string_view version_to_string(version value) NOEXCEPT;

include/bitcoin/server/protocols/protocol_electrum.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <bitcoin/server/define.hpp>
2626
#include <bitcoin/server/interfaces/interfaces.hpp>
2727
#include <bitcoin/server/parsers/parsers.hpp>
28+
#include <bitcoin/server/protocols/protocol_electrum_version.hpp>
2829
#include <bitcoin/server/protocols/protocol_rpc.hpp>
2930

3031
namespace libbitcoin {
@@ -91,6 +92,9 @@ class BCS_API protocol_electrum
9192
void handle_blockchain_transaction_broadcast(const code& ec,
9293
rpc_interface::blockchain_transaction_broadcast,
9394
const std::string& raw_tx) NOEXCEPT;
95+
void handle_blockchain_transaction_broadcast_package(const code& ec,
96+
rpc_interface::blockchain_transaction_broadcast_package,
97+
const std::string& raw_txs, bool verbose) NOEXCEPT;
9498
void handle_blockchain_transaction_get(const code& ec,
9599
rpc_interface::blockchain_transaction_get, const std::string& tx_hash,
96100
bool verbose) NOEXCEPT;
@@ -122,6 +126,8 @@ class BCS_API protocol_electrum
122126
/// Handlers (mempool).
123127
void handle_mempool_get_fee_histogram(const code& ec,
124128
rpc_interface::mempool_get_fee_histogram) NOEXCEPT;
129+
void handle_mempool_get_info(const code& ec,
130+
rpc_interface::mempool_get_info) NOEXCEPT;
125131

126132
protected:
127133
/// Common implementation for block_header/s.
@@ -131,7 +137,7 @@ class BCS_API protocol_electrum
131137
/// Notify client of new header.
132138
void do_header(node::header_t link) NOEXCEPT;
133139

134-
inline bool is_version(server::electrum::version version) const NOEXCEPT
140+
inline bool at_least(server::electrum::version version) const NOEXCEPT
135141
{
136142
return channel_->version() >= version;
137143
}
@@ -142,6 +148,13 @@ class BCS_API protocol_electrum
142148
}
143149

144150
private:
151+
using version_t = protocol_electrum_version;
152+
static constexpr electrum::version minimum = version_t::minimum;
153+
static constexpr electrum::version maximum = version_t::maximum;
154+
155+
// Compute server.features.hosts value from config.
156+
network::rpc::object_t advertised_hosts() const NOEXCEPT;
157+
145158
// These are thread safe.
146159
const options_t& options_;
147160
std::atomic_bool subscribed_{};

include/bitcoin/server/protocols/protocol_electrum_version.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class BCS_API protocol_electrum_version
3737
typedef std::shared_ptr<protocol_electrum_version> ptr;
3838
using rpc_interface = interface::electrum;
3939

40-
static constexpr electrum::version minimum = electrum::version::v1_4;
41-
static constexpr electrum::version maximum = electrum::version::v1_4_2;
40+
static constexpr electrum::version minimum = electrum::version::v1_0;
41+
static constexpr electrum::version maximum = electrum::version::v1_6;
4242

4343
inline protocol_electrum_version(const auto& session,
4444
const network::channel::ptr& channel,

src/parsers/electrum_version.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ std::string_view version_to_string(version value) NOEXCEPT
4040
{ version::v1_4, "1.4" },
4141
{ version::v1_4_1, "1.4.1" },
4242
{ version::v1_4_2, "1.4.2" },
43-
{ version::v1_6, "1.6" }
43+
{ version::v1_6, "1.6" },
44+
{ version::v1_7, "1.7" }
4445
};
4546

4647
const auto it = map.find(value);
@@ -63,7 +64,8 @@ version version_from_string( const std::string_view& value) NOEXCEPT
6364
{ "1.4", version::v1_4 },
6465
{ "1.4.1", version::v1_4_1 },
6566
{ "1.4.2", version::v1_4_2 },
66-
{ "1.6", version::v1_6 }
67+
{ "1.6", version::v1_6 },
68+
{ "1.7", version::v1_7 }
6769
};
6870

6971
const auto it = map.find(value);

0 commit comments

Comments
 (0)