Skip to content

Commit a0f30f0

Browse files
authored
Merge pull request #691 from evoskuil/master
Adapt to database get_balance() change (unconfirmed delta).
2 parents 3025228 + 7d6c92e commit a0f30f0

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

src/protocols/electrum/protocol_electrum.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ void protocol_electrum::do_outpoint(node::address_t) NOEXCEPT
241241
{
242242
chain::point point{};
243243

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

273-
// EXAMPLE
274+
// EXAMPLE:
274275
// script_hash is a payment address for address.
275276
send_notification("blockchain.address.subscribe", array_t
276277
{
@@ -285,7 +286,7 @@ void protocol_electrum::do_scripthash(node::address_t) NOEXCEPT
285286
std::string status_hash{};
286287
std::string script_hash{};
287288

288-
// EXAMPLE
289+
// EXAMPLE:
289290
// script_hash is a payment address for address.
290291
send_notification("blockchain.scripthash.subscribe", array_t
291292
{
@@ -300,7 +301,7 @@ void protocol_electrum::do_scriptpubkey(node::address_t) NOEXCEPT
300301
std::string status_hash{};
301302
std::string script_hash{};
302303

303-
// EXAMPLE
304+
// EXAMPLE:
304305
// script_hash is a payment address for address.
305306
send_notification("blockchain.scriptpubkey.subscribe", array_t
306307
{

src/protocols/electrum/protocol_electrum_scripthash.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,9 @@ void protocol_electrum::do_get_balance(const hash_digest& hash) NOEXCEPT
7979
{
8080
BC_ASSERT(!stranded());
8181

82-
int64_t unconfirmed{};
83-
uint64_t confirmed{}, combined{};
84-
8582
const auto& query = archive();
86-
auto ec = query.get_balance(stopping_, confirmed, combined, hash);
87-
88-
// get_balance() query returns positive net balances.
89-
// These are differenced to obtain relative unconfirmed for electrum.
90-
if (!ec)
91-
{
92-
if (is_limited<int64_t>(confirmed) || is_limited<int64_t>(combined) ||
93-
is_subtract_overflow<int64_t>(combined, confirmed))
94-
ec = error::server_error;
95-
else
96-
unconfirmed = subtract<int64_t>(combined, confirmed);
97-
}
98-
83+
uint64_t confirmed{}, unconfirmed{};
84+
auto ec = query.get_balance(stopping_, confirmed, unconfirmed, hash);
9985
POST(complete_get_balance, ec, confirmed, unconfirmed);
10086
}
10187

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

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

398391
return object;
399392
});

0 commit comments

Comments
 (0)