Transition to ureq http client (#5777)
* Transition to ureq http client * Remove unwrap
This commit is contained in:
@ -44,7 +44,6 @@ num-traits = "0.2"
|
||||
rand = "0.6.5"
|
||||
rand_chacha = "0.1.1"
|
||||
rayon = "1.2.0"
|
||||
reqwest = "0.9.20"
|
||||
serde = "1.0.99"
|
||||
serde_derive = "1.0.99"
|
||||
serde_json = "1.0.40"
|
||||
@ -95,6 +94,7 @@ hex-literal = "0.2.1"
|
||||
matches = "0.1.6"
|
||||
serial_test = "0.2.0"
|
||||
serial_test_derive = "0.2.0"
|
||||
ureq = { version = "0.11.0", default-features = false, features = ["json"] }
|
||||
|
||||
[[bench]]
|
||||
name = "banking_stage"
|
||||
|
@ -1,7 +1,5 @@
|
||||
use bincode::serialize;
|
||||
use log::*;
|
||||
use reqwest;
|
||||
use reqwest::header::CONTENT_TYPE;
|
||||
use serde_json::{json, Value};
|
||||
use solana_client::rpc_client::get_rpc_request_str;
|
||||
use solana_core::validator::new_validator_for_tests;
|
||||
@ -19,7 +17,7 @@ fn test_rpc_send_tx() {
|
||||
let (server, leader_data, alice, ledger_path) = new_validator_for_tests();
|
||||
let bob_pubkey = Pubkey::new_rand();
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let client = ureq::agent();
|
||||
let request = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
@ -28,20 +26,18 @@ fn test_rpc_send_tx() {
|
||||
});
|
||||
let rpc_addr = leader_data.rpc;
|
||||
let rpc_string = get_rpc_request_str(rpc_addr, false);
|
||||
let mut response = client
|
||||
let response = client
|
||||
.post(&rpc_string)
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.body(request.to_string())
|
||||
.send()
|
||||
.unwrap();
|
||||
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
||||
.set("Content-Type", "application/json")
|
||||
.send_json(request);
|
||||
let json: Value = serde_json::from_str(&response.into_string().unwrap()).unwrap();
|
||||
let blockhash: Hash = json["result"][0].as_str().unwrap().parse().unwrap();
|
||||
|
||||
info!("blockhash: {:?}", blockhash);
|
||||
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash);
|
||||
let serial_tx = serialize(&tx).unwrap();
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let client = ureq::agent();
|
||||
let request = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
@ -50,18 +46,16 @@ fn test_rpc_send_tx() {
|
||||
});
|
||||
let rpc_addr = leader_data.rpc;
|
||||
let rpc_string = get_rpc_request_str(rpc_addr, false);
|
||||
let mut response = client
|
||||
let response = client
|
||||
.post(&rpc_string)
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.body(request.to_string())
|
||||
.send()
|
||||
.unwrap();
|
||||
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
||||
.set("Content-Type", "application/json")
|
||||
.send_json(request);
|
||||
let json: Value = serde_json::from_str(&response.into_string().unwrap()).unwrap();
|
||||
let signature = &json["result"];
|
||||
|
||||
let mut confirmed_tx = false;
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let client = ureq::agent();
|
||||
let request = json!({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
@ -70,13 +64,11 @@ fn test_rpc_send_tx() {
|
||||
});
|
||||
|
||||
for _ in 0..solana_sdk::timing::DEFAULT_TICKS_PER_SLOT {
|
||||
let mut response = client
|
||||
let response = client
|
||||
.post(&rpc_string)
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.body(request.to_string())
|
||||
.send()
|
||||
.unwrap();
|
||||
let response_json_text = response.text().unwrap();
|
||||
.set("Content-Type", "application/json")
|
||||
.send_json(request.clone());
|
||||
let response_json_text = response.into_string().unwrap();
|
||||
let json: Value = serde_json::from_str(&response_json_text).unwrap();
|
||||
|
||||
if true == json["result"] {
|
||||
|
Reference in New Issue
Block a user