@@ -91,9 +91,12 @@ void protocol_electrum::do_scripthash_subscribe(const hash_digest& hash,
9191 hash_digest status{};
9292 if (address_subscriptions_.size () < options_.maximum_subscriptions )
9393 {
94+ using mid = midstate;
95+ const auto limit = options ().maximum_history ;
96+
9497 // Subscription response is idempotent.
95- auto at = address_subscriptions_.try_emplace (hash, type, midstate {});
96- ec = get_scripthash_status (status, at.first -> second , at.first -> first );
98+ auto & at = * address_subscriptions_.try_emplace (hash, type, mid {}). first ;
99+ ec = get_scripthash_status (status, at.second , at.first , limit );
97100 subscribed_address_.store (true , relaxed);
98101 }
99102 else
@@ -105,14 +108,15 @@ void protocol_electrum::do_scripthash_subscribe(const hash_digest& hash,
105108}
106109
107110void protocol_electrum::complete_scripthash_subscribe (const code& ec,
108- hash_digest& status, const hash_digest& hash) NOEXCEPT
111+ const hash_digest& status, const hash_digest& hash) NOEXCEPT
109112{
110113 BC_ASSERT (stranded ());
111114
112115 monitor (false );
113116 if (stopped ())
114117 return ;
115118
119+ // TODO: map database::error::maximum_depth to server code?
116120 if (ec)
117121 {
118122 send_code (ec);
@@ -281,9 +285,10 @@ hash_digest protocol_electrum::to_status(const histories& histories) NOEXCEPT
281285}
282286
283287code protocol_electrum::get_scripthash_status (hash_digest& out,
284- subscription& /* sub */ , const hash_digest& hash) NOEXCEPT
288+ subscription& /* sub */ , const hash_digest& hash, size_t /* limit */ ) NOEXCEPT
285289{
286290 // TODO: use cursors and midstate to optimize succesive queries.
291+ // TODO: limit first pass query depth.
287292
288293 histories histories{};
289294 const auto & query = archive ();
0 commit comments