mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 09:15:11 +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,6 +356,7 @@ class ElectrumClient {
|
||||||
BehaviorSubject<Map<String, dynamic>>? tipListener;
|
BehaviorSubject<Map<String, dynamic>>? tipListener;
|
||||||
int? currentTip;
|
int? currentTip;
|
||||||
Future<int?> getCurrentBlockChainTip() async {
|
Future<int?> getCurrentBlockChainTip() async {
|
||||||
|
try {
|
||||||
final method = 'blockchain.headers.subscribe';
|
final method = 'blockchain.headers.subscribe';
|
||||||
final cb = (result) => currentTip = result['height'] as int;
|
final cb = (result) => currentTip = result['height'] as int;
|
||||||
if (tipListener == null) {
|
if (tipListener == null) {
|
||||||
|
@ -364,6 +365,9 @@ class ElectrumClient {
|
||||||
callWithTimeout(method: method).then(cb);
|
callWithTimeout(method: method).then(cb);
|
||||||
}
|
}
|
||||||
return currentTip;
|
return currentTip;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BehaviorSubject<Object>? chainTipSubscribe() {
|
BehaviorSubject<Object>? chainTipSubscribe() {
|
||||||
|
|
|
@ -1238,8 +1238,6 @@ abstract class ElectrumWalletBase
|
||||||
try {
|
try {
|
||||||
unspents = await electrumClient.getListUnspent(address.getScriptHash(network));
|
unspents = await electrumClient.getListUnspent(address.getScriptHash(network));
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
print(e);
|
|
||||||
print(s);
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,9 +167,9 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await subscribeForUpdates();
|
// await subscribeForUpdates();
|
||||||
await updateTransactions();
|
// await updateTransactions();
|
||||||
await updateFeeRates();
|
// await updateFeeRates();
|
||||||
|
|
||||||
Timer.periodic(const Duration(minutes: 1), (timer) async => 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?.cancel();
|
||||||
_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 height = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
// final height = await electrumClient.getCurrentBlockChainTip() ?? 0;
|
||||||
|
final height = 0;
|
||||||
final resp = await _stub.status(StatusRequest());
|
final resp = await _stub.status(StatusRequest());
|
||||||
if (resp.blockHeaderHeight < height) {
|
if (resp.blockHeaderHeight < height) {
|
||||||
int h = resp.blockHeaderHeight;
|
int h = resp.blockHeaderHeight;
|
||||||
|
@ -208,8 +209,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateUnspent();
|
// updateUnspent();
|
||||||
fetchBalances();
|
// fetchBalances();
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
|
@ -782,4 +783,13 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
stopSync();
|
stopSync();
|
||||||
startSync();
|
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;
|
final litecoinWallet = wallet as LitecoinWallet;
|
||||||
return litecoinWallet.mwebEnabled;
|
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 'dart:io';
|
||||||
|
|
||||||
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||||
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
||||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
|
@ -25,6 +27,11 @@ void callbackDispatcher() {
|
||||||
try {
|
try {
|
||||||
switch (task) {
|
switch (task) {
|
||||||
case mwebSyncTaskKey:
|
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
|
final List<WalletListItem> ltcWallets = getIt
|
||||||
.get<WalletListViewModel>()
|
.get<WalletListViewModel>()
|
||||||
.wallets
|
.wallets
|
||||||
|
@ -39,17 +46,51 @@ void callbackDispatcher() {
|
||||||
|
|
||||||
var wallet =
|
var wallet =
|
||||||
await walletLoadingService.load(ltcWallets.first.type, ltcWallets.first.name);
|
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++) {
|
for (int i = 0;; i++) {
|
||||||
await Future<void>.delayed(const Duration(seconds: 1));
|
await Future<void>.delayed(const Duration(seconds: 1));
|
||||||
if (wallet.syncStatus.progress() == 1.0) {
|
if (syncStatus == 1) {
|
||||||
|
print("sync done!");
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
print("Sync status ${syncStatus}");
|
||||||
}
|
}
|
||||||
if (i > 600) {
|
if (i > 600) {
|
||||||
return Future.error("Synchronization Timed out");
|
return Future.error("Synchronization Timed out");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_syncTimer?.cancel();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -162,7 +203,7 @@ class BackgroundTasks {
|
||||||
requiresDeviceIdle: syncMode.type == SyncType.unobtrusive,
|
requiresDeviceIdle: syncMode.type == SyncType.unobtrusive,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS && syncMode.type == SyncType.unobtrusive) {
|
||||||
// await Workmanager().registerOneOffTask(
|
// await Workmanager().registerOneOffTask(
|
||||||
// moneroSyncTaskKey,
|
// moneroSyncTaskKey,
|
||||||
// moneroSyncTaskKey,
|
// moneroSyncTaskKey,
|
||||||
|
@ -174,7 +215,7 @@ class BackgroundTasks {
|
||||||
await Workmanager().registerOneOffTask(
|
await Workmanager().registerOneOffTask(
|
||||||
mwebSyncTaskKey,
|
mwebSyncTaskKey,
|
||||||
mwebSyncTaskKey,
|
mwebSyncTaskKey,
|
||||||
initialDelay: Duration(seconds: 10),
|
initialDelay: Duration(seconds: 30),
|
||||||
existingWorkPolicy: ExistingWorkPolicy.replace,
|
existingWorkPolicy: ExistingWorkPolicy.replace,
|
||||||
inputData: inputData,
|
inputData: inputData,
|
||||||
constraints: constraints,
|
constraints: constraints,
|
||||||
|
|
|
@ -24,5 +24,5 @@ Future<void> loadCurrentWallet() async {
|
||||||
final wallet = await walletLoadingService.load(type, name);
|
final wallet = await walletLoadingService.load(type, name);
|
||||||
await appStore.changeCurrentWallet(wallet);
|
await appStore.changeCurrentWallet(wallet);
|
||||||
|
|
||||||
getIt.get<BackgroundTasks>().registerSyncTask();
|
// getIt.get<BackgroundTasks>().registerSyncTask();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@ class SyncMode {
|
||||||
static final all = [
|
static final all = [
|
||||||
SyncMode("Disabled", SyncType.disabled, Duration.zero),
|
SyncMode("Disabled", SyncType.disabled, Duration.zero),
|
||||||
SyncMode("Unobtrusive", SyncType.unobtrusive, Duration(hours: 12)),
|
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