mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 01:04:43 +00:00
experimental testing [skip ci]
This commit is contained in:
parent
1b8218f970
commit
2721a9ad5e
7 changed files with 87 additions and 22 deletions
|
@ -356,14 +356,18 @@ class ElectrumClient {
|
|||
BehaviorSubject<Map<String, dynamic>>? tipListener;
|
||||
int? currentTip;
|
||||
Future<int?> getCurrentBlockChainTip() async {
|
||||
final method = 'blockchain.headers.subscribe';
|
||||
final cb = (result) => currentTip = result['height'] as int;
|
||||
if (tipListener == null) {
|
||||
tipListener = subscribe(id: method, method: method);
|
||||
tipListener?.listen(cb);
|
||||
callWithTimeout(method: method).then(cb);
|
||||
try {
|
||||
final method = 'blockchain.headers.subscribe';
|
||||
final cb = (result) => currentTip = result['height'] as int;
|
||||
if (tipListener == null) {
|
||||
tipListener = subscribe(id: method, method: method);
|
||||
tipListener?.listen(cb);
|
||||
callWithTimeout(method: method).then(cb);
|
||||
}
|
||||
return currentTip;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
return currentTip;
|
||||
}
|
||||
|
||||
BehaviorSubject<Object>? chainTipSubscribe() {
|
||||
|
|
|
@ -1238,8 +1238,6 @@ abstract class ElectrumWalletBase
|
|||
try {
|
||||
unspents = await electrumClient.getListUnspent(address.getScriptHash(network));
|
||||
} catch (e, s) {
|
||||
print(e);
|
||||
print(s);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
@ -167,9 +167,9 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
return;
|
||||
}
|
||||
|
||||
await subscribeForUpdates();
|
||||
await updateTransactions();
|
||||
await updateFeeRates();
|
||||
// await subscribeForUpdates();
|
||||
// await updateTransactions();
|
||||
// await updateFeeRates();
|
||||
|
||||
Timer.periodic(const Duration(minutes: 1), (timer) async => await updateFeeRates());
|
||||
|
||||
|
@ -177,7 +177,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
_syncTimer?.cancel();
|
||||
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
|
||||
if (syncStatus is FailedSyncStatus) return;
|
||||
final height = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
||||
// final height = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
||||
final height = 0;
|
||||
final resp = await _stub.status(StatusRequest());
|
||||
if (resp.blockHeaderHeight < height) {
|
||||
int h = resp.blockHeaderHeight;
|
||||
|
@ -208,8 +209,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
}
|
||||
}
|
||||
});
|
||||
updateUnspent();
|
||||
fetchBalances();
|
||||
// updateUnspent();
|
||||
// fetchBalances();
|
||||
// this runs in the background and processes new utxos as they come in:
|
||||
processMwebUtxos();
|
||||
}
|
||||
|
@ -541,7 +542,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
updatedUnspentCoins.add(unspent);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
unspentCoins = updatedUnspentCoins;
|
||||
}
|
||||
|
||||
|
@ -782,4 +783,13 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
stopSync();
|
||||
startSync();
|
||||
}
|
||||
|
||||
Future<RpcClient> getStub() async {
|
||||
return CwMweb.stub();
|
||||
}
|
||||
|
||||
Future<StatusResponse> getStatusRequest() async {
|
||||
final resp = await _stub.status(StatusRequest());
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -597,4 +597,16 @@ class CWBitcoin extends Bitcoin {
|
|||
final litecoinWallet = wallet as LitecoinWallet;
|
||||
return litecoinWallet.mwebEnabled;
|
||||
}
|
||||
|
||||
@override
|
||||
dynamic getMwebStub(Object wallet) {
|
||||
final litecoinWallet = wallet as LitecoinWallet;
|
||||
return litecoinWallet.getStub();
|
||||
}
|
||||
|
||||
@override
|
||||
dynamic getStatusRequest(Object wallet) {
|
||||
final litecoinWallet = wallet as LitecoinWallet;
|
||||
return litecoinWallet.getStatusRequest();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
|
@ -25,6 +27,11 @@ void callbackDispatcher() {
|
|||
try {
|
||||
switch (task) {
|
||||
case mwebSyncTaskKey:
|
||||
|
||||
/// The work manager runs on a separate isolate from the main flutter isolate.
|
||||
/// thus we initialize app configs first; hive, getIt, etc...
|
||||
await initializeAppConfigs();
|
||||
|
||||
final List<WalletListItem> ltcWallets = getIt
|
||||
.get<WalletListViewModel>()
|
||||
.wallets
|
||||
|
@ -39,17 +46,51 @@ void callbackDispatcher() {
|
|||
|
||||
var wallet =
|
||||
await walletLoadingService.load(ltcWallets.first.type, ltcWallets.first.name);
|
||||
await wallet.startSync();
|
||||
|
||||
print("STARTING SYNC FROM BG!!");
|
||||
// await wallet.startSync();
|
||||
|
||||
// RpcClient _stub = bitcoin!.getMwebStub();
|
||||
|
||||
double syncStatus = 0.0;
|
||||
|
||||
Timer? _syncTimer;
|
||||
|
||||
dynamic _stub = await bitcoin!.getMwebStub(wallet);
|
||||
|
||||
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
|
||||
// if (syncStatus is FailedSyncStatus) return;
|
||||
// final height = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
||||
final height = 0;
|
||||
dynamic resp = await bitcoin!.getStatusRequest(wallet);
|
||||
int blockHeaderHeight = resp.blockHeaderHeight as int;
|
||||
int mwebHeaderHeight = resp.mwebHeaderHeight as int;
|
||||
int mwebUtxosHeight = resp.mwebUtxosHeight as int;
|
||||
|
||||
if (blockHeaderHeight < height) {
|
||||
syncStatus = blockHeaderHeight / height;
|
||||
} else if (mwebHeaderHeight < height) {
|
||||
syncStatus = mwebHeaderHeight / height;
|
||||
} else if (mwebUtxosHeight < height) {
|
||||
syncStatus = 0.999;
|
||||
} else {
|
||||
syncStatus = 1;
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0;; i++) {
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
if (wallet.syncStatus.progress() == 1.0) {
|
||||
if (syncStatus == 1) {
|
||||
print("sync done!");
|
||||
break;
|
||||
} else {
|
||||
print("Sync status ${syncStatus}");
|
||||
}
|
||||
if (i > 600) {
|
||||
return Future.error("Synchronization Timed out");
|
||||
}
|
||||
}
|
||||
_syncTimer?.cancel();
|
||||
|
||||
break;
|
||||
|
||||
|
@ -162,7 +203,7 @@ class BackgroundTasks {
|
|||
requiresDeviceIdle: syncMode.type == SyncType.unobtrusive,
|
||||
);
|
||||
|
||||
if (Platform.isIOS) {
|
||||
if (Platform.isIOS && syncMode.type == SyncType.unobtrusive) {
|
||||
// await Workmanager().registerOneOffTask(
|
||||
// moneroSyncTaskKey,
|
||||
// moneroSyncTaskKey,
|
||||
|
@ -174,7 +215,7 @@ class BackgroundTasks {
|
|||
await Workmanager().registerOneOffTask(
|
||||
mwebSyncTaskKey,
|
||||
mwebSyncTaskKey,
|
||||
initialDelay: Duration(seconds: 10),
|
||||
initialDelay: Duration(seconds: 30),
|
||||
existingWorkPolicy: ExistingWorkPolicy.replace,
|
||||
inputData: inputData,
|
||||
constraints: constraints,
|
||||
|
|
|
@ -24,5 +24,5 @@ Future<void> loadCurrentWallet() async {
|
|||
final wallet = await walletLoadingService.load(type, name);
|
||||
await appStore.changeCurrentWallet(wallet);
|
||||
|
||||
getIt.get<BackgroundTasks>().registerSyncTask();
|
||||
// getIt.get<BackgroundTasks>().registerSyncTask();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,6 @@ class SyncMode {
|
|||
static final all = [
|
||||
SyncMode("Disabled", SyncType.disabled, Duration.zero),
|
||||
SyncMode("Unobtrusive", SyncType.unobtrusive, Duration(hours: 12)),
|
||||
SyncMode("Aggressive", SyncType.aggressive, Duration(hours: 3)),
|
||||
SyncMode("Aggressive", SyncType.aggressive, Duration(minutes: 20)),
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue