@@ -133,7 +133,6 @@ bool protocol_electrum::get_outpoint_history(outpoint_subscription& out,
133133 return false ;
134134 }
135135
136- // TODO: this could be accept stopping_ but it's a small query.
137136 out.spenders = query.get_spenders_history (prevout);
138137 return true ;
139138}
@@ -169,6 +168,7 @@ void protocol_electrum::handle_blockchain_outpoint_subscribe(const code& ec,
169168 NOTIFY (do_outpoint_subscribe, point{ hash, index });
170169}
171170
171+ // Subscription response is idempotent.
172172void protocol_electrum::do_outpoint_subscribe (const point& prevout) NOEXCEPT
173173{
174174 // Cancellability is preserved because not on channel strand.
@@ -180,7 +180,6 @@ void protocol_electrum::do_outpoint_subscribe(const point& prevout) NOEXCEPT
180180 {
181181 ec = get_outpoint_history (sub, prevout) ?
182182 error::success : ec = error::not_found;
183-
184183 outpoint_subscriptions_.emplace (prevout, sub);
185184 subscribed_outpoint_.store (true , relaxed);
186185 }
@@ -207,9 +206,9 @@ void protocol_electrum::complete_outpoint_subscribe(const code& ec,
207206 // Send first spender only.
208207 send_result (to_outpoint_status (sub), 128 , BIND (complete, _1));
209208
209+ // Send remaining spenders as notifications.
210210 // Send here vs. completion handler because asio will queue it up
211211 // behind the send anyway, and this prevents another sub copy.
212- // Send remaining spenders as notifications.
213212 if (!sub.spenders .empty ())
214213 {
215214 const auto height = sub.outpoint .tx .height ();
@@ -283,40 +282,40 @@ void protocol_electrum::do_outpoint(node::header_t) NOEXCEPT
283282 auto & sub = subscription.second ;
284283 const auto & prevout = subscription.first ;
285284
286- outpoint_subscription res {};
287- if (!get_outpoint_history (res , prevout))
285+ outpoint_subscription result {};
286+ if (!get_outpoint_history (result , prevout))
288287 {
289288 LOGV (" Electrum::do_outpoint, outpoint not found." );
290289 continue ;
291290 }
292291
293292 // There is no change.
294- if (sub == res ) continue ;
293+ if (sub == result ) continue ;
295294
296295 const auto height = sub.outpoint .tx .height ();
297296 if (!sub.outpoint .valid () || sub.outpoint .tx .height () != height)
298297 {
299298 // Outpoint changed (or newly found), send all current spenders.
300- if (res .spenders .empty ())
299+ if (result .spenders .empty ())
301300 {
302301 POST (outpoint_notify, make_status (height), prevout);
303302 }
304- else for (const auto & spender: res .spenders )
303+ else for (const auto & spender: result .spenders )
305304 {
306305 POST (outpoint_notify, make_status (height, spender), prevout);
307306 }
308307 }
309308 else
310309 {
311310 // Outpoint unchanged, send only new or changed spenders.
312- for (const auto & spender: difference (res .spenders , sub.spenders ))
311+ for (const auto & spender: difference (result .spenders , sub.spenders ))
313312 {
314313 POST (outpoint_notify, make_status (height, spender), prevout);
315314 }
316315 }
317316
318317 // Update subscription state.
319- sub = std::move (res );
318+ sub = std::move (result );
320319 }
321320}
322321
0 commit comments