Skip to content
Open
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
12 changes: 10 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ src_libbitcoin_server_la_SOURCES = \
src/settings.cpp \
src/parsers/bitcoind_query.cpp \
src/parsers/bitcoind_target.cpp \
src/parsers/electrum_version.cpp \
src/parsers/native_query.cpp \
src/parsers/native_target.cpp \
src/protocols/protocol_bitcoind_rest.cpp \
Expand Down Expand Up @@ -71,11 +72,18 @@ test_libbitcoin_server_test_SOURCES = \
test/settings.cpp \
test/test.cpp \
test/test.hpp \
test/endpoints/electrum.cpp \
test/parsers/bitcoind_query.cpp \
test/parsers/bitcoind_target.cpp \
test/parsers/electrum_version.cpp \
test/parsers/native_query.cpp \
test/parsers/native_target.cpp
test/parsers/native_target.cpp \
test/protocols/blocks.cpp \
test/protocols/blocks.hpp \
test/protocols/electrum/electrum.cpp \
test/protocols/electrum/electrum.hpp \
test/protocols/electrum/electrum_block_header.cpp \
test/protocols/electrum/electrum_server.cpp \
test/protocols/electrum/electrum_server_version.cpp

endif WITH_TESTS

Expand Down
12 changes: 10 additions & 2 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ add_library( ${CANONICAL_LIB_NAME}
"../../src/settings.cpp"
"../../src/parsers/bitcoind_query.cpp"
"../../src/parsers/bitcoind_target.cpp"
"../../src/parsers/electrum_version.cpp"
"../../src/parsers/native_query.cpp"
"../../src/parsers/native_target.cpp"
"../../src/protocols/protocol_bitcoind_rest.cpp"
Expand Down Expand Up @@ -296,15 +297,22 @@ if (with-tests)
"../../test/test.hpp"
"../../test/endpoints/README.md"
"../../test/endpoints/conftest.py"
"../../test/endpoints/electrum.cpp"
"../../test/endpoints/test_bitcoind_rpc.py"
"../../test/endpoints/test_electrum.py"
"../../test/endpoints/test_native.py"
"../../test/endpoints/utils.py"
"../../test/parsers/bitcoind_query.cpp"
"../../test/parsers/bitcoind_target.cpp"
"../../test/parsers/electrum_version.cpp"
"../../test/parsers/native_query.cpp"
"../../test/parsers/native_target.cpp" )
"../../test/parsers/native_target.cpp"
"../../test/protocols/blocks.cpp"
"../../test/protocols/blocks.hpp"
"../../test/protocols/electrum/electrum.cpp"
"../../test/protocols/electrum/electrum.hpp"
"../../test/protocols/electrum/electrum_block_header.cpp"
"../../test/protocols/electrum/electrum_server.cpp"
"../../test/protocols/electrum/electrum_server_version.cpp" )

