mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 06:55:59 +00:00
fix regression
This commit is contained in:
parent
81b81f0c24
commit
dadae35c95
2 changed files with 45 additions and 45 deletions
|
@ -1262,23 +1262,20 @@ abstract class ElectrumWalletBase
|
|||
updatedUnspentCoins.addAll(await fetchUnspent(address));
|
||||
}));
|
||||
|
||||
unspentCoins = updatedUnspentCoins;
|
||||
|
||||
if (unspentCoinsInfo.length != updatedUnspentCoins.length) {
|
||||
updatedUnspentCoins.forEach((coin) => addCoinInfo(coin));
|
||||
}
|
||||
|
||||
await updateCoins(updatedUnspentCoins, set: true);
|
||||
await _refreshUnspentCoinsInfo();
|
||||
}
|
||||
|
||||
Future<void> updateCoins(List<BitcoinUnspent> newUnspentCoins, {bool set = false}) async {
|
||||
if (newUnspentCoins.isEmpty) {
|
||||
unspentCoins.forEach((coin) => addCoinInfo(coin));
|
||||
return;
|
||||
}
|
||||
|
||||
if (set) {
|
||||
unspentCoins = newUnspentCoins;
|
||||
} else {
|
||||
unspentCoins.addAll(newUnspentCoins);
|
||||
await updateCoins(unspentCoins);
|
||||
await _refreshUnspentCoinsInfo();
|
||||
}
|
||||
|
||||
Future<void> updateCoins(List<BitcoinUnspent> newUnspentCoins) async {
|
||||
if (newUnspentCoins.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
newUnspentCoins.forEach((coin) {
|
||||
|
@ -1467,7 +1464,6 @@ abstract class ElectrumWalletBase
|
|||
// Create a list of available outputs
|
||||
final outputs = <BitcoinOutput>[];
|
||||
for (final out in bundle.originalTransaction.outputs) {
|
||||
|
||||
// Check if the script contains OP_RETURN
|
||||
final script = out.scriptPubKey.script;
|
||||
if (script.contains('OP_RETURN') && memo == null) {
|
||||
|
|
|
@ -226,40 +226,43 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
await updateBalance();
|
||||
|
||||
_syncTimer?.cancel();
|
||||
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
|
||||
if (syncStatus is FailedSyncStatus) return;
|
||||
final nodeHeight = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
||||
final resp = await _stub.status(StatusRequest());
|
||||
// delay the timer by a second so we don't overrride the restoreheight if one is set
|
||||
Timer(const Duration(seconds: 1), () async {
|
||||
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
|
||||
if (syncStatus is FailedSyncStatus) return;
|
||||
final nodeHeight = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
||||
final resp = await _stub.status(StatusRequest());
|
||||
|
||||
if (resp.blockHeaderHeight < nodeHeight) {
|
||||
int h = resp.blockHeaderHeight;
|
||||
syncStatus = SyncingSyncStatus(nodeHeight - h, h / nodeHeight);
|
||||
} else if (resp.mwebHeaderHeight < nodeHeight) {
|
||||
int h = resp.mwebHeaderHeight;
|
||||
syncStatus = SyncingSyncStatus(nodeHeight - h, h / nodeHeight);
|
||||
} else if (resp.mwebUtxosHeight < nodeHeight) {
|
||||
syncStatus = SyncingSyncStatus(1, 0.999);
|
||||
} else {
|
||||
// prevent unnecessary reaction triggers:
|
||||
if (syncStatus is! SyncedSyncStatus) {
|
||||
syncStatus = SyncedSyncStatus();
|
||||
}
|
||||
|
||||
if (resp.mwebUtxosHeight > walletInfo.restoreHeight) {
|
||||
await walletInfo.updateRestoreHeight(resp.mwebUtxosHeight);
|
||||
await checkMwebUtxosSpent();
|
||||
// update the confirmations for each transaction:
|
||||
for (final transaction in transactionHistory.transactions.values) {
|
||||
if (transaction.isPending) continue;
|
||||
int txHeight = transaction.height ?? resp.mwebUtxosHeight;
|
||||
final confirmations = (resp.mwebUtxosHeight - txHeight) + 1;
|
||||
if (transaction.confirmations == confirmations) continue;
|
||||
transaction.confirmations = confirmations;
|
||||
transactionHistory.addOne(transaction);
|
||||
if (resp.blockHeaderHeight < nodeHeight) {
|
||||
int h = resp.blockHeaderHeight;
|
||||
syncStatus = SyncingSyncStatus(nodeHeight - h, h / nodeHeight);
|
||||
} else if (resp.mwebHeaderHeight < nodeHeight) {
|
||||
int h = resp.mwebHeaderHeight;
|
||||
syncStatus = SyncingSyncStatus(nodeHeight - h, h / nodeHeight);
|
||||
} else if (resp.mwebUtxosHeight < nodeHeight) {
|
||||
syncStatus = SyncingSyncStatus(1, 0.999);
|
||||
} else {
|
||||
// prevent unnecessary reaction triggers:
|
||||
if (syncStatus is! SyncedSyncStatus) {
|
||||
syncStatus = SyncedSyncStatus();
|
||||
}
|
||||
|
||||
if (resp.mwebUtxosHeight > walletInfo.restoreHeight) {
|
||||
await walletInfo.updateRestoreHeight(resp.mwebUtxosHeight);
|
||||
await checkMwebUtxosSpent();
|
||||
// update the confirmations for each transaction:
|
||||
for (final transaction in transactionHistory.transactions.values) {
|
||||
if (transaction.isPending) continue;
|
||||
int txHeight = transaction.height ?? resp.mwebUtxosHeight;
|
||||
final confirmations = (resp.mwebUtxosHeight - txHeight) + 1;
|
||||
if (transaction.confirmations == confirmations) continue;
|
||||
transaction.confirmations = confirmations;
|
||||
transactionHistory.addOne(transaction);
|
||||
}
|
||||
await transactionHistory.save();
|
||||
}
|
||||
await transactionHistory.save();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
// this runs in the background and processes new utxos as they come in:
|
||||
processMwebUtxos();
|
||||
|
@ -305,6 +308,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
}) async {
|
||||
await mwebUtxosBox.clear();
|
||||
transactionHistory.clear();
|
||||
_syncTimer?.cancel();
|
||||
await walletInfo.updateRestoreHeight(height);
|
||||
|
||||
// reset coin balances and txCount to 0:
|
||||
|
|
Loading…
Reference in a new issue