mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
epic transaction migration
This commit is contained in:
parent
14b2424c3f
commit
75c5a1d7d9
1 changed files with 72 additions and 6 deletions
|
@ -1,8 +1,10 @@
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:stackwallet/db/main_db.dart';
|
||||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||||
import 'package:stackwallet/hive/db.dart';
|
import 'package:stackwallet/hive/db.dart';
|
||||||
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
|
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
|
||||||
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
|
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
|
||||||
|
import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
|
||||||
import 'package:stackwallet/models/models.dart';
|
import 'package:stackwallet/models/models.dart';
|
||||||
import 'package:stackwallet/models/node_model.dart';
|
import 'package:stackwallet/models/node_model.dart';
|
||||||
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
import 'package:stackwallet/services/mixins/wallet_db.dart';
|
||||||
|
@ -14,6 +16,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/prefs.dart';
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
class DbVersionMigrator with WalletDB {
|
class DbVersionMigrator with WalletDB {
|
||||||
Future<void> migrate(
|
Future<void> migrate(
|
||||||
|
@ -195,6 +198,7 @@ class DbVersionMigrator with WalletDB {
|
||||||
final prefs = Prefs.instance;
|
final prefs = Prefs.instance;
|
||||||
final walletInfoList = await walletsService.walletNames;
|
final walletInfoList = await walletsService.walletNames;
|
||||||
await prefs.init();
|
await prefs.init();
|
||||||
|
await MainDB.instance.initMainDB();
|
||||||
|
|
||||||
for (final walletId in walletInfoList.keys) {
|
for (final walletId in walletInfoList.keys) {
|
||||||
final info = walletInfoList[walletId]!;
|
final info = walletInfoList[walletId]!;
|
||||||
|
@ -205,6 +209,64 @@ class DbVersionMigrator with WalletDB {
|
||||||
const receiveAddressesPrefix = "receivingAddresses";
|
const receiveAddressesPrefix = "receivingAddresses";
|
||||||
const changeAddressesPrefix = "changeAddresses";
|
const changeAddressesPrefix = "changeAddresses";
|
||||||
|
|
||||||
|
// we need to manually migrate epic cash transactions as they are not
|
||||||
|
// stored on the epic cash blockchain
|
||||||
|
if (info.coin == Coin.epicCash) {
|
||||||
|
final txnData = walletBox.get("latest_tx_model") as TransactionData?;
|
||||||
|
|
||||||
|
// we ever only used index 0 in the past
|
||||||
|
const rcvIndex = 0;
|
||||||
|
|
||||||
|
final List<Tuple2<isar_models.Transaction, isar_models.Address?>>
|
||||||
|
transactionsData = [];
|
||||||
|
if (txnData != null) {
|
||||||
|
final txns = txnData.getAllTransactions();
|
||||||
|
|
||||||
|
for (final tx in txns.values) {
|
||||||
|
bool isIncoming = tx.txType == "Received";
|
||||||
|
|
||||||
|
final iTx = isar_models.Transaction(
|
||||||
|
walletId: walletId,
|
||||||
|
txid: tx.txid,
|
||||||
|
timestamp: tx.timestamp,
|
||||||
|
type: isIncoming
|
||||||
|
? isar_models.TransactionType.incoming
|
||||||
|
: isar_models.TransactionType.outgoing,
|
||||||
|
subType: isar_models.TransactionSubType.none,
|
||||||
|
amount: tx.amount,
|
||||||
|
fee: tx.fees,
|
||||||
|
height: tx.height,
|
||||||
|
isCancelled: tx.isCancelled,
|
||||||
|
isLelantus: false,
|
||||||
|
slateId: tx.slateId,
|
||||||
|
otherData: tx.otherData,
|
||||||
|
inputs: [],
|
||||||
|
outputs: [],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (tx.address.isEmpty) {
|
||||||
|
transactionsData.add(Tuple2(iTx, null));
|
||||||
|
} else {
|
||||||
|
final address = isar_models.Address(
|
||||||
|
walletId: walletId,
|
||||||
|
value: tx.address,
|
||||||
|
publicKey: [],
|
||||||
|
derivationIndex: isIncoming ? rcvIndex : -1,
|
||||||
|
derivationPath: null,
|
||||||
|
type: isIncoming
|
||||||
|
? isar_models.AddressType.mimbleWimble
|
||||||
|
: isar_models.AddressType.unknown,
|
||||||
|
subType: isIncoming
|
||||||
|
? isar_models.AddressSubType.receiving
|
||||||
|
: isar_models.AddressSubType.unknown,
|
||||||
|
);
|
||||||
|
transactionsData.add(Tuple2(iTx, address));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await MainDB.instance.addNewTransactionData(transactionsData, walletId);
|
||||||
|
}
|
||||||
|
|
||||||
// delete data from hive
|
// delete data from hive
|
||||||
await walletBox.delete(receiveAddressesPrefix);
|
await walletBox.delete(receiveAddressesPrefix);
|
||||||
await walletBox.delete("${receiveAddressesPrefix}P2PKH");
|
await walletBox.delete("${receiveAddressesPrefix}P2PKH");
|
||||||
|
@ -224,12 +286,16 @@ class DbVersionMigrator with WalletDB {
|
||||||
key: '${walletId}_mnemonicPassphrase', value: "");
|
key: '${walletId}_mnemonicPassphrase', value: "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// set flag to initiate full rescan on opening wallet
|
// doing this for epic cash will delete transaction history as it is not
|
||||||
await DB.instance.put<dynamic>(
|
// stored on the epic cash blockchain
|
||||||
boxName: DB.boxNameDBInfo,
|
if (info.coin != Coin.epicCash) {
|
||||||
key: "rescan_on_open_$walletId",
|
// set flag to initiate full rescan on opening wallet
|
||||||
value: Constants.rescanV1,
|
await DB.instance.put<dynamic>(
|
||||||
);
|
boxName: DB.boxNameDBInfo,
|
||||||
|
key: "rescan_on_open_$walletId",
|
||||||
|
value: Constants.rescanV1,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue