Transition to ureq http client (#5777)

* Transition to ureq http client

* Remove unwrap
This commit is contained in:
Tyera Eulberg
2019-09-04 12:11:44 -07:00
committed by GitHub
parent 355640b5db
commit b19d9a50d3
16 changed files with 236 additions and 324 deletions

View File

@ -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"] {