mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-30 14:15:52 +00:00
changenow trade to generic trade db migration
This commit is contained in:
parent
65cedbac02
commit
cdcda481bf
5 changed files with 148 additions and 115 deletions
|
@ -4,6 +4,7 @@ import 'package:cw_core/wallet_info.dart' as xmr;
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:mutex/mutex.dart';
|
||||
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
|
||||
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
|
||||
import 'package:stackwallet/models/node_model.dart';
|
||||
import 'package:stackwallet/models/notification_model.dart';
|
||||
import 'package:stackwallet/models/trade_wallet_lookup.dart';
|
||||
|
@ -22,6 +23,7 @@ class DB {
|
|||
"watchedTxNotificationModels";
|
||||
static const String boxNameWatchedTrades = "watchedTradesNotificationModels";
|
||||
static const String boxNameTrades = "exchangeTransactionsBox";
|
||||
static const String boxNameTradesV2 = "exchangeTradesBox";
|
||||
static const String boxNameTradeNotes = "tradeNotesBox";
|
||||
static const String boxNameTradeLookup = "tradeToTxidLookUpBox";
|
||||
static const String boxNameFavoriteWallets = "favoriteWallets";
|
||||
|
@ -48,6 +50,7 @@ class DB {
|
|||
late final Box<NotificationModel> _boxWatchedTransactions;
|
||||
late final Box<NotificationModel> _boxWatchedTrades;
|
||||
late final Box<ExchangeTransaction> _boxTrades;
|
||||
late final Box<Trade> _boxTradesV2;
|
||||
late final Box<String> _boxTradeNotes;
|
||||
late final Box<String> _boxFavoriteWallets;
|
||||
late final Box<xmr.WalletInfo> _walletInfoSource;
|
||||
|
@ -125,6 +128,7 @@ class DB {
|
|||
_boxWatchedTrades =
|
||||
await Hive.openBox<NotificationModel>(boxNameWatchedTrades);
|
||||
_boxTrades = await Hive.openBox<ExchangeTransaction>(boxNameTrades);
|
||||
_boxTradesV2 = await Hive.openBox<Trade>(boxNameTradesV2);
|
||||
_boxTradeNotes = await Hive.openBox<String>(boxNameTradeNotes);
|
||||
_boxTradeLookup =
|
||||
await Hive.openBox<TradeWalletLookup>(boxNameTradeLookup);
|
||||
|
|
|
@ -5,6 +5,8 @@ import 'package:uuid/uuid.dart';
|
|||
|
||||
part '../../type_adaptors/exchange_transaction.g.dart';
|
||||
|
||||
@Deprecated(
|
||||
"Do not use. Migrated to Trade in db_version_migration to hive_data_version 2")
|
||||
// @HiveType(typeId: 13)
|
||||
class ExchangeTransaction {
|
||||
/// You can use it to get transaction status at the Transaction status API endpoint
|
||||
|
|
|
@ -23,40 +23,40 @@ class Trade {
|
|||
final DateTime updatedAt;
|
||||
|
||||
@HiveField(6)
|
||||
final String from;
|
||||
final String payInCurrency;
|
||||
|
||||
@HiveField(7)
|
||||
final String fromAmount;
|
||||
final String payInAmount;
|
||||
|
||||
@HiveField(8)
|
||||
final String fromAddress;
|
||||
final String payInAddress;
|
||||
|
||||
@HiveField(9)
|
||||
final String fromNetwork;
|
||||
final String payInNetwork;
|
||||
|
||||
@HiveField(10)
|
||||
final String fromExtraId;
|
||||
final String payInExtraId;
|
||||
|
||||
@HiveField(11)
|
||||
final String fromTxid;
|
||||
final String payInTxid;
|
||||
|
||||
@HiveField(12)
|
||||
final String to;
|
||||
final String payOutCurrency;
|
||||
|
||||
@HiveField(13)
|
||||
final String toAmount;
|
||||
final String payOutAmount;
|
||||
|
||||
@HiveField(14)
|
||||
final String toAddress;
|
||||
final String payOutAddress;
|
||||
|
||||
@HiveField(15)
|
||||
final String toNetwork;
|
||||
final String payOutNetwork;
|
||||
|
||||
@HiveField(16)
|
||||
final String toExtraId;
|
||||
final String payOutExtraId;
|
||||
|
||||
@HiveField(17)
|
||||
final String toTxid;
|
||||
final String payOutTxid;
|
||||
|
||||
@HiveField(18)
|
||||
final String refundAddress;
|
||||
|
@ -74,65 +74,64 @@ class Trade {
|
|||
required this.direction,
|
||||
required this.timestamp,
|
||||
required this.updatedAt,
|
||||
required this.from,
|
||||
required this.fromAmount,
|
||||
required this.fromAddress,
|
||||
required this.fromNetwork,
|
||||
required this.fromExtraId,
|
||||
required this.fromTxid,
|
||||
required this.to,
|
||||
required this.toAmount,
|
||||
required this.toAddress,
|
||||
required this.toNetwork,
|
||||
required this.toExtraId,
|
||||
required this.toTxid,
|
||||
required this.payInCurrency,
|
||||
required this.payInAmount,
|
||||
required this.payInAddress,
|
||||
required this.payInNetwork,
|
||||
required this.payInExtraId,
|
||||
required this.payInTxid,
|
||||
required this.payOutCurrency,
|
||||
required this.payOutAmount,
|
||||
required this.payOutAddress,
|
||||
required this.payOutNetwork,
|
||||
required this.payOutExtraId,
|
||||
required this.payOutTxid,
|
||||
required this.refundAddress,
|
||||
required this.refundExtraId,
|
||||
required this.status,
|
||||
});
|
||||
|
||||
Trade copyWith({
|
||||
String? uuid,
|
||||
String? tradeId,
|
||||
String? rateType,
|
||||
String? direction,
|
||||
DateTime? timestamp,
|
||||
DateTime? updatedAt,
|
||||
String? from,
|
||||
String? fromAmount,
|
||||
String? fromAddress,
|
||||
String? fromNetwork,
|
||||
String? fromExtraId,
|
||||
String? fromTxid,
|
||||
String? to,
|
||||
String? toAmount,
|
||||
String? toAddress,
|
||||
String? toNetwork,
|
||||
String? toExtraId,
|
||||
String? toTxid,
|
||||
String? payInCurrency,
|
||||
String? payInAmount,
|
||||
String? payInAddress,
|
||||
String? payInNetwork,
|
||||
String? payInExtraId,
|
||||
String? payInTxid,
|
||||
String? payOutCurrency,
|
||||
String? payOutAmount,
|
||||
String? payOutAddress,
|
||||
String? payOutNetwork,
|
||||
String? payOutExtraId,
|
||||
String? payOutTxid,
|
||||
String? refundAddress,
|
||||
String? refundExtraId,
|
||||
String? status,
|
||||
}) {
|
||||
return Trade(
|
||||
uuid: uuid ?? this.uuid,
|
||||
uuid: uuid,
|
||||
tradeId: tradeId ?? this.tradeId,
|
||||
rateType: rateType ?? this.rateType,
|
||||
direction: direction ?? this.direction,
|
||||
timestamp: timestamp ?? this.timestamp,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
from: from ?? this.from,
|
||||
fromAmount: fromAmount ?? this.fromAmount,
|
||||
fromAddress: fromAddress ?? this.fromAddress,
|
||||
fromNetwork: fromNetwork ?? this.fromNetwork,
|
||||
fromExtraId: fromExtraId ?? this.fromExtraId,
|
||||
fromTxid: fromTxid ?? this.fromTxid,
|
||||
to: to ?? this.to,
|
||||
toAmount: toAmount ?? this.toAmount,
|
||||
toAddress: toAddress ?? this.toAddress,
|
||||
toNetwork: toNetwork ?? this.toNetwork,
|
||||
toExtraId: toExtraId ?? this.toExtraId,
|
||||
toTxid: toTxid ?? this.toTxid,
|
||||
payInCurrency: payInCurrency ?? this.payInCurrency,
|
||||
payInAmount: payInAmount ?? this.payInAmount,
|
||||
payInAddress: payInAddress ?? this.payInAddress,
|
||||
payInNetwork: payInNetwork ?? this.payInNetwork,
|
||||
payInExtraId: payInExtraId ?? this.payInExtraId,
|
||||
payInTxid: payInTxid ?? this.payInTxid,
|
||||
payOutCurrency: payOutCurrency ?? this.payOutCurrency,
|
||||
payOutAmount: payOutAmount ?? this.payOutAmount,
|
||||
payOutAddress: payOutAddress ?? this.payOutAddress,
|
||||
payOutNetwork: payOutNetwork ?? this.payOutNetwork,
|
||||
payOutExtraId: payOutExtraId ?? this.payOutExtraId,
|
||||
payOutTxid: payOutTxid ?? this.payOutTxid,
|
||||
refundAddress: refundAddress ?? this.refundAddress,
|
||||
refundExtraId: refundExtraId ?? this.refundExtraId,
|
||||
status: status ?? this.status,
|
||||
|
@ -141,27 +140,27 @@ class Trade {
|
|||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"uuid,": uuid,
|
||||
"tradeId,": tradeId,
|
||||
"rateType,": rateType,
|
||||
"direction,": direction,
|
||||
"timestamp,": timestamp,
|
||||
"updatedAt,": updatedAt,
|
||||
"from,": from,
|
||||
"fromAmount,": fromAmount,
|
||||
"fromAddress,": fromAddress,
|
||||
"fromNetwork,": fromNetwork,
|
||||
"fromExtraId,": fromExtraId,
|
||||
"fromTxid,": fromTxid,
|
||||
"to,": to,
|
||||
"toAmount,": toAmount,
|
||||
"toAddress,": toAddress,
|
||||
"toNetwork,": toNetwork,
|
||||
"toExtraId,": toExtraId,
|
||||
"toTxid,": toTxid,
|
||||
"refundAddress,": refundAddress,
|
||||
"refundExtraId,": refundExtraId,
|
||||
"status,": status,
|
||||
"uuid": uuid,
|
||||
"tradeId": tradeId,
|
||||
"rateType": rateType,
|
||||
"direction": direction,
|
||||
"timestamp": timestamp,
|
||||
"updatedAt": updatedAt,
|
||||
"payInCurrency": payInCurrency,
|
||||
"payInAmount": payInAmount,
|
||||
"payInAddress": payInAddress,
|
||||
"payInNetwork": payInNetwork,
|
||||
"payInExtraId": payInExtraId,
|
||||
"payInTxid": payInTxid,
|
||||
"payOutCurrency": payOutCurrency,
|
||||
"payOutAmount": payOutAmount,
|
||||
"payOutAddress": payOutAddress,
|
||||
"payOutNetwork": payOutNetwork,
|
||||
"payOutExtraId": payOutExtraId,
|
||||
"payOutTxid": payOutTxid,
|
||||
"refundAddress": refundAddress,
|
||||
"refundExtraId": refundExtraId,
|
||||
"status": status,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -109,18 +109,18 @@ class SimpleSwapAPI {
|
|||
direction: "direct",
|
||||
timestamp: DateTime.parse(json["timestamp"] as String),
|
||||
updatedAt: DateTime.parse(json["updated_at"] as String),
|
||||
from: json["currency_from"] as String,
|
||||
fromAmount: json["amount_from"] as String,
|
||||
fromAddress: json["address_from"] as String,
|
||||
fromNetwork: "",
|
||||
fromExtraId: json["extra_id_from"] as String,
|
||||
fromTxid: json["tx_from"] as String,
|
||||
to: json["currency_to"] as String,
|
||||
toAmount: json["amount_to"] as String,
|
||||
toAddress: json["address_to"] as String,
|
||||
toNetwork: "",
|
||||
toExtraId: json["extra_id_to"] as String? ?? "",
|
||||
toTxid: json["tx_to"] as String,
|
||||
payInCurrency: json["currency_from"] as String,
|
||||
payInAmount: json["amount_from"] as String,
|
||||
payInAddress: json["address_from"] as String,
|
||||
payInNetwork: "",
|
||||
payInExtraId: json["extra_id_payIn"] as String,
|
||||
payInTxid: json["tx_from"] as String,
|
||||
payOutCurrency: json["currency_to"] as String,
|
||||
payOutAmount: json["amount_to"] as String,
|
||||
payOutAddress: json["address_to"] as String,
|
||||
payOutNetwork: "",
|
||||
payOutExtraId: json["extra_id_to"] as String? ?? "",
|
||||
payOutTxid: json["tx_to"] as String,
|
||||
refundAddress: json["user_refund_address"] as String,
|
||||
refundExtraId: json["user_refund_extra_id"] as String,
|
||||
status: json["status"] as String,
|
||||
|
@ -355,18 +355,18 @@ class SimpleSwapAPI {
|
|||
direction: "direct",
|
||||
timestamp: ts,
|
||||
updatedAt: DateTime.tryParse(json["updated_at"] as String? ?? "") ?? ts,
|
||||
from: json["currency_from"] as String,
|
||||
fromAmount: json["amount_from"] as String,
|
||||
fromAddress: json["address_from"] as String,
|
||||
fromNetwork: "",
|
||||
fromExtraId: json["extra_id_from"] as String,
|
||||
fromTxid: json["tx_from"] as String,
|
||||
to: json["currency_to"] as String,
|
||||
toAmount: json["amount_to"] as String,
|
||||
toAddress: json["address_to"] as String,
|
||||
toNetwork: "",
|
||||
toExtraId: json["extra_id_to"] as String? ?? "",
|
||||
toTxid: json["tx_to"] as String,
|
||||
payInCurrency: json["currency_from"] as String,
|
||||
payInAmount: json["amount_from"] as String,
|
||||
payInAddress: json["address_from"] as String,
|
||||
payInNetwork: "",
|
||||
payInExtraId: json["extra_id_payIn"] as String,
|
||||
payInTxid: json["tx_from"] as String,
|
||||
payOutCurrency: json["currency_to"] as String,
|
||||
payOutAmount: json["amount_to"] as String,
|
||||
payOutAddress: json["address_to"] as String,
|
||||
payOutNetwork: "",
|
||||
payOutExtraId: json["extra_id_to"] as String? ?? "",
|
||||
payOutTxid: json["tx_to"] as String,
|
||||
refundAddress: json["user_refund_address"] as String,
|
||||
refundExtraId: json["user_refund_extra_id"] as String,
|
||||
status: json["status"] as String,
|
||||
|
|
|
@ -2,6 +2,8 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
|
||||
import 'package:stackwallet/hive/db.dart';
|
||||
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
|
||||
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
|
||||
import 'package:stackwallet/models/lelantus_coin.dart';
|
||||
import 'package:stackwallet/models/node_model.dart';
|
||||
import 'package:stackwallet/services/node_service.dart';
|
||||
|
@ -114,26 +116,52 @@ class DbVersionMigrator {
|
|||
// try to continue migrating
|
||||
return await migrate(1);
|
||||
|
||||
// case 1:
|
||||
// await Hive.openBox<dynamic>(DB.boxNameAllWalletsData);
|
||||
// final walletsService = WalletsService();
|
||||
// final walletInfoList = await walletsService.walletNames;
|
||||
// for (final walletInfo in walletInfoList.values) {
|
||||
// if (walletInfo.coin == Coin.firo) {
|
||||
// await Hive.openBox<dynamic>(walletInfo.walletId);
|
||||
// await DB.instance.delete<dynamic>(
|
||||
// key: "latest_tx_model", boxName: walletInfo.walletId);
|
||||
// await DB.instance.delete<dynamic>(
|
||||
// key: "latest_lelantus_tx_model", boxName: walletInfo.walletId);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // update version
|
||||
// await DB.instance.put<dynamic>(
|
||||
// boxName: DB.boxNameDBInfo, key: "hive_data_version", value: 2);
|
||||
//
|
||||
// // try to continue migrating
|
||||
// return await migrate(2);
|
||||
case 1:
|
||||
await Hive.openBox<dynamic>(DB.boxNameTrades);
|
||||
await Hive.openBox<dynamic>(DB.boxNameTradesV2);
|
||||
final trades =
|
||||
DB.instance.values<ExchangeTransaction>(boxName: DB.boxNameTrades);
|
||||
|
||||
for (final old in trades) {
|
||||
if (old.statusObject != null) {
|
||||
final trade = Trade(
|
||||
uuid: old.uuid,
|
||||
tradeId: old.id,
|
||||
rateType: "",
|
||||
direction: "direct",
|
||||
timestamp: old.date,
|
||||
updatedAt: DateTime.tryParse(old.statusObject?.updatedAt ?? "") ??
|
||||
old.date,
|
||||
payInCurrency: old.fromCurrency,
|
||||
payInAmount: old.statusObject!.expectedSendAmountDecimal,
|
||||
payInAddress: old.payinAddress,
|
||||
payInNetwork: "",
|
||||
payInExtraId: old.payinExtraId,
|
||||
payInTxid: "",
|
||||
payOutCurrency: old.toCurrency,
|
||||
payOutAmount: old.amount,
|
||||
payOutAddress: old.payoutAddress,
|
||||
payOutNetwork: "",
|
||||
payOutExtraId: old.payoutExtraId,
|
||||
payOutTxid: "",
|
||||
refundAddress: old.refundAddress,
|
||||
refundExtraId: old.refundExtraId,
|
||||
status: old.statusObject!.status.name,
|
||||
);
|
||||
await DB.instance.put<Trade>(
|
||||
boxName: DB.boxNameTradesV2,
|
||||
key: trade.uuid,
|
||||
value: trade,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// update version
|
||||
await DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNameDBInfo, key: "hive_data_version", value: 2);
|
||||
|
||||
// try to continue migrating
|
||||
return await migrate(2);
|
||||
|
||||
default:
|
||||
// finally return
|
||||
|
|
Loading…
Reference in a new issue