From 39cd1380f961db0662c25a1afb17b256d03b36a8 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 27 Jun 2023 10:00:42 +0200 Subject: [PATCH] Move get_output_with_metadata --- sdk/src/client/node_api/core/mod.rs | 15 +++++++++++++++ sdk/src/client/node_api/core/routes.rs | 18 ++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/sdk/src/client/node_api/core/mod.rs b/sdk/src/client/node_api/core/mod.rs index 03c602f359..0dfce551c6 100644 --- a/sdk/src/client/node_api/core/mod.rs +++ b/sdk/src/client/node_api/core/mod.rs @@ -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::{ @@ -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 { + 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> { #[cfg(target_family = "wasm")] diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 64c0b9169b..de61831d9b 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -21,7 +21,7 @@ use crate::{ block::{ output::{ dto::{OutputDto, OutputMetadataDto}, - Output, OutputId, OutputMetadata, OutputWithMetadata, + Output, OutputId, OutputMetadata, }, payload::transaction::TransactionId, slot::{SlotCommitment, SlotCommitmentId, SlotIndex}, @@ -304,19 +304,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 { - 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 { @@ -458,8 +445,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())