fix invalid wallet pointer getting set even when we throw (#1556)
Some checks failed
Cache Dependencies / test (push) Has been cancelled

* fix invalid wallet pointer getting set even when we throw

* Hide "wallet seeds" field if there is no seeds (cases of restore from keys)

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
cyan 2024-07-26 17:36:18 +02:00 committed by GitHub
parent d5fca1969e
commit eb8158e996
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 53 additions and 37 deletions

View file

@ -32,13 +32,14 @@ void createWalletSync(
required String language,
int nettype = 0}) {
txhistory = null;
wptr = monero.WalletManager_createWallet(wmPtr,
final newWptr = monero.WalletManager_createWallet(wmPtr,
path: path, password: password, language: language, networkType: 0);
final status = monero.Wallet_status(wptr!);
final status = monero.Wallet_status(newWptr);
if (status != 0) {
throw WalletCreationException(message: monero.Wallet_errorString(wptr!));
throw WalletCreationException(message: monero.Wallet_errorString(newWptr));
}
wptr = newWptr;
monero.Wallet_store(wptr!, path: path);
openedWalletsByPath[path] = wptr!;
@ -57,7 +58,7 @@ void restoreWalletFromSeedSync(
int nettype = 0,
int restoreHeight = 0}) {
txhistory = null;
wptr = monero.WalletManager_recoveryWallet(
final newWptr = monero.WalletManager_recoveryWallet(
wmPtr,
path: path,
password: password,
@ -67,12 +68,13 @@ void restoreWalletFromSeedSync(
networkType: 0,
);
final status = monero.Wallet_status(wptr!);
final status = monero.Wallet_status(newWptr);
if (status != 0) {
final error = monero.Wallet_errorString(wptr!);
final error = monero.Wallet_errorString(newWptr);
throw WalletRestoreFromSeedException(message: error);
}
wptr = newWptr;
openedWalletsByPath[path] = wptr!;
}
@ -87,7 +89,7 @@ void restoreWalletFromKeysSync(
int nettype = 0,
int restoreHeight = 0}) {
txhistory = null;
wptr = monero.WalletManager_createWalletFromKeys(
final newWptr = monero.WalletManager_createWalletFromKeys(
wmPtr,
path: path,
password: password,
@ -98,12 +100,14 @@ void restoreWalletFromKeysSync(
nettype: 0,
);
final status = monero.Wallet_status(wptr!);
final status = monero.Wallet_status(newWptr);
if (status != 0) {
throw WalletRestoreFromKeysException(
message: monero.Wallet_errorString(wptr!));
message: monero.Wallet_errorString(newWptr));
}
wptr = newWptr;
openedWalletsByPath[path] = wptr!;
}
@ -128,7 +132,7 @@ void restoreWalletFromSpendKeySync(
// );
txhistory = null;
wptr = monero.WalletManager_createDeterministicWalletFromSpendKey(
final newWptr = monero.WalletManager_createDeterministicWalletFromSpendKey(
wmPtr,
path: path,
password: password,
@ -138,14 +142,16 @@ void restoreWalletFromSpendKeySync(
restoreHeight: restoreHeight,
);
final status = monero.Wallet_status(wptr!);
final status = monero.Wallet_status(newWptr);
if (status != 0) {
final err = monero.Wallet_errorString(wptr!);
final err = monero.Wallet_errorString(newWptr);
print("err: $err");
throw WalletRestoreFromKeysException(message: err);
}
wptr = newWptr;
monero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed);
storeSync();
@ -203,15 +209,16 @@ void loadWallet(
});
}
txhistory = null;
wptr = monero.WalletManager_openWallet(wmPtr,
final newWptr = monero.WalletManager_openWallet(wmPtr,
path: path, password: password);
_lastOpenedWallet = path;
final status = monero.Wallet_status(wptr!);
final status = monero.Wallet_status(newWptr);
if (status != 0) {
final err = monero.Wallet_errorString(wptr!);
final err = monero.Wallet_errorString(newWptr);
print(err);
throw WalletOpeningException(message: err);
}
wptr = newWptr;
openedWalletsByPath[path] = wptr!;
}
}

View file

@ -32,13 +32,14 @@ void createWalletSync(
required String language,
int nettype = 0}) {
txhistory = null;
wptr = wownero.WalletManager_createWallet(wmPtr,
final newWptr = wownero.WalletManager_createWallet(wmPtr,
path: path, password: password, language: language, networkType: 0);
final status = wownero.Wallet_status(wptr!);
final status = wownero.Wallet_status(newWptr);
if (status != 0) {
throw WalletCreationException(message: wownero.Wallet_errorString(wptr!));
throw WalletCreationException(message: wownero.Wallet_errorString(newWptr));
}
wptr = newWptr;
wownero.Wallet_store(wptr!, path: path);
openedWalletsByPath[path] = wptr!;
@ -56,9 +57,10 @@ void restoreWalletFromSeedSync(
required String seed,
int nettype = 0,
int restoreHeight = 0}) {
var newWptr;
if (seed.split(" ").length == 14) {
txhistory = null;
wptr = wownero.WOWNERO_deprecated_restore14WordSeed(
newWptr = wownero.WOWNERO_deprecated_restore14WordSeed(
path: path,
password: password,
language: seed, // I KNOW - this is supposed to be called seed
@ -70,7 +72,7 @@ void restoreWalletFromSeedSync(
);
} else {
txhistory = null;
wptr = wownero.WalletManager_recoveryWallet(
newWptr = wownero.WalletManager_recoveryWallet(
wmPtr,
path: path,
password: password,
@ -81,13 +83,15 @@ void restoreWalletFromSeedSync(
);
}
final status = wownero.Wallet_status(wptr!);
final status = wownero.Wallet_status(newWptr);
if (status != 0) {
final error = wownero.Wallet_errorString(wptr!);
final error = wownero.Wallet_errorString(newWptr);
throw WalletRestoreFromSeedException(message: error);
}
wptr = newWptr;
openedWalletsByPath[path] = wptr!;
}
@ -101,7 +105,7 @@ void restoreWalletFromKeysSync(
int nettype = 0,
int restoreHeight = 0}) {
txhistory = null;
wptr = wownero.WalletManager_createWalletFromKeys(
final newWptr = wownero.WalletManager_createWalletFromKeys(
wmPtr,
path: path,
password: password,
@ -112,12 +116,14 @@ void restoreWalletFromKeysSync(
nettype: 0,
);
final status = wownero.Wallet_status(wptr!);
final status = wownero.Wallet_status(newWptr);
if (status != 0) {
throw WalletRestoreFromKeysException(
message: wownero.Wallet_errorString(wptr!));
message: wownero.Wallet_errorString(newWptr));
}
wptr = newWptr;
openedWalletsByPath[path] = wptr!;
}
@ -142,7 +148,7 @@ void restoreWalletFromSpendKeySync(
// );
txhistory = null;
wptr = wownero.WalletManager_createDeterministicWalletFromSpendKey(
final newWptr = wownero.WalletManager_createDeterministicWalletFromSpendKey(
wmPtr,
path: path,
password: password,
@ -152,14 +158,16 @@ void restoreWalletFromSpendKeySync(
restoreHeight: restoreHeight,
);
final status = wownero.Wallet_status(wptr!);
final status = wownero.Wallet_status(newWptr);
if (status != 0) {
final err = wownero.Wallet_errorString(wptr!);
final err = wownero.Wallet_errorString(newWptr);
print("err: $err");
throw WalletRestoreFromKeysException(message: err);
}
wptr = newWptr;
wownero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed);
storeSync();
@ -217,15 +225,16 @@ void loadWallet(
});
}
txhistory = null;
wptr = wownero.WalletManager_openWallet(wmPtr,
final newWptr = wownero.WalletManager_openWallet(wmPtr,
path: path, password: password);
_lastOpenedWallet = path;
final status = wownero.Wallet_status(wptr!);
final status = wownero.Wallet_status(newWptr);
if (status != 0) {
final err = wownero.Wallet_errorString(wptr!);
final err = wownero.Wallet_errorString(newWptr);
print(err);
throw WalletOpeningException(message: err);
}
wptr = newWptr;
openedWalletsByPath[path] = wptr!;
}
}

View file

@ -83,8 +83,8 @@ abstract class WalletKeysViewModelBase with Store {
StandartListItem(
title: S.current.view_key_private,
value: keys['privateViewKey']!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
if (_appStore.wallet!.seed!.isNotEmpty)
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
]);
if (_appStore.wallet?.seed != null &&
@ -123,8 +123,8 @@ abstract class WalletKeysViewModelBase with Store {
StandartListItem(
title: S.current.view_key_private,
value: keys['privateViewKey']!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
if (_appStore.wallet!.seed!.isNotEmpty)
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
]);
}
@ -147,8 +147,8 @@ abstract class WalletKeysViewModelBase with Store {
StandartListItem(
title: S.current.view_key_private,
value: keys['privateViewKey']!),
StandartListItem(
title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
if (_appStore.wallet!.seed!.isNotEmpty)
StandartListItem(title: S.current.wallet_seed, value: _appStore.wallet!.seed!),
]);
if (_appStore.wallet?.seed != null &&