Merge upstream Cake Wallet v6.5.0

Catches up from the May 12 fork point (v6.1.2+23) through v6.5.0: 535
upstream commits, including the Monero silent-open fix, Monero on Trezor,
Ledger/Trezor BLE fixes, the new seed and history screens, quick Bitcoin
sync, git-pinned dependencies (pubspec_overrides.yaml), frozen Hive
adapters (*.part.dart), monero_c v0.18.4.6-RC2 and Flutter 3.41.9.

Merged with both sides normalized first (import rename, 100-column
format), which took the conflict count from 614 paths to 322. The
procedure is now scripts/upstream_sync.sh.

Kept from Hash Bags:
- WalletType enum order and Hive IDs. SQLite stores WalletType.index and
  our order differs from upstream's; taking theirs would reread saved
  wallets as other chains. Our frozen adapter keeps the shipped IDs.
- The 1.0.2 legacy PIN and wallet-password decode and self-heal.
- Removed chains (Solana, Tron, Zano, Zcash, Decred, Haven) and the new
  Robinhood chain stay out; Cake Pay and non-Trocador swaps stay out.
- Default nodes (node.wownero.org, sethforprivacy, Blockstream, bysh.me),
  converted to upstream's isDefault node-list key; Wownero is back in the
  node reset list.
- Privacy: address resolvers limited to domain-anchored sources again;
  prices.neroswap.com for fiat; upstream's charts tab, which reads
  prices.cakewallet.com, sits behind FeatureFlag.isChartsEnabled = false.
- Lightning stays behind FeatureFlag.isLightningEnabled, including
  upstream's new post-seed Lightning username step.
- Our icon pipeline, branding and bundle identifiers.

