@@ -47,6 +47,9 @@ void protocol_electrum::start() NOEXCEPT
4747 if (started ())
4848 return ;
4949
50+ // Events subscription is asynchronous, events may be missed.
51+ subscribe_events (BIND (handle_event, _1, _2, _3));
52+
5053 // Blockchain methods.
5154 SUBSCRIBE_RPC (handle_blockchain_block_header, _1, _2, _3, _4);
5255 SUBSCRIBE_RPC (handle_blockchain_block_headers, _1, _2, _3, _4, _5);
@@ -78,17 +81,51 @@ void protocol_electrum::start() NOEXCEPT
7881 protocol_rpc<channel_electrum>::start ();
7982}
8083
84+ void protocol_electrum::stopping (const code& ec) NOEXCEPT
85+ {
86+ // Unsubscriber race is ok.
87+ BC_ASSERT (stranded ());
88+ unsubscribe_events ();
89+ protocol_rpc<channel_electrum>::stopping (ec);
90+ }
91+
92+ // Handlers (event subscription).
93+ // ----------------------------------------------------------------------------
94+
95+ bool protocol_electrum::handle_event (const code&, node::chase event_,
96+ node::event_value) NOEXCEPT
97+ {
98+ // Do not pass ec to stopped as it is not a call status.
99+ if (stopped ())
100+ return false ;
101+
102+ switch (event_)
103+ {
104+ case node::chase::suspend:
105+ {
106+ break ;
107+ }
108+ default :
109+ {
110+ break ;
111+ }
112+ }
113+
114+ return true ;
115+ }
116+
81117// Handlers (blockchain).
82118// ----------------------------------------------------------------------------
83119
120+ // electrum-protocol.readthedocs.io/en/latest/protocol-basics.html#block-headers
84121void protocol_electrum::handle_blockchain_block_header (const code& ec,
85- rpc_interface::blockchain_block_header, double ,
86- double ) NOEXCEPT
122+ rpc_interface::blockchain_block_header, double height ,
123+ double cp_height ) NOEXCEPT
87124{
88- if (stopped (ec)) return ;
89- send_code (error::not_implemented);
125+ handle_blockchain_block_headers (ec, {}, height, 1 , cp_height);
90126}
91127
128+ // electrum-protocol.readthedocs.io/en/latest/protocol-basics.html#block-headers
92129void protocol_electrum::handle_blockchain_block_headers (const code& ec,
93130 rpc_interface::blockchain_block_headers, double ,
94131 double , double ) NOEXCEPT
@@ -120,6 +157,8 @@ void protocol_electrum::handle_blockchain_headers_subscribe(const code& ec,
120157 header->to_data (writer);
121158 BC_ASSERT (writer);
122159
160+ // TODO: signal header subscription.
161+
123162 // TODO: idempotent subscribe to chase::organized via session/chaser/node.
124163 // TODO: upon notification send just the header notified by the link.
125164 // TODO: it is client responsibility to deal with reorgs and race gaps.
@@ -269,6 +308,7 @@ void protocol_electrum::handle_server_features(const code& ec,
269308 send_code (error::not_implemented);
270309}
271310
311+ // This is not actually a subscription method.
272312void protocol_electrum::handle_server_peers_subscribe (const code& ec,
273313 rpc_interface::server_peers_subscribe) NOEXCEPT
274314{
0 commit comments