Skip to content
2 changes: 1 addition & 1 deletion crypto_plugins/flutter_libmwc
120 changes: 62 additions & 58 deletions lib/db/db_version_migration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,11 @@ class DbVersionMigrator with WalletDB {
final count = await MainDB.instance.isar.addresses.count();
// add change/receiving tags to address labels
for (var i = 0; i < count; i += 50) {
final addresses =
await MainDB.instance.isar.addresses
.where()
.offset(i)
.limit(50)
.findAll();
final addresses = await MainDB.instance.isar.addresses
.where()
.offset(i)
.limit(50)
.findAll();

final List<isar_models.AddressLabel> labels = [];
for (final address in addresses) {
Expand Down Expand Up @@ -203,14 +202,13 @@ class DbVersionMigrator with WalletDB {

// update/create label if tags is not empty
if (tags != null) {
isar_models.AddressLabel? label =
await MainDB.instance.isar.addressLabels
.where()
.addressStringWalletIdEqualTo(
address.value,
address.walletId,
)
.findFirst();
isar_models.AddressLabel? label = await MainDB
.instance
.isar
.addressLabels
.where()
.addressStringWalletIdEqualTo(address.value, address.walletId)
.findFirst();
if (label == null) {
label = isar_models.AddressLabel(
walletId: address.walletId,
Expand Down Expand Up @@ -268,13 +266,12 @@ class DbVersionMigrator with WalletDB {
Bitcoincash(CryptoCurrencyNetwork.main).identifier ||
info.coinIdentifier ==
Bitcoincash(CryptoCurrencyNetwork.test).identifier) {
final ids =
await MainDB.instance
.getAddresses(walletId)
.filter()
.typeEqualTo(isar_models.AddressType.p2sh)
.idProperty()
.findAll();
final ids = await MainDB.instance
.getAddresses(walletId)
.filter()
.typeEqualTo(isar_models.AddressType.p2sh)
.idProperty()
.findAll();

await MainDB.instance.isar.writeTxn(() async {
await MainDB.instance.isar.addresses.deleteAll(ids);
Expand Down Expand Up @@ -376,6 +373,20 @@ class DbVersionMigrator with WalletDB {
// try to continue migrating
return await migrate(15, secureStore: secureStore);

case 15:
// No-op: nodeApiSecret field added to NodeModel (Hive field 15).
// Existing nodes read null; updateDefaults() backfills from defaultNode.

// update version
await DB.instance.put<dynamic>(
boxName: DB.boxNameDBInfo,
key: "hive_data_version",
value: 16,
);

// try to continue migrating
return await migrate(16, secureStore: secureStore);

default:
// finally return
return;
Expand Down Expand Up @@ -421,17 +432,15 @@ class DbVersionMigrator with WalletDB {
walletId: walletId,
txid: tx.txid,
timestamp: tx.timestamp,
type:
isIncoming
? isar_models.TransactionType.incoming
: isar_models.TransactionType.outgoing,
type: isIncoming
? isar_models.TransactionType.incoming
: isar_models.TransactionType.outgoing,
subType: isar_models.TransactionSubType.none,
amount: tx.amount,
amountString:
Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: epic.fractionDigits,
).toJsonString(),
amountString: Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: epic.fractionDigits,
).toJsonString(),
fee: tx.fees,
height: tx.height,
isCancelled: tx.isCancelled,
Expand All @@ -453,14 +462,12 @@ class DbVersionMigrator with WalletDB {
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,
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));
}
Expand Down Expand Up @@ -518,28 +525,25 @@ class DbVersionMigrator with WalletDB {
final crypto = AppConfig.getCryptoCurrencyFor(info.coinIdentifier)!;

for (var i = 0; i < count; i += 50) {
final txns =
await MainDB.instance
.getTransactions(walletId)
.offset(i)
.limit(50)
.findAll();
final txns = await MainDB.instance
.getTransactions(walletId)
.offset(i)
.limit(50)
.findAll();

// migrate amount to serialized amount string
final txnsData =
txns
.map(
(tx) => Tuple2(
tx
..amountString =
Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: crypto.fractionDigits,
).toJsonString(),
tx.address.value,
),
)
.toList();
final txnsData = txns
.map(
(tx) => Tuple2(
tx
..amountString = Amount(
rawValue: BigInt.from(tx.amount),
fractionDigits: crypto.fractionDigits,
).toJsonString(),
tx.address.value,
),
)
.toList();

// update db records
await MainDB.instance.addNewTransactionData(txnsData, walletId);
Expand Down
6 changes: 6 additions & 0 deletions lib/models/node_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class NodeModel {
final bool forceNoTor;
// @HiveField(14)
final bool isPrimary;
// @HiveField(15)
final String? nodeApiSecret;

NodeModel({
required this.host,
Expand All @@ -64,6 +66,7 @@ class NodeModel {
this.forceNoTor = false,
this.loginName,
this.trusted,
this.nodeApiSecret,
});

NodeModel copyWith({
Expand All @@ -81,6 +84,7 @@ class NodeModel {
bool? forceNoTor,
bool? clearnetEnabled,
bool? isPrimary,
String? nodeApiSecret,
}) {
return NodeModel(
host: host ?? this.host,
Expand All @@ -98,6 +102,7 @@ class NodeModel {
clearnetEnabled: clearnetEnabled ?? this.clearnetEnabled,
forceNoTor: forceNoTor ?? this.forceNoTor,
isPrimary: isPrimary ?? this.isPrimary,
nodeApiSecret: nodeApiSecret ?? this.nodeApiSecret,
);
}

Expand All @@ -123,6 +128,7 @@ class NodeModel {
map['clearEnabled'] = clearnetEnabled;
map['forceNoTor'] = forceNoTor;
map['isPrimary'] = isPrimary;
map['nodeApiSecret'] = nodeApiSecret;
return map;
}

Expand Down
7 changes: 5 additions & 2 deletions lib/models/type_adaptors/node_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
}

class NodeFormData {
String? name, host, login, password;
String? name, host, login, password, apiSecret;
int? port;
bool? useSSL, isFailover, trusted, forceNoTor, isPrimary;
TorPlainNetworkOption? netOption;
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class Constants {
// Enable Logger.print statements
static const bool disableLogger = false;

static const int currentDataVersion = 15;
static const int currentDataVersion = 16;

static const int rescanV1 = 1;

Expand Down
10 changes: 4 additions & 6 deletions lib/utilities/test_mwcmqs_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ import '../services/tor_service.dart';
import 'logger.dart';
import 'prefs.dart';

Future<bool> _testMwcMqsNodeConnection(Uri uri) async {
Future<bool> _testMwcMqsNodeConnection(Uri uri, {String? apiSecret}) async {
final HTTP client = HTTP();
try {
final headers = {'Content-Type': 'application/json'};

if (uri.toString() == 'https://mwc713.mwc.mw/v1/version') {
const username = 'mwcmain';
const password = '11ne3EAUtOXVKwhxm84U';
final credentials = base64Encode(utf8.encode('$username:$password'));
if (apiSecret != null) {
final credentials = base64Encode(utf8.encode('mwcmain:$apiSecret'));
headers['Authorization'] = 'Basic $credentials';
}
final response = await client
Expand Down Expand Up @@ -80,7 +78,7 @@ Future<NodeFormData?> testMwcNodeConnection(NodeFormData data) async {
uri = uri.replace(port: data.port);

try {
if (await _testMwcMqsNodeConnection(uri)) {
if (await _testMwcMqsNodeConnection(uri, apiSecret: data.apiSecret)) {
return data;
} else {
return null;
Expand Down
1 change: 1 addition & 0 deletions lib/wallets/crypto_currency/coins/mimblewimblecoin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Mimblewimblecoin extends Bip39Currency {
torEnabled: true,
clearnetEnabled: true,
isPrimary: true,
nodeApiSecret: '11ne3EAUtOXVKwhxm84U',
);

default:
Expand Down
Loading
Loading