Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions include/bitcoin/node/interfaces/electrum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ namespace interface {

struct electrum_methods
{
/// Electrum protocol version 1.4.2
static constexpr std::tuple methods
{
/// Blockchain methods.
method<"blockchain.block.header", number_t, optional<0.0>>{ "height", "cp_height" },
method<"blockchain.block.headers", number_t, number_t, optional<0.0>>{ "start_height", "count", "cp_height" },
method<"blockchain.estimatefee", number_t>{ "number" },
method<"blockchain.block.header", number_t, number_t>{ "height", "cp_height" },
method<"blockchain.block.headers", number_t, number_t, number_t>{ "start_height", "count", "cp_height" },
method<"blockchain.headers.subscribe">{},
method<"blockchain.estimatefee", number_t>{ "number" },
method<"blockchain.relayfee">{},
method<"blockchain.scripthash.get_balance", string_t>{ "scripthash" },
method<"blockchain.scripthash.get_history", string_t>{ "scripthash" },
Expand All @@ -43,9 +44,9 @@ struct electrum_methods
method<"blockchain.scripthash.subscribe", string_t>{ "scripthash" },
method<"blockchain.scripthash.unsubscribe", string_t>{ "scripthash" },
method<"blockchain.transaction.broadcast", string_t>{ "raw_tx" },
method<"blockchain.transaction.get", string_t, optional<false>>{ "tx_hash", "verbose" },
method<"blockchain.transaction.get", string_t, boolean_t>{ "tx_hash", "verbose" },
method<"blockchain.transaction.get_merkle", string_t, number_t>{ "tx_hash", "height" },
method<"blockchain.transaction.id_from_pos", number_t, number_t, optional<false>>{ "height", "tx_pos", "merkle" },
method<"blockchain.transaction.id_from_pos", number_t, number_t, boolean_t>{ "height", "tx_pos", "merkle" },

/// Server methods.
method<"server.add_peer", object_t>{ "features" },
Expand All @@ -54,7 +55,10 @@ struct electrum_methods
method<"server.features">{},
method<"server.peers.subscribe">{},
method<"server.ping">{},
method<"server.version", optional<""_t>, optional<"1.4"_t>>{ "client_name", "protocol_version" }
method<"server.version", string_t, value_t>{ "client_name", "protocol_version" },

/// Mempool methods.
method<"mempool.get_fee_histogram">{}
};

template <typename... Args>
Expand All @@ -66,8 +70,8 @@ struct electrum_methods
// Derive this from above in c++26 using reflection.
using blockchain_block_header = at<0>;
using blockchain_block_headers = at<1>;
using blockchain_estimatefee = at<2>;
using blockchain_headers_subscribe = at<3>;
using blockchain_headers_subscribe = at<2>;
using blockchain_estimatefee = at<3>;
using blockchain_relayfee = at<4>;
using blockchain_scripthash_get_balance = at<5>;
using blockchain_scripthash_get_history = at<6>;
Expand All @@ -86,6 +90,7 @@ struct electrum_methods
using server_peers_subscribe = at<19>;
using server_ping = at<20>;
using server_version = at<21>;
using mempool_get_fee_histogram = at<22>;
};

} // namespace interface
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/node/interfaces/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ using string_t = network::rpc::string_t;
using number_t = network::rpc::number_t;
using object_t = network::rpc::object_t;
using array_t = network::rpc::array_t;
using value_t = network::rpc::value_t;

namespace empty { constexpr auto array = network::rpc::empty::array; };
namespace empty { constexpr auto object = network::rpc::empty::object; };
namespace empty { constexpr auto value = network::rpc::empty::value; };

} // namespace interface
} // namespace node
Expand Down
62 changes: 61 additions & 1 deletion include/bitcoin/node/protocols/protocol_electrum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,71 @@ class BCN_API protocol_electrum
void start() NOEXCEPT override;

