Skip to content

Commit c3276ff

Browse files
authored
Merge pull request #945 from evoskuil/master
Stub in all electrum handlers with error::not_implemented.
2 parents 642ca85 + f0828bf commit c3276ff

File tree

7 files changed

+308
-18
lines changed

7 files changed

+308
-18
lines changed

include/bitcoin/node/interfaces/electrum.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ namespace interface {
2828

2929
struct electrum_methods
3030
{
31+
/// Electrum protocol version 1.4.2
3132
static constexpr std::tuple methods
3233
{
3334
/// Blockchain methods.
34-
method<"blockchain.block.header", number_t, optional<0.0>>{ "height", "cp_height" },
35-
method<"blockchain.block.headers", number_t, number_t, optional<0.0>>{ "start_height", "count", "cp_height" },
36-
method<"blockchain.estimatefee", number_t>{ "number" },
35+
method<"blockchain.block.header", number_t, number_t>{ "height", "cp_height" },
36+
method<"blockchain.block.headers", number_t, number_t, number_t>{ "start_height", "count", "cp_height" },
3737
method<"blockchain.headers.subscribe">{},
38+
method<"blockchain.estimatefee", number_t>{ "number" },
3839
method<"blockchain.relayfee">{},
3940
method<"blockchain.scripthash.get_balance", string_t>{ "scripthash" },
4041
method<"blockchain.scripthash.get_history", string_t>{ "scripthash" },
@@ -43,9 +44,9 @@ struct electrum_methods
4344
method<"blockchain.scripthash.subscribe", string_t>{ "scripthash" },
4445
method<"blockchain.scripthash.unsubscribe", string_t>{ "scripthash" },
4546
method<"blockchain.transaction.broadcast", string_t>{ "raw_tx" },
46-
method<"blockchain.transaction.get", string_t, optional<false>>{ "tx_hash", "verbose" },
47+
method<"blockchain.transaction.get", string_t, boolean_t>{ "tx_hash", "verbose" },
4748
method<"blockchain.transaction.get_merkle", string_t, number_t>{ "tx_hash", "height" },
48-
method<"blockchain.transaction.id_from_pos", number_t, number_t, optional<false>>{ "height", "tx_pos", "merkle" },
49+
method<"blockchain.transaction.id_from_pos", number_t, number_t, boolean_t>{ "height", "tx_pos", "merkle" },
4950

5051
/// Server methods.
5152
method<"server.add_peer", object_t>{ "features" },
@@ -54,7 +55,10 @@ struct electrum_methods
5455
method<"server.features">{},
5556
method<"server.peers.subscribe">{},
5657
method<"server.ping">{},
57-
method<"server.version", optional<""_t>, optional<"1.4"_t>>{ "client_name", "protocol_version" }
58+
method<"server.version", string_t, value_t>{ "client_name", "protocol_version" },
59+
60+
/// Mempool methods.
61+
method<"mempool.get_fee_histogram">{}
5862
};
5963

6064
template <typename... Args>
@@ -66,8 +70,8 @@ struct electrum_methods
6670
// Derive this from above in c++26 using reflection.
6771
using blockchain_block_header = at<0>;
6872
using blockchain_block_headers = at<1>;
69-
using blockchain_estimatefee = at<2>;
70-
using blockchain_headers_subscribe = at<3>;
73+
using blockchain_headers_subscribe = at<2>;
74+
using blockchain_estimatefee = at<3>;
7175
using blockchain_relayfee = at<4>;
7276
using blockchain_scripthash_get_balance = at<5>;
7377
using blockchain_scripthash_get_history = at<6>;
@@ -86,6 +90,7 @@ struct electrum_methods
8690
using server_peers_subscribe = at<19>;
8791
using server_ping = at<20>;
8892
using server_version = at<21>;
93+
using mempool_get_fee_histogram = at<22>;
8994
};
9095

9196
} // namespace interface

include/bitcoin/node/interfaces/types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ using string_t = network::rpc::string_t;
4444
using number_t = network::rpc::number_t;
4545
using object_t = network::rpc::object_t;
4646
using array_t = network::rpc::array_t;
47+
using value_t = network::rpc::value_t;
4748

4849
namespace empty { constexpr auto array = network::rpc::empty::array; };
4950
namespace empty { constexpr auto object = network::rpc::empty::object; };
51+
namespace empty { constexpr auto value = network::rpc::empty::value; };
5052

5153
} // namespace interface
5254
} // namespace node

include/bitcoin/node/protocols/protocol_electrum.hpp

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,71 @@ class BCN_API protocol_electrum
4747
void start() NOEXCEPT override;
4848

