mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
Force SSL for Electrum and Monero nodes
Some Cleanup
This commit is contained in:
parent
ac1c198940
commit
0c1b7ce668
2 changed files with 31 additions and 40 deletions
|
@ -167,7 +167,11 @@ Future<void> defaultSettingsMigration(
|
|||
break;
|
||||
|
||||
case 18:
|
||||
await addOnionNode(nodes);
|
||||
await updateWalletTypeNodesWithNewNode(
|
||||
nodes: nodes,
|
||||
newNodeUri: "cakexmrl7bonq7ovjka5kuwuyd3f7qnkz6z6s6dmsy3uckwra7bvggyd.onion:18081",
|
||||
type: WalletType.monero,
|
||||
);
|
||||
break;
|
||||
|
||||
case 19:
|
||||
|
@ -261,15 +265,15 @@ Future<void> defaultSettingsMigration(
|
|||
await updateTronNodesWithNowNodes(sharedPreferences: sharedPreferences, nodes: nodes);
|
||||
break;
|
||||
case 42:
|
||||
updateBtcElectrumNodeToUseSSL(nodes, sharedPreferences);
|
||||
_fixNodesUseSSLFlag(nodes);
|
||||
break;
|
||||
case 43:
|
||||
await _updateCakeXmrNode(nodes);
|
||||
_fixNodesUseSSLFlag(nodes);
|
||||
_deselectExchangeProvider(sharedPreferences, "THORChain");
|
||||
_deselectExchangeProvider(sharedPreferences, "SimpleSwap");
|
||||
break;
|
||||
case 44:
|
||||
await _updateCakeXmrNode(nodes);
|
||||
_fixNodesUseSSLFlag(nodes);
|
||||
await _changeDefaultNode(
|
||||
nodes: nodes,
|
||||
sharedPreferences: sharedPreferences,
|
||||
|
@ -297,14 +301,12 @@ Future<void> defaultSettingsMigration(
|
|||
|
||||
updateWalletTypeNodesWithNewNode(
|
||||
newNodeUri: 'matic.nownodes.io',
|
||||
sharedPreferences: sharedPreferences,
|
||||
nodes: nodes,
|
||||
type: WalletType.polygon,
|
||||
useSSL: true,
|
||||
);
|
||||
updateWalletTypeNodesWithNewNode(
|
||||
newNodeUri: 'eth.nownodes.io',
|
||||
sharedPreferences: sharedPreferences,
|
||||
nodes: nodes,
|
||||
type: WalletType.ethereum,
|
||||
useSSL: true,
|
||||
|
@ -330,6 +332,22 @@ Future<void> defaultSettingsMigration(
|
|||
useSSL: true,
|
||||
oldUri: ['rpc.ankr.com'],
|
||||
);
|
||||
break;
|
||||
case 46:
|
||||
_fixNodesUseSSLFlag(nodes);
|
||||
updateWalletTypeNodesWithNewNode(
|
||||
newNodeUri: 'litecoin.stackwallet.com:20063',
|
||||
nodes: nodes,
|
||||
type: WalletType.litecoin,
|
||||
useSSL: true,
|
||||
);
|
||||
updateWalletTypeNodesWithNewNode(
|
||||
newNodeUri: 'electrum-ltc.bysh.me:50002',
|
||||
nodes: nodes,
|
||||
type: WalletType.litecoin,
|
||||
useSSL: true,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -361,7 +379,8 @@ Future<void> _changeDefaultNode({
|
|||
required String newDefaultUri,
|
||||
required String currentNodePreferenceKey,
|
||||
required bool useSSL,
|
||||
required List<String> oldUri, // leave empty if you want to force replace the node regardless of the user's current node
|
||||
required List<String>
|
||||
oldUri, // leave empty if you want to force replace the node regardless of the user's current node
|
||||
}) async {
|
||||
final currentNodeId = sharedPreferences.getInt(currentNodePreferenceKey);
|
||||
final currentNode = nodes.values.firstWhere((node) => node.key == currentNodeId);
|
||||
|
@ -389,11 +408,10 @@ Future<void> _changeDefaultNode({
|
|||
|
||||
/// Generic function for adding a new Node for a Wallet Type.
|
||||
Future<void> updateWalletTypeNodesWithNewNode({
|
||||
required SharedPreferences sharedPreferences,
|
||||
required Box<Node> nodes,
|
||||
required WalletType type,
|
||||
required String newNodeUri,
|
||||
required bool useSSL,
|
||||
bool? useSSL,
|
||||
}) async {
|
||||
// If it already exists in the box of nodes, no need to add it annymore.
|
||||
if (nodes.values.any((node) => node.uriRaw == newNodeUri)) return;
|
||||
|
@ -407,26 +425,6 @@ Future<void> updateWalletTypeNodesWithNewNode({
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> _updateCakeXmrNode(Box<Node> nodes) async {
|
||||
final node = nodes.values.firstWhereOrNull((element) => element.uriRaw == newCakeWalletMoneroUri);
|
||||
|
||||
if (node != null) {
|
||||
node.trusted = true;
|
||||
node.useSSL = true;
|
||||
await node.save();
|
||||
}
|
||||
}
|
||||
|
||||
void updateBtcElectrumNodeToUseSSL(Box<Node> nodes, SharedPreferences sharedPreferences) {
|
||||
final btcElectrumNode =
|
||||
nodes.values.firstWhereOrNull((element) => element.uriRaw == newCakeWalletBitcoinUri);
|
||||
|
||||
if (btcElectrumNode != null) {
|
||||
btcElectrumNode.useSSL = true;
|
||||
btcElectrumNode.save();
|
||||
}
|
||||
}
|
||||
|
||||
void _deselectExchangeProvider(SharedPreferences sharedPreferences, String providerName) {
|
||||
final Map<String, dynamic> exchangeProvidersSelection =
|
||||
json.decode(sharedPreferences.getString(PreferencesKey.exchangeProvidersSelection) ?? "{}")
|
||||
|
@ -445,8 +443,10 @@ void _fixNodesUseSSLFlag(Box<Node> nodes) {
|
|||
switch (node.uriRaw) {
|
||||
case cakeWalletLitecoinElectrumUri:
|
||||
case cakeWalletBitcoinElectrumUri:
|
||||
case newCakeWalletBitcoinUri:
|
||||
case newCakeWalletMoneroUri:
|
||||
node.useSSL = true;
|
||||
break;
|
||||
node.trusted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -580,15 +580,6 @@ Future<void> validateBitcoinSavedTransactionPriority(SharedPreferences sharedPre
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> addOnionNode(Box<Node> nodes) async {
|
||||
final onionNodeUri = "cakexmrl7bonq7ovjka5kuwuyd3f7qnkz6z6s6dmsy3uckwra7bvggyd.onion:18081";
|
||||
|
||||
// check if the user has this node before (added it manually)
|
||||
if (nodes.values.firstWhereOrNull((element) => element.uriRaw == onionNodeUri) == null) {
|
||||
await nodes.add(Node(uri: onionNodeUri, type: WalletType.monero));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> replaceNodesMigration({required Box<Node> nodes}) async {
|
||||
final replaceNodes = <String, Node>{
|
||||
'eu-node.cakewallet.io:18081':
|
||||
|
|
|
@ -215,7 +215,7 @@ Future<void> initializeAppConfigs() async {
|
|||
secureStorage: secureStorage,
|
||||
anonpayInvoiceInfo: anonpayInvoiceInfo,
|
||||
havenSeedStore: havenSeedStore,
|
||||
initialMigrationVersion: 45,
|
||||
initialMigrationVersion: 46,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue