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
25 changes: 12 additions & 13 deletions include/bitcoin/node/protocols/protocol_explore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,34 +134,33 @@ class BCN_API protocol_explore

bool handle_get_address(const code& ec, interface::address,
uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
bool handle_get_address_confirmed(const code& ec,
interface::address_confirmed, uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
bool handle_get_address_unconfirmed(const code& ec,
interface::address_unconfirmed, uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
const system::hash_cptr& hash, bool turbo) NOEXCEPT;
bool handle_get_address_balance(const code& ec,
interface::address_balance, uint8_t version, uint8_t media,
const system::hash_cptr& hash) NOEXCEPT;
const system::hash_cptr& hash, bool turbo) NOEXCEPT;

private:
using balance_handler = std::function<void(code, uint8_t, uint64_t)>;
using address_handler = std::function<void(code, uint8_t,
database::outpoints&&)>;

void do_get_address(uint8_t media, const system::hash_cptr& hash,
const address_handler& handler) NOEXCEPT;
void do_get_address_confirmed(uint8_t media, const system::hash_cptr& hash,
const address_handler& handler) NOEXCEPT;
void do_get_address_unconfirmed(uint8_t media,
const system::hash_cptr& hash,
const address_handler& handler) NOEXCEPT;
void do_get_address(uint8_t media, bool turbo,
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
void do_get_address_confirmed(uint8_t media, bool turbo,
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
void do_get_address_unconfirmed(uint8_t media, bool turbo,
const system::hash_cptr& hash, const address_handler& handler) NOEXCEPT;
void complete_get_address(const code& ec, uint8_t media,
const database::outpoints& set) NOEXCEPT;

void do_get_address_balance(uint8_t media, const system::hash_cptr& hash,
const balance_handler& handler) NOEXCEPT;
void do_get_address_balance(uint8_t media, bool turbo,
const system::hash_cptr& hash, const balance_handler& handler) NOEXCEPT;
void complete_get_address_balance(const code& ec, uint8_t media,
const uint64_t balance) NOEXCEPT;

Expand Down
35 changes: 28 additions & 7 deletions src/parse/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ using namespace system;
using namespace network;
using namespace network::http;

BC_PUSH_WARNING(NO_ARRAY_INDEXING)
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

bool parse_query(rpc::request_t& out, const request& request) NOEXCEPT
{
wallet::uri uri{};
Expand All @@ -45,15 +48,30 @@ bool parse_query(rpc::request_t& out, const request& request) NOEXCEPT
return false;

auto& params = std::get<rpc::object_t>(out.params.value());
const auto& witness = query["witness"];

// Validate prper bool value if set.
if (!witness.empty() && witness != "true" && witness != "false")
return false;
// Validate proper witness bool value if set.
const auto witness = query.find("witness");
if (witness != query.end())
{
if (witness->second != "true" && witness->second != "false")
return false;

// Witness is optional<true> (where applicable) so only set if false.
if (witness == "false")
params["witness"] = false;
// Witness is optional<true> (where applicable), so only set if false.
if (witness->second == "false")
params["witness"] = false;
}

// Validate proper turbo bool value if set.
const auto turbo = query.find("turbo");
if (turbo != query.end())
{
if (turbo->second != "true" && turbo->second != "false")
return false;

// Turbo is optional<true> (where applicable), so only set if false.
if (turbo->second == "false")
params["turbo"] = false;
}

const auto accepts = to_media_types((request)[field::accept]);

Expand All @@ -80,5 +98,8 @@ bool parse_query(rpc::request_t& out, const request& request) NOEXCEPT
return true;
}

BC_POP_WARNING()
BC_POP_WARNING()

} // namespace node
} // namespace libbitcoin
5 changes: 5 additions & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,11 @@ options_metadata parser::load_settings() THROWS
value<std::filesystem::path>(&configured.database.path),
"The blockchain database directory, defaults to 'blockchain'."
)
(
"database.turbo",
value<bool>(&configured.database.turbo),
"Allow indiviudal non-validation queries to use all CPUs, defaults to false."
)

/* header */
(
Expand Down
47 changes: 23 additions & 24 deletions src/protocols/protocol_explore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ void protocol_explore::start() NOEXCEPT
SUBSCRIBE_EXPLORE(handle_get_output_spender, _1, _2, _3, _4, _5, _6);
SUBSCRIBE_EXPLORE(handle_get_output_spenders, _1, _2, _3, _4, _5, _6);

SUBSCRIBE_EXPLORE(handle_get_address, _1, _2, _3, _4, _5);
SUBSCRIBE_EXPLORE(handle_get_address_confirmed, _1, _2, _3, _4, _5);
SUBSCRIBE_EXPLORE(handle_get_address_unconfirmed, _1, _2, _3, _4, _5);
SUBSCRIBE_EXPLORE(handle_get_address_balance, _1, _2, _3, _4, _5);
SUBSCRIBE_EXPLORE(handle_get_address, _1, _2, _3, _4, _5, _6);
SUBSCRIBE_EXPLORE(handle_get_address_confirmed, _1, _2, _3, _4, _5, _6);
SUBSCRIBE_EXPLORE(handle_get_address_unconfirmed, _1, _2, _3, _4, _5, _6);
SUBSCRIBE_EXPLORE(handle_get_address_balance, _1, _2, _3, _4, _5, _6);
protocol_html::start();
}