protected:
/// Handlers.
/// Handlers (blockchain).
bool handle_blockchain_block_header(const code& ec,
rpc_interface::blockchain_block_header, double height,
double cp_height) NOEXCEPT;
bool handle_blockchain_block_headers(const code& ec,
rpc_interface::blockchain_block_headers, double start_height,
double count, double cp_height) NOEXCEPT;
bool handle_blockchain_headers_subscribe(const code& ec,
rpc_interface::blockchain_headers_subscribe) NOEXCEPT;
bool handle_blockchain_estimatefee(const code& ec,
rpc_interface::blockchain_estimatefee, double) NOEXCEPT;
bool handle_blockchain_relayfee(const code& ec,
rpc_interface::blockchain_relayfee) NOEXCEPT;
bool handle_blockchain_scripthash_get_balance(const code& ec,
rpc_interface::blockchain_scripthash_get_balance,
const std::string& scripthash) NOEXCEPT;
bool handle_blockchain_scripthash_get_history(const code& ec,
rpc_interface::blockchain_scripthash_get_history,
const std::string& scripthash) NOEXCEPT;
bool handle_blockchain_scripthash_get_mempool(const code& ec,
rpc_interface::blockchain_scripthash_get_mempool,
const std::string& scripthash) NOEXCEPT;
bool handle_blockchain_scripthash_listunspent(const code& ec,
rpc_interface::blockchain_scripthash_listunspent,
const std::string& scripthash) NOEXCEPT;
bool handle_blockchain_scripthash_subscribe(const code& ec,
rpc_interface::blockchain_scripthash_subscribe,
const std::string& scripthash) NOEXCEPT;
bool handle_blockchain_scripthash_unsubscribe(const code& ec,
rpc_interface::blockchain_scripthash_unsubscribe,
const std::string& scripthash) NOEXCEPT;
bool handle_blockchain_transaction_broadcast(const code& ec,
rpc_interface::blockchain_transaction_broadcast,
const std::string& raw_tx) NOEXCEPT;
bool handle_blockchain_transaction_get(const code& ec,
rpc_interface::blockchain_transaction_get, const std::string& tx_hash,
bool verbose) NOEXCEPT;
bool handle_blockchain_transaction_get_merkle(const code& ec,
rpc_interface::blockchain_transaction_get_merkle,
const std::string& tx_hash, double height) NOEXCEPT;
bool 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).
bool handle_server_add_peer(const code& ec,
rpc_interface::server_add_peer,
const network::rpc::object_t& features) NOEXCEPT;
bool handle_server_banner(const code& ec,
rpc_interface::server_banner) NOEXCEPT;
bool handle_server_donation_address(const code& ec,
rpc_interface::server_donation_address) NOEXCEPT;
bool handle_server_features(const code& ec,
rpc_interface::server_features) NOEXCEPT;
bool handle_server_peers_subscribe(const code& ec,
rpc_interface::server_peers_subscribe) NOEXCEPT;
bool handle_server_ping(const code& ec,
rpc_interface::server_ping) NOEXCEPT;
bool handle_server_version(const code& ec,
rpc_interface::server_version, const std::string& client_name,
const network::rpc::value_t& protocol_version) NOEXCEPT;

/// Handlers (mempool).
bool handle_mempool_get_fee_histogram(const code& ec,
rpc_interface::mempool_get_fee_histogram) NOEXCEPT;
};

} // namespace node
Expand Down
6 changes: 5 additions & 1 deletion include/bitcoin/node/protocols/protocol_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace libbitcoin {
namespace node {

/// Abstract base for RPC protocols, thread safe.
template <typename Interface>
class BCN_API protocol_rpc
Expand All @@ -47,6 +47,10 @@ class BCN_API protocol_rpc
}
};

#define SUBSCRIBE_RPC(...) SUBSCRIBE_CHANNEL(void, __VA_ARGS__)
#define SEND_RPC(message, size_hint, method, ...) \
send<CLASS>(message, size_hint, &CLASS::method, __VA_ARGS__)

} // namespace node
} // namespace libbitcoin

Expand Down
2 changes: 1 addition & 1 deletion src/protocols/protocol_bitcoind_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ bool protocol_bitcoind_rpc::handle_verify_tx_out_set(const code& ec,
return true;
}

// Senders
// Senders.
// ----------------------------------------------------------------------------

void protocol_bitcoind_rpc::send_error(const code& ec) NOEXCEPT
Expand Down
Loading
Loading