mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 01:04:43 +00:00
save mweb addresses, auto-restart sync process if it gets stuck [skip ci]
This commit is contained in:
parent
cd307bf6e8
commit
554df09c99
4 changed files with 32 additions and 3 deletions
|
@ -1150,6 +1150,7 @@ abstract class ElectrumWalletBase
|
||||||
'derivationPath': walletInfo.derivationInfo?.derivationPath,
|
'derivationPath': walletInfo.derivationInfo?.derivationPath,
|
||||||
'silent_addresses': walletAddresses.silentAddresses.map((addr) => addr.toJSON()).toList(),
|
'silent_addresses': walletAddresses.silentAddresses.map((addr) => addr.toJSON()).toList(),
|
||||||
'silent_address_index': walletAddresses.currentSilentAddressIndex.toString(),
|
'silent_address_index': walletAddresses.currentSilentAddressIndex.toString(),
|
||||||
|
'mweb_addresses': walletAddresses.mwebAddresses.map((addr) => addr.toJSON()).toList(),
|
||||||
});
|
});
|
||||||
|
|
||||||
int feeRate(TransactionPriority priority) {
|
int feeRate(TransactionPriority priority) {
|
||||||
|
|
|
@ -481,6 +481,11 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
||||||
foundAddress = addressRecord;
|
foundAddress = addressRecord;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mwebAddresses.forEach((addressRecord) {
|
||||||
|
if (addressRecord.address == address) {
|
||||||
|
foundAddress = addressRecord;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (foundAddress != null) {
|
if (foundAddress != null) {
|
||||||
foundAddress!.setNewName(label);
|
foundAddress!.setNewName(label);
|
||||||
|
|
|
@ -59,10 +59,11 @@ class ElectrumWalletSnapshot {
|
||||||
final path = await pathForWallet(name: name, type: type);
|
final path = await pathForWallet(name: name, type: type);
|
||||||
final jsonSource = await encryptionFileUtils.read(path: path, password: password);
|
final jsonSource = await encryptionFileUtils.read(path: path, password: password);
|
||||||
final data = json.decode(jsonSource) as Map;
|
final data = json.decode(jsonSource) as Map;
|
||||||
final addressesTmp = data['addresses'] as List? ?? <Object>[];
|
|
||||||
final mnemonic = data['mnemonic'] as String?;
|
final mnemonic = data['mnemonic'] as String?;
|
||||||
final xpub = data['xpub'] as String?;
|
final xpub = data['xpub'] as String?;
|
||||||
final passphrase = data['passphrase'] as String? ?? '';
|
final passphrase = data['passphrase'] as String? ?? '';
|
||||||
|
|
||||||
|
final addressesTmp = data['addresses'] as List? ?? <Object>[];
|
||||||
final addresses = addressesTmp
|
final addresses = addressesTmp
|
||||||
.whereType<String>()
|
.whereType<String>()
|
||||||
.map((addr) => BitcoinAddressRecord.fromJSON(addr, network: network))
|
.map((addr) => BitcoinAddressRecord.fromJSON(addr, network: network))
|
||||||
|
|
|
@ -272,10 +272,12 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
|
|
||||||
_syncTimer?.cancel();
|
_syncTimer?.cancel();
|
||||||
// delay the timer by a second so we don't overrride the restoreheight if one is set
|
// delay the timer by a second so we don't overrride the restoreheight if one is set
|
||||||
Timer(const Duration(seconds: 1), () async {
|
Timer(const Duration(seconds: 2), () async {
|
||||||
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
|
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
|
||||||
if (syncStatus is FailedSyncStatus) return;
|
if (syncStatus is FailedSyncStatus) return;
|
||||||
final nodeHeight = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
|
||||||
|
final nodeHeight =
|
||||||
|
await electrumClient.getCurrentBlockChainTip() ?? 0; // current block height of our node
|
||||||
final resp = await _stub.status(StatusRequest());
|
final resp = await _stub.status(StatusRequest());
|
||||||
|
|
||||||
if (resp.blockHeaderHeight < nodeHeight) {
|
if (resp.blockHeaderHeight < nodeHeight) {
|
||||||
|
@ -308,6 +310,26 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// setup a watch dog to restart the sync process if it gets stuck:
|
||||||
|
List<double> lastFewProgresses = [];
|
||||||
|
Timer.periodic(const Duration(seconds: 10), (timer) async {
|
||||||
|
if (syncStatus is! SyncingSyncStatus) return;
|
||||||
|
if (syncStatus.progress() > 0.98) return;
|
||||||
|
lastFewProgresses.add(syncStatus.progress());
|
||||||
|
if (lastFewProgresses.length < 4) return;
|
||||||
|
// limit list size to 4:
|
||||||
|
while(lastFewProgresses.length > 4) {
|
||||||
|
lastFewProgresses.removeAt(0);
|
||||||
|
}
|
||||||
|
// if the progress is the same over the last 40 seconds, restart the sync:
|
||||||
|
if (lastFewProgresses.every((p) => p == lastFewProgresses.first)) {
|
||||||
|
print("mweb syncing is stuck, restarting...");
|
||||||
|
await stopSync();
|
||||||
|
startSync();
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// this runs in the background and processes new utxos as they come in:
|
// this runs in the background and processes new utxos as they come in:
|
||||||
processMwebUtxos();
|
processMwebUtxos();
|
||||||
|
|
Loading…
Reference in a new issue