diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index 3f81575eb7..c83185c600 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -1289,12 +1289,12 @@ async fn print_wallet_address(wallet: &Wallet) -> Result<(), Error> { let mut delegations = Vec::new(); let mut anchors = Vec::new(); - for output_data in wallet.ledger().await.unspent_outputs().values() { - let output_id = output_data.output_id; + for output_with_ext_metadata in wallet.ledger().await.unspent_outputs().values() { + let output_id = output_with_ext_metadata.output_id; output_ids.push(output_id); // Output might be associated with the address, but can't be unlocked by it, so we check that here. - let required_address = &output_data + let required_address = &output_with_ext_metadata .output .required_address(slot_index, protocol_parameters.committable_age_range())?; @@ -1302,10 +1302,10 @@ async fn print_wallet_address(wallet: &Wallet) -> Result<(), Error> { .as_ref() .is_some_and(|required_address| required_address == address.inner()) { - if let Some(nt) = output_data.output.native_token() { + if let Some(nt) = output_with_ext_metadata.output.native_token() { native_tokens.add_native_token(*nt)?; } - match &output_data.output { + match &output_with_ext_metadata.output { Output::Basic(_) => {} Output::Account(account) => accounts.push(account.account_id_non_null(&output_id)), Output::Foundry(foundry) => foundries.push(foundry.id()), @@ -1313,7 +1313,7 @@ async fn print_wallet_address(wallet: &Wallet) -> Result<(), Error> { Output::Delegation(delegation) => delegations.push(delegation.delegation_id_non_null(&output_id)), Output::Anchor(anchor) => anchors.push(anchor.anchor_id_non_null(&output_id)), } - let unlock_conditions = output_data + let unlock_conditions = output_with_ext_metadata .output .unlock_conditions() .expect("output must have unlock conditions"); @@ -1322,7 +1322,7 @@ async fn print_wallet_address(wallet: &Wallet) -> Result<(), Error> { .map(|sdr| sdr.amount()) .unwrap_or(0); - amount += output_data.output.amount() - sdr_amount; + amount += output_with_ext_metadata.output.amount() - sdr_amount; } } @@ -1650,26 +1650,30 @@ pub async fn prompt_internal( Ok(PromptResponse::Reprompt) } -fn print_outputs(mut outputs: Vec, title: &str) -> Result<(), Error> { - if outputs.is_empty() { +fn print_outputs(mut outputs_with_ext_metadata: Vec, title: &str) -> Result<(), Error> { + if outputs_with_ext_metadata.is_empty() { println_log_info!("No outputs found"); } else { println_log_info!("{title}"); - outputs.sort_unstable_by_key(|o| o.output_id); + outputs_with_ext_metadata.sort_unstable_by_key(|o| o.output_id); - for (i, output_data) in outputs.into_iter().enumerate() { - let kind_str = if output_data.output.is_implicit_account() { + for (i, output_with_ext_metadata) in outputs_with_ext_metadata.into_iter().enumerate() { + let kind_str = if output_with_ext_metadata.output.is_implicit_account() { "ImplicitAccount" } else { - output_data.output.kind_str() + output_with_ext_metadata.output.kind_str() }; println_log_info!( "{:<5}{} {:<16}{}", i, - &output_data.output_id, + &output_with_ext_metadata.output_id, kind_str, - if output_data.is_spent() { "Spent" } else { "Unspent" }, + if output_with_ext_metadata.is_spent() { + "Spent" + } else { + "Unspent" + }, ); } } diff --git a/sdk/examples/how_tos/wallet/consolidate_outputs.rs b/sdk/examples/how_tos/wallet/consolidate_outputs.rs index 846f1afde6..163ff87a50 100644 --- a/sdk/examples/how_tos/wallet/consolidate_outputs.rs +++ b/sdk/examples/how_tos/wallet/consolidate_outputs.rs @@ -51,12 +51,12 @@ async fn main() -> Result<(), Box> { .unspent_outputs() .values() .enumerate() - .for_each(|(i, output_data)| { + .for_each(|(i, output_with_ext_metadata)| { println!("OUTPUT #{i}"); println!( "- amount: {:?}\n- native tokens: {:?}", - output_data.output.amount(), - output_data.output.native_token() + output_with_ext_metadata.output.amount(), + output_with_ext_metadata.output.native_token() ) }); @@ -91,12 +91,12 @@ async fn main() -> Result<(), Box> { .unspent_outputs() .values() .enumerate() - .for_each(|(i, output_data)| { + .for_each(|(i, output_with_ext_metadata)| { println!("OUTPUT #{i}"); println!( "- amount: {:?}\n- native tokens: {:?}", - output_data.output.amount(), - output_data.output.native_token() + output_with_ext_metadata.output.amount(), + output_with_ext_metadata.output.native_token() ) }); diff --git a/sdk/src/wallet/core/mod.rs b/sdk/src/wallet/core/mod.rs index f20e88a0b9..d19e3022cc 100644 --- a/sdk/src/wallet/core/mod.rs +++ b/sdk/src/wallet/core/mod.rs @@ -287,14 +287,14 @@ impl WalletLedger { pub fn implicit_accounts(&self) -> impl Iterator { self.unspent_outputs .values() - .filter(|output_data| output_data.output.is_implicit_account()) + .filter(|output_with_ext_metadata| output_with_ext_metadata.output.is_implicit_account()) } /// Returns accounts of the wallet. pub fn accounts(&self) -> impl Iterator { self.unspent_outputs .values() - .filter(|output_data| output_data.output.is_account()) + .filter(|output_with_ext_metadata| output_with_ext_metadata.output.is_account()) } // Returns the first possible Account id, which can be an implicit account. @@ -305,7 +305,7 @@ impl WalletLedger { .or_else(|| self.implicit_accounts().next().map(|o| AccountId::from(&o.output_id))) } - /// Get the [`OutputData`] of an output stored in the wallet. + /// Get the [`OutputWithExtendedMetadata`] of an output stored in the wallet. pub fn get_output(&self, output_id: &OutputId) -> Option<&OutputWithExtendedMetadata> { self.outputs.get(output_id) } @@ -345,10 +345,10 @@ impl Wallet { pub async fn get_foundry_output(&self, native_token_id: TokenId) -> Result { let foundry_id = FoundryId::from(native_token_id); - for output_data in self.ledger.read().await.outputs.values() { - if let Output::Foundry(foundry_output) = &output_data.output { + for output_with_ext_metadata in self.ledger.read().await.outputs.values() { + if let Output::Foundry(foundry_output) = &output_with_ext_metadata.output { if foundry_output.id() == foundry_id { - return Ok(output_data.output.clone()); + return Ok(output_with_ext_metadata.output.clone()); } } } diff --git a/sdk/src/wallet/operations/balance.rs b/sdk/src/wallet/operations/balance.rs index e137da3c04..6d71b5ded9 100644 --- a/sdk/src/wallet/operations/balance.rs +++ b/sdk/src/wallet/operations/balance.rs @@ -51,13 +51,13 @@ impl Wallet { let mut reward_outputs = HashSet::new(); - for (output_id, output_data) in &wallet_ledger.unspent_outputs { + for (output_id, output_with_ext_metadata) in &wallet_ledger.unspent_outputs { // Check if output is from the network we're currently connected to - if output_data.network_id != network_id { + if output_with_ext_metadata.network_id != network_id { continue; } - let output = &output_data.output; + let output = &output_with_ext_metadata.output; let storage_cost = output.minimum_amount(storage_score_params); // Add account, foundry, and delegation outputs here because they can't have a @@ -270,17 +270,17 @@ impl Wallet { if balance.potentially_locked_outputs.contains_key(locked_output) { continue; } - if let Some(output_data) = wallet_ledger.unspent_outputs.get(locked_output) { + if let Some(output_with_ext_metadata) = wallet_ledger.unspent_outputs.get(locked_output) { // Only check outputs that are in this network - if output_data.network_id == network_id { - locked_amount += output_data.output.amount(); - locked_mana += output_data.output.decayed_mana( + if output_with_ext_metadata.network_id == network_id { + locked_amount += output_with_ext_metadata.output.amount(); + locked_mana += output_with_ext_metadata.output.decayed_mana( &protocol_parameters, - output_data.output_id.transaction_id().slot_index(), + output_with_ext_metadata.output_id.transaction_id().slot_index(), slot_index, )?; - if let Some(native_token) = output_data.output.native_token() { + if let Some(native_token) = output_with_ext_metadata.output.native_token() { locked_native_tokens.add_native_token(*native_token)?; } } diff --git a/sdk/src/wallet/operations/helpers/time.rs b/sdk/src/wallet/operations/helpers/time.rs index d8a481e8e8..fa9dd38291 100644 --- a/sdk/src/wallet/operations/helpers/time.rs +++ b/sdk/src/wallet/operations/helpers/time.rs @@ -9,17 +9,17 @@ use crate::{ // Check if an output can be unlocked by the wallet address at the current time pub(crate) fn can_output_be_unlocked_now( wallet_address: &Address, - output_data: &OutputWithExtendedMetadata, + output_with_ext_metadata: &OutputWithExtendedMetadata, commitment_slot_index: impl Into + Copy, committable_age_range: CommittableAgeRange, ) -> Result { - if let Some(unlock_conditions) = output_data.output.unlock_conditions() { + if let Some(unlock_conditions) = output_with_ext_metadata.output.unlock_conditions() { if unlock_conditions.is_timelocked(commitment_slot_index, committable_age_range.min) { return Ok(false); } } - let required_address = output_data + let required_address = output_with_ext_metadata .output .required_address(commitment_slot_index.into(), committable_age_range)?; diff --git a/sdk/src/wallet/operations/output_claiming.rs b/sdk/src/wallet/operations/output_claiming.rs index 35ded2e8d9..1fd132c2e5 100644 --- a/sdk/src/wallet/operations/output_claiming.rs +++ b/sdk/src/wallet/operations/output_claiming.rs @@ -56,14 +56,14 @@ impl WalletLedger { // Get outputs for the claim let mut output_ids_to_claim: HashSet = HashSet::new(); - for (output_id, output_data) in self + for (output_id, output_with_ext_metadata) in self .unspent_outputs .iter() .filter(|(_, o)| o.output.is_basic() || o.output.is_nft()) { // Don't use outputs that are locked for other transactions if !self.locked_outputs.contains(output_id) && self.outputs.contains_key(output_id) { - if let Some(unlock_conditions) = output_data.output.unlock_conditions() { + if let Some(unlock_conditions) = output_with_ext_metadata.output.unlock_conditions() { // If there is a single [UnlockCondition], then it's an // [AddressUnlockCondition] and we own it already without // further restrictions @@ -72,7 +72,7 @@ impl WalletLedger { // We use the addresses with unspent outputs, because other addresses of the // account without unspent outputs can't be related to this output wallet_address.inner(), - output_data, + output_with_ext_metadata, slot_index, protocol_parameters.committable_age_range(), )? @@ -87,8 +87,8 @@ impl WalletLedger { Some(false) => { // Only micro transaction if not the same amount needs to be returned // (resulting in 0 amount to claim) - if sdr.amount() != output_data.output.amount() { - output_ids_to_claim.insert(output_data.output_id); + if sdr.amount() != output_with_ext_metadata.output.amount() { + output_ids_to_claim.insert(output_with_ext_metadata.output_id); } } _ => continue, @@ -96,17 +96,17 @@ impl WalletLedger { } } OutputsToClaim::NativeTokens => { - if output_data.output.native_token().is_some() { - output_ids_to_claim.insert(output_data.output_id); + if output_with_ext_metadata.output.native_token().is_some() { + output_ids_to_claim.insert(output_with_ext_metadata.output_id); } } OutputsToClaim::Nfts => { - if output_data.output.is_nft() { - output_ids_to_claim.insert(output_data.output_id); + if output_with_ext_metadata.output.is_nft() { + output_ids_to_claim.insert(output_with_ext_metadata.output_id); } } OutputsToClaim::Amount => { - let mut claimable_amount = output_data.output.amount(); + let mut claimable_amount = output_with_ext_metadata.output.amount(); if unlock_conditions.is_expired(slot_index, protocol_parameters.committable_age_range()) == Some(false) { @@ -116,11 +116,11 @@ impl WalletLedger { .unwrap_or_default() }; if claimable_amount > 0 { - output_ids_to_claim.insert(output_data.output_id); + output_ids_to_claim.insert(output_with_ext_metadata.output_id); } } OutputsToClaim::All => { - output_ids_to_claim.insert(output_data.output_id); + output_ids_to_claim.insert(output_with_ext_metadata.output_id); } } } @@ -172,11 +172,11 @@ where // Get basic outputs only with AddressUnlockCondition and no other unlock condition let mut basic_outputs: Vec = Vec::new(); - for (output_id, output_data) in &wallet_ledger.unspent_outputs { + for (output_id, output_with_ext_metadata) in &wallet_ledger.unspent_outputs { #[cfg(feature = "participation")] if let Some(ref voting_output) = voting_output { // Remove voting output from inputs, because we don't want to spent it to claim something else. - if output_data.output_id == voting_output.output_id { + if output_with_ext_metadata.output_id == voting_output.output_id { continue; } } @@ -189,7 +189,7 @@ where if !a.address().is_implicit_account_creation() { // Store outputs with [`AddressUnlockCondition`] alone, because they could be used as // additional input, if required - basic_outputs.push(output_data.clone()); + basic_outputs.push(output_with_ext_metadata.clone()); } } } @@ -240,9 +240,9 @@ where let mut outputs_to_claim = Vec::new(); for output_id in output_ids_to_claim { - if let Some(output_data) = wallet_ledger.unspent_outputs.get(&output_id) { + if let Some(output_with_extended_metadata) = wallet_ledger.unspent_outputs.get(&output_id) { if !wallet_ledger.locked_outputs.contains(&output_id) { - outputs_to_claim.push(output_data.clone()); + outputs_to_claim.push(output_with_extended_metadata.clone()); } } } @@ -266,8 +266,8 @@ where .sum::() >= BasicOutput::minimum_amount(&Address::from(Ed25519Address::null()), storage_score_params); - for output_data in &outputs_to_claim { - if let Output::Nft(nft_output) = &output_data.output { + for output_with_ext_metadata in &outputs_to_claim { + if let Output::Nft(nft_output) = &output_with_ext_metadata.output { // build new output with same amount, nft_id, immutable/feature blocks and native tokens, just // updated address unlock conditions @@ -275,13 +275,13 @@ where // Only update address and nft id if we have no additional inputs which can provide the storage // deposit for the remaining amount and possible native tokens NftOutputBuilder::from(nft_output) - .with_nft_id(nft_output.nft_id_non_null(&output_data.output_id)) + .with_nft_id(nft_output.nft_id_non_null(&output_with_ext_metadata.output_id)) .with_unlock_conditions([AddressUnlockCondition::new(&wallet_address)]) .finish_output()? } else { NftOutputBuilder::from(nft_output) .with_minimum_amount(storage_score_params) - .with_nft_id(nft_output.nft_id_non_null(&output_data.output_id)) + .with_nft_id(nft_output.nft_id_non_null(&output_with_ext_metadata.output_id)) .with_unlock_conditions([AddressUnlockCondition::new(&wallet_address)]) .finish_output()? }; diff --git a/sdk/src/wallet/operations/output_consolidation.rs b/sdk/src/wallet/operations/output_consolidation.rs index 289f27a454..2556be4a4c 100644 --- a/sdk/src/wallet/operations/output_consolidation.rs +++ b/sdk/src/wallet/operations/output_consolidation.rs @@ -126,11 +126,11 @@ where /// Determines whether an output should be consolidated or not. async fn should_consolidate_output( &self, - output_data: &OutputWithExtendedMetadata, + output_with_ext_metadata: &OutputWithExtendedMetadata, slot_index: SlotIndex, wallet_address: &Address, ) -> Result { - Ok(if let Output::Basic(basic_output) = &output_data.output { + Ok(if let Output::Basic(basic_output) = &output_with_ext_metadata.output { let protocol_parameters = self.client().get_protocol_parameters().await?; let unlock_conditions = basic_output.unlock_conditions(); @@ -158,7 +158,7 @@ where can_output_be_unlocked_now( wallet_address, - output_data, + output_with_ext_metadata, slot_index, protocol_parameters.committable_age_range(), )? @@ -182,48 +182,54 @@ where let mut outputs_to_consolidate = Vec::new(); let mut native_token_inputs = HashMap::new(); - for (output_id, output_data) in &wallet_ledger.unspent_outputs { + for (output_id, output_with_ext_metadata) in &wallet_ledger.unspent_outputs { // #[cfg(feature = "participation")] // if let Some(ref voting_output) = voting_output { // // Remove voting output from inputs, because we want to keep its features and not consolidate it. - // if output_data.output_id == voting_output.output_id { + // if output_with_ext_metadata.output_id == voting_output.output_id { // continue; // }.await // } let is_locked_output = wallet_ledger.locked_outputs.contains(output_id); let should_consolidate_output = self - .should_consolidate_output(output_data, slot_index, wallet_address.as_ref()) + .should_consolidate_output(output_with_ext_metadata, slot_index, wallet_address.as_ref()) .await?; if !is_locked_output && should_consolidate_output { - outputs_to_consolidate.push(output_data.clone()); + outputs_to_consolidate.push(output_with_ext_metadata.clone()); // Keep track of inputs with native tokens. - if let Some(nt) = &output_data.output.native_token() { + if let Some(nt) = &output_with_ext_metadata.output.native_token() { native_token_inputs .entry(*nt.token_id()) .or_insert_with(HashSet::new) - .insert(output_data.output_id); + .insert(output_with_ext_metadata.output_id); } } } // Remove outputs if they have a native token, <= minimum amount and there are no other outputs with the same // native token. - outputs_to_consolidate.retain(|output_data| { - output_data.output.native_token().as_ref().map_or(true, |nt| { - // `<=` because outputs in genesis snapshot can have a lower amount than min amount. - if output_data.output.amount() <= output_data.output.minimum_amount(storage_score_parameters) { - // If there is only a single output with this native token, then it shouldn't be consolidated, - // because no amount will be made available, since we need to create a remainder output with the - // native token again. - native_token_inputs - .get(nt.token_id()) - .map_or_else(|| false, |ids| ids.len() > 1) - } else { - true - } - }) + outputs_to_consolidate.retain(|output_with_ext_metadata| { + output_with_ext_metadata + .output + .native_token() + .as_ref() + .map_or(true, |nt| { + // `<=` because outputs in genesis snapshot can have a lower amount than min amount. + if output_with_ext_metadata.output.amount() + <= output_with_ext_metadata.output.minimum_amount(storage_score_parameters) + { + // If there is only a single output with this native token, then it shouldn't be consolidated, + // because no amount will be made available, since we need to create a remainder output with the + // native token again. + native_token_inputs + .get(nt.token_id()) + .map_or_else(|| false, |ids| ids.len() > 1) + } else { + true + } + }) }); drop(wallet_ledger); diff --git a/sdk/src/wallet/operations/participation/mod.rs b/sdk/src/wallet/operations/participation/mod.rs index a3b111c431..c10171c1b8 100644 --- a/sdk/src/wallet/operations/participation/mod.rs +++ b/sdk/src/wallet/operations/participation/mod.rs @@ -63,19 +63,19 @@ impl Wallet { // restored_spent_cached_outputs_len // ); // let wallet_ledger = self.data().await; - // let participation_outputs = wallet_ledger.outputs().values().filter(|output_data| { - // is_valid_participation_output(&output_data.output) + // let participation_outputs = wallet_ledger.outputs().values().filter(|output_with_ext_metadata| { + // is_valid_participation_output(&output_with_ext_metadata.output) // // Check that the metadata exists, because otherwise we aren't participating for anything - // && output_data.output.features().and_then(|f| f.metadata()).is_some() + // && output_with_ext_metadata.output.features().and_then(|f| f.metadata()).is_some() // // Don't add spent cached outputs, we have their data already and it can't change anymore - // && !spent_cached_outputs.contains_key(&output_data.output_id) + // && !spent_cached_outputs.contains_key(&output_with_ext_metadata.output_id) // }); // let mut events = HashMap::new(); // let mut spent_outputs = HashSet::new(); - // for output_data in participation_outputs { + // for output_with_ext_metadata in participation_outputs { // // PANIC: the filter already checks that the metadata exists. - // let metadata = output_data.output.features().and_then(|f| f.metadata()).unwrap(); + // let metadata = output_with_ext_metadata.output.features().and_then(|f| f.metadata()).unwrap(); // if let Ok(participations) = Participations::from_bytes(&mut metadata.data()) { // for participation in participations.participations { // // Skip events that aren't in `event_ids` if not None @@ -86,14 +86,14 @@ impl Wallet { // } // match events.entry(participation.event_id) { // Entry::Vacant(entry) => { - // entry.insert(vec![output_data.output_id]); + // entry.insert(vec![output_with_ext_metadata.output_id]); // } // Entry::Occupied(mut entry) => { - // entry.get_mut().push(output_data.output_id); + // entry.get_mut().push(output_with_ext_metadata.output_id); // } // } - // if output_data.is_spent() { - // spent_outputs.insert(output_data.output_id); + // if output_with_ext_metadata.is_spent() { + // spent_outputs.insert(output_with_ext_metadata.output_id); // } // } // }; @@ -275,8 +275,8 @@ impl WalletLedger { log::debug!("[get_voting_output]"); self.unspent_outputs .values() - .filter(|output_data| is_valid_participation_output(&output_data.output)) - .max_by_key(|output_data| output_data.output.amount()) + .filter(|output_with_ext_metadata| is_valid_participation_output(&output_with_ext_metadata.output)) + .max_by_key(|output_with_ext_metadata| output_with_ext_metadata.output.amount()) .cloned() } } diff --git a/sdk/src/wallet/operations/participation/voting_power.rs b/sdk/src/wallet/operations/participation/voting_power.rs index d48388604e..ea05dd405a 100644 --- a/sdk/src/wallet/operations/participation/voting_power.rs +++ b/sdk/src/wallet/operations/participation/voting_power.rs @@ -50,8 +50,8 @@ where /// Prepares the transaction for [Wallet::increase_voting_power()]. pub async fn prepare_increase_voting_power(&self, amount: u64) -> Result { let (new_output, tx_options) = match self.get_voting_output().await? { - Some(current_output_data) => { - let output = current_output_data.output.as_basic(); + Some(current_output_with_ext_metadata) => { + let output = current_output_with_ext_metadata.output.as_basic(); let new_amount = output.amount().checked_add(amount).ok_or(Error::InvalidVotingPower)?; @@ -62,7 +62,7 @@ where new_output, Some(TransactionOptions { // Use the previous voting output and additionally other for the additional amount. - required_inputs: Some(vec![current_output_data.output_id]), + required_inputs: Some(vec![current_output_with_ext_metadata.output_id]), tagged_data_payload: Some(tagged_data_payload), ..Default::default() }), @@ -97,11 +97,11 @@ where /// Prepares the transaction for [Wallet::decrease_voting_power()]. pub async fn prepare_decrease_voting_power(&self, amount: u64) -> Result { - let current_output_data = self + let current_output_with_ext_metadata = self .get_voting_output() .await? .ok_or_else(|| crate::wallet::Error::Voting("No unspent voting output found".to_string()))?; - let output = current_output_data.output.as_basic(); + let output = current_output_with_ext_metadata.output.as_basic(); // If the amount to decrease is the amount of the output, then we just remove the features. let (new_output, tagged_data_payload) = if amount == output.amount() { @@ -119,7 +119,7 @@ where Some(TransactionOptions { // Use the previous voting output and additionally others for possible additional required amount for // the remainder to reach the minimum required storage deposit. - required_inputs: Some(vec![current_output_data.output_id]), + required_inputs: Some(vec![current_output_with_ext_metadata.output_id]), tagged_data_payload, ..Default::default() }), diff --git a/sdk/src/wallet/operations/syncing/mod.rs b/sdk/src/wallet/operations/syncing/mod.rs index 55aca906d5..5da1666cbc 100644 --- a/sdk/src/wallet/operations/syncing/mod.rs +++ b/sdk/src/wallet/operations/syncing/mod.rs @@ -237,9 +237,11 @@ where .ledger() .await .implicit_accounts() - .filter_map(|output_data| { - if output_data.output.as_basic().address() == implicit_account_creation_address.inner() { - Some(output_data.output_id) + .filter_map(|output_with_ext_metadata| { + if output_with_ext_metadata.output.as_basic().address() + == implicit_account_creation_address.inner() + { + Some(output_with_ext_metadata.output_id) } else { None } diff --git a/sdk/src/wallet/operations/syncing/outputs.rs b/sdk/src/wallet/operations/syncing/outputs.rs index ecb69cb4fd..bcca1aef17 100644 --- a/sdk/src/wallet/operations/syncing/outputs.rs +++ b/sdk/src/wallet/operations/syncing/outputs.rs @@ -73,16 +73,16 @@ impl Wallet { for output_id in output_ids { match wallet_ledger.outputs.get_mut(&output_id) { // set unspent if not already - Some(output_data) => { - if output_data.is_spent() { + Some(output_with_ext_metadata) => { + if output_with_ext_metadata.is_spent() { log::warn!("Removing spent output metadata for {output_id}, because it's still unspent"); - output_data.metadata.spent = None; + output_with_ext_metadata.metadata.spent = None; } - unspent_outputs.push((*output_id, output_data.clone())); + unspent_outputs.push((*output_id, output_with_ext_metadata.clone())); outputs.push(OutputWithMetadataResponse::new( - output_data.output.clone(), - output_data.output_id_proof.clone(), - output_data.metadata, + output_with_ext_metadata.output.clone(), + output_with_ext_metadata.output_id_proof.clone(), + output_with_ext_metadata.metadata, )); } None => unknown_outputs.push(*output_id), @@ -90,8 +90,10 @@ impl Wallet { } // known output is unspent, so insert it to the unspent outputs again, because if it was an // account/nft/foundry output it could have been removed when syncing without them - for (output_id, output_data) in unspent_outputs { - wallet_ledger.unspent_outputs.insert(output_id, output_data); + for (output_id, output_with_ext_metadata) in unspent_outputs { + wallet_ledger + .unspent_outputs + .insert(output_id, output_with_ext_metadata); } drop(wallet_ledger); diff --git a/sdk/src/wallet/operations/syncing/transactions.rs b/sdk/src/wallet/operations/syncing/transactions.rs index 0e88e68ac4..772f9cf38a 100644 --- a/sdk/src/wallet/operations/syncing/transactions.rs +++ b/sdk/src/wallet/operations/syncing/transactions.rs @@ -91,14 +91,15 @@ where { let wallet_ledger = self.ledger().await; // Safe to unwrap, we just got the output - let confirmed_output_data = wallet_ledger.outputs.get(&transaction_output).expect("output exists"); + let confirmed_output_with_ext_metadata = + wallet_ledger.outputs.get(&transaction_output).expect("output exists"); log::debug!( "[SYNC] confirmed transaction {transaction_id} in block {}", - confirmed_output_data.metadata.block_id() + confirmed_output_with_ext_metadata.metadata.block_id() ); updated_transaction_and_outputs( transaction, - Some(*confirmed_output_data.metadata.block_id()), + Some(*confirmed_output_with_ext_metadata.metadata.block_id()), InclusionState::Confirmed, &mut updated_transactions, &mut spent_output_ids, @@ -246,8 +247,8 @@ fn process_transaction_with_unknown_state( let mut all_inputs_spent = true; for input in transaction.payload.transaction().inputs() { let Input::Utxo(input) = input; - if let Some(output_data) = wallet_ledger.outputs.get(input.output_id()) { - if !output_data.is_spent() { + if let Some(output_with_ext_metadata) = wallet_ledger.outputs.get(input.output_id()) { + if !output_with_ext_metadata.is_spent() { // unspent output needs to be made available again output_ids_to_unlock.push(*input.output_id()); all_inputs_spent = false; diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index 41738dd531..cb8946dd08 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -112,13 +112,13 @@ fn filter_inputs<'a>( ) -> Result, WalletError> { let mut available_outputs_signing_data = Vec::new(); - for output_data in available_outputs { - if !required_inputs.contains(&output_data.output_id) { + for output_with_ext_metadata in available_outputs { + if !required_inputs.contains(&output_with_ext_metadata.output_id) { let output_can_be_unlocked_now_and_in_future = can_output_be_unlocked_forever_from_now_on( // We use the addresses with unspent outputs, because other addresses of the // account without unspent outputs can't be related to this output wallet_address.inner(), - &output_data.output, + &output_with_ext_metadata.output, slot_index, committable_age_range, ); @@ -129,9 +129,12 @@ fn filter_inputs<'a>( } } - if let Some(available_input) = - output_data.input_signing_data(wallet_address, wallet_bip_path, slot_index, committable_age_range)? - { + if let Some(available_input) = output_with_ext_metadata.input_signing_data( + wallet_address, + wallet_bip_path, + slot_index, + committable_age_range, + )? { available_outputs_signing_data.push(available_input); } } diff --git a/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs index 2c9098ce60..b372de8603 100644 --- a/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs @@ -51,14 +51,14 @@ where let foundry_id = FoundryId::from(token_id); let account_id = *foundry_id.account_address().account_id(); - let (existing_account_output_data, existing_foundry_output) = self - .find_account_and_foundry_output_data(account_id, foundry_id) + let (existing_account_output_with_ext_metadata, existing_foundry_output) = self + .find_account_and_foundry_output_with_ext_metadata(account_id, foundry_id) .await .map(|(account_data, foundry_data)| match foundry_data.output { Output::Foundry(foundry_output) => (account_data, foundry_output), _ => unreachable!("We already checked it's a foundry output"), })?; - let account_output_id = existing_account_output_data.output_id; + let account_output_id = existing_account_output_with_ext_metadata.output_id; let mut options = options.into(); if let Some(options) = options.as_mut() { options.required_inputs.insert(account_output_id); @@ -81,43 +81,46 @@ where self.prepare_send_outputs(outputs, options).await } - /// Find and return unspent `OutputData` for given `account_id` and `foundry_id` - async fn find_account_and_foundry_output_data( + /// Find and return unspent `OutputWithExtendedMetadata` for given `account_id` and `foundry_id` + async fn find_account_and_foundry_output_with_ext_metadata( &self, account_id: AccountId, foundry_id: FoundryId, ) -> Result<(OutputWithExtendedMetadata, OutputWithExtendedMetadata), WalletError> { - let mut existing_account_output_data = None; + let mut existing_account_output_with_ext_metadata = None; let mut existing_foundry_output = None; - for (output_id, output_data) in self.ledger().await.unspent_outputs.iter() { - match &output_data.output { + for (output_id, output_with_ext_metadata) in self.ledger().await.unspent_outputs.iter() { + match &output_with_ext_metadata.output { Output::Account(output) => { if output.account_id_non_null(output_id) == account_id { - existing_account_output_data = Some(output_data.clone()); + existing_account_output_with_ext_metadata = Some(output_with_ext_metadata.clone()); } } Output::Foundry(output) => { if output.id() == foundry_id { - existing_foundry_output = Some(output_data.clone()); + existing_foundry_output = Some(output_with_ext_metadata.clone()); } } // Not interested in these outputs here _ => {} } - if existing_account_output_data.is_some() && existing_foundry_output.is_some() { + if existing_account_output_with_ext_metadata.is_some() && existing_foundry_output.is_some() { break; } } - let existing_account_output_data = existing_account_output_data.ok_or_else(|| { + let existing_account_output_with_ext_metadata = existing_account_output_with_ext_metadata.ok_or_else(|| { WalletError::BurningOrMeltingFailed("required account output for foundry not found".to_string()) })?; - let existing_foundry_output_data = existing_foundry_output + let existing_foundry_output_with_ext_metadata = existing_foundry_output .ok_or_else(|| WalletError::BurningOrMeltingFailed("required foundry output not found".to_string()))?; - Ok((existing_account_output_data, existing_foundry_output_data)) + Ok(( + existing_account_output_with_ext_metadata, + existing_foundry_output_with_ext_metadata, + )) } } diff --git a/sdk/src/wallet/operations/transaction/high_level/create_account.rs b/sdk/src/wallet/operations/transaction/high_level/create_account.rs index cc9ea5d1f0..168f97d6b3 100644 --- a/sdk/src/wallet/operations/transaction/high_level/create_account.rs +++ b/sdk/src/wallet/operations/transaction/high_level/create_account.rs @@ -110,19 +110,16 @@ where ) -> Option<(AccountId, OutputWithExtendedMetadata)> { log::debug!("[get_account_output]"); let account_id = account_id.into(); - self.ledger() - .await - .unspent_outputs - .values() - .find_map(|output_data| match &output_data.output { + self.ledger().await.unspent_outputs.values().find_map( + |output_with_ext_metadata| match &output_with_ext_metadata.output { Output::Account(account_output) => { - let output_account_id = account_output.account_id_non_null(&output_data.output_id); + let output_account_id = account_output.account_id_non_null(&output_with_ext_metadata.output_id); account_id.map_or_else( - || Some((output_account_id, output_data.clone())), + || Some((output_account_id, output_with_ext_metadata.clone())), |account_id| { if output_account_id == account_id { - Some((output_account_id, output_data.clone())) + Some((output_account_id, output_with_ext_metadata.clone())) } else { None } @@ -130,7 +127,8 @@ where ) } _ => None, - }) + }, + ) } } diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs index a00e862141..402eb5eebd 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs @@ -96,22 +96,24 @@ where let protocol_parameters = self.client().get_protocol_parameters().await?; let storage_score_params = protocol_parameters.storage_score_parameters(); - let (account_id, account_output_data) = self + let (account_id, account_output_with_ext_metadata) = self .get_account_output(params.account_id) .await .ok_or_else(|| WalletError::MintingFailed("Missing account output".to_string()))?; let mut options = options.into(); if let Some(options) = options.as_mut() { - options.required_inputs.insert(account_output_data.output_id); + options + .required_inputs + .insert(account_output_with_ext_metadata.output_id); } else { options.replace(TransactionOptions { - required_inputs: [account_output_data.output_id].into(), + required_inputs: [account_output_with_ext_metadata.output_id].into(), ..Default::default() }); } - if let Output::Account(account_output) = &account_output_data.output { + if let Output::Account(account_output) = &account_output_with_ext_metadata.output { // create foundry output with minted native tokens let foundry_id = FoundryId::build( &AccountAddress::new(account_id), diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs index 3b465419d1..7cf0c0193c 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs @@ -55,8 +55,8 @@ where let mint_amount = mint_amount.into(); let wallet_ledger = self.ledger().await; - let existing_foundry_output = wallet_ledger.unspent_outputs.values().find(|output_data| { - if let Output::Foundry(output) = &output_data.output { + let existing_foundry_output = wallet_ledger.unspent_outputs.values().find(|output_with_ext_metadata| { + if let Output::Foundry(output) = &output_with_ext_metadata.output { TokenId::new(*output.id()) == token_id } else { false @@ -78,9 +78,10 @@ where } // Get the account output that controls the foundry output - let existing_account_output = wallet_ledger.unspent_outputs.values().find(|output_data| { - if let Output::Account(output) = &output_data.output { - output.account_id_non_null(&output_data.output_id) == **foundry_output.account_address() + let existing_account_output = wallet_ledger.unspent_outputs.values().find(|output_with_ext_metadata| { + if let Output::Account(output) = &output_with_ext_metadata.output { + output.account_id_non_null(&output_with_ext_metadata.output_id) + == **foundry_output.account_address() } else { false } diff --git a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs index 8ac76efa4b..98ed6b5c41 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs @@ -93,8 +93,8 @@ where self.client().bech32_hrp_matches(address.hrp()).await?; // Find nft output from the inputs - if let Some(nft_output_data) = self.ledger().await.unspent_nft_output(&nft_id) { - if let Output::Nft(nft_output) = &nft_output_data.output { + if let Some(nft_output_with_ext_metadata) = self.ledger().await.unspent_nft_output(&nft_id) { + if let Output::Nft(nft_output) = &nft_output_with_ext_metadata.output { // Set the nft id and new address unlock condition let nft_builder = NftOutputBuilder::from(nft_output) .with_nft_id(nft_id) diff --git a/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs b/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs index 387cf32cae..908c1c9c87 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/begin.rs @@ -58,14 +58,14 @@ where log::debug!("[TRANSACTION] prepare_begin_staking"); let account_id = params.account_id; - let account_output_data = self + let account_output_with_ext_metadata = self .ledger() .await .unspent_account_output(&account_id) .cloned() .ok_or_else(|| WalletError::AccountNotFound)?; - if account_output_data + if account_output_with_ext_metadata .output .features() .map_or(false, |f| f.staking().is_some()) @@ -89,7 +89,7 @@ where let slot_commitment_id = self.client().get_issuance().await?.latest_commitment.id(); let start_epoch = protocol_parameters.epoch_index_of(protocol_parameters.past_bounded_slot(slot_commitment_id)); - let output = AccountOutputBuilder::from(account_output_data.output.as_account()) + let output = AccountOutputBuilder::from(account_output_with_ext_metadata.output.as_account()) .with_account_id(account_id) .add_feature(StakingFeature::new( params.staked_amount, diff --git a/sdk/src/wallet/operations/transaction/high_level/staking/end.rs b/sdk/src/wallet/operations/transaction/high_level/staking/end.rs index 4dd5ca0abf..62e0e45a04 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/end.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/end.rs @@ -35,14 +35,14 @@ where ) -> Result { log::debug!("[TRANSACTION] prepare_end_staking"); - let account_output_data = self + let account_output_with_ext_metadata = self .ledger() .await .unspent_account_output(&account_id) .cloned() .ok_or_else(|| WalletError::AccountNotFound)?; - let staking_feature = account_output_data + let staking_feature = account_output_with_ext_metadata .output .features() .and_then(|f| f.staking()) @@ -61,7 +61,7 @@ where ))); } - let features = account_output_data + let features = account_output_with_ext_metadata .output .features() .map(|f| f.iter().filter(|f| !f.is_staking())) @@ -69,7 +69,7 @@ where .flatten() .cloned(); - let output = AccountOutputBuilder::from(account_output_data.output.as_account()) + let output = AccountOutputBuilder::from(account_output_with_ext_metadata.output.as_account()) .with_account_id(account_id) .with_features(features) .finish_output()?; diff --git a/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs b/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs index a4c8b9414f..03d074c853 100644 --- a/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs +++ b/sdk/src/wallet/operations/transaction/high_level/staking/extend.rs @@ -39,7 +39,7 @@ where ) -> Result { log::debug!("[TRANSACTION] prepare_extend_staking"); - let account_output_data = self + let account_output_with_ext_metadata = self .ledger() .await .unspent_account_output(&account_id) @@ -52,14 +52,14 @@ where let future_bounded_epoch = protocol_parameters.future_bounded_epoch(slot_commitment_id); - let staking_feature = account_output_data + let staking_feature = account_output_with_ext_metadata .output .features() .and_then(|f| f.staking()) .ok_or_else(|| WalletError::StakingFailed(format!("account id {account_id} is not staking")))?; - let mut output_builder = - AccountOutputBuilder::from(account_output_data.output.as_account()).with_account_id(account_id); + let mut output_builder = AccountOutputBuilder::from(account_output_with_ext_metadata.output.as_account()) + .with_account_id(account_id); // Just extend the end epoch if it's still possible if future_bounded_epoch <= staking_feature.end_epoch() { diff --git a/sdk/src/wallet/operations/transaction/prepare_output.rs b/sdk/src/wallet/operations/transaction/prepare_output.rs index c987e1e2f6..0a77d9002b 100644 --- a/sdk/src/wallet/operations/transaction/prepare_output.rs +++ b/sdk/src/wallet/operations/transaction/prepare_output.rs @@ -44,7 +44,7 @@ impl Wallet { let nft_id = params.assets.as_ref().and_then(|a| a.nft_id); - let (mut first_output_builder, existing_nft_output_data) = self + let (mut first_output_builder, existing_nft_output_with_ext_metadata) = self .create_initial_output_builder(params.recipient_address, nft_id, storage_score_params) .await?; @@ -164,8 +164,10 @@ impl Wallet { let mut available_base_coin = self.balance().await?.base_coin.available; // If we're sending an existing NFT, its minimum required storage deposit is not part of the available base_coin // balance, so we add it here - if let Some(existing_nft_output_data) = existing_nft_output_data { - available_base_coin += existing_nft_output_data.output.minimum_amount(storage_score_params); + if let Some(existing_nft_output_with_ext_metadata) = existing_nft_output_with_ext_metadata { + available_base_coin += existing_nft_output_with_ext_metadata + .output + .minimum_amount(storage_score_params); } if final_amount > available_base_coin { @@ -226,7 +228,7 @@ impl Wallet { nft_id: Option, params: StorageScoreParameters, ) -> Result<(OutputBuilder, Option), WalletError> { - let (mut first_output_builder, existing_nft_output_data) = if let Some(nft_id) = &nft_id { + let (mut first_output_builder, existing_nft_output_with_ext_metadata) = if let Some(nft_id) = &nft_id { if nft_id.is_null() { // Mint a new NFT output ( @@ -238,8 +240,8 @@ impl Wallet { let unspent_nft_output = self.ledger().await.unspent_nft_output(nft_id).cloned(); // Find nft output from the inputs - let mut first_output_builder = if let Some(nft_output_data) = &unspent_nft_output { - let nft_output = nft_output_data.output.as_nft(); + let mut first_output_builder = if let Some(nft_output_with_ext_metadata) = &unspent_nft_output { + let nft_output = nft_output_with_ext_metadata.output.as_nft(); NftOutputBuilder::from(nft_output).with_nft_id(*nft_id) } else { return Err(WalletError::NftNotFoundInUnspentOutputs); @@ -259,7 +261,7 @@ impl Wallet { // Set new address unlock condition first_output_builder = first_output_builder.add_unlock_condition(AddressUnlockCondition::new(recipient_address)); - Ok((first_output_builder, existing_nft_output_data)) + Ok((first_output_builder, existing_nft_output_with_ext_metadata)) } // Get a remainder address based on transaction_options or use the first account address diff --git a/sdk/src/wallet/types/mod.rs b/sdk/src/wallet/types/mod.rs index 204b47a604..c44ce863de 100644 --- a/sdk/src/wallet/types/mod.rs +++ b/sdk/src/wallet/types/mod.rs @@ -32,7 +32,12 @@ use crate::{ wallet::WalletError, }; -// TODO: you may nott like this name, but I think it's still better than OutputData tbh. I wanted something that +// TODO: This type is heavily used in the syncing logic so I found it appropriate to change its name in this PR, +// it's a cleanup PR afterall. You may not like this name, but I think it's still better than `OutputData` tbh. +// Some alternatives I had in mind were: `OutputWithMetadataExt` or `OutputWithExtMetadata`, but I think that +// doesn't matter a lot. What's important is that just by reading the name it's pretty clear that this type +// contains a bit of extra information on top of a `OutputWithMetadata`. +// // prevents adding more and more nouns to the name of the struct, and still expresses that it's similar to // `OutputWithMetadata` but a bit more than that without being explicit and probably inaccurate in the future. I am open // to suggestions though!! diff --git a/sdk/src/wallet/update.rs b/sdk/src/wallet/update.rs index f1aad27b54..1427b1fe3e 100644 --- a/sdk/src/wallet/update.rs +++ b/sdk/src/wallet/update.rs @@ -58,7 +58,7 @@ impl Wallet { /// Update wallet with newly synced data and emit events for outputs. pub(crate) async fn update_after_sync( &self, - unspent_outputs: Vec, + unspent_outputs_with_ext_metadata: Vec, spent_or_unsynced_output_metadata_map: HashMap>, ) -> Result<(), WalletError> { log::debug!("[SYNC] Update wallet ledger with new synced transactions"); @@ -67,13 +67,13 @@ impl Wallet { let mut wallet_ledger = self.ledger_mut().await; // Update spent outputs - for (output_id, output_metadata_response_opt) in spent_or_unsynced_output_metadata_map { + for (output_id, output_metadata_opt) in spent_or_unsynced_output_metadata_map { // If we got the output response and it's still unspent, skip it - if let Some(output_metadata_response) = output_metadata_response_opt { - if output_metadata_response.is_spent() { + if let Some(output_metadata) = output_metadata_opt { + if output_metadata.is_spent() { wallet_ledger.unspent_outputs.remove(&output_id); - if let Some(output_data) = wallet_ledger.outputs.get_mut(&output_id) { - output_data.metadata = output_metadata_response; + if let Some(output_with_ext_metadata) = wallet_ledger.outputs.get_mut(&output_id) { + output_with_ext_metadata.metadata = output_metadata; } } else { // not spent, just not synced, skip @@ -88,15 +88,15 @@ impl Wallet { wallet_ledger.locked_outputs.remove(&output_id); wallet_ledger.unspent_outputs.remove(&output_id); // Update spent data fields - if let Some(output_data) = wallet_ledger.outputs.get_mut(&output_id) { - if !output_data.is_spent() { + if let Some(output_with_ext_metadata) = wallet_ledger.outputs.get_mut(&output_id) { + if !output_with_ext_metadata.is_spent() { log::warn!( "[SYNC] Setting output {} as spent without having the OutputConsumptionMetadata", output_id ); // Set 0 values because we don't have the actual metadata and also couldn't get it, probably // because it got pruned. - output_data.metadata.spent = Some(OutputConsumptionMetadata::new( + output_with_ext_metadata.metadata.spent = Some(OutputConsumptionMetadata::new( 0.into(), TransactionId::new([0u8; TransactionId::LENGTH]), None, @@ -106,7 +106,7 @@ impl Wallet { #[cfg(feature = "events")] { self.emit(WalletEvent::SpentOutput(Box::new(SpentOutputEvent { - output: output_data.clone(), + output: output_with_ext_metadata.clone(), }))) .await; } @@ -116,20 +116,23 @@ impl Wallet { } // Add new synced outputs - for output_data in unspent_outputs { + for unspent_output_with_ext_metadata in unspent_outputs_with_ext_metadata { // Insert output, if it's unknown emit the NewOutputEvent if wallet_ledger .outputs - .insert(output_data.output_id, output_data.clone()) + .insert( + unspent_output_with_ext_metadata.output_id, + unspent_output_with_ext_metadata.clone(), + ) .is_none() { #[cfg(feature = "events")] { let transaction = wallet_ledger .incoming_transactions - .get(output_data.output_id.transaction_id()); + .get(unspent_output_with_ext_metadata.output_id.transaction_id()); self.emit(WalletEvent::NewOutput(Box::new(NewOutputEvent { - output: output_data.clone(), + output: unspent_output_with_ext_metadata.clone(), transaction: transaction .as_ref() .map(|tx| SignedTransactionPayloadDto::from(&tx.payload)), @@ -138,8 +141,11 @@ impl Wallet { .await; } }; - if !output_data.is_spent() { - wallet_ledger.unspent_outputs.insert(output_data.output_id, output_data); + if !unspent_output_with_ext_metadata.is_spent() { + wallet_ledger.unspent_outputs.insert( + unspent_output_with_ext_metadata.output_id, + unspent_output_with_ext_metadata, + ); } } @@ -190,15 +196,15 @@ impl Wallet { } for output_to_unlock in &spent_output_ids { - if let Some(output_data) = wallet_ledger.outputs.get_mut(output_to_unlock) { - if !output_data.is_spent() { + if let Some(output_with_ext_metadata) = wallet_ledger.outputs.get_mut(output_to_unlock) { + if !output_with_ext_metadata.is_spent() { log::warn!( "[SYNC] Setting output {} as spent without having the OutputConsumptionMetadata", - output_data.output_id + output_with_ext_metadata.output_id ); // Set 0 values because we don't have the actual metadata and also couldn't get it, probably because // it got pruned. - output_data.metadata.spent = Some(OutputConsumptionMetadata::new( + output_with_ext_metadata.metadata.spent = Some(OutputConsumptionMetadata::new( 0.into(), TransactionId::new([0u8; TransactionId::LENGTH]), None, diff --git a/sdk/tests/wallet/syncing.rs b/sdk/tests/wallet/syncing.rs index f1e75e40a6..17fd271f58 100644 --- a/sdk/tests/wallet/syncing.rs +++ b/sdk/tests/wallet/syncing.rs @@ -125,11 +125,11 @@ // assert_eq!(balance.accounts().len(), 0); // let unspent_outputs = wallet_1.unspent_outputs(None).await?; // assert_eq!(unspent_outputs.len(), 1); -// unspent_outputs.into_iter().for_each(|output_data| { -// assert!(output_data.output.is_basic()); -// assert_eq!(output_data.output.unlock_conditions().unwrap().len(), 1); +// unspent_outputs.into_iter().for_each(|output_with_ext_metadata| { +// assert!(output_with_ext_metadata.output.is_basic()); +// assert_eq!(output_with_ext_metadata.output.unlock_conditions().unwrap().len(), 1); // assert_eq!( -// output_data +// output_with_ext_metadata // .output // .unlock_conditions() // .unwrap()