mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
Improve multithread use of zano api
This commit is contained in:
parent
4918aeb984
commit
45a3a9bba6
2 changed files with 45 additions and 5 deletions
|
@ -418,13 +418,14 @@ abstract class ZanoWalletBase extends WalletBase<ZanoBalance, ZanoTransactionHis
|
|||
|
||||
Future<void> updateTransactions() async {
|
||||
try {
|
||||
print("isTransactionUpdating: $_isTransactionUpdating");
|
||||
if (_isTransactionUpdating) {
|
||||
return;
|
||||
}
|
||||
_isTransactionUpdating = true;
|
||||
final transactions = await fetchTransactions();
|
||||
print("transactions: $transactions");
|
||||
if (transactions.length == transactionHistory.transactions.length) {
|
||||
return;
|
||||
}
|
||||
transactionHistory.clear();
|
||||
transactionHistory.addMany(transactions);
|
||||
await transactionHistory.save();
|
||||
|
|
|
@ -67,7 +67,7 @@ mixin ZanoWalletApi {
|
|||
}
|
||||
|
||||
Future<GetWalletInfoResult> getWalletInfo() async {
|
||||
final json = zano.PlainWallet_getWalletInfo(hWallet);
|
||||
final json = await _getWalletInfo(hWallet);
|
||||
final result = GetWalletInfoResult.fromJson(jsonDecode(json) as Map<String, dynamic>);
|
||||
_json('get_wallet_info', json);
|
||||
info('get_wallet_info got ${result.wi.balances.length} balances: ${result.wi.balances} seed: ${_shorten(result.wiExtended.seed)}');
|
||||
|
@ -75,7 +75,7 @@ mixin ZanoWalletApi {
|
|||
}
|
||||
|
||||
Future<GetWalletStatusResult> getWalletStatus() async {
|
||||
final json = zano.PlainWallet_getWalletStatus(hWallet);
|
||||
final json = await _getWalletStatus(hWallet);
|
||||
if (json == Consts.errorWalletWrongId) {
|
||||
error('wrong wallet id');
|
||||
throw ZanoWalletException('Wrong wallet id');
|
||||
|
@ -217,7 +217,7 @@ mixin ZanoWalletApi {
|
|||
final json = await invokeMethod('store', '{}');
|
||||
final map = jsonDecode(json) as Map<String, dynamic>?;
|
||||
_checkForErrors(map);
|
||||
return StoreResult.fromJson(map!['result']['result'] as Map<String, dynamic>);
|
||||
return StoreResult.fromJson(map!['result'] as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
error('store $e');
|
||||
return null;
|
||||
|
@ -431,4 +431,43 @@ Map<String, dynamic> jsonDecode(String json) {
|
|||
|
||||
String jsonEncode(Object? object) {
|
||||
return convert.jsonEncode(object);
|
||||
}
|
||||
|
||||
Future<String> _getWalletStatus(int hWallet) async {
|
||||
final jsonPtr = await Isolate.run(() async {
|
||||
final lib = zanoapi.ZanoC(DynamicLibrary.open(zano.libPath));
|
||||
final status = lib.ZANO_PlainWallet_getWalletStatus(
|
||||
hWallet,
|
||||
);
|
||||
return status.address;
|
||||
});
|
||||
String json = "";
|
||||
try {
|
||||
final strPtr = Pointer.fromAddress(jsonPtr).cast<Utf8>();
|
||||
final str = strPtr.toDartString();
|
||||
zano.ZANO_free(strPtr.cast());
|
||||
json = str;
|
||||
} catch (e) {
|
||||
json = "";
|
||||
}
|
||||
return json;
|
||||
}
|
||||
Future<String> _getWalletInfo(int hWallet) async {
|
||||
final jsonPtr = await Isolate.run(() async {
|
||||
final lib = zanoapi.ZanoC(DynamicLibrary.open(zano.libPath));
|
||||
final status = lib.ZANO_PlainWallet_getWalletInfo(
|
||||
hWallet,
|
||||
);
|
||||
return status.address;
|
||||
});
|
||||
String json = "";
|
||||
try {
|
||||
final strPtr = Pointer.fromAddress(jsonPtr).cast<Utf8>();
|
||||
final str = strPtr.toDartString();
|
||||
zano.ZANO_free(strPtr.cast());
|
||||
json = str;
|
||||
} catch (e) {
|
||||
json = "";
|
||||
}
|
||||
return json;
|
||||
}
|
Loading…
Reference in a new issue