mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
* fix: key image comparision
* Revert "fix: frozen coins displaying incorrect amounts in monero (#2385)"
This reverts commit b6a7dde8e4.
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);
|
|
if (keyImage == coin.keyImage()) {
|
|
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();
|
|
}
|