Skip to content

Commit

Permalink
Merge branch 'main' into jon-becker/inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker authored Dec 11, 2023
2 parents c69346a + c135098 commit 5c574ed
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 81 deletions.
70 changes: 35 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 55 additions & 46 deletions common/src/resources/transpose.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use backoff::ExponentialBackoff;
use indicatif::ProgressBar;
use reqwest::header::HeaderMap;
use serde_json::Value;
Expand All @@ -21,59 +22,67 @@ struct TransposeResponse {
}

/// executes a transpose SQL query and returns the response
/// TODO: exponential backoff
async fn call_transpose(query: &str, api_key: &str) -> Option<TransposeResponse> {
// get a new logger
let logger = Logger::default();
backoff::future::retry(
ExponentialBackoff {
max_elapsed_time: Some(Duration::from_secs(10)),
..ExponentialBackoff::default()
},
|| async {
// get a new logger
let logger = Logger::default();

// build the headers
let mut headers = HeaderMap::new();
headers.insert("Content-Type", "application/json".parse().unwrap());
headers.insert("X-API-KEY", api_key.parse().unwrap());
// build the headers
let mut headers = HeaderMap::new();
headers.insert("Content-Type", "application/json".parse().unwrap());
headers.insert("X-API-KEY", api_key.parse().unwrap());

// clone the query
let query = query.to_owned();
// clone the query
let query = query.to_owned();

// make the request
let client = reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
.timeout(Duration::from_secs(999999999))
.build()
.unwrap();
// make the request
let client = reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
.timeout(Duration::from_secs(999999999))
.build()
.unwrap();

let response = match client
.post("https://api.transpose.io/sql")
.body(query.clone())
.headers(headers)
.send()
.await
{
Ok(res) => res,
Err(e) => {
logger.error("failed to call Transpose .");
logger.error(&format!("error: {e}"));
std::process::exit(1)
}
};
let response = match client
.post("https://api.transpose.io/sql")
.body(query.clone())
.headers(headers)
.send()
.await
{
Ok(res) => res,
Err(e) => {
logger.error("failed to call Transpose .");
logger.error(&format!("error: {e}"));
return Err(backoff::Error::Permanent(()))
}
};

// parse body
match response.text().await {
Ok(body) => Some(match serde_json::from_str(&body) {
Ok(json) => json,
Err(e) => {
logger.error("Transpose request unsucessful.");
logger.debug(&format!("curl: curl -X GET \"https://api.transpose.io/sql\" -H \"accept: application/json\" -H \"Content-Type: application/json\" -H \"X-API-KEY: {api_key}\" -d {query}"));
logger.error(&format!("error: {e}"));
logger.debug(&format!("response body: {body:?}"));
std::process::exit(1)
// parse body
match response.text().await {
Ok(body) => Ok(match serde_json::from_str(&body) {
Ok(json) => json,
Err(e) => {
logger.error("Transpose request unsucessful.");
logger.debug(&format!("curl: curl -X GET \"https://api.transpose.io/sql\" -H \"accept: application/json\" -H \"Content-Type: application/json\" -H \"X-API-KEY: {api_key}\" -d {query}"));
logger.error(&format!("error: {e}"));
logger.debug(&format!("response body: {body:?}"));
return Err(backoff::Error::Permanent(()))
}
}),
Err(e) => {
logger.error("failed to parse Transpose response body.");
logger.error(&format!("error: {e}"));
Err(backoff::Error::Permanent(()))
}
}
}),
Err(e) => {
logger.error("failed to parse Transpose response body.");
logger.error(&format!("error: {e}"));
std::process::exit(1)
}
}
},
).await
.ok()
}

/// Get all interactions with the given address. Includes transactions to, from, as well as internal
Expand Down

0 comments on commit 5c574ed

Please sign in to comment.