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