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
1 change: 1 addition & 0 deletions include/bitcoin/node/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ enum error_t : uint8_t
missing_position,
missing_id_type,
invalid_id_type,
missing_type_id,
missing_component,
invalid_component,
invalid_subcomponent,
Expand Down
92 changes: 58 additions & 34 deletions include/bitcoin/node/protocols/protocol_explore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,45 +66,69 @@ class BCN_API protocol_explore
bool handle_get_header(const code& ec, interface::header,
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
////bool handle_get_filter(const code& ec, interface::filter,
//// uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
//// std::optional<uint32_t> height) NOEXCEPT;
////bool handle_get_block_txs(const code& ec, interface::block_txs,
//// uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
//// std::optional<uint32_t> height) NOEXCEPT;

////bool handle_get_block_tx(const code& ec, interface::block_tx,
//// uint8_t version, uint8_t media, uint32_t position,
//// std::optional<system::hash_cptr> hash,
//// std::optional<uint32_t> height, bool witness) NOEXCEPT;

bool handle_get_block_txs(const code& ec, interface::block_txs,
uint8_t version, uint8_t media, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_block_tx(const code& ec, interface::block_tx,
uint8_t version, uint8_t media, uint32_t position,
std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height, bool witness) NOEXCEPT;
bool handle_get_transaction(const code& ec, interface::transaction,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
bool witness) NOEXCEPT;
////bool handle_get_address(const code& ec, interface::address,
//// uint8_t version, uint8_t media, const system::hash_cptr& hash) NOEXCEPT;

////bool handle_get_input(const code& ec, interface::input,
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
//// std::optional<uint32_t> index) NOEXCEPT;
////bool handle_get_input_script(const code& ec, interface::input_script,
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
//// std::optional<uint32_t> index) NOEXCEPT;
////bool handle_get_input_witness(const code& ec, interface::input_witness,
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
//// std::optional<uint32_t> index) NOEXCEPT;

////bool handle_get_output(const code& ec, interface::output,
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
//// std::optional<uint32_t> index) NOEXCEPT;
////bool handle_get_output_script(const code& ec, interface::output_script,
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
//// std::optional<uint32_t> index) NOEXCEPT;
////bool handle_get_output_spender(const code& ec, interface::output_spender,
//// uint8_t version, uint8_t media, const system::hash_cptr& hash,
//// std::optional<uint32_t> index) NOEXCEPT;
bool handle_get_tx_block(const code& ec, interface::tx_block,
uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;

bool handle_get_inputs(const code& ec, interface::inputs,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
bool witness) NOEXCEPT;
bool handle_get_input(const code& ec, interface::input,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index, bool witness) NOEXCEPT;
bool handle_get_input_script(const code& ec, interface::input_script,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_input_witness(const code& ec, interface::input_witness,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;

bool handle_get_outputs(const code& ec, interface::outputs,
uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
bool handle_get_output(const code& ec, interface::output,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_output_script(const code& ec, interface::output_script,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_output_spender(const code& ec, interface::output_spender,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;
bool handle_get_output_spenders(const code& ec, interface::output_spender,
uint8_t version, uint8_t media, const system::hash_cptr& hash,
uint32_t index) NOEXCEPT;

bool handle_get_address(const code& ec, interface::address,
uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
bool handle_get_filter(const code& ec, interface::filter, uint8_t version,
uint8_t media, uint8_t type, std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_filter_hash(const code& ec, interface::filter_hash,
uint8_t version, uint8_t media, uint8_t type,
std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;
bool handle_get_filter_header(const code& ec, interface::filter_header,
uint8_t version, uint8_t media, uint8_t type,
std::optional<system::hash_cptr> hash,
std::optional<uint32_t> height) NOEXCEPT;

private:
void send_wire(uint8_t media, system::data_chunk&& data) NOEXCEPT;
database::header_link to_header(const std::optional<uint32_t>& height,
const std::optional<system::hash_cptr>& hash) NOEXCEPT;

dispatcher dispatcher_{};
};

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/protocols/protocol_html.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BCN_API protocol_html
boost::json::value&& model, size_t size_hint) NOEXCEPT;
virtual void send_text(const network::http::request& request,
std::string&& hexidecimal) NOEXCEPT;
virtual void send_data(const network::http::request& request,
virtual void send_chunk(const network::http::request& request,
system::data_chunk&& bytes) NOEXCEPT;
virtual void send_file(const network::http::request& request,
network::http::file&& file, network::http::media_type type) NOEXCEPT;
Expand Down
1 change: 1 addition & 0 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
{ missing_position, "missing_position" },
{ missing_id_type, "missing_id_type" },
{ invalid_id_type, "invalid_id_type" },
{ missing_type_id, "missing_type_id" },
{ missing_component, "missing_component" },
{ invalid_component, "invalid_component" },
{ invalid_subcomponent, "invalid_subcomponent" },
Expand Down
127 changes: 81 additions & 46 deletions src/parse/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,7 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
// transaction, address, inputs, and outputs are identical excluding names;
// input and output are identical excluding names; block is unique.
const auto target = segments[segment++];
if (target == "transaction")
{
if (segment == segments.size())
return error::missing_hash;

const auto hash = to_hash(segments[segment++]);
if (!hash) return error::invalid_hash;

method = "transaction";
params["hash"] = hash;
}
else if (target == "address")
if (target == "address")
{
if (segment == segments.size())
return error::missing_hash;
Expand All @@ -114,7 +103,7 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
const auto hash = to_hash(segments[segment++]);
if (!hash) return error::invalid_hash;

method = "input";
method = "inputs";
params["hash"] = hash;
}
else if (target == "outputs")
Expand All @@ -125,7 +114,7 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
const auto hash = to_hash(segments[segment++]);
if (!hash) return error::invalid_hash;

method = "output";
method = "outputs";
params["hash"] = hash;
}
else if (target == "input")
Expand All @@ -141,36 +130,36 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
return error::missing_component;

const auto component = segments[segment++];
if (component == "scripts")
{
method = "input_script";
}
else if (component == "witnesses")
////if (component == "scripts")
////{
//// method = "input_scripts";
////}
////else if (component == "witnesses")
////{
//// method = "input_witnesses";
////}
////else
////{
uint32_t index{};
if (!to_number(index, component))
return error::invalid_number;

params["index"] = index;
if (segment == segments.size())
{
method = "input_witness";
method = "input";
}
else
{
uint32_t index{};
if (!to_number(index, component))
return error::invalid_number;

params["index"] = index;
if (segment == segments.size())
{
method = "input";
}
auto subcomponent = segments[segment++];
if (subcomponent == "script")
method = "input_script";
else if (subcomponent == "witness")
method = "input_witness";
else
{
auto subcomponent = segments[segment++];
if (subcomponent == "script")
method = "input_script";
else if (subcomponent == "witness")
method = "input_witness";
else
return error::invalid_subcomponent;
}
return error::invalid_subcomponent;
}
////}
}
else if (target == "output")
{
Expand All @@ -185,13 +174,14 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
return error::missing_component;

const auto component = segments[segment++];
if (component == "scripts")
{
method = "output_script";
}
else if (component == "spenders")
////if (component == "scripts")
////{
//// method = "output_scripts";
////}
////else
if (component == "spenders")
{
method = "output_spender";
method = "output_spenders";
}
else
{
Expand All @@ -216,6 +206,28 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
}
}
}
else if (target == "transaction")
{
if (segment == segments.size())
return error::missing_hash;

const auto hash = to_hash(segments[segment++]);
if (!hash) return error::invalid_hash;

params["hash"] = hash;
if (segment == segments.size())
{
method = "transaction";
}
else
{
const auto component = segments[segment++];
if (component == "block")
method = "tx_block";
else
return error::invalid_component;
}
}
else if (target == "block")
{
if (segment == segments.size())
Expand Down Expand Up @@ -273,10 +285,33 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
}
else if (component == "header")
method = "header";
else if (component == "filter")
method = "filter";
else if (component == "transactions")
method = "block_txs";
else if (component == "filter")
{
if (segment == segments.size())
return error::missing_type_id;

uint8_t type{};
if (!to_number(type, segments[segment++]))
return error::invalid_number;

params["type"] = type;
if (segment == segments.size())
{
method = "filter";
}
else
{
const auto subcomponent = segments[segment++];
if (subcomponent == "hash")
method = "filter_hash";
else if (subcomponent == "header")
method = "filter_header";
else
return error::invalid_subcomponent;
}
}
else
return error::invalid_component;
}
Expand Down
Loading
Loading