mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
apply scans error propagation fix
This commit is contained in:
parent
6efcdf97ea
commit
381672d368
1 changed files with 100 additions and 81 deletions
|
@ -437,7 +437,10 @@ class EpicCashWallet extends CoinServiceAPI
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
Logging.instance.log("result?: $result", level: LogLevel.Info);
|
Logging.instance.log(
|
||||||
|
"cancel $txSlateId result: $result",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
return result;
|
return result;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("$e, $s", level: LogLevel.Error);
|
Logging.instance.log("$e, $s", level: LogLevel.Error);
|
||||||
|
@ -661,25 +664,8 @@ class EpicCashWallet extends CoinServiceAPI
|
||||||
|
|
||||||
await epicUpdateLastScannedBlock(await getRestoreHeight());
|
await epicUpdateLastScannedBlock(await getRestoreHeight());
|
||||||
|
|
||||||
if (!await startScans()) {
|
await _startScans();
|
||||||
refreshMutex = false;
|
|
||||||
GlobalEventBus.instance.fire(
|
|
||||||
NodeConnectionStatusChangedEvent(
|
|
||||||
NodeConnectionStatus.disconnected,
|
|
||||||
walletId,
|
|
||||||
coin,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
GlobalEventBus.instance.fire(
|
|
||||||
WalletSyncStatusChangedEvent(
|
|
||||||
WalletSyncStatus.unableToSync,
|
|
||||||
walletId,
|
|
||||||
coin,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await refresh();
|
|
||||||
GlobalEventBus.instance.fire(
|
GlobalEventBus.instance.fire(
|
||||||
WalletSyncStatusChangedEvent(
|
WalletSyncStatusChangedEvent(
|
||||||
WalletSyncStatus.synced,
|
WalletSyncStatus.synced,
|
||||||
|
@ -688,12 +674,23 @@ class EpicCashWallet extends CoinServiceAPI
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
|
GlobalEventBus.instance.fire(
|
||||||
|
WalletSyncStatusChangedEvent(
|
||||||
|
WalletSyncStatus.unableToSync,
|
||||||
|
walletId,
|
||||||
|
coin,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Logging.instance.log(
|
||||||
|
"Exception rethrown from fullRescan(): $e\n$s",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
printFullLength: true,
|
||||||
|
);
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
refreshMutex = false;
|
refreshMutex = false;
|
||||||
Logging.instance
|
|
||||||
.log("$e, $s", level: LogLevel.Error, printFullLength: true);
|
|
||||||
}
|
}
|
||||||
refreshMutex = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1159,58 +1156,97 @@ class EpicCashWallet extends CoinServiceAPI
|
||||||
// TODO: refresh anything that needs to be refreshed/updated due to epicbox info changed
|
// TODO: refresh anything that needs to be refreshed/updated due to epicbox info changed
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> startScans() async {
|
Future<void> _startScans() async {
|
||||||
try {
|
try {
|
||||||
|
//First stop the current listener
|
||||||
if (ListenerManager.pointer != null) {
|
if (ListenerManager.pointer != null) {
|
||||||
|
Logging.instance
|
||||||
|
.log("LISTENER HANDLER IS NOT NULL ....", level: LogLevel.Info);
|
||||||
|
Logging.instance
|
||||||
|
.log("STOPPING ANY WALLET LISTENER ....", level: LogLevel.Info);
|
||||||
epicboxListenerStop(ListenerManager.pointer!);
|
epicboxListenerStop(ListenerManager.pointer!);
|
||||||
}
|
}
|
||||||
|
|
||||||
final wallet = await _secureStore.read(key: '${_walletId}_wallet');
|
final wallet = await _secureStore.read(key: '${_walletId}_wallet');
|
||||||
|
|
||||||
var restoreHeight = epicGetRestoreHeight();
|
// max number of blocks to scan per loop iteration
|
||||||
var chainHeight = await this.chainHeight;
|
const scanChunkSize = 10000;
|
||||||
if (epicGetLastScannedBlock() == null) {
|
|
||||||
await epicUpdateLastScannedBlock(await getRestoreHeight());
|
|
||||||
}
|
|
||||||
int lastScannedBlock = epicGetLastScannedBlock()!;
|
|
||||||
const MAX_PER_LOOP = 10000;
|
|
||||||
await getSyncPercent;
|
|
||||||
for (; lastScannedBlock < chainHeight;) {
|
|
||||||
chainHeight = await this.chainHeight;
|
|
||||||
lastScannedBlock = epicGetLastScannedBlock()!;
|
|
||||||
Logging.instance.log(
|
|
||||||
"chainHeight: $chainHeight, restoreHeight: $restoreHeight, lastScannedBlock: $lastScannedBlock",
|
|
||||||
level: LogLevel.Info);
|
|
||||||
int? nextScannedBlock;
|
|
||||||
await m.protect(() async {
|
|
||||||
ReceivePort receivePort = await getIsolate({
|
|
||||||
"function": "scanOutPuts",
|
|
||||||
"wallet": wallet!,
|
|
||||||
"startHeight": lastScannedBlock,
|
|
||||||
"numberOfBlocks": MAX_PER_LOOP,
|
|
||||||
}, name: walletName);
|
|
||||||
|
|
||||||
var message = await receivePort.first;
|
// force firing of scan progress event
|
||||||
if (message is String) {
|
await getSyncPercent;
|
||||||
Logging.instance
|
|
||||||
.log("this is a string $message", level: LogLevel.Error);
|
// fetch current chain height and last scanned block (should be the
|
||||||
stop(receivePort);
|
// restore height if full rescan or a wallet restore)
|
||||||
throw Exception("scanOutPuts isolate failed");
|
int chainHeight = await this.chainHeight;
|
||||||
|
int lastScannedBlock =
|
||||||
|
epicGetLastScannedBlock() ?? await getRestoreHeight();
|
||||||
|
|
||||||
|
// loop while scanning in chain in chunks (of blocks?)
|
||||||
|
while (lastScannedBlock < chainHeight) {
|
||||||
|
Logging.instance.log(
|
||||||
|
"chainHeight: $chainHeight, lastScannedBlock: $lastScannedBlock",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
|
|
||||||
|
final int nextScannedBlock = await m.protect(() async {
|
||||||
|
ReceivePort? receivePort;
|
||||||
|
try {
|
||||||
|
receivePort = await getIsolate({
|
||||||
|
"function": "scanOutPuts",
|
||||||
|
"wallet": wallet!,
|
||||||
|
"startHeight": lastScannedBlock,
|
||||||
|
"numberOfBlocks": scanChunkSize,
|
||||||
|
}, name: walletName);
|
||||||
|
|
||||||
|
// get response
|
||||||
|
final message = await receivePort.first;
|
||||||
|
|
||||||
|
// check for error message
|
||||||
|
if (message is String) {
|
||||||
|
throw Exception("scanOutPuts isolate failed: $message");
|
||||||
|
}
|
||||||
|
|
||||||
|
// attempt to grab next scanned block number
|
||||||
|
final nextScanned = int.tryParse(message['outputs'] as String);
|
||||||
|
if (nextScanned == null) {
|
||||||
|
throw Exception(
|
||||||
|
"scanOutPuts failed to parse next scanned block number from: $message",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return nextScanned;
|
||||||
|
} catch (_) {
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
|
if (receivePort != null) {
|
||||||
|
// kill isolate
|
||||||
|
stop(receivePort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nextScannedBlock = int.parse(message['outputs'] as String);
|
|
||||||
stop(receivePort);
|
|
||||||
Logging.instance
|
|
||||||
.log('Closing scanOutPuts!\n $message', level: LogLevel.Info);
|
|
||||||
});
|
});
|
||||||
await epicUpdateLastScannedBlock(nextScannedBlock!);
|
|
||||||
|
// update local cache
|
||||||
|
await epicUpdateLastScannedBlock(nextScannedBlock);
|
||||||
|
|
||||||
|
// force firing of scan progress event
|
||||||
await getSyncPercent;
|
await getSyncPercent;
|
||||||
|
|
||||||
|
// update while loop condition variables
|
||||||
|
chainHeight = await this.chainHeight;
|
||||||
|
lastScannedBlock = nextScannedBlock;
|
||||||
}
|
}
|
||||||
Logging.instance.log("successfully at the tip", level: LogLevel.Info);
|
|
||||||
|
Logging.instance.log(
|
||||||
|
"_startScans successfully at the tip",
|
||||||
|
level: LogLevel.Info,
|
||||||
|
);
|
||||||
|
//Once scanner completes restart listener
|
||||||
await listenToEpicbox();
|
await listenToEpicbox();
|
||||||
return true;
|
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("$e, $s", level: LogLevel.Warning);
|
Logging.instance.log(
|
||||||
return false;
|
"_startScans failed: $e\n$s",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1490,24 +1526,7 @@ class EpicCashWallet extends CoinServiceAPI
|
||||||
final int curAdd = await setCurrentIndex();
|
final int curAdd = await setCurrentIndex();
|
||||||
await _getReceivingAddressForIndex(curAdd);
|
await _getReceivingAddressForIndex(curAdd);
|
||||||
|
|
||||||
if (!await startScans()) {
|
await _startScans();
|
||||||
refreshMutex = false;
|
|
||||||
GlobalEventBus.instance.fire(
|
|
||||||
NodeConnectionStatusChangedEvent(
|
|
||||||
NodeConnectionStatus.disconnected,
|
|
||||||
walletId,
|
|
||||||
coin,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
GlobalEventBus.instance.fire(
|
|
||||||
WalletSyncStatusChangedEvent(
|
|
||||||
WalletSyncStatus.unableToSync,
|
|
||||||
walletId,
|
|
||||||
coin,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unawaited(startSync());
|
unawaited(startSync());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue