From 5e5a55d159b503836f4d486f2e834a2a4d06a2e8 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 29 May 2024 16:32:16 +0200 Subject: [PATCH] fix: missing utils functions --- examples/all_requests.rs | 2 ++ src/api/endpoints/mod.rs | 1 + src/api/endpoints/utils.rs | 21 +++++++-------------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/examples/all_requests.rs b/examples/all_requests.rs index 51640ce..00d69b8 100644 --- a/examples/all_requests.rs +++ b/examples/all_requests.rs @@ -137,6 +137,8 @@ async fn main() -> BlockfrostResult<()> { .await; let nutlink_ticker_by_id = api.nutlink_ticker_by_id(ticker, pagination).await; + // Utils + println!("root: {:#?}", root); println!("health: {:#?}", health); println!("health_clock: {:#?}", health_clock); diff --git a/src/api/endpoints/mod.rs b/src/api/endpoints/mod.rs index 36f2099..22ffd2c 100644 --- a/src/api/endpoints/mod.rs +++ b/src/api/endpoints/mod.rs @@ -13,3 +13,4 @@ mod nutlink; mod pools; mod scripts; mod transactions; +mod utils; diff --git a/src/api/endpoints/utils.rs b/src/api/endpoints/utils.rs index 4592426..66547b3 100644 --- a/src/api/endpoints/utils.rs +++ b/src/api/endpoints/utils.rs @@ -1,18 +1,11 @@ -use crate::*; -use blockfrost_openapi::models::{ - pool::Pool, pool_delegators_inner::PoolDelegatorsInner, pool_history_inner::PoolHistoryInner, - pool_list_retire_inner::PoolListRetireInner, pool_metadata::PoolMetadata, - pool_updates_inner::PoolUpdatesInner, - tx_content_pool_certs_inner_relays_inner::TxContentPoolCertsInnerRelaysInner, -}; +use crate::{request::send_request, url::Url, *}; +use reqwest::{header::HeaderValue, Body, Method}; +use serde_json::from_str as json_from; impl BlockfrostAPI { pub async fn derive_address( - &self, - xpub: &str, - role: &str, - index: &str, - ) -> BlockfrostResult { + &self, xpub: &str, role: &str, index: &str, + ) -> BlockfrostResult { self.call_endpoint(format!("/utils/addresses/xpub/{}/{}/{}", xpub, role, index).as_str()) .await } @@ -37,12 +30,12 @@ impl BlockfrostAPI { if !status.is_success() { return Err(process_error_response(&text, status, &url)); } + json_from(&text).map_err(|reason| json_error(url, text, reason)) } pub async fn utils_tx_evaluate_utxos( - &self, - transaction_data: Vec, + &self, transaction_data: Vec, ) -> BlockfrostResult { let body = Body::from(transaction_data); let url = Url::from_endpoint(self.base_url.as_str(), "/utils/txs/evaluate/utxos")?;