store crash fix

This commit is contained in:
Czarek Nakamoto 2024-05-11 22:27:34 +02:00
parent ae1fe4023d
commit 2d883f8f3f
4 changed files with 50 additions and 28 deletions

View file

@ -1,8 +1,11 @@
import 'dart:async';
import 'dart:ffi';
import 'dart:isolate';
import 'package:cw_monero/api/account_list.dart';
import 'package:cw_monero/api/exceptions/setup_wallet_exception.dart';
import 'package:monero/monero.dart' as monero;
import 'package:mutex/mutex.dart';
int getSyncingHeight() {
// final height = monero.MONERO_cw_WalletListener_height(getWlptr());
@ -10,6 +13,7 @@ int getSyncingHeight() {
// print("height: $height / $h2");
return h2;
}
bool isNeededToRefresh() {
final ret = monero.MONERO_cw_WalletListener_isNeedToRefresh(getWlptr());
monero.MONERO_cw_WalletListener_resetNeedToRefresh(getWlptr());
@ -21,11 +25,13 @@ bool isNewTransactionExist() {
monero.MONERO_cw_WalletListener_resetIsNewTransactionExist(getWlptr());
return ret;
}
String getFilename() => monero.Wallet_filename(wptr!);
String getSeed() {
// monero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed);
final cakepolyseed = monero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed");
final cakepolyseed =
monero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed");
if (cakepolyseed != "") {
return cakepolyseed;
}
@ -37,11 +43,15 @@ String getSeed() {
return legacy;
}
String getAddress({int accountIndex = 0, int addressIndex = 1}) => monero.Wallet_address(wptr!, accountIndex: accountIndex, addressIndex: addressIndex);
String getAddress({int accountIndex = 0, int addressIndex = 1}) =>
monero.Wallet_address(wptr!,
accountIndex: accountIndex, addressIndex: addressIndex);
int getFullBalance({int accountIndex = 0}) => monero.Wallet_balance(wptr!, accountIndex: accountIndex);
int getFullBalance({int accountIndex = 0}) =>
monero.Wallet_balance(wptr!, accountIndex: accountIndex);
int getUnlockedBalance({int accountIndex = 0}) => monero.Wallet_unlockedBalance(wptr!, accountIndex: accountIndex);
int getUnlockedBalance({int accountIndex = 0}) =>
monero.Wallet_unlockedBalance(wptr!, accountIndex: accountIndex);
int getCurrentHeight() => monero.Wallet_blockChainHeight(wptr!);
@ -66,16 +76,14 @@ bool setupNodeSync(
daemonPassword: $password ?? ''
}
''');
monero.Wallet_init(
wptr!,
daemonAddress: address,
useSsl: useSSL,
proxyAddress: socksProxyAddress ?? '',
daemonUsername: login ?? '',
daemonPassword: password ?? ''
);
monero.Wallet_init(wptr!,
daemonAddress: address,
useSsl: useSSL,
proxyAddress: socksProxyAddress ?? '',
daemonUsername: login ?? '',
daemonPassword: password ?? '');
// monero.Wallet_init3(wptr!, argv0: '', defaultLogBaseName: 'moneroc', console: true);
final status = monero.Wallet_status(wptr!);
if (status != 0) {
@ -96,18 +104,26 @@ Future<bool> connectToNode() async {
return true;
}
void setRefreshFromBlockHeight({required int height}) => monero.Wallet_setRefreshFromBlockHeight(wptr!, refresh_from_block_height: height);
void setRefreshFromBlockHeight({required int height}) =>
monero.Wallet_setRefreshFromBlockHeight(wptr!,
refresh_from_block_height: height);
void setRecoveringFromSeed({required bool isRecovery}) => monero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery);
void setRecoveringFromSeed({required bool isRecovery}) =>
monero.Wallet_setRecoveringFromSeed(wptr!, recoveringFromSeed: isRecovery);
void storeSync() {
monero.Wallet_store(wptr!);
final storeMutex = Mutex();
void storeSync() async {
await storeMutex.acquire();
final addr = wptr!.address;
Isolate.run(() {
monero.Wallet_store(Pointer.fromAddress(addr));
});
storeMutex.release();
}
void setPasswordSync(String password) {
monero.Wallet_setPassword(wptr!, password: password);
final status = monero.Wallet_status(wptr!);
if (status == 0) {
throw Exception(monero.Wallet_errorString(wptr!));
@ -127,11 +143,10 @@ String getSecretSpendKey() => monero.Wallet_secretSpendKey(wptr!);
String getPublicSpendKey() => monero.Wallet_publicSpendKey(wptr!);
class SyncListener {
SyncListener(this.onNewBlock, this.onNewTransaction)
: _cachedBlockchainHeight = 0,
_lastKnownBlockHeight = 0,
_initialSyncHeight = 0;
SyncListener(this.onNewBlock, this.onNewTransaction)
: _cachedBlockchainHeight = 0,
_lastKnownBlockHeight = 0,
_initialSyncHeight = 0;
void Function(int, int, double) onNewBlock;
void Function() onNewTransaction;
@ -236,7 +251,7 @@ Future<void> setupNode(
bool isLightWallet = false}) async =>
_setupNodeSync({
'address': address,
'login': login ,
'login': login,
'password': password,
'useSSL': useSSL,
'isLightWallet': isLightWallet,
@ -252,10 +267,12 @@ Future<int> getNodeHeight() async => _getNodeHeight(0);
void rescanBlockchainAsync() => monero.Wallet_rescanBlockchainAsync(wptr!);
String getSubaddressLabel(int accountIndex, int addressIndex) {
return monero.Wallet_getSubaddressLabel(wptr!, accountIndex: accountIndex, addressIndex: addressIndex);
return monero.Wallet_getSubaddressLabel(wptr!,
accountIndex: accountIndex, addressIndex: addressIndex);
}
Future setTrustedDaemon(bool trusted) async => monero.Wallet_setTrustedDaemon(wptr!, arg: trusted);
Future setTrustedDaemon(bool trusted) async =>
monero.Wallet_setTrustedDaemon(wptr!, arg: trusted);
Future<bool> trustedDaemon() async => monero.Wallet_trustedDaemon(wptr!);

View file

@ -1,4 +1,5 @@
import 'dart:ffi';
import 'dart:isolate';
import 'package:cw_monero/api/account_list.dart';
import 'package:cw_monero/api/exceptions/wallet_creation_exception.dart';
@ -190,7 +191,10 @@ void loadWallet(
try {
if (wptr == null || path != _lastOpenedWallet) {
if (wptr != null) {
monero.Wallet_store(wptr!);
final addr = wptr!.address;
Isolate.run(() {
monero.Wallet_store(Pointer.fromAddress(addr));
});
}
wptr = monero.WalletManager_openWallet(wmPtr,
path: path, password: password);

View file

@ -26,6 +26,7 @@ dependencies:
git:
url: https://git.mrcyjanek.net/mrcyjanek/monero.dart
ref: 6a17a405a1a260fa228b2f4fc94044088a4335ac
mutex: ^3.1.0
dev_dependencies:
flutter_test:

View file

@ -10,7 +10,7 @@ if [[ ! -d "monero_c" ]];
then
git clone https://github.com/mrcyjanek/monero_c --branch rewrite-wip
cd monero_c
git checkout 6781419926d38e045680035a6c2dfcfe32fa22a2
git checkout 4a9142a36f1fca90372216f40e799fabb38e27d7
git reset --hard
git submodule update --init --force --recursive
./apply_patches.sh monero