mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 04:09:23 +00:00
Replace reqwest with simple-request
reqwest was replaced with hyper and hyper-rustls within monero-serai due to reqwest *solely* offering a connection pool API. In the process, it was demonstrated how quickly we can achieve equivalent functionality to reqwest for our use cases with a fraction of the code. This adds our own reqwest alternative to the tree, applying it to both bitcoin-serai and message-queue. By doing so, bitcoin-serai decreases its tree by 21 packages and the processor by 18. Cargo.lock decreases by 8 dependencies, solely adding simple-request. Notably removed is openssl-sys and openssl. One noted decrease functionality is the requirement on the system having installed CA certificates. While we could fallback to the rustls certificates if the system doesn't have any, that's blocked by https://github.com/rustls/hyper-rustls/pulls/228.
This commit is contained in:
@@ -11,7 +11,7 @@ use schnorr_signatures::SchnorrSignature;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use reqwest::Client;
|
||||
use simple_request::{Request, Client};
|
||||
|
||||
use serai_env as env;
|
||||
|
||||
@@ -45,7 +45,7 @@ impl MessageQueue {
|
||||
service,
|
||||
pub_key: Ristretto::generator() * priv_key.deref(),
|
||||
priv_key,
|
||||
client: Client::new(),
|
||||
client: Client::with_connection_pool(),
|
||||
url,
|
||||
}
|
||||
}
|
||||
@@ -81,18 +81,30 @@ impl MessageQueue {
|
||||
id: u64,
|
||||
}
|
||||
|
||||
let res = loop {
|
||||
let mut res = loop {
|
||||
// Make the request
|
||||
match self
|
||||
.client
|
||||
.post(&self.url)
|
||||
.json(&JsonRpcRequest { jsonrpc: "2.0", method, params: params.clone(), id: 0 })
|
||||
.send()
|
||||
.request(
|
||||
Request::post(&self.url)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(
|
||||
serde_json::to_vec(&JsonRpcRequest {
|
||||
jsonrpc: "2.0",
|
||||
method,
|
||||
params: params.clone(),
|
||||
id: 0,
|
||||
})
|
||||
.unwrap()
|
||||
.into(),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(req) => {
|
||||
// Get the response
|
||||
match req.text().await {
|
||||
match req.body().await {
|
||||
Ok(res) => break res,
|
||||
Err(e) => {
|
||||
dbg!(e);
|
||||
@@ -108,8 +120,8 @@ impl MessageQueue {
|
||||
tokio::time::sleep(core::time::Duration::from_secs(1)).await;
|
||||
};
|
||||
|
||||
let json =
|
||||
serde_json::from_str::<serde_json::Value>(&res).expect("message-queue returned invalid JSON");
|
||||
let json: serde_json::Value =
|
||||
serde_json::from_reader(&mut res).expect("message-queue returned invalid JSON");
|
||||
if json.get("result").is_none() {
|
||||
panic!("call failed: {json}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user