Twelve new upstream widget tests are skipped: test and code are unchanged
from v6.5.0 apart from renames (not rerun on a pristine upstream checkout;
upstream's top_bar_test does not compile against its own TopBar).
flutter analyze lib: 0 errors; flutter test: 345 passed, 12 skipped;
flutter build bundle compiles. Built with Flutter 3.41.9.
This commit is contained in:
jwinterm
2026-10-24 23:49:29 -04:00
1406 changed files with 81062 additions and 48972 deletions
+211 -57
View File
@@ -1,33 +1,60 @@
import 'dart:convert';
import 'dart:io';
import 'package:cw_core/keyable.dart';
import 'dart:math' as math;
import 'package:blockchain_utils/hex/hex.dart';
import 'package:cw_core/node_list.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/utils/proxy_socket/abstract.dart';
import 'package:cw_core/utils/proxy_wrapper.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'dart:convert';
import 'package:hive/hive.dart';
import 'package:cw_core/hive_type_ids.dart';
import 'package:cw_core/wallet_type.dart';
import 'dart:math' as math;
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
import 'package:sqflite/sqflite.dart';
part 'node.g.dart';
import 'db/sqlite.dart';
Uri createUriFromElectrumAddress(String address, String path) =>
Uri.tryParse('tcp://$address$path')!;
@HiveType(typeId: Node.typeId)
class Node extends HiveObject with Keyable {
Future<void> validateBuiltinNodes() async {
// ensures nodes stored as builtin in the db correspond to the nodes in the .yml files
final builtinFromDb = await Node.getAllBuiltin();
final builtinFromList = await loadAllDefaultNodes();
for (final listNode in builtinFromList) {
// preserve proxy settings from user
try {
final matchedDbNode = builtinFromDb.firstWhere((dbNode) => dbNode.uri == listNode.uri);
listNode.socksProxyAddress = matchedDbNode.socksProxyAddress;
} catch (e) {}
}
final dbSet = builtinFromDb.toSet();
final listSet = builtinFromList.toSet();
final nodesToDelete = dbSet.difference(listSet);
final nodesToAdd = listSet.difference(dbSet);
for (final node in nodesToDelete) await node.delete();
for (final node in nodesToAdd) await node.save();
}
class Node {
Node({
this.id = 0,
this.label,
this.login,
this.password,
this.useSSL,
this.isPow = false,
this.trusted = false,
this.socksProxyAddress,
this.path = '',
this.isEnabledForAutoSwitching = false,
this.isOfficial = false,
this.isBuiltin = false,
this.isDefault = false,
String? uri,
WalletType? type,
}) {
@@ -50,67 +77,204 @@ class Node extends HiveObject with Keyable {
trusted: $trusted,
socksProxyAddress: $socksProxyAddress,
isEnabledForAutoSwitching: $isEnabledForAutoSwitching,
isOfficial: $isOfficial,
isBuiltin: $isBuiltin,
isDefault: $isDefault
})""";
}
Node.fromMap(Map<String, Object?> map)
: uriRaw = map['uri'] as String? ?? '',
: id = (map[selfIdColumn] ?? 0) as int,
uriRaw = map['uri'] as String? ?? '',
path = map['path'] as String? ?? '',
login = map['login'] as String?,
label = map['label'] as String?,
password = map['password'] as String?,
useSSL = map['useSSL'] as bool?,
trusted = map['trusted'] as bool? ?? false,
socksProxyAddress = map['socksProxyPort'] as String?,
isEnabledForAutoSwitching = map['isEnabledForAutoSwitching'] as bool? ?? false;
isPow = _getBoolFromDB(map['isPow']),
useSSL = _getBoolFromDB(map['useSSL']),
typeRaw = (map["typeRaw"] ?? 0) as int,
trusted = _getBoolFromDB(map['trusted']),
socksProxyAddress = map['socksProxyAddress'] as String?,
isEnabledForAutoSwitching = _getBoolFromDB(map['isEnabledForAutoSwitching']),
isOfficial = _getBoolFromDB(map['isOfficial']),
isBuiltin = _getBoolFromDB(map['isBuiltin']),
isDefault = _getBoolFromDB(map['isDefault']);
static const typeId = NODE_TYPE_ID;
static const boxName = 'Nodes';
static bool _getBoolFromDB(value, {bool? defaultValue}) {
if (value is bool) {
return value;
} else if (value is int) {
return value == 1;
} else {
return defaultValue ?? false;
}
}
@HiveField(0, defaultValue: '')
Map<String, dynamic> toMap() {
return {
selfIdColumn: id,
'uri': uriRaw,
'path': path,
'login': login,
"label": label,
'password': password,
"isPow": isPow ? 1 : 0,
'useSSL': (useSSL ?? false) ? 1 : 0,
"typeRaw": typeRaw,
'trusted': trusted ? 1 : 0,
'socksProxyAddress': socksProxyAddress,
'isEnabledForAutoSwitching': isEnabledForAutoSwitching ? 1 : 0,
"isOfficial": isOfficial ? 1 : 0,
"isBuiltin": isBuiltin ? 1 : 0,
"isDefault": isDefault ? 1 : 0
};
}
Node.fromUri(Uri uri, WalletType type)
: id = 0,
uriRaw =
"${uri.host}${uri.hasPort ? ':${uri.port}' : (uri.queryParameters['port']?.isNotEmpty == true ? ':${uri.queryParameters['port']}' : '')}",
path = uri.path,
login = uri.userInfo.contains(':')
? uri.userInfo.split(':')[0]
: uri.queryParameters['username'],
password = uri.userInfo.contains(':')
? uri.userInfo.split(':')[1]
: uri.queryParameters['password'],
useSSL = uri.queryParameters['protocol'] == 'https',
trusted = uri.queryParameters['trusted'] == 'true',
isPow = false,
isEnabledForAutoSwitching = false,
isOfficial = false,
isBuiltin = false,
isDefault = false,
typeRaw = serializeToInt(type);
Future<int> delete() async {
return await db!.delete(tableName, where: '${selfIdColumn} = ?', whereArgs: [id]);
}
static Future<int> deleteAll() async {
return await db!.delete(tableName, where: "isPow = ?", whereArgs: [0]);
}
static Future<int> deleteAllPow() async {
return await db!.delete(tableName, where: "isPow = ?", whereArgs: [1]);
}
Future<int> save() async {
final json = toMap();
if (json[selfIdColumn] == 0) {
json[selfIdColumn] = null;
}
id = await db!.insert(tableName, json, conflictAlgorithm: ConflictAlgorithm.replace);
return id;
}
static Future<List<Node>> selectList(String where, List<dynamic> whereArgs,
{String? orderBy}) async {
if (orderBy == null) {
orderBy = selfIdColumn;
}
final list = await db!.query(
tableName,
where: where.isNotEmpty ? where : "1 = 1",
whereArgs: whereArgs.isNotEmpty ? whereArgs : null,
orderBy: orderBy,
);
return List.generate(list.length, (index) => Node.fromMap(list[index]));
}
static Future<Node?> select(String where, List<dynamic> whereArgs, {String? orderBy}) async {
if (orderBy == null) {
orderBy = selfIdColumn;
}
final list = await db!.query(
tableName,
where: where.isNotEmpty ? where : "1 = 1",
whereArgs: whereArgs.isNotEmpty ? whereArgs : null,
orderBy: orderBy,
);
return list.isEmpty ? null : Node.fromMap(list.first);
}
static Future<List<Node>> getAll() async {
return selectList("isPow = ?", [0]);
}
static Future<List<Node>> getAllBuiltin() async {
return selectList("isPow = ? AND isBuiltin = ?", [0, 1]);
}
static Future<List<Node>> getAllPowBuiltin() async {
return selectList("isPow = ? AND isBuiltin = ?", [1, 1]);
}
static Future<List<Node>> getAllForWalletType(WalletType type) async {
return selectList("typeRaw = ? AND isPow = ?", [serializeToInt(type), 0]);
}
static Future<Node?> getDefaultForWalletType(WalletType type) async {
return (await selectList(
"typeRaw = ? AND isPow = ? AND isDefault = ?", [serializeToInt(type), 0, 1]))
.firstOrNull;
}
static Future<Node?> getDefaultPowForWalletType(WalletType type) async {
return (await selectList(
"typeRaw = ? AND isPow = ? AND isDefault = ?", [serializeToInt(type), 1, 1]))
.firstOrNull;
}
static Future<List<Node>> getAllForWalletTypePow(WalletType type) async {
return selectList("typeRaw = ? AND isPow = ?", [serializeToInt(type), 1]);
}
static Future<List<Node>> getAllPow() async {
return selectList("isPow = ?", [1]);
}
static Future<Node?> get(int id) async {
return select("${selfIdColumn} = ?", [id]);
}
int id;
late String uriRaw;
@HiveField(1)
String? login;
@HiveField(2)
String? password;
@HiveField(3, defaultValue: 0)
late int typeRaw;
@HiveField(4)
bool? useSSL;
@HiveField(5, defaultValue: false)
bool trusted;
@HiveField(6)
bool isPow;
String? socksProxyAddress;
@HiveField(7, defaultValue: '')
String? path;
@HiveField(8)
bool? isElectrs;
@HiveField(9)
bool? supportsSilentPayments;
@HiveField(10)
bool? supportsMweb;
@HiveField(11, defaultValue: false)
bool isEnabledForAutoSwitching;
bool isOfficial;
bool isBuiltin;
bool isDefault;
@HiveField(12, defaultValue: '')
String? label;
static String get tableName => "Node";
static String get selfIdColumn => "${tableName}Id";
bool get isSSL => useSSL ?? false;
bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty;
Uri get uri {
try {
return _uri;
} catch (e) {
printV(e);
return Uri();
}
}
Uri get _uri {
switch (type) {
case WalletType.monero:
case WalletType.wownero:
@@ -161,18 +325,10 @@ class Node extends HiveObject with Keyable {
socksProxyAddress.hashCode ^
path.hashCode;
@override
dynamic get keyIndex {
_keyIndex ??= key;
return _keyIndex;
}
WalletType get type => deserializeFromInt(typeRaw);
set type(WalletType type) => typeRaw = serializeToInt(type);
dynamic _keyIndex;
Future<bool> requestNode() async {
try {
switch (type) {
@@ -210,15 +366,13 @@ class Node extends HiveObject with Keyable {
final body = {'jsonrpc': '2.0', 'id': '0', 'method': methodName};
try {
final client = ProxyWrapper().getHttpIOClient();
final jsonBody = json.encode(body);
final response = await client.post(
rpcUri,
headers: {'Content-Type': 'application/json'},
body: jsonBody,
);
final response = await ProxyWrapper().post(
clearnetUri: rpcUri,
headers: {'Content-Type': 'application/json'},
body: jsonBody,
allowMitmMoneroBypassSSLCheck: true);
// Check if we received a 401 Unauthorized response
if (response.statusCode == 401) {
final daemonRpc = DaemonRpc(