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/network/channels/channel_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,37 @@

namespace libbitcoin {
namespace network {

// TODO: Interface argument provides templated dispatch for rpc protocols.
// TODO: transport independent sender methods in each are duck typed for rpc protocol.
// TODO: network::channel_trpc<Interface> : network::channel
// TODO: network::channel_wrpc<Interface> : network::channel_ws
// : network::channel_http
// : network::channel
//
// TODO: reused channel state unique to electrum/bitcoind.
// TODO: server::channel_electrum_base
// TODO: server::channel_bitcoind_base
//
// TODO: aliases.
// TODO: server::channel_electrum_tcp : channel_electrum_base, network::channel_trpc<electrum>
// TODO: server::channel_electrum_web : channel_electrum_base, network::channel_wrpc<electrum>
// TODO: server::channel_bitcoind_tcp : channel_bitcoind_base, network::channel_trpc<bitcoind>
// TODO: server::channel_bitcoind_web : channel_bitcoind_base, network::channel_wrpc<bitcoind>
//
// TODO: base sender methods for passthrough to channel senders.
// TODO: these could be implemented in the two protocols to reduce compile time.
// TODO: network::protocol_rpc<Channel> : network::protocol
//
// TODO: reused protocol logic unique to electrum/bitcoind.
// TODO: server::protocol_electrum<Channel> : network::protocol_rpc<Channel>
// TODO: server::protocol_bitcoind<Channel> : network::protocol_rpc<Channel>
//
// TODO: aliases.
// TODO: server::protocol_electrum_tcp : network::protocol_electrum<channel_electrum_tcp>
// TODO: server::protocol_electrum_web : network::protocol_electrum<channel_electrum_web>
// TODO: server::protocol_bitcoind_tcp : network::protocol_bitcoind<channel_bitcoind_tcp>
// TODO: server::protocol_bitcoind_web : network::protocol_bitcoind<channel_bitcoind_web>

/// Read rpc-request and send rpc-response, dispatch to Interface.
template <typename Interface>
Expand Down
10 changes: 9 additions & 1 deletion include/bitcoin/network/messages/rpc/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ using string_t = std::string;
using array_t = std::vector<value_t>;
using object_t = std::unordered_map<string_t, value_t>;
using any_t = rpc::any;
using json_t = boost::json::value;

struct value_t
{
/// 88 bytes (object_t).
using inner_t = std::variant
<
/// json-rpc
Expand All @@ -72,7 +74,10 @@ struct value_t

/// type-erased shared_ptr<Type>, not json deserializable.
/// Pass ptr via any_t and specify it directly in the handler.
any_t
any_t,

/// Embeds json DOM.
json_t
>;

/// Explicit initialization constructors.
Expand All @@ -94,6 +99,8 @@ struct value_t
value_t(uint16_t value) NOEXCEPT : inner_{ value } {}
value_t(uint32_t value) NOEXCEPT : inner_{ value } {}
value_t(uint64_t value) NOEXCEPT : inner_{ value } {}
value_t(const json_t& value) NOEXCEPT : inner_{ value } {}
value_t(json_t&& value) NOEXCEPT : inner_{ std::move(value) } {}
value_t(const any_t& value) NOEXCEPT : inner_{ value } {}
value_t(any_t&& value) NOEXCEPT : inner_{ std::move(value) } {}

Expand All @@ -113,6 +120,7 @@ struct value_t
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, uint16_t, inner_)
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, uint32_t, inner_)
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, uint64_t, inner_)
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, json_t, inner_)
ALTERNATIVE_VARIANT_ASSIGNMENT(value_t, any_t, inner_)

inner_t& value() NOEXCEPT
Expand Down
11 changes: 8 additions & 3 deletions src/messages/rpc/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ DEFINE_JSON_FROM_TAG(value_t)
{
value = visit;
},
[&](const json_t& visit) NOEXCEPT
{
// This is a deep copy.
value = visit;
},
[&](const array_t& visit) THROWS
{
value.emplace_array();
Expand Down Expand Up @@ -173,7 +178,7 @@ DEFINE_JSON_FROM_TAG(identity_t)
{
[&](null_t) NOEXCEPT
{
value = boost::json::value{};
value = json_t{};
},
[&](code_t visit) NOEXCEPT
{
Expand Down Expand Up @@ -332,7 +337,7 @@ DEFINE_JSON_FROM_TAG(response_t)
else if (instance.jsonrpc == version::v1 ||
instance.jsonrpc == version::undefined)
{
object["error"] = boost::json::value{};
object["error"] = json_t{};
}

if (instance.result.has_value())
Expand All @@ -342,7 +347,7 @@ DEFINE_JSON_FROM_TAG(response_t)
else if (instance.jsonrpc == version::v1 ||
instance.jsonrpc == version::undefined)
{
object["result"] = boost::json::value{};
object["result"] = json_t{};
}

value = object;
Expand Down
Loading