Skip to content

Commit dfc3194

Browse files
committed
Merge remote-tracking branch 'origin/dev' into add-lints
2 parents 990adc1 + 031a117 commit dfc3194

58 files changed

Lines changed: 1370 additions & 864 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr_test_build_linux.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ jobs:
179179
with:
180180
path: ${{ github.workspace }}/build/linux/x64/release/cakewallet_linux.zip
181181
name: cakewallet_linux
182-
- name: Verify lint
183-
run: |
184-
exec env ABORT_ON_CHANGE=true ./scripts/lint.sh
185182

186183
- name: Prepare virtual desktop
187184
if: ${{ contains(env.message, 'run tests') }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ RUN set -o xtrace \
5252
# for x86 emulators
5353
libatk-bridge2.0-0 libgdk-pixbuf-xlib-2.0-0 libgtk-3-0 libnspr4 libnss3-dev libsqlite3-dev libxtst6 libxss1 lftp sqlite3 xxd \
5454
# Linux desktop dependencies
55-
clang cmake libgtk-3-dev ninja-build pkg-config libsecret-1-0 libsecret-1-dev gir1.2-secret-1 \
55+
clang lld cmake libgtk-3-dev ninja-build pkg-config libsecret-1-0 libsecret-1-dev gir1.2-secret-1 \
5656
# monero_c dependencies
5757
autoconf automake build-essential ccache gperf libtool llvm \
5858
# extra stuff for KVM

cw_bitcoin/lib/bitcoin_wallet.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,16 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
345345
return balance;
346346
}
347347

348+
try {
348349
final lBalance = await lightningWallet!.getBalance();
349350

350351
this.balance[CryptoCurrency.btcln] = ElectrumBalance(
351352
confirmed: lBalance,
352353
unconfirmed: Money.zero(CryptoCurrency.btcln),
353354
frozen: Money.zero(CryptoCurrency.btcln));
355+
} catch (e) {
356+
printV("Error fetching lightning balance: $e");
357+
}
354358

355359
return ElectrumBalance(
356360
confirmed: balance.confirmed,

cw_bitcoin/lib/bitcoin_wallet_service.dart

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:cw_core/encryption_file_utils.dart';
88
import 'package:cw_core/payjoin_session.dart';
99
import 'package:cw_core/unspent_coins_info.dart';
1010
import 'package:cw_core/utils/zpub.dart';
11-
import 'package:cw_core/wallet_base.dart';
1211
import 'package:cw_core/wallet_service.dart';
1312
import 'package:cw_bitcoin/bitcoin_wallet.dart';
1413
import 'package:cw_core/pathForWallet.dart';
@@ -130,31 +129,6 @@ class BitcoinWalletService extends WalletService<
130129
}
131130
}
132131

133-
@override
134-
Future<void> rename(String currentName, String password, String newName) async {
135-
final currentWalletInfo = await WalletInfo.get(currentName, getType());
136-
if (currentWalletInfo == null) {
137-
throw Exception('Wallet not found');
138-
}
139-
final currentWallet = await BitcoinWalletBase.open(
140-
password: password,
141-
name: currentName,
142-
walletInfo: currentWalletInfo,
143-
unspentCoinsInfo: unspentCoinsInfoSource,
144-
payjoinBox: payjoinSessionSource,
145-
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
146-
);
147-
148-
await currentWallet.renameWalletFiles(newName);
149-
await saveBackup(newName);
150-
151-
final newWalletInfo = currentWalletInfo;
152-
newWalletInfo.id = WalletBase.idFor(newName, getType());
153-
newWalletInfo.name = newName;
154-
155-
await newWalletInfo.save();
156-
}
157-
158132
@override
159133
Future<BitcoinWallet> restoreFromHardwareWallet(BitcoinRestoreWalletFromHardware credentials,
160134
{bool? isTestnet}) async {

cw_bitcoin/lib/electrum_wallet.dart

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:async';
22
import 'dart:convert';
3-
import 'dart:io';
43
import 'dart:isolate';
54

65
import 'package:bitcoin_base/bitcoin_base.dart';
@@ -38,7 +37,6 @@ import 'package:cw_core/get_height_by_date.dart';
3837
import 'package:cw_core/hardware/hardware_wallet_service.dart';
3938
import 'package:cw_core/node.dart';
4039
import 'package:cw_core/output_info.dart';
41-
import 'package:cw_core/pathForWallet.dart';
4240
import 'package:cw_core/pending_transaction.dart';
4341
import 'package:cw_core/root_dir.dart';
4442
import 'package:cw_core/sync_status.dart';
@@ -1539,6 +1537,7 @@ abstract class ElectrumWalletBase
15391537
fee: estimatedTx.fee.amount,
15401538
network: network,
15411539
memo: estimatedTx.memo,
1540+
inputOrdering: BitcoinOrdering.shuffle,
15421541
outputOrdering: BitcoinOrdering.none,
15431542
enableRBF: !estimatedTx.spendsUnconfirmedTX,
15441543
);
@@ -1736,37 +1735,6 @@ abstract class ElectrumWalletBase
17361735
await transactionHistory.save();
17371736
}
17381737

1739-
@override
1740-
Future<void> renameWalletFiles(String newWalletName) async {
1741-
final currentWalletPath = await pathForWallet(name: walletInfo.name, type: type);
1742-
final currentWalletFile = File(currentWalletPath);
1743-
1744-
final currentDirPath = await pathForWalletDir(name: walletInfo.name, type: type);
1745-
final currentTransactionsFile = File('$currentDirPath/$transactionsHistoryFileName');
1746-
1747-
// Copies current wallet files into new wallet name's dir and files
1748-
if (currentWalletFile.existsSync()) {
1749-
final newWalletPath = await pathForWallet(name: newWalletName, type: type);
1750-
await currentWalletFile.copy(newWalletPath);
1751-
}
1752-
if (currentTransactionsFile.existsSync()) {
1753-
final newDirPath = await pathForWalletDir(name: newWalletName, type: type);
1754-
await currentTransactionsFile.copy('$newDirPath/$transactionsHistoryFileName');
1755-
}
1756-
1757-
// Delete old name's dir and files
1758-
final dir = Directory(currentDirPath);
1759-
for (var attempt = 0; attempt < 3; attempt++) {
1760-
try {
1761-
await dir.delete(recursive: true);
1762-
break;
1763-
} on FileSystemException {
1764-
if (attempt == 2) rethrow;
1765-
await Future<void>.delayed(const Duration(milliseconds: 200));
1766-
}
1767-
}
1768-
}
1769-
17701738
@override
17711739
Future<void> changePassword(String password) async {
17721740
_password = password;
@@ -2335,6 +2303,7 @@ abstract class ElectrumWalletBase
23352303
fee: BigInt.from(newFee),
23362304
network: network,
23372305
memo: memo,
2306+
inputOrdering: BitcoinOrdering.shuffle,
23382307
outputOrdering: BitcoinOrdering.none,
23392308
enableRBF: true,
23402309
);

cw_bitcoin/lib/litecoin_wallet.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,22 +497,25 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
497497
mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(boxName);
498498
}
499499

500-
@override
501-
Future<void> renameWalletFiles(String newWalletName) async {
502-
// rename the hive box:
503-
final oldBoxName = "${walletInfo.name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
504-
final newBoxName = "${newWalletName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
500+
static Future<void> copyMwebBox({
501+
required String fromName,
502+
required String toName,
503+
}) async {
504+
final oldBoxName = "${fromName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
505+
final newBoxName = "${toName.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
506+
if (oldBoxName == newBoxName) return;
505507

506508
final oldBox = await CakeHive.openBox<MwebUtxo>(oldBoxName);
507-
mwebUtxosBox = await CakeHive.openBox<MwebUtxo>(newBoxName);
509+
final newBox = await CakeHive.openBox<MwebUtxo>(newBoxName);
508510
for (final key in oldBox.keys) {
509-
final value = oldBox.get(key);
510-
await oldBox.delete(key);
511-
await mwebUtxosBox.put(key, value!);
511+
await newBox.put(key, oldBox.get(key)!);
512512
}
513-
oldBox.deleteFromDisk();
513+
}
514514

515-
await super.renameWalletFiles(newWalletName);
515+
static Future<void> deleteMwebBox(String name) async {
516+
final boxName = "${name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";
517+
final box = await CakeHive.openBox<MwebUtxo>(boxName);
518+
await box.deleteFromDisk();
516519
}
517520

518521
@action

cw_bitcoin/lib/litecoin_wallet_service.dart

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import 'package:cw_core/wallet_service.dart';
1212
import 'package:cw_core/pathForWallet.dart';
1313
import 'package:cw_core/wallet_type.dart';
1414
import 'package:cw_core/wallet_info.dart';
15-
import 'package:cw_core/wallet_base.dart';
16-
import 'package:collection/collection.dart';
1715
import 'package:bip39/bip39.dart' as bip39;
1816
import 'package:path_provider/path_provider.dart';
1917

@@ -139,26 +137,11 @@ class LitecoinWalletService extends WalletService<
139137

140138
@override
141139
Future<void> rename(String currentName, String password, String newName) async {
142-
final currentWalletInfo = await WalletInfo.get(currentName, getType());
143-
if (currentWalletInfo == null) {
144-
throw Exception('Wallet not found');
145-
}
146-
final currentWallet = await LitecoinWalletBase.open(
147-
password: password,
148-
name: currentName,
149-
walletInfo: currentWalletInfo,
150-
unspentCoinsInfo: unspentCoinsInfoSource,
151-
encryptionFileUtils: encryptionFileUtilsFor(isDirect),
152-
);
153-
154-
await currentWallet.renameWalletFiles(newName);
155-
await saveBackup(newName);
156-
157-
final newWalletInfo = currentWalletInfo;
158-
newWalletInfo.id = WalletBase.idFor(newName, getType());
159-
newWalletInfo.name = newName;
140+
if (currentName == newName) return;
160141

161-
await newWalletInfo.save();
142+
await LitecoinWalletBase.copyMwebBox(fromName: currentName, toName: newName);
143+
await super.rename(currentName, password, newName);
144+
await LitecoinWalletBase.deleteMwebBox(currentName);
162145
}
163146

164147
@override

cw_bitcoin_cash/lib/src/bitcoin_cash_wallet_service.dart

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import 'dart:io';
22

33
import 'package:bip39/bip39.dart';
4-
import 'package:collection/collection.dart';
54
import 'package:cw_bitcoin/bitcoin_mnemonics_bip39.dart';
65
import 'package:cw_bitcoin_cash/cw_bitcoin_cash.dart';
76
import 'package:cw_core/encryption_file_utils.dart';
87
import 'package:cw_core/pathForWallet.dart';
98
import 'package:cw_core/unspent_coins_info.dart';
10-
import 'package:cw_core/wallet_base.dart';
119
import 'package:cw_core/wallet_info.dart';
1210
import 'package:cw_core/wallet_service.dart';
1311
import 'package:cw_core/wallet_type.dart';
@@ -99,29 +97,6 @@ class BitcoinCashWalletService extends WalletService<
9997
}
10098
}
10199

