|
1 | 1 | import 'package:bb_mobile/core/storage/sqlite_database.dart'; |
2 | 2 | import 'package:bb_mobile/core/storage/sqlite_database.steps.dart'; |
| 3 | +import 'package:bb_mobile/core/utils/constants.dart'; |
3 | 4 | import 'package:drift/drift.dart'; |
4 | 5 |
|
5 | 6 | class Schema10To11 { |
@@ -39,5 +40,58 @@ class Schema10To11 { |
39 | 40 | await db.managers.settings.update( |
40 | 41 | (f) => f(themeMode: const Value('system')), |
41 | 42 | ); |
| 43 | + |
| 44 | + final electrumServers = schema11.electrumServers; |
| 45 | + final fulcrumUrl = ApiServiceConstants.fulcrumElectrumUrl; |
| 46 | + final fulcrumUrlWithoutProtocol = fulcrumUrl.replaceAll('ssl://', ''); |
| 47 | + |
| 48 | + // Delete any existing custom entries for the fulcrum server |
| 49 | + await (m.database.delete(electrumServers)..where( |
| 50 | + (e) => |
| 51 | + electrumServers.url.equals(fulcrumUrl) | |
| 52 | + electrumServers.url.equals(fulcrumUrlWithoutProtocol), |
| 53 | + )) |
| 54 | + .go(); |
| 55 | + |
| 56 | + // Get all Bitcoin mainnet servers and update their priority |
| 57 | + final serversToUpdate = |
| 58 | + await (m.database.select(electrumServers)..where( |
| 59 | + (e) => |
| 60 | + electrumServers.isTestnet.equals(0) & |
| 61 | + electrumServers.isLiquid.equals(0), |
| 62 | + )) |
| 63 | + .get(); |
| 64 | + |
| 65 | + for (final server in serversToUpdate) { |
| 66 | + final url = server.read('url') as String; |
| 67 | + final isTestnet = server.read('is_testnet') as bool; |
| 68 | + final isLiquid = server.read('is_liquid') as bool; |
| 69 | + final priority = server.read('priority') as int; |
| 70 | + final isCustom = server.read('is_custom') as bool; |
| 71 | + |
| 72 | + await m.database |
| 73 | + .into(electrumServers) |
| 74 | + .insertOnConflictUpdate( |
| 75 | + RawValuesInsertable({ |
| 76 | + 'url': Constant(url), |
| 77 | + 'is_testnet': Constant(isTestnet), |
| 78 | + 'is_liquid': Constant(isLiquid), |
| 79 | + 'priority': Constant(priority + 1), |
| 80 | + 'is_custom': Constant(isCustom), |
| 81 | + }), |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + await m.database |
| 86 | + .into(electrumServers) |
| 87 | + .insert( |
| 88 | + RawValuesInsertable({ |
| 89 | + 'url': Constant(fulcrumUrl), |
| 90 | + 'is_testnet': const Constant(false), |
| 91 | + 'is_liquid': const Constant(false), |
| 92 | + 'priority': const Constant(0), |
| 93 | + 'is_custom': const Constant(false), |
| 94 | + }), |
| 95 | + ); |
42 | 96 | } |
43 | 97 | } |
0 commit comments