Expand Down Expand Up @@ -480,10 +480,8 @@ bool protocol_explore::handle_get_block_filter_header(const code& ec,
switch (media)
{
case data:
{
send_chunk(to_chunk(filter_head));
return true;
}
case text:
send_text(encode_base16(filter_head));
return true;
Expand Down Expand Up @@ -935,7 +933,7 @@ bool protocol_explore::handle_get_output_spenders(const code& ec,
// ----------------------------------------------------------------------------

bool protocol_explore::handle_get_address(const code& ec, interface::address,
uint8_t, uint8_t media, const hash_cptr& hash) NOEXCEPT
uint8_t, uint8_t media, const hash_cptr& hash, bool turbo) NOEXCEPT
{
if (stopped(ec))
return false;
Expand All @@ -947,16 +945,17 @@ bool protocol_explore::handle_get_address(const code& ec, interface::address,
}

address_handler complete = BIND(complete_get_address, _1, _2, _3);
PARALLEL(do_get_address, media, hash, std::move(complete));
PARALLEL(do_get_address, media, turbo, hash, std::move(complete));
return true;
}

// private
void protocol_explore::do_get_address(uint8_t media, const hash_cptr& hash,
const address_handler& handler) NOEXCEPT
void protocol_explore::do_get_address(uint8_t media, bool turbo,
const hash_cptr& hash, const address_handler& handler) NOEXCEPT
{
outpoints set{};
if (const auto ec = archive().get_address_outputs(stopping_, set, *hash))
if (const auto ec = archive().get_address_outputs(stopping_, set,
*hash, turbo))
{
handler(ec, {}, {});
return;
Expand All @@ -965,7 +964,7 @@ void protocol_explore::do_get_address(uint8_t media, const hash_cptr& hash,
handler(network::error::success, media, std::move(set));
}

// This is shared by the tree get_address.. methods.
// This is shared by the three get_address... methods.
void protocol_explore::complete_get_address(const code& ec, uint8_t media,
const outpoints& set) NOEXCEPT
{
Expand Down Expand Up @@ -1008,7 +1007,7 @@ void protocol_explore::complete_get_address(const code& ec, uint8_t media,

bool protocol_explore::handle_get_address_confirmed(const code& ec,
interface::address_confirmed, uint8_t, uint8_t media,
const hash_cptr& hash) NOEXCEPT
const hash_cptr& hash, bool turbo) NOEXCEPT
{
if (stopped(ec))
return false;
Expand All @@ -1020,17 +1019,17 @@ bool protocol_explore::handle_get_address_confirmed(const code& ec,
}

address_handler complete = BIND(complete_get_address, _1, _2, _3);
PARALLEL(do_get_address_confirmed, media, hash, std::move(complete));
PARALLEL(do_get_address_confirmed, media, turbo, hash, std::move(complete));
return true;
}

// private
void protocol_explore::do_get_address_confirmed(uint8_t media,
void protocol_explore::do_get_address_confirmed(uint8_t media, bool turbo,
const hash_cptr& hash, const address_handler& handler) NOEXCEPT
{
outpoints set{};
if (const auto ec = archive().get_confirmed_unspent_outputs(stopping_, set,
*hash))
if (const auto ec = archive().get_confirmed_unspent_outputs(stopping_,
set, *hash, turbo))
{
handler(ec, {}, {});
return;
Expand All @@ -1044,7 +1043,7 @@ void protocol_explore::do_get_address_confirmed(uint8_t media,

bool protocol_explore::handle_get_address_unconfirmed(const code& ec,
interface::address_unconfirmed, uint8_t, uint8_t media,
const hash_cptr& hash) NOEXCEPT
const hash_cptr& hash, bool turbo) NOEXCEPT
{
if (stopped(ec))
return false;
Expand All @@ -1054,11 +1053,11 @@ bool protocol_explore::handle_get_address_unconfirmed(const code& ec,
return true;

address_handler complete = BIND(complete_get_address, _1, _2, _3);
PARALLEL(do_get_address_unconfirmed, media, hash, std::move(complete));
PARALLEL(do_get_address_unconfirmed, media, turbo, hash, std::move(complete));
return true;
}

void protocol_explore::do_get_address_unconfirmed(uint8_t media,
void protocol_explore::do_get_address_unconfirmed(uint8_t media, bool,
const system::hash_cptr&, const address_handler& handler) NOEXCEPT
{
handler(network::error::success, media, {});
Expand All @@ -1069,7 +1068,7 @@ void protocol_explore::do_get_address_unconfirmed(uint8_t media,

bool protocol_explore::handle_get_address_balance(const code& ec,
interface::address_balance, uint8_t, uint8_t media,
const hash_cptr& hash) NOEXCEPT
const hash_cptr& hash, bool turbo) NOEXCEPT
{
if (stopped(ec))
return false;
Expand All @@ -1082,16 +1081,16 @@ bool protocol_explore::handle_get_address_balance(const code& ec,
}

balance_handler complete = BIND(complete_get_address_balance, _1, _2, _3);
PARALLEL(do_get_address_balance, media, hash, std::move(complete));
PARALLEL(do_get_address_balance, media, turbo, hash, std::move(complete));
return true;
}

void protocol_explore::do_get_address_balance(uint8_t media,
void protocol_explore::do_get_address_balance(uint8_t media, bool turbo,
const system::hash_cptr& hash, const balance_handler& handler) NOEXCEPT
{
uint64_t balance{};
if (const auto ec = archive().get_confirmed_balance(stopping_, balance,
*hash))
*hash, turbo))
{
handler(ec, {}, {});
return;
Expand Down
Loading