102-
@override
103-
Future<void> rename(String currentName, String password, String newName) async {
104-
final currentWalletInfo = await WalletInfo.get(currentName, getType());
105-
if (currentWalletInfo == null) {
106-
throw Exception('Wallet not found');
107-
}
108-
final currentWallet = await BitcoinCashWalletBase.open(
109-
password: password,
110-
name: currentName,
111-
walletInfo: currentWalletInfo,
112-
unspentCoinsInfo: unspentCoinsInfoSource,
113-
encryptionFileUtils: encryptionFileUtilsFor(isDirect));
114-
115-
await currentWallet.renameWalletFiles(newName);
116-
await saveBackup(newName);
117-
118-
final newWalletInfo = currentWalletInfo;
119-
newWalletInfo.id = WalletBase.idFor(newName, getType());
120-
newWalletInfo.name = newName;
121-
122-
await newWalletInfo.save();
123-
}
124-
125100
@override
126101
Future<BitcoinCashWallet> restoreFromHardwareWallet(BitcoinCashNewWalletCredentials credentials) {
127102
throw UnimplementedError(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'dart:math';
2+
import 'package:cw_core/amount/money.dart';
3+
import 'package:cw_core/currency.dart';
4+
5+
extension ToMoney on double {
6+
/// Turn a double representation of a currency amount to a proper Money representation
7+
/// truncating currencies with more than 20 decimals because double can not handle more
8+
Money? tryToMoney(Currency currency) =>
9+
Money.tryParse(toStringAsFixed(min(currency.decimals, 20)), currency);
10+
11+
Money toMoney(Currency currency) =>
12+
Money.parse(toStringAsFixed(min(currency.decimals, 20)), currency);
13+
}

cw_core/lib/pathForWallet.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22
import 'package:cw_core/root_dir.dart';
33
import 'package:cw_core/wallet_type.dart';
4+
import 'package:path/path.dart' as p;
45

56
Future<String> pathForWalletTypeDir({required WalletType type}) async {
67
final root = await getAppDir();
@@ -36,3 +37,43 @@ Future<String> outdatedAndroidPathForWalletDir({required String name}) async {
3637

3738
return pathDir;
3839
}
40+
41+
Future<void> copyWalletFilesTo({
42+
required String fromName,
43+
required String toName,
44+
required WalletType type,
45+
}) async {
46+
if (fromName == toName) return;
47+
48+
final typeRoot = await pathForWalletTypeDir(type: type);
49+
final sourceDir = Directory(p.join(typeRoot, fromName));
50+
if (!sourceDir.existsSync()) {
51+
throw "Source wallet not found: $fromName $type";
52+
}
53+
54+
if (Directory(p.join(typeRoot, toName)).existsSync()) {
55+
throw Exception('Cannot rename wallet: "$toName" already exists');
56+
}
57+
58+
final destinationDir = Directory(p.join(typeRoot, toName));
59+
await _copyDirectory(sourceDir, destinationDir);
60+
61+
for (final suffix in const ['', '.keys', '.keys.backup']) {
62+
final file = File(p.join(destinationDir.path, '$fromName$suffix'));
63+
if (file.existsSync()) {
64+
await file.rename(p.join(destinationDir.path, '$toName$suffix'));
65+
}
66+
}
67+
}
68+
69+
Future<void> _copyDirectory(Directory source, Directory destination) async {
70+
await destination.create(recursive: true);
71+
await for (final entity in source.list(followLinks: false)) {
72+
final name = p.basename(entity.path);
73+
if (entity is File) {
74+
await entity.copy(p.join(destination.path, name));
75+
} else if (entity is Directory) {
76+
await _copyDirectory(entity, Directory(p.join(destination.path, name)));
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)