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
31 changes: 31 additions & 0 deletions include/bitcoin/node/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ using type_id = network::messages::peer::inventory_item::type_id;
} // namespace node
} // namespace libbitcoin

/// Augment limited xcode placeholder defines (10 vs. common 20).
/// ---------------------------------------------------------------------------
#if defined (HAVE_XCODE)

/// Define custom placeholder types in the global namespace to avoid conflicts.
struct placeholder_11 {};
struct placeholder_12 {};
struct placeholder_13 {};

/// Specialize std::is_placeholder within the std namespace.
namespace std
{
template <>
struct is_placeholder<::placeholder_11> : integral_constant<int, 11> {};
template <>
struct is_placeholder<::placeholder_12> : integral_constant<int, 12> {};
template <>
struct is_placeholder<::placeholder_13> : integral_constant<int, 13> {};
}

/// Add instances to std::placeholders for standard usage syntax.
namespace std::placeholders
{
inline constexpr ::placeholder_11 _11{};
inline constexpr ::placeholder_12 _12{};
inline constexpr ::placeholder_13 _13{};
}

#endif // HAVE_XCODE
/// ---------------------------------------------------------------------------

#endif

// define.hpp is the common include for /node.
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/interfaces/electrum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ struct electrum_methods
method<"server.features">{},
method<"server.peers.subscribe">{},
method<"server.ping">{},
method<"server.version", string_t, value_t>{ "client_name", "protocol_version" },
method<"server.version", string_t, optional<empty::value>>{ "client_name", "protocol_version" },

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

template <typename... Args>
using subscriber = network::unsubscriber<Args...>;
using subscriber = network::subscriber<Args...>;

template <size_t Index>
using at = method_at<methods, Index>;
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node/interfaces/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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;
using null_t = network::rpc::null_t;

namespace empty { constexpr auto array = network::rpc::empty::array; };
namespace empty { constexpr auto object = network::rpc::empty::object; };
Expand Down
119 changes: 94 additions & 25 deletions include/bitcoin/node/protocols/protocol_electrum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define LIBBITCOIN_NODE_PROTOCOLS_PROTOCOL_ELECTRUM_HPP

#include <memory>
#include <unordered_map>
#include <bitcoin/node/channels/channels.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/interfaces/interfaces.hpp>
Expand Down Expand Up @@ -48,70 +49,138 @@ class BCN_API protocol_electrum

