@@ -29,6 +29,8 @@ namespace server {
2929
3030#define CLASS protocol_electrum
3131
32+ using namespace system ;
33+ using namespace network ::rpc;
3234using namespace std ::placeholders;
3335
3436// Start.
@@ -118,7 +120,13 @@ bool protocol_electrum::handle_event(const code&, node::chase event_,
118120 {
119121 case node::chase::organized:
120122 {
121- if (subscribed_.load (std::memory_order_relaxed))
123+ if (subscribed_height_.load (std::memory_order_relaxed))
124+ {
125+ BC_ASSERT (std::holds_alternative<node::header_t >(value));
126+ POST (do_height, std::get<node::header_t >(value));
127+ }
128+
129+ if (subscribed_header_.load (std::memory_order_relaxed))
122130 {
123131 BC_ASSERT (std::holds_alternative<node::header_t >(value));
124132 POST (do_header, std::get<node::header_t >(value));
@@ -135,5 +143,50 @@ bool protocol_electrum::handle_event(const code&, node::chase event_,
135143 return true ;
136144}
137145
146+ // Notifier for handle_blockchain_number_of_blocks_subscribe events.
147+ void protocol_electrum::do_height (node::header_t link) NOEXCEPT
148+ {
149+ BC_ASSERT (stranded ());
150+
151+ const auto & query = archive ();
152+ const auto height = query.get_height (link);
153+
154+ if (height.is_terminal ())
155+ {
156+ LOGF (" Electrum::do_height, object not found (" << link << " )." );
157+ return ;
158+ }
159+
160+ send_notification (" blockchain.numblocks.subscribe" ,
161+ {
162+ array_t { height.value }
163+ }, 48 , BIND (complete, _1));
164+ }
165+
166+ // Notifier for blockchain_headers_subscribe events.
167+ void protocol_electrum::do_header (node::header_t link) NOEXCEPT
168+ {
169+ BC_ASSERT (stranded ());
170+
171+ const auto & query = archive ();
172+ const auto height = query.get_height (link);
173+ const auto header = query.get_wire_header (link);
174+
175+ if (height.is_terminal ())
176+ {
177+ LOGF (" Electrum::do_header, object not found (" << link << " )." );
178+ return ;
179+ }
180+
181+ send_notification (" blockchain.headers.subscribe" ,
182+ {
183+ object_t
184+ {
185+ { " height" , height.value },
186+ { " hex" , encode_base16 (header) }
187+ }
188+ }, 64 , BIND (complete, _1));
189+ }
190+
138191} // namespace server
139192} // namespace libbitcoin
0 commit comments