jsonrpc2 client uses a random ID fr now + displaying the request in test

This commit is contained in:
Mahesh Bansod 2021-09-22 20:47:33 +05:30
parent c33955b515
commit ff96accc3e
3 changed files with 14 additions and 6 deletions

1
Cargo.lock generated
View File

@ -407,6 +407,7 @@ dependencies = [
name = "jsonrpc2-client"
version = "0.1.0"
dependencies = [
"rand 0.8.4",
"reqwest",
"serde",
"serde_json",

View File

@ -9,4 +9,5 @@ edition = "2018"
tokio = {version = "1.11.0", features = ["full"]}
reqwest = {version = "0.11.4", features = ["json"]}
serde = { version = "1.0", features = ["derive"]}
serde_json = "1.0.67"
serde_json = "1.0.67"
rand = "0.8.4"

View File

@ -1,3 +1,5 @@
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};
pub struct Client {
@ -26,10 +28,10 @@ impl Client {
params: Some(params),
};
// println!(
// "Request: {}",
// serde_json::to_string_pretty(&request).unwrap()
// );
println!(
"Request: {}",
serde_json::to_string_pretty(&request).unwrap()
);
//TODO: maybe check the response better as well??
let resp = self
@ -81,7 +83,11 @@ impl<T> RawResponse<T> {
}
fn generate_id() -> String {
"1".to_string()
thread_rng()
.sample_iter(&Alphanumeric)
.take(30)
.map(char::from)
.collect()
}
#[cfg(test)]