add_test( NAME libbitcoin-server-test COMMAND libbitcoin-server-test
--run_test=*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,31 @@
</ImportGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\test\configuration.cpp" />
<ClCompile Include="..\..\..\..\test\endpoints\electrum.cpp" />
<ClCompile Include="..\..\..\..\test\error.cpp" />
<ClCompile Include="..\..\..\..\test\estimator.cpp" />
<ClCompile Include="..\..\..\..\test\main.cpp" />
<ClCompile Include="..\..\..\..\test\parsers\bitcoind_query.cpp" />
<ClCompile Include="..\..\..\..\test\parsers\bitcoind_target.cpp" />
<ClCompile Include="..\..\..\..\test\parsers\electrum_version.cpp" />
<ClCompile Include="..\..\..\..\test\parsers\native_query.cpp" />
<ClCompile Include="..\..\..\..\test\parsers\native_target.cpp" />
<ClCompile Include="..\..\..\..\test\protocols\blocks.cpp">
<ObjectFileName>$(IntDir)test_protocols_blocks.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum.cpp">
<ObjectFileName>$(IntDir)test_protocols_electrum_electrum.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_block_header.cpp" />
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_server.cpp" />
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_server_version.cpp" />
<ClCompile Include="..\..\..\..\test\settings.cpp" />
<ClCompile Include="..\..\..\..\test\test.cpp">
<ObjectFileName>$(IntDir)test_test.obj</ObjectFileName>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\test\protocols\blocks.hpp" />
<ClInclude Include="..\..\..\..\test\protocols\electrum\electrum.hpp" />
<ClInclude Include="..\..\..\..\test\test.hpp" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
<Filter Include="src\parsers">
<UniqueIdentifier>{66A0E586-2E3A-448F-0000-000000000002}</UniqueIdentifier>
</Filter>
<Filter Include="src\protocols">
<UniqueIdentifier>{66A0E586-2E3A-448F-0000-000000000003}</UniqueIdentifier>
</Filter>
<Filter Include="src\protocols\electrum">
<UniqueIdentifier>{66A0E586-2E3A-448F-0000-000000000004}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\test\configuration.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\endpoints\electrum.cpp">
<Filter>src\endpoints</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\error.cpp">
<Filter>src</Filter>
</ClCompile>
Expand All @@ -39,12 +42,30 @@
<ClCompile Include="..\..\..\..\test\parsers\bitcoind_target.cpp">
<Filter>src\parsers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\parsers\electrum_version.cpp">
<Filter>src\parsers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\parsers\native_query.cpp">
<Filter>src\parsers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\parsers\native_target.cpp">
<Filter>src\parsers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocols\blocks.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum.cpp">
<Filter>src\protocols\electrum</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_block_header.cpp">
<Filter>src\protocols\electrum</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_server.cpp">
<Filter>src\protocols\electrum</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\protocols\electrum\electrum_server_version.cpp">
<Filter>src\protocols\electrum</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\settings.cpp">
<Filter>src</Filter>
</ClCompile>
Expand All @@ -53,6 +74,12 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\test\protocols\blocks.hpp">
<Filter>src\protocols</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\test\protocols\electrum\electrum.hpp">
<Filter>src\protocols\electrum</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\test\test.hpp">
<Filter>src</Filter>
</ClInclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<ClCompile Include="..\..\..\..\src\parser.cpp" />
<ClCompile Include="..\..\..\..\src\parsers\bitcoind_query.cpp" />
<ClCompile Include="..\..\..\..\src\parsers\bitcoind_target.cpp" />
<ClCompile Include="..\..\..\..\src\parsers\electrum_version.cpp" />
<ClCompile Include="..\..\..\..\src\parsers\native_query.cpp" />
<ClCompile Include="..\..\..\..\src\parsers\native_target.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_bitcoind_rest.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<ClCompile Include="..\..\..\..\src\parsers\bitcoind_target.cpp">
<Filter>src\parsers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\parsers\electrum_version.cpp">
<Filter>src\parsers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\parsers\native_query.cpp">
<Filter>src\parsers</Filter>
</ClCompile>
Expand Down
35 changes: 31 additions & 4 deletions include/bitcoin/server/channels/channel_electrum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,37 @@ class BCS_API channel_electrum
public:
typedef std::shared_ptr<channel_electrum> ptr;
using interface_t = interface::electrum;
using options_t = typename network::channel_rpc<interface_t>::options_t;
using options_t = settings::electrum_server;

inline channel_electrum(const network::logger& log,
const network::socket::ptr& socket, uint64_t identifier,
const node::configuration& config, const options_t& options) NOEXCEPT
: server::channel(log, socket, identifier, config),
options_(options),
network::channel_rpc<interface::electrum>(log, socket, identifier,
config.network, options),
network::tracker<channel_electrum>(log)
{
}

void stop(const code& ec) NOEXCEPT override
{
std::cerr << "[STOP TRIGGERED] value=" << ec.value()
<< " message=\"" << ec.message() << "\""
<< " category=" << ec.category().name() << std::endl;

network::channel_rpc<interface::electrum>::stop(ec);
}

void stopping(const code& ec) NOEXCEPT override
{
std::cerr << "[STOPPING - ASYNC] value=" << ec.value()
<< " message=\"" << ec.message() << "\""
<< " category=" << ec.category().name() << std::endl;

network::channel_rpc<interface::electrum>::stopping(ec);
}

/// Properties.
/// -----------------------------------------------------------------------

Expand All @@ -64,19 +83,27 @@ class BCS_API channel_electrum
return name_;
}

