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
9 changes: 5 additions & 4 deletions src/protocols/electrum/protocol_electrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ void protocol_electrum::do_outpoint(node::address_t) NOEXCEPT
{
chain::point point{};

// TODO: compute and return outpont status from a store query.
// TODO: compute and return outpoint status from a store query.
// TODO: unlike scripthash, this is not a cumulative "status" hash.
send_notification("blockchain.outpoint.subscribe", array_t
{
array_t{ encode_hash(point.hash()), point.index() },
Expand Down Expand Up @@ -270,7 +271,7 @@ void protocol_electrum::do_address(node::address_t ) NOEXCEPT
midstate value{};
auto copy = value;

// EXAMPLE
// EXAMPLE:
// script_hash is a payment address for address.
send_notification("blockchain.address.subscribe", array_t
{
Expand All @@ -285,7 +286,7 @@ void protocol_electrum::do_scripthash(node::address_t) NOEXCEPT
std::string status_hash{};
std::string script_hash{};

// EXAMPLE
// EXAMPLE:
// script_hash is a payment address for address.
send_notification("blockchain.scripthash.subscribe", array_t
{
Expand All @@ -300,7 +301,7 @@ void protocol_electrum::do_scriptpubkey(node::address_t) NOEXCEPT
std::string status_hash{};
std::string script_hash{};

// EXAMPLE
// EXAMPLE:
// script_hash is a payment address for address.
send_notification("blockchain.scriptpubkey.subscribe", array_t
{
Expand Down
25 changes: 9 additions & 16 deletions src/protocols/electrum/protocol_electrum_scripthash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,9 @@ void protocol_electrum::do_get_balance(const hash_digest& hash) NOEXCEPT
{
BC_ASSERT(!stranded());

int64_t unconfirmed{};
uint64_t confirmed{}, combined{};

const auto& query = archive();
auto ec = query.get_balance(stopping_, confirmed, combined, hash);

// get_balance() query returns positive net balances.
// These are differenced to obtain relative unconfirmed for electrum.
if (!ec)
{
if (is_limited<int64_t>(confirmed) || is_limited<int64_t>(combined) ||
is_subtract_overflow<int64_t>(combined, confirmed))
ec = error::server_error;
else
unconfirmed = subtract<int64_t>(combined, confirmed);
}

uint64_t confirmed{}, unconfirmed{};
auto ec = query.get_balance(stopping_, confirmed, unconfirmed, hash);
POST(complete_get_balance, ec, confirmed, unconfirmed);
}

Expand Down Expand Up @@ -393,7 +379,14 @@ array_t protocol_electrum::transform(const database::histories& ins) NOEXCEPT
};

if (unconfirmed)
{
// A fee of max_uint64 implies missing prevout(s). This will happen
// for a block-downloaded tx queried during parallel block download
// when the prevout block(s) are not yet archived or even if the tx
// turned out to be in an invalid block after its block download. A
// transaction is technically never invalid absent a block context.
object["fee"] = in.fee;
}

return object;
});
Expand Down