Skip to content

Commit

Permalink
Fix #314
Browse files Browse the repository at this point in the history
  • Loading branch information
romanz committed Nov 5, 2020
1 parent a25d8af commit 8f2f533
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,26 @@ impl Connection {
Ok(result)
}

fn server_version(&self) -> Result<Value> {
fn server_version(&self, params: &[Value]) -> Result<Value> {
if params.len() != 2 {
bail!("invalid params: {:?}", params);
}
let client_id = params[0]
.as_str()
.chain_err(|| format!("invalid client_id: {:?}", params[0]))?;
// TODO: support (min, max) protocol version limits
let client_version = params[1]
.as_str()
.chain_err(|| format!("invalid client_version: {:?}", params[1]))?;

if client_version != PROTOCOL_VERSION {
bail!(
"{} requested protocol version {}, server supports {}",
client_id,
client_version,
PROTOCOL_VERSION
);
}
Ok(json!([
format!("electrs {}", ELECTRS_VERSION),
PROTOCOL_VERSION
Expand Down Expand Up @@ -334,7 +353,7 @@ impl Connection {
"server.donation_address" => self.server_donation_address(),
"server.peers.subscribe" => self.server_peers_subscribe(),
"server.ping" => Ok(Value::Null),
"server.version" => self.server_version(),
"server.version" => self.server_version(params),
&_ => bail!("unknown method {} {:?}", method, params),
};
timer.observe_duration();
Expand Down

0 comments on commit 8f2f533

Please sign in to comment.