@@ -204,22 +204,29 @@ class BCS_API protocol_electrum
204204 rpc_interface::mempool_get_info) NOEXCEPT;
205205
206206protected:
207+ using hash_digest = system::hash_digest;
208+ enum class notify_t { address, scripthash, scriptpubkey };
209+ typedef std::function<void (const code&, const hash_digest&,
210+ const hash_digest&)> status_handler;
211+
207212 // / Common implementation for block_header/s.
208213 void blockchain_block_headers (size_t starting, size_t quantity,
209214 size_t waypoint, bool multiplicity) NOEXCEPT;
210215
211216 // / Completion handlers (for long-running address queries).
212217 // / -----------------------------------------------------------------------
213218
214- void get_balance (const system:: hash_digest& hash) NOEXCEPT;
215- void get_history (const system:: hash_digest& hash) NOEXCEPT;
216- void get_mempool (const system:: hash_digest& hash) NOEXCEPT;
217- void list_unspent (const system:: hash_digest& hash) NOEXCEPT;
219+ void get_balance (const hash_digest& hash) NOEXCEPT;
220+ void get_history (const hash_digest& hash) NOEXCEPT;
221+ void get_mempool (const hash_digest& hash) NOEXCEPT;
222+ void list_unspent (const hash_digest& hash) NOEXCEPT;
218223
219- void do_get_balance (const system::hash_digest& hash) NOEXCEPT;
220- void do_get_history (const system::hash_digest& hash) NOEXCEPT;
221- void do_get_mempool (const system::hash_digest& hash) NOEXCEPT;
222- void do_list_unspent (const system::hash_digest& hash) NOEXCEPT;
224+ void do_get_balance (const hash_digest& hash) NOEXCEPT;
225+ void do_get_history (const hash_digest& hash) NOEXCEPT;
226+ void do_get_mempool (const hash_digest& hash) NOEXCEPT;
227+ void do_list_unspent (const hash_digest& hash) NOEXCEPT;
228+ void do_status (const hash_digest& hash,
229+ const status_handler& sender) NOEXCEPT;
223230
224231 void complete_get_balance (const code& ec, uint64_t confirmed,
225232 int64_t unconfirmed) NOEXCEPT;
@@ -229,16 +236,22 @@ class BCS_API protocol_electrum
229236 const database::histories& histories) NOEXCEPT;
230237 void complete_list_unspent (const code& ec,
231238 const database::unspents& unspents) NOEXCEPT;
239+ void complete_status (const code& ec, const hash_digest& hash,
240+ const hash_digest& status, const status_handler& sender) NOEXCEPT;
241+
242+ void send_status (const code& ec, const hash_digest& hash,
243+ const hash_digest& status) NOEXCEPT;
244+ void notify_status (const code& ec, const hash_digest& hash,
245+ const hash_digest& status, notify_t type,
246+ node::address_t link) NOEXCEPT;
232247
233248 // / Notification senders and send handlers.
234249 // / -----------------------------------------------------------------------
235250
236251 void do_height (node::header_t link) NOEXCEPT;
237252 void do_header (node::header_t link) NOEXCEPT;
238253 void do_outpoint (node::header_t link) NOEXCEPT;
239- void do_address (node::address_t link) NOEXCEPT;
240254 void do_scripthash (node::address_t link) NOEXCEPT;
241- void do_scriptpubkey (node::address_t link) NOEXCEPT;
242255
243256 // / Utilities.
244257 // / -----------------------------------------------------------------------
@@ -254,19 +267,32 @@ class BCS_API protocol_electrum
254267 }
255268
256269private:
270+ // Status hash optimization (~200 bytes).
271+ struct midstate
272+ {
273+ hash_digest status{};
274+ system::stream::out::fast stream{ status };
275+ system::hash::sha256::fast writer{ stream };
276+ };
277+
278+ // Aliases.
257279 using array_t = network::rpc::array_t ;
258280 using object_t = network::rpc::object_t ;
259281 using version_t = protocol_electrum_version;
260282 static constexpr electrum::version minimum = version_t ::minimum;
261283 static constexpr electrum::version maximum = version_t ::maximum;
262284
285+ // Address transformations.
286+ static array_t transform (const database::histories& histories) NOEXCEPT;
287+ static array_t transform (const database::unspents& unspents) NOEXCEPT;
288+ static std::string to_method_name (notify_t type) NOEXCEPT;
289+
263290 // Compute server.features.hosts value from config.
264291 object_t self_hosts () const NOEXCEPT;
265292 array_t more_hosts () const NOEXCEPT;
266293
267294 // Convert between legacy bitcoin payment address and scripthash.
268- system::hash_digest extract_scripthash (
269- const std::string& address) const NOEXCEPT;
295+ hash_digest extract_scripthash (const std::string& address) const NOEXCEPT;
270296 system::wallet::payment_address extract_address (
271297 const system::chain::script& script) const NOEXCEPT;
272298
@@ -275,15 +301,13 @@ class BCS_API protocol_electrum
275301 code validate_tx (const system::chain::transaction& tx) const NOEXCEPT;
276302 code broadcast_tx (const system::chain::transaction::cptr& tx) NOEXCEPT;
277303
278- // Address transformations.
279- array_t transform (const database::histories& histories) NOEXCEPT;
280- array_t transform (const database::unspents& unspents) NOEXCEPT;
281-
282- // Shared implementations.
283- void send_scripthash_unsubscribe (const system::hash_digest& hash) NOEXCEPT;
284- void send_scripthash_subscribe (const system::hash_digest& hash) NOEXCEPT;
285- bool send_get_status (const system::chain::point& prevout,
304+ // Shared send/get implementations.
305+ void send_scripthash_unsubscribe (const hash_digest& hash) NOEXCEPT;
306+ void send_scripthash_subscribe (const hash_digest& hash) NOEXCEPT;
307+ bool send_outpoint_status (const system::chain::point& prevout,
286308 const std::string& spk_hint) NOEXCEPT;
309+ bool get_outpoint_status (object_t & status,
310+ const system::chain::point& prevout) const NOEXCEPT;
287311
288312 // These are thread safe.
289313 const options_t & options_;
@@ -294,15 +318,13 @@ class BCS_API protocol_electrum
294318 std::atomic_bool subscribed_height_{};
295319 std::atomic_bool subscribed_header_{};
296320 std::atomic_bool subscribed_outpoint_{};
297- std::atomic_bool subscribed_address_{};
298321 std::atomic_bool subscribed_scripthash_{};
299- std::atomic_bool subscribed_scriptpubkey_{};
300322
301323 // This is mostly thread safe, and used in a thread safe manner.
302324 const channel_t ::ptr channel_;
303325
304326 // This is protected by strand.
305- std::unordered_set<system:: hash_digest> subscriptions_{};
327+ std::unordered_set<hash_digest> subscriptions_{};
306328};
307329
308330} // namespace server
0 commit comments