Skip to content

Commit

Permalink
Add retrying to all IPFS requests, and Cardanos transactions_submit
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Nov 11, 2021
1 parent abef38f commit db8d83a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/api/endpoints/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use reqwest::{header::HeaderValue, Body, Method};
use serde::{Deserialize, Serialize};

use crate::{url::Url, *};
use crate::{request::send_request_with_retries, url::Url, *};

impl BlockFrostApi {
/// Obtain information about Move Instantaneous Rewards (MIRs) of a specific transaction.
Expand All @@ -16,13 +16,12 @@ impl BlockFrostApi {
let endpoint_suffix = "/tx/submit";
let Url(url) = Url::from_endpoint_without_parameters(&self.settings, endpoint_suffix);

let response = self
let request = self
.client
.request(Method::POST, &url)
.header(content_type_header.0, content_type_header.1)
.body(body)
.send()
.await?;
.body(body);
let response = send_request_with_retries(request, self.settings.retry_settings).await?;

let status_code = response.status();
let text = response.text().await?;
Expand Down
21 changes: 14 additions & 7 deletions src/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use reqwest::multipart::{Form, Part};
use serde::{Deserialize, Serialize};

use crate::{
error::process_error_response, utils::create_client_with_project_id, Integer, IpfsSettings,
error::process_error_response, request::send_request_with_retries,
utils::create_client_with_project_id, Integer, IpfsSettings,
};

/// Provides methods for making requests to the
Expand Down Expand Up @@ -44,7 +45,7 @@ impl IpfsApi {
let form = Form::new().part("file", part);

let request = self.client.post(&url).multipart(form);
let response = request.send().await?;
let response = send_request_with_retries(request, self.settings.retry_settings).await?;

let status_code = response.status();
let text = response.text().await?;
Expand All @@ -67,7 +68,8 @@ impl IpfsApi {
let url = self.settings.network_address.clone()
+ &format!("/ipfs/gateway/{IPFS_path}", IPFS_path = ipfs_path);

let response = self.client.get(&url).send().await?;
let request = self.client.get(&url);
let response = send_request_with_retries(request, self.settings.retry_settings).await?;
let status_code = response.status();

if !status_code.is_success() {
Expand All @@ -88,7 +90,8 @@ impl IpfsApi {
let url = self.settings.network_address.clone()
+ &format!("/ipfs/pin/add/{IPFS_path}", IPFS_path = ipfs_path);

let response = self.client.post(&url).send().await?;
let request = self.client.post(&url);
let response = send_request_with_retries(request, self.settings.retry_settings).await?;
let status_code = response.status();
let text = response.text().await?;
if !status_code.is_success() {
Expand All @@ -106,7 +109,9 @@ impl IpfsApi {
pub async fn pin_list(&self) -> crate::Result<Vec<IpfsPinList>> {
let url = self.settings.network_address.clone() + "/ipfs/pin/list";

let response = self.client.get(&url).send().await?;
let request = self.client.get(&url);
let response = send_request_with_retries(request, self.settings.retry_settings).await?;

let status_code = response.status();
let text = response.text().await?;
if !status_code.is_success() {
Expand All @@ -125,7 +130,8 @@ impl IpfsApi {
let url = self.settings.network_address.clone()
+ &format!("/ipfs/pin/list/{IPFS_path}", IPFS_path = ipfs_path);

let response = self.client.get(&url).send().await?;
let request = self.client.get(&url);
let response = send_request_with_retries(request, self.settings.retry_settings).await?;
let status_code = response.status();
let text = response.text().await?;
if !status_code.is_success() {
Expand All @@ -144,7 +150,8 @@ impl IpfsApi {
let url = self.settings.network_address.clone()
+ &format!("/ipfs/pin/remove/{IPFS_path}", IPFS_path = ipfs_path);

let response = self.client.post(&url).send().await?;
let request = self.client.post(&url);
let response = send_request_with_retries(request, self.settings.retry_settings).await?;
let status_code = response.status();
let text = response.text().await?;
if !status_code.is_success() {
Expand Down

0 comments on commit db8d83a

Please sign in to comment.