@@ -114,6 +114,31 @@ bool protocol_electrum::handle_event(const code&, node::chase event_,
114114 return true ;
115115}
116116
117+ // Utility.
118+ // ----------------------------------------------------------------------------
119+
120+ // TODO: move to system/math.
121+ template <typename Integer, if_integer<Integer> = true >
122+ bool to_integer (Integer& out, double value) NOEXCEPT
123+ {
124+ if (!std::isfinite (value))
125+ return false ;
126+
127+ double integral{};
128+ const double fractional = std::modf (value, &integral);
129+ if (fractional != 0.0 )
130+ return false ;
131+
132+ if (integral > static_cast <double >(system::maximum<Integer>) ||
133+ integral < static_cast <double >(system::minimum<Integer>))
134+ return false ;
135+
136+ BC_PUSH_WARNING (NO_STATIC_CAST)
137+ out = static_cast <Integer>(integral);
138+ BC_POP_WARNING ()
139+ return true ;
140+ }
141+
117142// Handlers (blockchain).
118143// ----------------------------------------------------------------------------
119144
@@ -127,10 +152,23 @@ void protocol_electrum::handle_blockchain_block_header(const code& ec,
127152
128153// electrum-protocol.readthedocs.io/en/latest/protocol-basics.html#block-headers
129154void protocol_electrum::handle_blockchain_block_headers (const code& ec,
130- rpc_interface::blockchain_block_headers, double ,
131- double , double ) NOEXCEPT
155+ rpc_interface::blockchain_block_headers, double start_height, double count ,
156+ double cp_height ) NOEXCEPT
132157{
133- if (stopped (ec)) return ;
158+ if (stopped (ec))
159+ return ;
160+
161+ size_t quantity{};
162+ size_t waypoint{};
163+ size_t starting{};
164+ if (!to_integer (quantity, count) ||
165+ !to_integer (waypoint, cp_height) ||
166+ !to_integer (starting, start_height))
167+ {
168+ send_code (error::invalid_argument);
169+ return ;
170+ }
171+
134172 send_code (error::not_implemented);
135173}
136174
0 commit comments