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/server/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ enum error_t : uint8_t
unconfirmable_transaction,
argument_overflow,
target_overflow,
maximum_depth,
wrong_version,
server_error
};
Expand Down
1 change: 1 addition & 0 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(error)
{ unconfirmable_transaction, "unconfirmable_transaction" },
{ argument_overflow, "argument_overflow" },
{ target_overflow, "target_overflow" },
{ maximum_depth, "maximum_depth" },
{ wrong_version, "wrong_version" },
{ server_error, "server_error" }
};
Expand Down
7 changes: 4 additions & 3 deletions src/protocols/electrum/protocol_electrum_subscribe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void protocol_electrum::do_scripthash_subscribe(const hash_digest& hash,
const auto limit = options().maximum_history;
auto& at = *address_subscriptions_.try_emplace(hash, type, mid{}).first;
ec = get_scripthash_history(status, at.second, at.first, limit);
if (ec == database::error::limited) ec = error::maximum_depth;
subscribed_address_.store(true, relaxed);
}

Expand All @@ -111,7 +112,6 @@ void protocol_electrum::complete_scripthash_subscribe(const code& ec,
if (stopped())
return;

// TODO: map database::error::maximum_depth to server code?
if (ec)
{
send_code(ec);
Expand Down Expand Up @@ -265,14 +265,15 @@ hash_digest protocol_electrum::to_status(const histories& histories) NOEXCEPT

code protocol_electrum::get_scripthash_history(hash_digest& out,
address_subscription& /* sub */, const hash_digest& hash,
size_t /* limit */) NOEXCEPT
size_t limit) NOEXCEPT
{
// TODO: use cursors and midstate to optimize succesive queries.
// TODO: limit first pass query depth.

histories histories{};
database::address_link cursor{};
const auto& query = archive();
const auto ec = query.get_history(stopping_, histories, hash, turbo_);
const auto ec = query.get_history(stopping_, cursor, histories, hash, limit, turbo_);
if (!ec) out = to_status(histories);
return ec;
}
Expand Down
9 changes: 9 additions & 0 deletions test/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ BOOST_AUTO_TEST_CASE(error_t__code__target_overflow__true_expected_message)
BOOST_REQUIRE_EQUAL(ec.message(), "target_overflow");
}

BOOST_AUTO_TEST_CASE(error_t__code__maximum_depth__true_expected_message)
{
constexpr auto value = error::maximum_depth;
const auto ec = code(value);
BOOST_REQUIRE(ec);
BOOST_REQUIRE(ec == value);
BOOST_REQUIRE_EQUAL(ec.message(), "maximum_depth");
}

BOOST_AUTO_TEST_CASE(error_t__code__wrong_version__true_expected_message)
{
constexpr auto value = error::wrong_version;
Expand Down