4949
protected:
50-
/// Handlers.
50+
/// Handlers (blockchain).
51+
bool handle_blockchain_block_header(const code& ec,
52+
rpc_interface::blockchain_block_header, double height,
53+
double cp_height) NOEXCEPT;
54+
bool handle_blockchain_block_headers(const code& ec,
55+
rpc_interface::blockchain_block_headers, double start_height,
56+
double count, double cp_height) NOEXCEPT;
5157
bool handle_blockchain_headers_subscribe(const code& ec,
5258
rpc_interface::blockchain_headers_subscribe) NOEXCEPT;
59+
bool handle_blockchain_estimatefee(const code& ec,
60+
rpc_interface::blockchain_estimatefee, double) NOEXCEPT;
5361
bool handle_blockchain_relayfee(const code& ec,
5462
rpc_interface::blockchain_relayfee) NOEXCEPT;
63+
bool handle_blockchain_scripthash_get_balance(const code& ec,
64+
rpc_interface::blockchain_scripthash_get_balance,
65+
const std::string& scripthash) NOEXCEPT;
66+
bool handle_blockchain_scripthash_get_history(const code& ec,
67+
rpc_interface::blockchain_scripthash_get_history,
68+
const std::string& scripthash) NOEXCEPT;
69+
bool handle_blockchain_scripthash_get_mempool(const code& ec,
70+
rpc_interface::blockchain_scripthash_get_mempool,
71+
const std::string& scripthash) NOEXCEPT;
72+
bool handle_blockchain_scripthash_listunspent(const code& ec,
73+
rpc_interface::blockchain_scripthash_listunspent,
74+
const std::string& scripthash) NOEXCEPT;
75+
bool handle_blockchain_scripthash_subscribe(const code& ec,
76+
rpc_interface::blockchain_scripthash_subscribe,
77+
const std::string& scripthash) NOEXCEPT;
78+
bool handle_blockchain_scripthash_unsubscribe(const code& ec,
79+
rpc_interface::blockchain_scripthash_unsubscribe,
80+
const std::string& scripthash) NOEXCEPT;
81+
bool handle_blockchain_transaction_broadcast(const code& ec,
82+
rpc_interface::blockchain_transaction_broadcast,
83+
const std::string& raw_tx) NOEXCEPT;
84+
bool handle_blockchain_transaction_get(const code& ec,
85+
rpc_interface::blockchain_transaction_get, const std::string& tx_hash,
86+
bool verbose) NOEXCEPT;
87+
bool handle_blockchain_transaction_get_merkle(const code& ec,
88+
rpc_interface::blockchain_transaction_get_merkle,
89+
const std::string& tx_hash, double height) NOEXCEPT;
90+
bool handle_blockchain_transaction_id_from_pos(const code& ec,
91+
rpc_interface::blockchain_transaction_id_from_pos, double height,
92+
double tx_pos, bool merkle) NOEXCEPT;
93+
94+
/// Handlers (server).
95+
bool handle_server_add_peer(const code& ec,
96+
rpc_interface::server_add_peer,
97+
const network::rpc::object_t& features) NOEXCEPT;
98+
bool handle_server_banner(const code& ec,
99+
rpc_interface::server_banner) NOEXCEPT;
100+
bool handle_server_donation_address(const code& ec,
101+
rpc_interface::server_donation_address) NOEXCEPT;
102+
bool handle_server_features(const code& ec,
103+
rpc_interface::server_features) NOEXCEPT;
104+
bool handle_server_peers_subscribe(const code& ec,
105+
rpc_interface::server_peers_subscribe) NOEXCEPT;
106+
bool handle_server_ping(const code& ec,
107+
rpc_interface::server_ping) NOEXCEPT;
108+
bool handle_server_version(const code& ec,
109+
rpc_interface::server_version, const std::string& client_name,
110+
const network::rpc::value_t& protocol_version) NOEXCEPT;
111+
112+
/// Handlers (mempool).
113+
bool handle_mempool_get_fee_histogram(const code& ec,
114+
rpc_interface::mempool_get_fee_histogram) NOEXCEPT;
55115
};
56116

57117
} // namespace node

include/bitcoin/node/protocols/protocol_rpc.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace libbitcoin {
2828
namespace node {
29-
29+
3030
/// Abstract base for RPC protocols, thread safe.
3131
template <typename Interface>
3232
class BCN_API protocol_rpc
@@ -47,6 +47,10 @@ class BCN_API protocol_rpc
4747
}
4848
};
4949

50+
#define SUBSCRIBE_RPC(...) SUBSCRIBE_CHANNEL(void, __VA_ARGS__)
51+
#define SEND_RPC(message, size_hint, method, ...) \
52+
send<CLASS>(message, size_hint, &CLASS::method, __VA_ARGS__)
53+
5054
} // namespace node
5155
} // namespace libbitcoin
5256

src/protocols/protocol_bitcoind_rpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ bool protocol_bitcoind_rpc::handle_verify_tx_out_set(const code& ec,
344344
return true;
345345
}
346346

347-
// Senders
347+
// Senders.
348348
// ----------------------------------------------------------------------------
349349

350350
void protocol_bitcoind_rpc::send_error(const code& ec) NOEXCEPT

0 commit comments

Comments
 (0)