Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 1, 2023
1 parent a5fe126 commit ae20ba2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 306 deletions.
285 changes: 0 additions & 285 deletions sdk/src/wallet/operations/output_finder.rs

This file was deleted.

12 changes: 5 additions & 7 deletions sdk/src/wallet/operations/syncing/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ where
) -> crate::wallet::Result<()> {
log::debug!("[SYNC] request_incoming_transaction_data");

let account_details = self.data().await;
let wallet_data = self.data().await;
transaction_ids.retain(|transaction_id| {
!(account_details.transactions.contains_key(transaction_id)
|| account_details.incoming_transactions.contains_key(transaction_id)
|| account_details
.inaccessible_incoming_transactions
.contains(transaction_id))
!(wallet_data.transactions.contains_key(transaction_id)
|| wallet_data.incoming_transactions.contains_key(transaction_id)
|| wallet_data.inaccessible_incoming_transactions.contains(transaction_id))
});
drop(account_details);
drop(wallet_data);

// Limit parallel requests to 100, to avoid timeouts
let results =
Expand Down
20 changes: 10 additions & 10 deletions sdk/src/wallet/operations/syncing/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ where
/// be synced again
pub(crate) async fn sync_pending_transactions(&self) -> crate::wallet::Result<bool> {
log::debug!("[SYNC] sync pending transactions");
let account_details = self.data().await;
let wallet_data = self.data().await;

// only set to true if a transaction got confirmed for which we don't have an output
// (transaction_output.is_none())
let mut confirmed_unknown_output = false;

if account_details.pending_transactions.is_empty() {
if wallet_data.pending_transactions.is_empty() {
return Ok(confirmed_unknown_output);
}

Expand All @@ -49,9 +49,9 @@ where
let mut output_ids_to_unlock = Vec::new();
let mut transactions_to_reissue = Vec::new();

for transaction_id in &account_details.pending_transactions {
for transaction_id in &wallet_data.pending_transactions {
log::debug!("[SYNC] sync pending transaction {transaction_id}");
let transaction = account_details
let transaction = wallet_data
.transactions
.get(transaction_id)
// panic during development to easier detect if something is wrong, should be handled different later
Expand All @@ -65,14 +65,14 @@ where

// check if we have an output (remainder, if not sending to an own address) that got created by this
// transaction, if that's the case, then the transaction got confirmed
let transaction_output = account_details
let transaction_output = wallet_data
.outputs
.keys()
.find(|o| o.transaction_id() == transaction_id);

if let Some(transaction_output) = transaction_output {
// Save to unwrap, we just got the output
let confirmed_output_data = account_details.outputs.get(transaction_output).expect("output exists");
let confirmed_output_data = wallet_data.outputs.get(transaction_output).expect("output exists");
log::debug!(
"[SYNC] confirmed transaction {transaction_id} in block {}",
confirmed_output_data.metadata.block_id()
Expand All @@ -91,7 +91,7 @@ where
let mut input_got_spent = false;
for input in transaction.payload.transaction().inputs() {
let Input::Utxo(input) = input;
if let Some(input) = account_details.outputs.get(input.output_id()) {
if let Some(input) = wallet_data.outputs.get(input.output_id()) {
if input.is_spent {
input_got_spent = true;
}
Expand Down Expand Up @@ -153,7 +153,7 @@ where
// no need to reissue if one input got spent
if input_got_spent {
process_transaction_with_unknown_state(
&account_details,
&wallet_data,
transaction,
&mut updated_transactions,
&mut output_ids_to_unlock,
Expand All @@ -172,7 +172,7 @@ where
// no need to reissue if one input got spent
if input_got_spent {
process_transaction_with_unknown_state(
&account_details,
&wallet_data,
transaction,
&mut updated_transactions,
&mut output_ids_to_unlock,
Expand All @@ -198,7 +198,7 @@ where
}
}
}
drop(account_details);
drop(wallet_data);

for mut transaction in transactions_to_reissue {
log::debug!("[SYNC] reissue transaction");
Expand Down
Loading

0 comments on commit ae20ba2

Please sign in to comment.