protected:
/// Handlers (blockchain).
bool handle_blockchain_block_header(const code& ec,
void 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,
void 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,
void handle_blockchain_headers_subscribe(const code& ec,
rpc_interface::blockchain_headers_subscribe) NOEXCEPT;
bool handle_blockchain_estimatefee(const code& ec,
void handle_blockchain_estimatefee(const code& ec,
rpc_interface::blockchain_estimatefee, double) NOEXCEPT;
bool handle_blockchain_relayfee(const code& ec,
void handle_blockchain_relayfee(const code& ec,
rpc_interface::blockchain_relayfee) NOEXCEPT;
bool handle_blockchain_scripthash_get_balance(const code& ec,
void 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,
void 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,
void 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,
void 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,
void 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,
void 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,
void 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,
void 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,
void 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,
void 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,
void 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,
const interface::object_t& features) NOEXCEPT;
void handle_server_banner(const code& ec,
rpc_interface::server_banner) NOEXCEPT;
bool handle_server_donation_address(const code& ec,
void handle_server_donation_address(const code& ec,
rpc_interface::server_donation_address) NOEXCEPT;
bool handle_server_features(const code& ec,
void handle_server_features(const code& ec,
rpc_interface::server_features) NOEXCEPT;
bool handle_server_peers_subscribe(const code& ec,
void handle_server_peers_subscribe(const code& ec,
rpc_interface::server_peers_subscribe) NOEXCEPT;
bool handle_server_ping(const code& ec,
void handle_server_ping(const code& ec,
rpc_interface::server_ping) NOEXCEPT;
bool handle_server_version(const code& ec,
void handle_server_version(const code& ec,
rpc_interface::server_version, const std::string& client_name,
const network::rpc::value_t& protocol_version) NOEXCEPT;
const interface::value_t& protocol_version) NOEXCEPT;

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

protected:
enum class protocol_version
{
/// Invalid version.
v0_0,

/// 2011, initial protocol negotiation.
v0_6,

/// 2012, enhanced protocol negotiation.
v0_8,

/// 2012, added pruning limits and transport indicators.
v0_9,

/// 2013, baseline for core methods in the official specification.
v0_10,

/// 2014, 1.x series, deprecations of utxo and block number methods.
v1_0,

/// 2015, updated version response and introduced scripthash methods.
v1_1,

/// 2017, added optional parameters for transactions and headers.
v1_2,

/// 2018, defaulted raw headers and introduced new block methods.
v1_3,

/// 2019, removed deserialized headers and added merkle proof features.
v1_4,

/// 2019, modifications for auxiliary proof-of-work handling.
v1_4_1,

/// 2020, added scripthash unsubscribe functionality.
v1_4_2,

/// 2022, updated response formats and added fee estimation modes.
v1_6
};

static constexpr protocol_version minimum = protocol_version::v1_4;
static constexpr protocol_version maximum = protocol_version::v1_4_2;

protocol_version version() const NOEXCEPT;
std::string_view get_version() const NOEXCEPT;
bool is_version(protocol_version version) const NOEXCEPT;
bool set_version(const interface::value_t& version) NOEXCEPT;
bool get_versions(protocol_version& min, protocol_version& max,
const interface::value_t& version) NOEXCEPT;

static std::string_view get_server() NOEXCEPT;
std::string_view get_client() 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(
protocol_version version) NOEXCEPT;
static protocol_version version_from_string(
const std::string_view& version) NOEXCEPT;

// These are protected by strand.
protocol_version version_{ protocol_version::v0_0 };
std::string name_{};
};

} // namespace node
Expand Down
36 changes: 35 additions & 1 deletion include/bitcoin/node/protocols/protocol_stratum_v1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,43 @@ class BCN_API protocol_stratum_v1
void start() NOEXCEPT override;

protected:
/// Handlers.
/// Handlers (client requests).
bool handle_mining_subscribe(const code& ec,
rpc_interface::mining_subscribe, const std::string& user_agent,
double extranonce1_size) NOEXCEPT;
bool handle_mining_authorize(const code& ec,
rpc_interface::mining_authorize, const std::string& username,
const std::string& password) NOEXCEPT;
bool handle_mining_submit(const code& ec,
rpc_interface::mining_submit, const std::string& worker_name,
const std::string& job_id, const std::string& extranonce2,
double ntime, const std::string& nonce) NOEXCEPT;
bool handle_mining_extranonce_subscribe(const code& ec,
rpc_interface::mining_extranonce_subscribe) NOEXCEPT;
bool handle_mining_extranonce_unsubscribe(const code& ec,
rpc_interface::mining_extranonce_unsubscribe, double id) NOEXCEPT;

/// Handlers (server notifications).
bool handle_mining_configure(const code& ec,
rpc_interface::mining_configure,
const interface::object_t& extensions) NOEXCEPT;
bool handle_mining_set_difficulty(const code& ec,
rpc_interface::mining_set_difficulty, double difficulty) NOEXCEPT;
bool handle_mining_notify(const code& ec,
rpc_interface::mining_notify, const std::string& job_id,
const std::string& prevhash, const std::string& coinb1,
const std::string& coinb2, const interface::array_t& merkle_branch,
double version, double nbits, double ntime, bool clean_jobs,
bool hash1, bool hash2) NOEXCEPT;
bool handle_client_reconnect(const code& ec,
rpc_interface::client_reconnect, const std::string& url, double port,
double id) NOEXCEPT;
bool handle_client_hello(const code& ec,
rpc_interface::client_hello,
const interface::object_t& protocol) NOEXCEPT;
bool handle_client_rejected(const code& ec,
rpc_interface::client_rejected, const std::string& job_id,
const std::string& reject_reason) NOEXCEPT;
};

} // namespace node
Expand Down
7 changes: 3 additions & 4 deletions include/bitcoin/node/sessions/session_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ class session_server
}

/// Override to implement a connection handshake as required. By default
/// this is bypassed, which applies to basic http services. A handshake
/// is used to implement TLS and WebSocket upgrade from http (for example).
/// Handshake protocol(s) must invoke handler one time at completion.
/// Use std::dynamic_pointer_cast<channel_t>(channel) to obtain channel_t.
/// this is bypassed, which applies to basic http services. Handshake
/// protocol(s) must invoke handler one time at completion. Use
/// std::dynamic_pointer_cast<channel_t>(channel) to obtain channel_t.
inline void attach_handshake(const channel_ptr& channel,
network::result_handler&& handler) NOEXCEPT override
{
Expand Down
6 changes: 3 additions & 3 deletions src/protocols/protocol_bitcoind_rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ void protocol_bitcoind_rest::handle_receive_get(const code& ec,
// Handlers.
// ----------------------------------------------------------------------------

constexpr auto data = to_value(media_type::application_octet_stream);
constexpr auto json = to_value(media_type::application_json);
constexpr auto text = to_value(media_type::text_plain);
////constexpr auto data = to_value(media_type::application_octet_stream);
////constexpr auto json = to_value(media_type::application_json);
////constexpr auto text = to_value(media_type::text_plain);

bool protocol_bitcoind_rest::handle_get_block(const code& ec,
rest_interface::block, uint8_t , system::hash_cptr ) NOEXCEPT
Expand Down
Loading
Loading