Skip to content

Commit

Permalink
Feat: batching of RPC requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
junderw committed Jul 27, 2024
1 parent d070272 commit c7c873c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.70
1.80
29 changes: 18 additions & 11 deletions src/electrum/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,18 +521,25 @@ impl Connection {
trace!("RPC {:?}", msg);
match msg {
Message::Request(line) => {
let cmd: Value = from_str(&line).chain_err(|| "invalid JSON format")?;
let reply = match (
cmd.get("method"),
cmd.get("params").unwrap_or(&empty_params),
cmd.get("id"),
) {
(Some(Value::String(method)), Value::Array(params), Some(id)) => {
self.handle_command(method, params, id)?
}
_ => bail!("invalid command: {}", cmd),
let cmd: [Value; 1] = [from_str(&line).chain_err(|| "invalid JSON format")?];
let cmds = match &cmd[..] {
[Value::Array(arr)] => arr,
x => x,
};
self.send_values(&[reply])?
let mut replies = Vec::with_capacity(cmds.len());
for cmd in cmds {
replies.push(match (
cmd.get("method"),
cmd.get("params").unwrap_or(&empty_params),
cmd.get("id"),
) {
(Some(Value::String(method)), Value::Array(params), Some(id)) => {
self.handle_command(method, params, id)?
}
_ => bail!("invalid command: {}", cmd),
});
}
self.send_values(&replies)?
}
Message::PeriodicUpdate => {
let values = self
Expand Down

0 comments on commit c7c873c

Please sign in to comment.