-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,77 @@ | ||
use crate::types::PoolChangesLiteRequest; | ||
use log::{info, warn}; | ||
use reqwest::header::HeaderMap; | ||
use reqwest::header::CONTENT_TYPE; | ||
use rocket::http::hyper::HeaderValue; | ||
use std::{thread, time}; | ||
use rocket::tokio::task::{self, spawn}; | ||
use serde_json::json; | ||
use std::{sync::Arc, thread, time}; | ||
|
||
//async fn get_pool_changes_lite() -> String {} | ||
async fn get_info() -> Result<(), reqwest::Error> { | ||
let client = reqwest::Client::new(); | ||
let response = client | ||
.get("http://privacymine.net:11898/info") | ||
.send() | ||
.await?; | ||
|
||
println!("response status: {:?}", response.status()); | ||
|
||
async fn get_pool_changes_lite(body: &str) -> String { | ||
Ok(()) | ||
} | ||
|
||
async fn get_pool_changes_lite() { | ||
let known = vec![""]; | ||
let body = serde_json::to_string(&json!({ "knownTxsIds": known })).unwrap(); | ||
let body = body.to_string(); | ||
|
||
// set headers | ||
let mut headers = HeaderMap::new(); | ||
headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json")); | ||
headers.insert("Content-Type", "application/json".parse().unwrap()); | ||
|
||
// set node and request endpoint | ||
let ip = String::from("privacymine.net"); | ||
let ip = String::from("blocksum.org"); | ||
let port = String::from("11898"); | ||
let url = format!("http://{}:{}/{}", ip, port, "get_pool_changes_lite"); | ||
let endpoint = String::from("get_pool_changes_lite"); | ||
let url = format!("http://{}:{}/{}", ip, port, endpoint); | ||
|
||
// make the post request | ||
let client = reqwest::Client::new(); | ||
let request = client | ||
.post(&url) | ||
.headers(headers.clone()) | ||
.body(body.clone()); | ||
|
||
let response = request.send().await; | ||
let response_text = response.unwrap().text().await; | ||
|
||
match response_text { | ||
Ok(text) => { | ||
info!("Response text: {}", text); | ||
text | ||
} | ||
Err(e) => { | ||
warn!("Error: {}", e); | ||
String::from("") | ||
} | ||
} | ||
let response = client | ||
.post(url) | ||
.headers(headers) | ||
.body(body) | ||
.send() | ||
.await | ||
.expect("Failed to get response") | ||
.text() | ||
.await | ||
.expect("Failed to get payload"); | ||
|
||
println!("response: {:?}", response); | ||
} | ||
|
||
pub async fn hugin_syncer() { | ||
info!(target: "sync_events", "Starting Hugin syncer..."); | ||
|
||
let delay = time::Duration::from_secs(2); | ||
let delay = time::Duration::from_secs(5); | ||
let known = vec!["37669a52df20daf42e74757d05547f9b151ec0383819b377be1c7df59d43e2f8"]; | ||
let pool_changes_lite_req = PoolChangesLiteRequest { | ||
known_txs_ids: &known, | ||
knownTxsIds: &known, | ||
}; | ||
|
||
// run the hugin syncer loop | ||
loop { | ||
info!("Hugin syncer loop..."); | ||
|
||
// convert the PoolChangesLiteRequest struct to a json string | ||
let json_body = serde_json::to_string(&pool_changes_lite_req); | ||
// let json_body = serde_json::to_string(&pool_changes_lite_req); | ||
|
||
println!("json_body: {:?}", json_body); | ||
// println!("json_body: {:?}", body); | ||
|
||
match json_body { | ||
Ok(body) => { | ||
let response = get_pool_changes_lite(&body).await; | ||
info!("Response: {}", response); | ||
|
||
// parse the deserialize the response into a PoolChangesLiteResponse | ||
} | ||
Err(e) => { | ||
warn!("Error: {}", e); | ||
} | ||
if let Err(e) = get_info().await { | ||
warn!("Error: {:?}", e); | ||
} | ||
|
||
thread::sleep(delay); | ||
} | ||
|
||
// get_info().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters