confirmation fixes

This commit is contained in:
fossephate 2024-10-22 14:02:16 -07:00
parent 73f80b1620
commit 6e441f48e6

View file

@ -347,22 +347,34 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
} else if (resp.mwebUtxosHeight < nodeHeight) { } else if (resp.mwebUtxosHeight < nodeHeight) {
mwebSyncStatus = SyncingSyncStatus(1, 0.999); mwebSyncStatus = SyncingSyncStatus(1, 0.999);
} else { } else {
bool confirmationsUpdated = false;
if (resp.mwebUtxosHeight > walletInfo.restoreHeight) { if (resp.mwebUtxosHeight > walletInfo.restoreHeight) {
await walletInfo.updateRestoreHeight(resp.mwebUtxosHeight); await walletInfo.updateRestoreHeight(resp.mwebUtxosHeight);
await checkMwebUtxosSpent(); await checkMwebUtxosSpent();
// update the confirmations for each transaction: // update the confirmations for each transaction:
for (final transaction in transactionHistory.transactions.values) { for (final tx in transactionHistory.transactions.values) {
if (transaction.isPending) continue; if (tx.height == null || tx.height == 0) {
int txHeight = transaction.height ?? resp.mwebUtxosHeight; // update with first confirmation on next block since it hasn't been confirmed yet:
final confirmations = (resp.mwebUtxosHeight - txHeight) + 1; tx.height = resp.mwebUtxosHeight;
if (transaction.confirmations == confirmations) continue; continue;
if (transaction.confirmations == 0) {
updateBalance();
} }
transaction.confirmations = confirmations;
transactionHistory.addOne(transaction); final confirmations = (resp.mwebUtxosHeight - tx.height!) + 1;
// if the confirmations haven't changed, skip updating:
if (tx.confirmations == confirmations) continue;
print("updating confs ${tx.id} from ${tx.confirmations} -> $confirmations");
tx.confirmations = confirmations;
tx.isPending = false;
transactionHistory.addOne(tx);
confirmationsUpdated = true;
}
if (confirmationsUpdated) {
await transactionHistory.save();
await updateTransactions();
} }
await transactionHistory.save();
} }
// prevent unnecessary reaction triggers: // prevent unnecessary reaction triggers:
@ -487,13 +499,12 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
outputAddresses: [utxo.outputId], outputAddresses: [utxo.outputId],
isReplaced: false, isReplaced: false,
); );
} } else {
if (tx.confirmations != confirmations || tx.height != utxo.height) {
// don't update the confirmations if the tx is updated by electrum: tx.height = utxo.height;
if (tx.confirmations == 0 || utxo.height != 0) { tx.confirmations = confirmations;
tx.height = utxo.height; tx.isPending = utxo.height == 0;
tx.isPending = utxo.height == 0; }
tx.confirmations = confirmations;
} }
bool isNew = transactionHistory.transactions[tx.id] == null; bool isNew = transactionHistory.transactions[tx.id] == null;
@ -815,7 +826,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
// update the txCount for each address using the tx history, since we can't rely on mwebd // update the txCount for each address using the tx history, since we can't rely on mwebd
// to have an accurate count, we should just keep it in sync with what we know from the tx history: // to have an accurate count, we should just keep it in sync with what we know from the tx history:
for (final tx in transactionHistory.transactions.values) { for (final tx in transactionHistory.transactions.values) {
// if (tx.isPending) continue;
if (tx.inputAddresses == null || tx.outputAddresses == null) { if (tx.inputAddresses == null || tx.outputAddresses == null) {
continue; continue;
} }