Remove polyseed seed workaround and fix properly by just storing the wallet (#1215)

Konstantin Ullrich committed Dec 4, 2023 at 12:52 UTC 3c28e2525970f380be9610367ceb9262a1c73b08
3 files changed +13 -29
cw_monero/lib/api/wallet_manager.dart
+10 -6
@@ -1,14 +1,16 @@
1 import 'dart:ffi';
2 -import 'package:ffi/ffi.dart';
3 -import 'package:flutter/foundation.dart';
2 +
3 import 'package:cw_monero/api/convert_utf8_to_string.dart';
5 -import 'package:cw_monero/api/signatures.dart';
6 -import 'package:cw_monero/api/types.dart';
7 -import 'package:cw_monero/api/monero_api.dart';
8 -import 'package:cw_monero/api/exceptions/wallet_opening_exception.dart';
4 import 'package:cw_monero/api/exceptions/wallet_creation_exception.dart';
5 +import 'package:cw_monero/api/exceptions/wallet_opening_exception.dart';
6 import 'package:cw_monero/api/exceptions/wallet_restore_from_keys_exception.dart';
7 import 'package:cw_monero/api/exceptions/wallet_restore_from_seed_exception.dart';
8 +import 'package:cw_monero/api/monero_api.dart';
9 +import 'package:cw_monero/api/signatures.dart';
10 +import 'package:cw_monero/api/types.dart';
11 +import 'package:cw_monero/api/wallet.dart';
12 +import 'package:ffi/ffi.dart';
13 +import 'package:flutter/foundation.dart';
14
15 final createWalletNative = moneroApi
16 .lookup<NativeFunction<create_wallet>>('create_wallet')
@@ -175,6 +177,8 @@ void restoreWalletFromSpendKeySync(
177 calloc.free(languagePointer);
178 calloc.free(spendKeyPointer);
179
180 + storeSync();
181 +
182 if (!isWalletRestored) {
183 throw WalletRestoreFromKeysException(
184 message: convertUTF8ToString(pointer: errorMessagePointer));
cw_monero/lib/monero_wallet.dart
+2 -7
@@ -97,8 +97,7 @@ abstract class MoneroWalletBase
97 ObservableMap<CryptoCurrency, MoneroBalance> balance;
98
99 @override
100 - String get seed => _seed;
101 - String _seed = monero_wallet.getSeed();
100 + String get seed => monero_wallet.getSeed();
101
102 @override
103 MoneroWalletKeys get keys => MoneroWalletKeys(
@@ -114,11 +113,7 @@ abstract class MoneroWalletBase
113 Timer? _autoSaveTimer;
114 List<MoneroUnspent> unspentCoins;
115
117 - Future<void> init({String seedFallback = ""}) async {
118 - if (_seed.isEmpty) {
119 - _seed = seedFallback;
120 - }
121 -
116 + Future<void> init() async {
117 await walletAddresses.init();
118 balance = ObservableMap<CryptoCurrency, MoneroBalance>.of(<CryptoCurrency, MoneroBalance>{
119 currency: MoneroBalance(
cw_monero/lib/monero_wallet_service.dart
+1 -16
@@ -2,7 +2,6 @@ import 'dart:io';
2 import 'package:cw_core/monero_wallet_utils.dart';
3 import 'package:cw_core/pathForWallet.dart';
4 import 'package:cw_core/unspent_coins_info.dart';
5 -import 'package:cw_core/utils/file.dart';
5 import 'package:cw_core/wallet_base.dart';
6 import 'package:cw_core/wallet_credentials.dart';
7 import 'package:cw_core/wallet_info.dart';
@@ -134,12 +133,7 @@ class MoneroWalletService extends WalletService<
133 return openWallet(name, password);
134 }
135
137 - if (wallet.seed.isEmpty) {
138 - final seedFallback = await _getSeedBackup(path, password);
139 - await wallet.init(seedFallback: seedFallback);
140 - } else {
141 - await wallet.init();
142 - }
136 + await wallet.init();
137
138 return wallet;
139 } catch (e) {
@@ -295,8 +289,6 @@ class MoneroWalletService extends WalletService<
289 restoreHeight: height,
290 spendKey: spendKey);
291
298 - await writeData(path: "$path.seed", password: password, data: seed);
299 -
292 final wallet = MoneroWallet(
293 walletInfo: walletInfo, unspentCoinsInfo: unspentCoinsInfoSource);
294 await wallet.init();
@@ -304,13 +296,6 @@ class MoneroWalletService extends WalletService<
296 return wallet;
297 }
298
307 - Future<String> _getSeedBackup(String path, String password) async {
308 - final seedFilePath = "$path.seed";
309 - final seedFile = File(seedFilePath);
310 - if (!seedFile.existsSync()) return "";
311 - return read(path: seedFilePath, password: password);
312 - }
313 -
299 Future<void> repairOldAndroidWallet(String name) async {
300 try {
301 if (!Platform.isAndroid) {