mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
* fix(cw_monero): prevent monero wallet from breaking during rename * update to cleaned up monero.dart * fix: transaction screen not refreshing in monero * fix: wallets not opening until app restart after rename. * fix(cw_decred): wallet renaming throwing * fix: transaction not being shown after sending until 1st confirmation * fix(cw_monero): loop safeguard * fix: don't await wallet.fetchTransactions
61 lines
1.6 KiB
Dart
61 lines
1.6 KiB
Dart
import 'dart:ffi';
|
|
import 'dart:isolate';
|
|
|
|
import 'package:cw_monero/api/account_list.dart';
|
|
import 'package:monero/monero.dart' as monero;
|
|
import 'package:monero/src/wallet2.dart';
|
|
import 'package:mutex/mutex.dart';
|
|
|
|
Wallet2Coins? coins = null;
|
|
final coinsMutex = Mutex();
|
|
|
|
Future<void> refreshCoins(int accountIndex) async {
|
|
if (coinsMutex.isLocked) {
|
|
return;
|
|
}
|
|
coins = currentWallet!.coins();
|
|
final coinsPtr = coins!.ffiAddress();
|
|
await coinsMutex.acquire();
|
|
await Isolate.run(() => monero.Coins_refresh(Pointer.fromAddress(coinsPtr)));
|
|
coinsMutex.release();
|
|
}
|
|
|
|
Future<int> countOfCoins() async {
|
|
await coinsMutex.acquire();
|
|
final count = coins!.count();
|
|
coinsMutex.release();
|
|
return count;
|
|
}
|
|
|
|
Future<Wallet2CoinsInfo> getCoin(int index) async {
|
|
await coinsMutex.acquire();
|
|
final coin = coins!.coin(index);
|
|
coinsMutex.release();
|
|
return coin;
|
|
}
|
|
|
|
Future<int?> getCoinByKeyImage(String keyImage) async {
|
|
final count = await countOfCoins();
|
|
for (int i = 0; i < count; i++) {
|
|
final coin = await getCoin(i);
|
|
final coinAddress = coin.keyImage;
|
|
if (keyImage == coinAddress) {
|
|
return i;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
Future<void> freezeCoin(int index) async {
|
|
await coinsMutex.acquire();
|
|
final coinsPtr = coins!.ffiAddress();
|
|
await Isolate.run(() => monero.Coins_setFrozen(Pointer.fromAddress(coinsPtr), index: index));
|
|
coinsMutex.release();
|
|
}
|
|
|
|
Future<void> thawCoin(int index) async {
|
|
await coinsMutex.acquire();
|
|
final coinsPtr = coins!.ffiAddress();
|
|
await Isolate.run(() => monero.Coins_thaw(Pointer.fromAddress(coinsPtr), index: index));
|
|
coinsMutex.release();
|
|
}
|