wownero restore tweaks

This commit is contained in:
julian 2024-06-13 12:00:03 -06:00
parent cb4a9b5180
commit f31d47f123

View file

@ -12,6 +12,7 @@ import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart'; import 'package:cw_monero/api/exceptions/creation_transaction_exception.dart';
import 'package:cw_wownero/api/account_list.dart';
import 'package:cw_wownero/pending_wownero_transaction.dart'; import 'package:cw_wownero/pending_wownero_transaction.dart';
import 'package:cw_wownero/wownero_wallet.dart'; import 'package:cw_wownero/wownero_wallet.dart';
import 'package:decimal/decimal.dart'; import 'package:decimal/decimal.dart';
@ -20,6 +21,7 @@ import 'package:flutter_libmonero/view_model/send/output.dart'
as wownero_output; as wownero_output;
import 'package:flutter_libmonero/wownero/wownero.dart' as wow_dart; import 'package:flutter_libmonero/wownero/wownero.dart' as wow_dart;
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:monero/wownero.dart' as wownerodart;
import 'package:mutex/mutex.dart'; import 'package:mutex/mutex.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
@ -383,19 +385,11 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
_walletCreationService.type = WalletType.wownero; _walletCreationService.type = WalletType.wownero;
// To restore from a seed // To restore from a seed
final wallet = await _walletCreationService.create(credentials); final wallet = await _walletCreationService.create(credentials);
//
// final bufferedCreateHeight = (seedWordsLength == 14) final height = wownerodart.Wallet_getRefreshFromBlockHeight(wptr!);
// ? getSeedHeightSync(wallet?.seed.trim() as String)
// : wownero.getHeightByDate(
// date: DateTime.now().subtract(const Duration(
// days:
// 2))); // subtract a couple days to ensure we have a buffer for SWB
// TODO(mrcyjanek): implement
const bufferedCreateHeight =
1; //getSeedHeightSync(wallet!.seed.trim());
await info.updateRestoreHeight( await info.updateRestoreHeight(
newRestoreHeight: bufferedCreateHeight, newRestoreHeight: height,
isar: mainDB.isar, isar: mainDB.isar,
); );
@ -410,7 +404,7 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
value: "", value: "",
); );
walletInfo.restoreHeight = bufferedCreateHeight; walletInfo.restoreHeight = height;
walletInfo.address = wallet.walletAddresses.address; walletInfo.address = wallet.walletAddresses.address;
await DB.instance await DB.instance
@ -515,8 +509,7 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
// extract seed height from 14 word seed // extract seed height from 14 word seed
if (seedLength == 14) { if (seedLength == 14) {
// TODO(mrcyjanek): implement height = 0;
height = 1; // getSeedHeightSync(mnemonic.trim());
} else { } else {
height = max(height, 0); height = max(height, 0);
} }
@ -563,7 +556,13 @@ class WowneroWallet extends CryptonoteWallet with CwBasedInterface {
// To restore from a seed // To restore from a seed
final wallet = await cwWalletCreationService final wallet = await cwWalletCreationService
.restoreFromSeed(credentials) as WowneroWalletBase; .restoreFromSeed(credentials) as WowneroWalletBase;
height = wownerodart.Wallet_getRefreshFromBlockHeight(wptr!);
walletInfo.address = wallet.walletAddresses.address; walletInfo.address = wallet.walletAddresses.address;
walletInfo.restoreHeight = height;
await info.updateRestoreHeight(
newRestoreHeight: height,
isar: mainDB.isar,
);
await DB.instance await DB.instance
.add<WalletInfo>(boxName: WalletInfo.boxName, value: walletInfo); .add<WalletInfo>(boxName: WalletInfo.boxName, value: walletInfo);
CwBasedInterface.cwWalletBase?.close(); CwBasedInterface.cwWalletBase?.close();