From f32ac1aabbf85a57702ffe69a82d13b7d62f89ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Mon, 11 Dec 2023 11:56:50 +0100 Subject: [PATCH] Add OutputIdProof to response for /api/core/v3/outputs/{outputId} --- sdk/examples/client/02_address_balance.rs | 4 ++-- sdk/src/client/node_api/core/mod.rs | 9 ++++++--- sdk/src/client/node_api/core/routes.rs | 8 ++++---- sdk/src/types/api/core.rs | 17 ++++++++--------- sdk/src/wallet/core/mod.rs | 4 ++-- sdk/src/wallet/operations/syncing/foundries.rs | 2 +- sdk/tests/client/node_api/core.rs | 2 +- 7 files changed, 24 insertions(+), 22 deletions(-) diff --git a/sdk/examples/client/02_address_balance.rs b/sdk/examples/client/02_address_balance.rs index 04019f6735..9df0ef3ccc 100644 --- a/sdk/examples/client/02_address_balance.rs +++ b/sdk/examples/client/02_address_balance.rs @@ -59,10 +59,10 @@ async fn main() -> Result<()> { let mut total_amount = 0; let mut total_native_tokens = NativeTokensBuilder::new(); for output in outputs { - if let Some(native_token) = output.native_token() { + if let Some(native_token) = output.output.native_token() { total_native_tokens.add_native_token(*native_token)?; } - total_amount += output.amount(); + total_amount += output.output.amount(); } println!( diff --git a/sdk/src/client/node_api/core/mod.rs b/sdk/src/client/node_api/core/mod.rs index e243916590..9dd7987017 100644 --- a/sdk/src/client/node_api/core/mod.rs +++ b/sdk/src/client/node_api/core/mod.rs @@ -7,18 +7,21 @@ pub mod routes; use crate::{ client::{node_api::error::Error as NodeApiError, Client, Error, Result}, - types::block::output::{Output, OutputId, OutputMetadata, OutputWithMetadata}, + types::{ + api::core::OutputResponse, + block::output::{OutputId, OutputMetadata, OutputWithMetadata}, + }, }; impl Client { /// Requests outputs by their output ID in parallel. - pub async fn get_outputs(&self, output_ids: &[OutputId]) -> Result> { + pub async fn get_outputs(&self, output_ids: &[OutputId]) -> Result> { futures::future::try_join_all(output_ids.iter().map(|id| self.get_output(id))).await } /// Requests outputs by their output ID in parallel, ignoring outputs not found. /// Useful to get data about spent outputs, that might not be pruned yet. - pub async fn get_outputs_ignore_not_found(&self, output_ids: &[OutputId]) -> Result> { + pub async fn get_outputs_ignore_not_found(&self, output_ids: &[OutputId]) -> Result> { futures::future::join_all(output_ids.iter().map(|id| self.get_output(id))) .await .into_iter() diff --git a/sdk/src/client/node_api/core/routes.rs b/sdk/src/client/node_api/core/routes.rs index 80c09664dd..d0a705ba54 100644 --- a/sdk/src/client/node_api/core/routes.rs +++ b/sdk/src/client/node_api/core/routes.rs @@ -17,12 +17,12 @@ use crate::{ types::{ api::core::{ BlockMetadataResponse, BlockWithMetadataResponse, CommitteeResponse, CongestionResponse, InfoResponse, - IssuanceBlockHeaderResponse, ManaRewardsResponse, PeerResponse, RoutesResponse, SubmitBlockResponse, - UtxoChangesResponse, ValidatorResponse, ValidatorsResponse, + IssuanceBlockHeaderResponse, ManaRewardsResponse, OutputResponse, PeerResponse, RoutesResponse, + SubmitBlockResponse, UtxoChangesResponse, ValidatorResponse, ValidatorsResponse, }, block::{ address::ToBech32Ext, - output::{AccountId, Output, OutputId, OutputMetadata, OutputWithMetadata}, + output::{AccountId, OutputId, OutputMetadata, OutputWithMetadata}, payload::signed_transaction::TransactionId, slot::{EpochIndex, SlotCommitment, SlotCommitmentId, SlotIndex}, Block, BlockDto, BlockId, @@ -234,7 +234,7 @@ impl ClientInner { /// Finds an output by its ID and returns it as object. /// GET /api/core/v3/outputs/{outputId} - pub async fn get_output(&self, output_id: &OutputId) -> Result { + pub async fn get_output(&self, output_id: &OutputId) -> Result { let path = &format!("api/core/v3/outputs/{output_id}"); self.get_request(path, None, false, true).await diff --git a/sdk/src/types/api/core.rs b/sdk/src/types/api/core.rs index a6e093e80d..56548657f1 100644 --- a/sdk/src/types/api/core.rs +++ b/sdk/src/types/api/core.rs @@ -14,7 +14,7 @@ use crate::{ types::block::{ address::Bech32Address, core::Parents, - output::{Output, OutputId, OutputMetadata, OutputWithMetadata}, + output::{Output, OutputId, OutputIdProof, OutputMetadata, OutputWithMetadata}, payload::signed_transaction::TransactionId, protocol::{ProtocolParameters, ProtocolParametersHash}, semantic::TransactionFailureReason, @@ -529,11 +529,10 @@ pub struct UtxoChangesResponse { pub consumed_outputs: Vec, } -// TODO use for outputs route https://github.com/iotaledger/iota-sdk/issues/1686 -// /// Contains the generic [`Output`] with associated [`OutputIdProof`]. -// #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -// #[serde(rename_all = "camelCase")] -// pub struct OutputResponse { -// pub output: Output, -// pub output_id_proof: OutputIdProof, -// } +/// Contains the generic [`Output`] with associated [`OutputIdProof`]. +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct OutputResponse { + pub output: Output, + pub output_id_proof: OutputIdProof, +} diff --git a/sdk/src/wallet/core/mod.rs b/sdk/src/wallet/core/mod.rs index 50fbaab439..4237cda2e7 100644 --- a/sdk/src/wallet/core/mod.rs +++ b/sdk/src/wallet/core/mod.rs @@ -391,9 +391,9 @@ where // Foundry was not found in the wallet, try to get it from the node let foundry_output_id = self.client().foundry_output_id(foundry_id).await?; - let output = self.client().get_output(&foundry_output_id).await?; + let output_response = self.client().get_output(&foundry_output_id).await?; - Ok(output) + Ok(output_response.output) } /// Save the wallet to the database, accepts the updated wallet data as option so we don't need to drop it before diff --git a/sdk/src/wallet/operations/syncing/foundries.rs b/sdk/src/wallet/operations/syncing/foundries.rs index 166c4fd64f..278ceca9a9 100644 --- a/sdk/src/wallet/operations/syncing/foundries.rs +++ b/sdk/src/wallet/operations/syncing/foundries.rs @@ -41,7 +41,7 @@ where // Update account with new foundries. for foundry in results.into_iter().flatten() { - if let Output::Foundry(foundry) = foundry { + if let Output::Foundry(foundry) = foundry.output { foundries.insert(foundry.id(), foundry); } } diff --git a/sdk/tests/client/node_api/core.rs b/sdk/tests/client/node_api/core.rs index 12edd7bf62..48da2a2cc3 100644 --- a/sdk/tests/client/node_api/core.rs +++ b/sdk/tests/client/node_api/core.rs @@ -163,7 +163,7 @@ async fn test_get_output_raw() { ) .unwrap(); - assert_eq!(output, output_raw); + assert_eq!(output.output, output_raw); } #[ignore]