inline void set_version(electrum_version version) NOEXCEPT
inline void set_version(electrum::version version) NOEXCEPT
{
version_ = version;
}

inline electrum_version version() const NOEXCEPT
inline electrum::version version() const NOEXCEPT
{
return version_;
}

inline const options_t& options() const NOEXCEPT
{
return options_;
}

private:
// This is thread safe.
const options_t& options_;

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

Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/server/interfaces/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ 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;
using code_t = network::rpc::code_t;

namespace empty { constexpr auto array = network::rpc::empty::array; };
namespace empty { constexpr auto object = network::rpc::empty::object; };
Expand Down
8 changes: 7 additions & 1 deletion include/bitcoin/server/parsers/electrum_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#ifndef LIBBITCOIN_SERVER_PARSERS_ELECTRUM_VERSION_HPP
#define LIBBITCOIN_SERVER_PARSERS_ELECTRUM_VERSION_HPP

#include <unordered_map>
#include <bitcoin/server/define.hpp>

namespace libbitcoin {
namespace server {
namespace electrum {

enum class electrum_version
enum class version
{
/// Invalid version.
v0_0,
Expand Down Expand Up @@ -66,6 +68,10 @@ enum class electrum_version
v1_6
};

std::string_view version_to_string(version value) NOEXCEPT;
version version_from_string(const std::string_view& value) NOEXCEPT;

} // namespace electrum
} // namespace server
} // namespace libbitcoin

Expand Down
11 changes: 10 additions & 1 deletion include/bitcoin/server/protocols/protocol_electrum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BCS_API protocol_electrum
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
: protocol_rpc<channel_electrum>(session, channel, options),
options_(options),
channel_(std::dynamic_pointer_cast<channel_t>(channel)),
network::tracker<protocol_electrum>(session->log)
{
Expand Down Expand Up @@ -127,12 +128,20 @@ class BCS_API protocol_electrum
void blockchain_block_headers(size_t starting, size_t quantity,
size_t waypoint, bool multiplicity) NOEXCEPT;

inline bool is_version(electrum_version version) const NOEXCEPT
inline bool is_version(electrum::version version) const NOEXCEPT
{
return channel_->version() >= version;
}

inline const options_t& options() const NOEXCEPT
{
return options_;
}

private:
// This is thread safe.
const options_t& options_;

// This is mostly thread safe, and used in a thread safe manner.
const channel_t::ptr channel_;
};
Expand Down
21 changes: 12 additions & 9 deletions include/bitcoin/server/protocols/protocol_electrum_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define LIBBITCOIN_SERVER_PROTOCOLS_PROTOCOL_ELECTRUM_VERSION_HPP

#include <memory>
#include <unordered_map>
#include <bitcoin/server/channels/channels.hpp>
#include <bitcoin/server/define.hpp>
#include <bitcoin/server/interfaces/interfaces.hpp>
Expand All @@ -42,6 +41,7 @@ class BCS_API protocol_electrum_version
const network::channel::ptr& channel,
const options_t& options) NOEXCEPT
: protocol_rpc<channel_electrum>(session, channel, options),
options_(options),
channel_(std::dynamic_pointer_cast<channel_t>(channel)),
network::tracker<protocol_electrum_version>(session->log)
{
Expand All @@ -51,30 +51,33 @@ class BCS_API protocol_electrum_version
virtual void finished(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 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;
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,
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;

inline const options_t& options() const NOEXCEPT
{
return options_;
}

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 thread safe.
const options_t& options_;

// This is mostly thread safe, and used in a thread safe manner.
const channel_t::ptr channel_;
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/server/protocols/protocol_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class BCS_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__)
////#define SEND_RPC(message, size_hint, method, ...) \
//// send<CLASS>(message, size_hint, &CLASS::method, __VA_ARGS__)

} // namespace server
} // namespace libbitcoin
Expand Down
Loading
Loading