Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OutputIdProof to response for /api/core/v3/outputs/{outputId} #1763

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/examples/client/02_address_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
9 changes: 6 additions & 3 deletions sdk/src/client/node_api/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Output>> {
pub async fn get_outputs(&self, output_ids: &[OutputId]) -> Result<Vec<OutputResponse>> {
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<Vec<Output>> {
pub async fn get_outputs_ignore_not_found(&self, output_ids: &[OutputId]) -> Result<Vec<OutputResponse>> {
futures::future::join_all(output_ids.iter().map(|id| self.get_output(id)))
.await
.into_iter()
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Output> {
pub async fn get_output(&self, output_id: &OutputId) -> Result<OutputResponse> {
let path = &format!("api/core/v3/outputs/{output_id}");

self.get_request(path, None, false, true).await
Expand Down
17 changes: 8 additions & 9 deletions sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -529,11 +529,10 @@ pub struct UtxoChangesResponse {
pub consumed_outputs: Vec<OutputId>,
}

// 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,
}
4 changes: 2 additions & 2 deletions sdk/src/wallet/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/syncing/foundries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/tests/client/node_api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async fn test_get_output_raw() {
)
.unwrap();

assert_eq!(output, output_raw);
assert_eq!(output.output, output_raw);
}

#[ignore]
Expand Down
Loading