mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
WIP migrate lcoins hive => isar
This commit is contained in:
parent
baa34ca9f2
commit
a5ba67aa1d
4 changed files with 68 additions and 2 deletions
|
@ -15,5 +15,6 @@ export 'blockchain_data/output.dart';
|
|||
export 'blockchain_data/transaction.dart';
|
||||
export 'blockchain_data/utxo.dart';
|
||||
export 'ethereum/eth_contract.dart';
|
||||
export 'firo_specific/lelantus_coin.dart';
|
||||
export 'log.dart';
|
||||
export 'transaction_note.dart';
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:hive/hive.dart';
|
|||
|
||||
part 'type_adaptors/lelantus_coin.g.dart';
|
||||
|
||||
@Deprecated("Use Isar object instead")
|
||||
// @HiveType(typeId: 9)
|
||||
class LelantusCoin {
|
||||
// @HiveField(0)
|
||||
|
@ -27,6 +28,7 @@ class LelantusCoin {
|
|||
// @HiveField(5)
|
||||
bool isUsed;
|
||||
|
||||
@Deprecated("Use Isar object instead")
|
||||
LelantusCoin(
|
||||
this.index,
|
||||
this.value,
|
||||
|
|
|
@ -58,7 +58,7 @@ abstract class Constants {
|
|||
// Enable Logger.print statements
|
||||
static const bool disableLogger = false;
|
||||
|
||||
static const int currentDataVersion = 10;
|
||||
static const int currentDataVersion = 11;
|
||||
|
||||
static const int rescanV1 = 1;
|
||||
|
||||
|
|
|
@ -180,7 +180,6 @@ class DbVersionMigrator with WalletDB {
|
|||
// clear possible broken firo cache
|
||||
await DB.instance.clearSharedTransactionCache(coin: Coin.firo);
|
||||
|
||||
|
||||
// update version
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNameDBInfo, key: "hive_data_version", value: 4);
|
||||
|
@ -343,12 +342,76 @@ class DbVersionMigrator with WalletDB {
|
|||
// try to continue migrating
|
||||
return await migrate(10, secureStore: secureStore);
|
||||
|
||||
case 10:
|
||||
// migrate
|
||||
await _v10(secureStore);
|
||||
|
||||
// update version
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNameDBInfo, key: "hive_data_version", value: 11);
|
||||
|
||||
// try to continue migrating
|
||||
return await migrate(11, secureStore: secureStore);
|
||||
|
||||
default:
|
||||
// finally return
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _v10(SecureStorageInterface secureStore) async {
|
||||
await Hive.openBox<dynamic>(DB.boxNameAllWalletsData);
|
||||
await Hive.openBox<dynamic>(DB.boxNamePrefs);
|
||||
final walletsService = WalletsService(secureStorageInterface: secureStore);
|
||||
final prefs = Prefs.instance;
|
||||
final walletInfoList = await walletsService.walletNames;
|
||||
await prefs.init();
|
||||
await MainDB.instance.initMainDB();
|
||||
|
||||
for (final walletId in walletInfoList.keys) {
|
||||
final info = walletInfoList[walletId]!;
|
||||
assert(info.walletId == walletId);
|
||||
|
||||
if (info.coin == Coin.firo &&
|
||||
MainDB.instance.isar.lelantusCoins
|
||||
.where()
|
||||
.walletIdEqualTo(walletId)
|
||||
.countSync() ==
|
||||
0) {
|
||||
final walletBox = await Hive.openBox<dynamic>(walletId);
|
||||
|
||||
final hiveLCoins = DB.instance.get<dynamic>(
|
||||
boxName: walletId,
|
||||
key: "_lelantus_coins",
|
||||
) as List? ??
|
||||
[];
|
||||
|
||||
final List<isar_models.LelantusCoin> coins = [];
|
||||
for (final e in hiveLCoins) {
|
||||
final lcoin = e as LelantusCoin;
|
||||
|
||||
final coin = isar_models.LelantusCoin(
|
||||
walletId: walletId,
|
||||
publicCoin: lcoin.publicCoin,
|
||||
txid: lcoin.txId,
|
||||
value: lcoin.value.toString(),
|
||||
index: lcoin.index,
|
||||
anonymitySetId: lcoin.anonymitySetId,
|
||||
isUsed: lcoin.isUsed,
|
||||
);
|
||||
|
||||
coins.add(coin);
|
||||
}
|
||||
|
||||
if (coins.isNotEmpty) {
|
||||
await MainDB.instance.isar.writeTxn(() async {
|
||||
await MainDB.instance.isar.lelantusCoins.putAll(coins);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _v4(SecureStorageInterface secureStore) async {
|
||||
await Hive.openBox<dynamic>(DB.boxNameAllWalletsData);
|
||||
await Hive.openBox<dynamic>(DB.boxNamePrefs);
|
||||
|
|
Loading…
Reference in a new issue