Skip to content

Commit

Permalink
Move get_output_with_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Jun 27, 2023
1 parent e3354d4 commit 159d2ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
15 changes: 15 additions & 0 deletions sdk/src/client/node_api/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

pub mod routes;

use packable::PackableExt;

#[cfg(not(target_family = "wasm"))]
use crate::client::constants::MAX_PARALLEL_API_REQUESTS;
use crate::{
Expand All @@ -13,6 +15,19 @@ use crate::{
};

impl Client {
// Finds output and its metadata by output ID.
/// GET /api/core/v3/outputs/{outputId}
/// + GET /api/core/v3/outputs/{outputId}/metadata
pub async fn get_output_with_metadata(&self, output_id: &OutputId) -> Result<OutputWithMetadata> {
let output = Output::unpack_verified(
self.get_output_raw(output_id).await?,
&self.get_protocol_parameters().await?,
)?;
let metadata = self.get_output_metadata(output_id).await?;

Ok(OutputWithMetadata::new(output, metadata))
}

/// Request outputs by their output ID in parallel
pub async fn get_outputs(&self, output_ids: &[OutputId]) -> Result<Vec<Output>> {
#[cfg(target_family = "wasm")]
Expand Down
18 changes: 2 additions & 16 deletions sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
block::{
output::{
dto::{OutputDto, OutputMetadataDto},
Output, OutputId, OutputMetadata, OutputWithMetadata,
Output, OutputId, OutputMetadata,
},
payload::transaction::TransactionId,
slot::{SlotCommitment, SlotCommitmentId, SlotIndex},
Expand Down Expand Up @@ -300,19 +300,6 @@ impl ClientInner {
Ok(OutputMetadata::try_from(metadata)?)
}

// Finds output and its metadata by output ID.
/// GET /api/core/v3/outputs/{outputId}
/// + GET /api/core/v3/outputs/{outputId}/metadata
pub async fn get_output_with_metadata(&self, output_id: &OutputId) -> Result<OutputWithMetadata> {
let output = Output::unpack_verified(
self.get_output_raw(output_id).await?,
&self.get_protocol_parameters().await?,
)?;
let metadata = self.get_output_metadata(output_id).await?;

Ok(OutputWithMetadata::new(output, metadata))
}

/// Returns the block that was included in the ledger for a given transaction ID, as object.
/// GET /api/core/v3/transactions/{transactionId}/included-block
pub async fn get_included_block(&self, transaction_id: &TransactionId) -> Result<Block> {
Expand Down Expand Up @@ -451,8 +438,7 @@ impl Client {
.map_err(|_| crate::client::Error::UrlAuth("password"))?;
}
}
let path = "api/core/v3/info";
url.set_path(path);
url.set_path(INFO_PATH);

let resp: InfoResponse =
crate::client::node_manager::http_client::HttpClient::new(DEFAULT_USER_AGENT.to_string())
Expand Down

0 comments on commit 159d2ba

Please sign in to comment.